semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Test
    public void testStandardTee() throws Exception {
        final String reference = "test";
        final Reader source = new StringReader(reference);
        final StringWriter destination1 = new StringWriter();
        final StringWriter destination2 = new StringWriter();
        final TeeWriter tee = new TeeWriter(destination1, destination2);
        org.apache.commons.io.IOUtils.copy(source, tee);
        tee.close();
        assertEquals("the two string are equals", reference, destination1.toString());
        assertEquals("the two string are equals", reference, destination2.toString());
        assertEquals("byte count", reference.length(), tee.getSize());
    }
public boolean referredFilesChanged() throws MalformedURLException, IOException {
        for (String file : referredFiles) {
            if (FileUtils.isURI(file)) {
                URLConnection url = new URL(file).openConnection();
                if (url.getLastModified() > created) return true;
            } else if (FileUtils.isFile(file)) {
                File f = new File(file);
                if (f.lastModified() > created) return true;
            }
        }
        return false;
    }
private void doFinishLoadAttachment(long attachmentId) {
        if (attachmentId != mLoadAttachmentId) {
            return;
        }
        Attachment attachment = Attachment.restoreAttachmentWithId(MessageView.this, attachmentId);
        Uri attachmentUri = AttachmentProvider.getAttachmentUri(mAccountId, attachment.mId);
        Uri contentUri = AttachmentProvider.resolveAttachmentIdToContentUri(getContentResolver(), attachmentUri);
        if (mLoadAttachmentSave) {
            try {
                File file = createUniqueFile(Environment.getExternalStorageDirectory(), attachment.mFileName);
                InputStream in = getContentResolver().openInputStream(contentUri);
                OutputStream out = new FileOutputStream(file);
                IOUtils.copy(in, out);
                out.flush();
                out.close();
                in.close();
                Toast.makeText(MessageView.this, String.format(getString(R.string.message_view_status_attachment_saved), file.getName()), Toast.LENGTH_LONG).show();
                new MediaScannerNotifier(this, file, mHandler);
            } catch (IOException ioe) {
                Toast.makeText(MessageView.this, getString(R.string.message_view_status_attachment_not_saved), Toast.LENGTH_LONG).show();
            }
        } else {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(contentUri);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                mHandler.attachmentViewError();
            }
        }
    }
public void saveUserUpFile(UserInfo userInfo, String distFileName, InputStream instream) throws IOException {
        String fullPicFile = BBSCSUtil.getUserWebFilePath(userInfo.getId()) + distFileName;
        String fullPicFileSmall = BBSCSUtil.getUserWebFilePath(userInfo.getId()) + distFileName + Constant.IMG_SMALL_FILEPREFIX;
        OutputStream bos = new FileOutputStream(fullPicFile);
        IOUtils.copy(instream, bos);
        ImgUtil.reduceImg(fullPicFile, fullPicFileSmall, this.getSysConfig().getFaceWidth(), this.getSysConfig().getFaceHigh(), 0);
    }
public synchronized String encrypt(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(text.getBytes("UTF-8"));
        byte raw[] = md.digest();
        return (new BASE64Encoder()).encode(raw);
    }
public static int[] rank(double[] data) {
        int[] rank = new int[data.length];
        for (int i = 0; i < data.length; i++) rank[i] = i;
        boolean swapped;
        double dtmp;
        int i, j, itmp;
        for (i = 0; i < data.length - 1; i++) {
            swapped = false;
            for (j = 0; j < data.length - 1 - i; j++) {
                if (data[j] < data[j + 1]) {
                    dtmp = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = dtmp;
                    itmp = rank[j];
                    rank[j] = rank[j + 1];
                    rank[j + 1] = itmp;
                    swapped = true;
                }
            }
        }
        return rank;
    }
public static Dictionary parseVertices(URL url, Graph g) throws FileNotFoundException, FlightException {
        InputStream is = null;
        try {
            is = url.openStream();
        } catch (IOException e) {
            throw new FlightException("IO Error: cannot read from URL " + url.toString());
        }
        Reader reader = new BufferedReader(new InputStreamReader(is));
        return Parser.parseVertices(reader, g);
    }
public static void parseEdges(URL url, Graph g, Dictionary airportToVertex) throws FileNotFoundException, FlightException {
        InputStream is = null;
        try {
            is = url.openStream();
        } catch (IOException e) {
            throw new FlightException("IO Error: cannot read from URL " + url.toString());
        }
        Reader reader = new BufferedReader(new InputStreamReader(is));
        Parser.parseEdges(reader, g, airportToVertex);
    }
private FTPClient getFTPConnection(String strUser, String strPassword, String strServer, boolean binaryTransfer, String connectionNote) {
        FTPClient ftp = new FTPClient();
        try {
            int reply;
            ftp.connect(strServer);
            ResourcePool.LogMessage(this, ResourcePool.INFO_MESSAGE, "Connected to " + strServer + ", " + connectionNote);
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                ResourcePool.LogMessage(this, ResourcePool.ERROR_MESSAGE, "FTP server refused connection.");
                return null;
            }
        } catch (IOException e) {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException f) {
                    return null;
                }
            }
            ResourcePool.LogMessage(this, ResourcePool.ERROR_MESSAGE, "FTP Could not connect to server.");
            ResourcePool.LogException(e, this);
            return null;
        }
        try {
            if (!ftp.login(strUser, strPassword)) {
                ftp.logout();
                ResourcePool.LogMessage(this, ResourcePool.ERROR_MESSAGE, "FTP login failed.");
                return null;
            }
            ResourcePool.LogMessage(this, ResourcePool.INFO_MESSAGE, "Remote system is " + ftp.getSystemName() + ", " + connectionNote);
            if (binaryTransfer) {
                ftp.setFileType(FTP.BINARY_FILE_TYPE);
            } else {
                ftp.setFileType(FTP.ASCII_FILE_TYPE);
            }
            ftp.enterLocalPassiveMode();
        } catch (FTPConnectionClosedException e) {
            ResourcePool.LogMessage(this, ResourcePool.ERROR_MESSAGE, "Server closed connection.");
            ResourcePool.LogException(e, this);
            return null;
        } catch (IOException e) {
            ResourcePool.LogException(e, this);
            return null;
        }
        return ftp;
    }
public final int connectAndLogin(Uri u, boolean cwd) throws UnknownHostException, IOException, InterruptedException {
        if (ftp.isLoggedIn()) {
            if (cwd) {
                String path = u.getPath();
                if (path != null) ftp.setCurrentDir(path);
            }
            return WAS_IN;
        }
        int port = u.getPort();
        if (port == -1) port = 21;
        String host = u.getHost();
        if (ftp.connect(host, port)) {
            if (theUserPass == null || theUserPass.isNotSet()) theUserPass = new FTPCredentials(u.getUserInfo());
            if (ftp.login(theUserPass.getUserName(), theUserPass.getPassword())) {
                if (cwd) {
                    String path = u.getPath();
                    if (path != null) ftp.setCurrentDir(path);
                }
                return LOGGED_IN;
            } else {
                ftp.logout(true);
                ftp.disconnect();
                Log.w(TAG, "Invalid credentials.");
                return NO_LOGIN;
            }
        }
        return NO_CONNECT;
    }
private byte[] md5Digest(String pPassword) {
        if (pPassword == null) {
            throw new NullPointerException("input null text for hashing");
        }
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(pPassword.getBytes());
            return md.digest();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Cannot find MD5 algorithm");
        }
    }
public byte[] getClassBytes(String className, ClassLoader classLoader) {
        URLClassLoader cl = new URLClassLoader(urls, classLoader);
        String resource = className.replace('.', '/') + ".class";
        InputStream is = null;
        try {
            URL url = cl.getResource(resource);
            if (url == null) {
                throw new RuntimeException("Class Resource not found for " + resource);
            }
            is = url.openStream();
            byte[] classBytes = InputStreamTransform.readBytes(is);
            return classBytes;
        } catch (IOException e) {
            throw new RuntimeException("IOException reading bytes for " + className, e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException("Error closing InputStream for " + className, e);
                }
            }
        }
    }
public void copyContent(long mailId1, long mailId2) throws Exception {
        File file1 = new File(this.getMailDir(mailId1) + "/");
        File file2 = new File(this.getMailDir(mailId2) + "/");
        this.recursiveDir(file2);
        if (file1.isDirectory()) {
            File[] files = file1.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    if (files[i].isFile()) {
                        File file2s = new File(file2.getAbsolutePath() + "/" + files[i].getName());
                        if (!file2s.exists()) {
                            file2s.createNewFile();
                            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file2s));
                            BufferedInputStream in = new BufferedInputStream(new FileInputStream(files[i]));
                            int read;
                            while ((read = in.read()) != -1) {
                                out.write(read);
                            }
                            out.flush();
                            if (in != null) {
                                try {
                                    in.close();
                                } catch (IOException ex1) {
                                    ex1.printStackTrace();
                                }
                            }
                            if (out != null) {
                                try {
                                    out.close();
                                } catch (IOException ex) {
                                    ex.printStackTrace();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
public void copyRes(long mailId1, long mailId2) throws Exception {
        File file1 = new File(this.getResDir(mailId1));
        File file2 = new File(this.getResDir(mailId2));
        this.recursiveDir(file2);
        if (file1.isDirectory()) {
            File[] files = file1.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    if (files[i].isFile()) {
                        File file2s = new File(file2.getAbsolutePath() + "/" + files[i].getName());
                        if (!file2s.exists()) {
                            file2s.createNewFile();
                            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file2s));
                            BufferedInputStream in = new BufferedInputStream(new FileInputStream(files[i]));
                            int read;
                            while ((read = in.read()) != -1) {
                                out.write(read);
                            }
                            out.flush();
                            if (in != null) {
                                try {
                                    in.close();
                                } catch (IOException ex1) {
                                    ex1.printStackTrace();
                                }
                            }
                            if (out != null) {
                                try {
                                    out.close();
                                } catch (IOException ex) {
                                    ex.printStackTrace();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
public void copyAffix(MailAffix affix, long mailId1, long mailId2) throws Exception {
        File file = new File(this.getResDir(mailId1) + affix.getAttachAlias());
        if (file.exists()) {
            File file2 = new File(this.getResDir(mailId2) + affix.getAttachAlias());
            if (!file2.exists()) {
                file2.createNewFile();
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
                BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
                int read;
                while ((read = in.read()) != -1) {
                    out.write(read);
                }
                out.flush();
                in.close();
                out.close();
            }
        } else {
            log.debug(file.getAbsolutePath() + file.getName() + "�����ڣ������ļ�ʧ�ܣ���������");
        }
    }
public void generateListOfSubscriptions() {
        try {
            java.net.URL url = new java.net.URL(NewGenLibDesktopRoot.getInstance().getURLRoot() + "/NEWGEN_JR/ListOfSubscriptions.xml");
            System.out.println(NewGenLibDesktopRoot.getRoot() + "/NEWGEN_JR/ListOfSubscriptions.xml");
            net.sf.jasperreports.engine.design.JasperDesign jd = net.sf.jasperreports.engine.xml.JRXmlLoader.load(url.openStream());
            System.out.println("in generate Report 30" + dtm.getRowCount());
            net.sf.jasperreports.engine.JasperReport jr = net.sf.jasperreports.engine.JasperCompileManager.compileReport(jd);
            System.out.println("in generate Report 32" + dtm.getRowCount());
            java.util.Map param = new java.util.HashMap();
            param.put("ReportTitle", "List of subscriptions");
            Class.forName("org.postgresql.Driver");
            System.out.println("in generate Report 37" + dtm.getRowCount());
            net.sf.jasperreports.engine.JasperPrint jp = net.sf.jasperreports.engine.JasperFillManager.fillReport(jr, param, new net.sf.jasperreports.engine.data.JRTableModelDataSource(dtm));
            System.out.println("in generate Report 39" + dtm.getRowCount());
            java.sql.Timestamp currentTime = new java.sql.Timestamp(java.util.Calendar.getInstance().getTimeInMillis());
            if (jp.getPages().size() != 0) net.sf.jasperreports.view.JasperViewer.viewReport(jp, false); else javax.swing.JOptionPane.showMessageDialog(reports.DeskTopFrame.getInstance(), "There are no records in the selected report option.");
            System.out.println("in generate Report 43" + dtm.getRowCount());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
protected String md5sum(String toCompute) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(toCompute.getBytes());
        java.math.BigInteger hash = new java.math.BigInteger(1, md.digest());
        return hash.toString(16);
    }
@Test
    public void unacceptableMimeTypeTest() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://localhost:8080/alfresco/sword/deposit/company_home");
        File file = new File("/Library/Application Support/Apple/iChat Icons/Planets/Mars.gif");
        FileEntity entity = new FileEntity(file, "text/xml");
        entity.setChunked(true);
        httppost.setEntity(entity);
        Date date = new Date();
        Long time = date.getTime();
        httppost.addHeader("content-disposition", "filename=x" + time + "x.gif");
        System.out.println("Executing request...." + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        if (resEntity != null) {
            InputStream is = resEntity.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line = "";
            while ((line = br.readLine()) != null) {
                if (!line.isEmpty()) System.out.println(line);
            }
        }
        if (resEntity != null) {
            resEntity.consumeContent();
        }
        httpclient.getConnectionManager().shutdown();
    }
private void announce(String trackerURL, byte[] hash, byte[] peerId, int port) {
        try {
            String strUrl = trackerURL + "?info_hash=" + URLEncoder.encode(new String(hash, Constants.BYTE_ENCODING), Constants.BYTE_ENCODING).replaceAll("\\+", "%20") + "&peer_id=" + URLEncoder.encode(new String(peerId, Constants.BYTE_ENCODING), Constants.BYTE_ENCODING).replaceAll("\\+", "%20") + "&port=" + port + "&uploaded=0&downloaded=0&left=0&numwant=50&no_peer_id=1&compact=1";
            URL url = new URL(strUrl);
            URLConnection con = url.openConnection();
            con.connect();
            con.getContent();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static String getKeyWithRightLength(final String key, int keyLength) {
        if (keyLength > 0) {
            if (key.length() == keyLength) {
                return key;
            } else {
                MessageDigest md = null;
                try {
                    md = MessageDigest.getInstance("SHA-1");
                } catch (NoSuchAlgorithmException e) {
                    return "";
                }
                md.update(key.getBytes());
                byte[] hash = md.digest();
                if (keyLength > 20) {
                    byte nhash[] = new byte[keyLength];
                    for (int i = 0; i < keyLength; i++) {
                        nhash[i] = hash[i % 20];
                    }
                    hash = nhash;
                }
                return new String(hash).substring(0, keyLength);
            }
        } else {
            return key;
        }
    }
public static String toMD5(String seed) {
        MessageDigest md5 = null;
        StringBuffer temp_sb = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(seed.getBytes());
            byte[] array = md5.digest();
            temp_sb = new StringBuffer();
            for (int i = 0; i < array.length; i++) {
                int b = array[i] & 0xFF;
                if (b < 0x10) temp_sb.append('0');
                temp_sb.append(Integer.toHexString(b));
            }
        } catch (NoSuchAlgorithmException err) {
            err.printStackTrace();
        }
        return temp_sb.toString();
    }
public String execute(Map params, String body, RenderContext renderContext) throws MacroException {
        loadData();
        String from = (String) params.get("from");
        if (body.length() > 0 && from != null) {
            try {
                URL url;
                String serverUser = null;
                String serverPassword = null;
                url = new URL(semformsSettings.getZRapServerUrl() + "ZRAP_QueryProcessor.php?from=" + URLEncoder.encode(from, "utf-8") + "&query=" + URLEncoder.encode(body, "utf-8"));
                if (url.getUserInfo() != null) {
                    String[] userInfo = url.getUserInfo().split(":");
                    if (userInfo.length == 2) {
                        serverUser = userInfo[0];
                        serverPassword = userInfo[1];
                    }
                }
                URLConnection connection = null;
                InputStreamReader bf;
                if (serverUser != null && serverPassword != null) {
                    connection = url.openConnection();
                    String encoding = new sun.misc.BASE64Encoder().encode((serverUser + ":" + serverPassword).getBytes());
                    connection.setRequestProperty("Authorization", "Basic " + encoding);
                    bf = new InputStreamReader(connection.getInputStream());
                } else {
                    bf = new InputStreamReader(url.openStream());
                }
                BufferedReader bbf = new BufferedReader(bf);
                String line = bbf.readLine();
                String buffer = "";
                while (line != null) {
                    buffer += line;
                    line = bbf.readLine();
                }
                return buffer;
            } catch (Exception e) {
                e.printStackTrace();
                return "ERROR:" + e.getLocalizedMessage();
            }
        } else return "Please write an RDQL query in the macro as body and an url of the model as 'from' parameter";
    }
public void copy(String source, String target) throws IOException {
        @Cleanup FileChannel sourceChannel = new FileInputStream(new File(source)).getChannel();
        @Cleanup FileChannel targetChannel = new FileOutputStream(new File(target)).getChannel();
        targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
    }