semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void copy(String from_name, String to_name) throws IOException {
        File from_file = new File(from_name);
        File to_file = new File(to_name);
        if (!from_file.exists()) abort("FileCopy: no such source file: " + from_name);
        if (!from_file.isFile()) abort("FileCopy: can't copy directory: " + from_name);
        if (!from_file.canRead()) abort("FileCopy: source file is unreadable: " + from_name);
        if (to_file.isDirectory()) to_file = new File(to_file, from_file.getName());
        if (to_file.exists()) {
            if (!to_file.canWrite()) abort("FileCopy: destination file is unwriteable: " + to_name);
        } else {
            String parent = to_file.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) abort("FileCopy: destination directory doesn't exist: " + parent);
            if (dir.isFile()) abort("FileCopy: destination is not a directory: " + parent);
            if (!dir.canWrite()) abort("FileCopy: destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(from_file);
            to = new FileOutputStream(to_file);
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) {
                to.write(buffer, 0, bytes_read);
            }
        } finally {
            if (from != null) {
                try {
                    from.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (to != null) {
                try {
                    to.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public static byte[] encode(String cryptPassword, byte[] credentials, byte[] salt) {
        try {
            MessageDigest digester = MessageDigest.getInstance(DIGEST);
            SecureRandom random = SecureRandom.getInstance(RANDOM);
            digester.reset();
            for (int i = 0; i < ITERATIONS; i++) {
                digester.update(salt);
                digester.update(cryptPassword.getBytes("UTF-8"));
            }
            byte[] hash = digester.digest();
            random.setSeed(hash);
            int maxKeySize = Cipher.getMaxAllowedKeyLength(CIPHER);
            KeyGenerator generator = KeyGenerator.getInstance(CIPHER);
            generator.init(maxKeySize, random);
            SecretKey key = generator.generateKey();
            Cipher cipher = Cipher.getInstance(CIPHER);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            byte[] cipherOut = cipher.doFinal(credentials);
            byte[] ret = new byte[salt.length + cipherOut.length];
            System.arraycopy(salt, 0, ret, 0, salt.length);
            System.arraycopy(cipherOut, 0, ret, salt.length, cipherOut.length);
            return ret;
        } catch (Exception e) {
            StorePlugin.getDefault().log(e);
        }
        return new byte[0];
    }
public static byte[] decode(String cryptPassword, byte[] encoded, byte[] salt) {
        try {
            MessageDigest digester = MessageDigest.getInstance(DIGEST);
            SecureRandom random = SecureRandom.getInstance(RANDOM);
            digester.reset();
            for (int i = 0; i < ITERATIONS; i++) {
                digester.update(salt);
                digester.update(cryptPassword.getBytes("UTF-8"));
            }
            byte[] hash = digester.digest();
            random.setSeed(hash);
            int maxKeySize = Cipher.getMaxAllowedKeyLength(CIPHER);
            KeyGenerator generator = KeyGenerator.getInstance(CIPHER);
            generator.init(maxKeySize, random);
            SecretKey key = generator.generateKey();
            Cipher cipher = Cipher.getInstance(CIPHER);
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] decoded = cipher.doFinal(encoded);
            return decoded;
        } catch (Exception e) {
            StorePlugin.getDefault().log(e);
        }
        return new byte[0];
    }
private void loadExample(String resourceFile) {
        try {
            URL url = EditorContextMenu.class.getResource(resourceFile);
            if (this.isDirty()) {
                if (this.support.saveAs() == JOptionPane.CANCEL_OPTION) {
                    return;
                }
            }
            this.support.loadInputStream(url.openStream());
        } catch (IOException ex) {
            Logger.getLogger(EditorContextMenu.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
public static String md5(String input) {
        String res = "";
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(input.getBytes());
            byte[] md5 = algorithm.digest();
            String tmp = "";
            for (int i = 0; i < md5.length; i++) {
                tmp = (Integer.toHexString(0xFF & md5[i]));
                if (tmp.length() == 1) {
                    res += "0" + tmp;
                } else {
                    res += tmp;
                }
            }
        } catch (NoSuchAlgorithmException ex) {
            if (globali.jcVariabili.DEBUG) globali.jcFunzioni.erroreSQL(ex.toString());
        }
        return res;
    }
public static String md5(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(text.getBytes());
            return convertToHex(md.digest());
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
public static void copyFile(File from, File to) throws IOException {
        FileInputStream in = new FileInputStream(from);
        FileOutputStream out = new FileOutputStream(to);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
    }
public static void main(String args[]) {
        int i, j, l;
        short NUMNUMBERS = 256;
        short numbers[] = new short[NUMNUMBERS];
        Darjeeling.print("START");
        for (l = 0; l < 100; l++) {
            for (i = 0; i < NUMNUMBERS; i++) numbers[i] = (short) (NUMNUMBERS - 1 - i);
            for (i = 0; i < NUMNUMBERS; i++) {
                for (j = 0; j < NUMNUMBERS - i - 1; j++) if (numbers[j] > numbers[j + 1]) {
                    short temp = numbers[j];
                    numbers[j] = numbers[j + 1];
                    numbers[j + 1] = temp;
                }
            }
        }
        Darjeeling.print("END");
    }
protected void doDownload(S3Bucket bucket, S3Object s3object) throws Exception {
        String key = s3object.getKey();
        key = trimPrefix(key);
        String[] path = key.split("/");
        String fileName = path[path.length - 1];
        String dirPath = "";
        for (int i = 0; i < path.length - 1; i++) {
            dirPath += path[i] + "/";
        }
        File outputDir = new File(downloadFileOutputDir + "/" + dirPath);
        if (outputDir.exists() == false) {
            outputDir.mkdirs();
        }
        File outputFile = new File(outputDir, fileName);
        long size = s3object.getContentLength();
        if (outputFile.exists() && outputFile.length() == size) {
            return;
        }
        long startTime = System.currentTimeMillis();
        log.info("Download start.S3 file=" + s3object.getKey() + " local file=" + outputFile.getAbsolutePath());
        FileOutputStream fout = null;
        S3Object dataObject = null;
        try {
            fout = new FileOutputStream(outputFile);
            dataObject = s3.getObject(bucket, s3object.getKey());
            InputStream is = dataObject.getDataInputStream();
            IOUtils.copyStream(is, fout);
            downloadedFileList.add(key);
            long downloadTime = System.currentTimeMillis() - startTime;
            log.info("Download complete.Estimete time=" + downloadTime + "ms " + IOUtils.toBPSText(downloadTime, size));
        } catch (Exception e) {
            log.error("Download fail. s3 file=" + key, e);
            outputFile.delete();
            throw e;
        } finally {
            IOUtils.closeNoException(fout);
            if (dataObject != null) {
                dataObject.closeDataInputStream();
            }
        }
    }
public String encode(String plain) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plain.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0) i += 256;
                if (i < 16) buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
public void login(LoginData loginData) throws ConnectionEstablishException, AccessDeniedException {
        try {
            int reply;
            this.ftpClient.connect(loginData.getFtpServer());
            reply = this.ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                this.ftpClient.disconnect();
                throw (new ConnectionEstablishException("FTP server refused connection."));
            }
        } catch (IOException e) {
            if (this.ftpClient.isConnected()) {
                try {
                    this.ftpClient.disconnect();
                } catch (IOException f) {
                }
            }
            e.printStackTrace();
            throw (new ConnectionEstablishException("Could not connect to server.", e));
        }
        try {
            if (!this.ftpClient.login(loginData.getFtpBenutzer(), loginData.getFtpPasswort())) {
                this.logout();
                throw (new AccessDeniedException("Could not login into server."));
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
            throw (new AccessDeniedException("Could not login into server.", ioe));
        }
    }
private String hashSong(Song s) {
        if (s == null) return null;
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            digest.update(s.getTitle().getBytes());
            digest.update(s.getAllLyrics().getBytes());
            String hash = Base64.encodeBytes(digest.digest());
            return hash;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
public static void copy(File in, File out) throws Exception {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
public static String sendGetRequest(String endpoint, String requestParameters) {
        if (endpoint == null) return null;
        String result = null;
        if (endpoint.startsWith("http://")) {
            try {
                StringBuffer data = new StringBuffer();
                String urlStr = endpoint;
                if (requestParameters != null && requestParameters.length() > 0) {
                    urlStr += "?" + requestParameters;
                }
                URL url = new URL(urlStr);
                URLConnection conn = url.openConnection();
                BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                StringBuffer sb = new StringBuffer();
                String line;
                while ((line = rd.readLine()) != null) {
                    sb.append(line);
                }
                rd.close();
                result = sb.toString();
            } catch (Exception e) {
                Logger.getLogger(HTTPClient.class.getClass().getName()).log(Level.FINE, "Could not connect to URL, is the service online?");
            }
        }
        return result;
    }
public static String getMD5Str(String str) {
        MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.reset();
            messageDigest.update(str.getBytes("UTF-8"));
        } catch (NoSuchAlgorithmException e) {
            System.out.println("NoSuchAlgorithmException caught!");
            System.exit(-1);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        byte[] byteArray = messageDigest.digest();
        StringBuffer md5StrBuff = new StringBuffer();
        for (int i = 0; i < byteArray.length; i++) {
            if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i])); else md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
        }
        return md5StrBuff.substring(8, 24).toString().toUpperCase();
    }
public void dumpToFile(File file) throws IOException {
        OutputStream out = new FileOutputStream(file);
        if (contentStream != null) {
            IOUtils.copy(contentStream, out);
            setPath(file.getAbsolutePath());
        } else {
            IOUtils.write(getContent(), out);
        }
        IOUtils.closeQuietly(out);
    }
public OutputStream getAsOutputStream() throws IOException {
        OutputStream out;
        if (contentStream != null) {
            File tmp = File.createTempFile(getId(), null);
            out = new FileOutputStream(tmp);
            IOUtils.copy(contentStream, out);
        } else {
            out = new ByteArrayOutputStream();
            out.write(getContent());
        }
        return out;
    }
private static String computeSHA(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(input.getBytes("UTF-8"));
            byte[] code = md.digest();
            return convertToHex(code);
        } catch (NoSuchAlgorithmException e) {
            log.error("Algorithm SHA-1 not found!", e);
            e.printStackTrace();
            return null;
        } catch (UnsupportedEncodingException e) {
            log.error("Encoding problem: UTF-8 not supported!", e);
            e.printStackTrace();
            return null;
        }
    }
public static Model downloadModel(String url) {
        Model model = ModelFactory.createDefaultModel();
        try {
            URLConnection connection = new URL(url).openConnection();
            if (connection instanceof HttpURLConnection) {
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                httpConnection.setRequestProperty("Accept", "application/rdf+xml, */*;q=.1");
                httpConnection.setRequestProperty("Accept-Language", "en");
            }
            InputStream in = connection.getInputStream();
            model.read(in, url);
            in.close();
            return model;
        } catch (MalformedURLException e) {
            logger.debug("Unable to download model from " + url, e);
            throw new RuntimeException(e);
        } catch (IOException e) {
            logger.debug("Unable to download model from " + url, e);
            throw new RuntimeException(e);
        }
    }
public String parse() {
        try {
            URL url = new URL(mUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setDoOutput(true);
            connection.connect();
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            boolean flag1 = false;
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (!flag1 && line.contains("</center>")) flag1 = true;
                if (flag1 && line.contains("<br><center>")) break;
                if (flag1) {
                    mText.append(line);
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return mText.toString();
    }
public static String generate(String documentSelector) {
        if (documentSelector == null) {
            return null;
        }
        String date = Long.toString(System.currentTimeMillis());
        try {
            MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
            md.update(documentSelector.getBytes());
            md.update(date.getBytes());
            byte[] digest = md.digest();
            return toHexString(digest);
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
public static ResultSet execute(String commands) {
        ResultSet rs = null;
        BufferedReader reader = new BufferedReader(new StringReader(commands));
        String sqlCommand = null;
        Connection conn = ConnPool.getConnection();
        try {
            Statement stmt = conn.createStatement();
            while ((sqlCommand = reader.readLine()) != null) {
                sqlCommand = sqlCommand.toLowerCase().trim();
                if (sqlCommand.equals("") || sqlCommand.startsWith("#")) {
                    continue;
                }
                if (dmaLogger.isInfoEnabled(SqlExecutor.class)) {
                    dmaLogger.logInfo("Executing SQL: " + sqlCommand, SqlExecutor.class);
                }
                long currentTimeMillis = System.currentTimeMillis();
                if (sqlCommand.startsWith("select")) {
                    rs = stmt.executeQuery(sqlCommand);
                } else {
                    stmt.executeUpdate(sqlCommand);
                }
                dmaLogger.logInfo(DateUtil.getElapsedTime("SQL execution of " + sqlCommand + "  took: ", (System.currentTimeMillis() - currentTimeMillis)), SqlExecutor.class);
            }
            if (rs == null) {
                stmt.close();
            }
            return rs;
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (SQLException se) {
            }
            throw new RuntimeException("Execution of " + sqlCommand + " failed:" + e.getMessage(), e);
        } catch (IOException e) {
            try {
                conn.rollback();
            } catch (SQLException se) {
            }
            throw new RuntimeException("Execution of " + sqlCommand + " failed:", e);
        } finally {
            ConnPool.releaseConnection(conn);
        }
    }
private void initialize(Resource location) {
        if (_log.isDebugEnabled()) _log.debug("loading messages from location: " + location);
        String descriptorName = location.getName();
        int dotx = descriptorName.lastIndexOf('.');
        String baseName = descriptorName.substring(0, dotx);
        String suffix = descriptorName.substring(dotx + 1);
        LocalizedNameGenerator g = new LocalizedNameGenerator(baseName, _locale, "." + suffix);
        List urls = new ArrayList();
        while (g.more()) {
            String name = g.next();
            Resource l = location.getRelativeResource(name);
            URL url = l.getResourceURL();
            if (url != null) urls.add(url);
        }
        _properties = new XMLProperties();
        int count = urls.size();
        boolean loaded = false;
        for (int i = count - 1; i >= 0 && !loaded; i--) {
            URL url = (URL) urls.get(i);
            InputStream stream = null;
            try {
                stream = url.openStream();
                _properties.load(stream);
                loaded = true;
                if (_log.isDebugEnabled()) _log.debug("Messages loaded from URL: " + url);
            } catch (IOException ex) {
                if (_log.isDebugEnabled()) _log.debug("Unable to load messages from URL: " + url, ex);
            } finally {
                if (stream != null) try {
                    stream.close();
                } catch (IOException ioe) {
                }
            }
        }
        if (!loaded) {
            _log.error("Messages can not be loaded from location: " + location);
        }
    }
public URL rawGetURLfromWebID(String id) {
        try {
            System.out.println("Resolving id" + id);
            String resolve = "/webid/ResolverServlet?wpid=MeetingMachine&method=form&uri=" + id + "&href=_[text/url]";
            String resolver = "http://webid.hpl.hp.com:5190";
            URL url = new URL(resolve + resolver);
            URLConnection c = url.openConnection();
            c.setDoOutput(true);
            c.setDoInput(true);
            c.setUseCaches(false);
        } catch (Exception e) {
            if (PropertyEventHeap.debug) {
                PropertyEventHeap.log("rawGetURLfromWebID " + e);
            }
        }
        return null;
    }
public static String getResourceFromURL(URL url, String acceptHeader) throws java.io.IOException {
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setUseCaches(false);
        urlConnection.setRequestProperty("Accept", acceptHeader);
        urlConnection.setInstanceFollowRedirects(true);
        BufferedReader input = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
        String content = "";
        String line;
        while ((line = input.readLine()) != null) {
            content += line;
        }
        input.close();
        return content;
    }
public void run() {
        LOG.debug(this);
        String[] parts = createCmdArray(getCommand());
        Runtime runtime = Runtime.getRuntime();
        try {
            Process process = runtime.exec(parts);
            if (isBlocking()) {
                process.waitFor();
                StringWriter out = new StringWriter();
                IOUtils.copy(process.getInputStream(), out);
                String stdout = out.toString().replaceFirst("\\s+$", "");
                if (StringUtils.isNotBlank(stdout)) {
                    LOG.info("Process stdout:\n" + stdout);
                }
                StringWriter err = new StringWriter();
                IOUtils.copy(process.getErrorStream(), err);
                String stderr = err.toString().replaceFirst("\\s+$", "");
                if (StringUtils.isNotBlank(stderr)) {
                    LOG.error("Process stderr:\n" + stderr);
                }
            }
        } catch (IOException ioe) {
            LOG.error(String.format("Could not exec [%s]", getCommand()), ioe);
        } catch (InterruptedException ie) {
            LOG.error(String.format("Interrupted [%s]", getCommand()), ie);
        }
    }