semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static boolean copyFile(String fromfile, String tofile) {
        File from = new File(fromfile);
        File to = new File(tofile);
        if (!from.exists()) return false;
        if (to.exists()) {
            log.error(tofile + "exists already");
            return false;
        }
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        FileInputStream fis = null;
        FileOutputStream ois = null;
        boolean flag = true;
        try {
            to.createNewFile();
            fis = new FileInputStream(from);
            ois = new FileOutputStream(to);
            in = new BufferedInputStream(fis);
            out = new BufferedOutputStream(ois);
            byte[] buf = new byte[2048];
            int readBytes = 0;
            while ((readBytes = in.read(buf, 0, buf.length)) != -1) {
                out.write(buf, 0, readBytes);
            }
        } catch (IOException e) {
            log.error(e);
            flag = false;
        } finally {
            try {
                if (in != null) in.close();
                if (out != null) out.close();
            } catch (IOException e) {
                log.error(e);
                flag = false;
            }
        }
        return flag;
    }
private int getPage(StringBuffer ret) throws IOException {
        Properties sysProp;
        int ResponseCode = HttpURLConnection.HTTP_OK;
        BufferedReader br = null;
        try {
            URLConnection con = url.openConnection();
            con.setDefaultUseCaches(false);
            con.setDoInput(true);
            con.setDoOutput(false);
            if (con instanceof HttpURLConnection) {
                HttpURLConnection httpcon = (HttpURLConnection) con;
                ResponseCode = httpcon.getResponseCode();
                if (ResponseCode != httpcon.HTTP_OK) {
                    httpcon.disconnect();
                    return (ResponseCode);
                }
                br = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String line;
                int NumberOfLines = 0;
                while ((line = br.readLine()) != null) {
                    ret.append(line + "\n");
                    ++NumberOfLines;
                }
                httpcon.disconnect();
            } else {
                br = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    ret.append(line + "\n");
                }
            }
        } catch (IOException e) {
        } finally {
            if (br != null) br.close();
        }
        return ResponseCode;
    }
public static void copyURLToFile(URL source, File destination) throws IOException {
        if (destination.getParentFile() != null && !destination.getParentFile().exists()) {
            destination.getParentFile().mkdirs();
        }
        if (destination.exists() && !destination.canWrite()) {
            String message = "Unable to open file " + destination + " for writing.";
            throw new IOException(message);
        }
        InputStream input = source.openStream();
        try {
            FileOutputStream output = new FileOutputStream(destination);
            try {
                IOUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(output);
            }
        } finally {
            IOUtils.closeQuietly(input);
        }
    }
void bubbleSort(int[] a) {
        int i = 0;
        int j = a.length - 1;
        int aux = 0;
        int stop = 0;
        while (stop == 0) {
            stop = 1;
            i = 0;
            while (i < j) {
                if (a[i] > a[i + 1]) {
                    aux = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = aux;
                    stop = 0;
                }
                i = i + 1;
            }
            j = j - 1;
        }
    }
public static void getGPX(String gpxURL, String fName) {
        try {
            URL url = new URL(gpxURL);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod("GET");
            urlConnection.setDoOutput(true);
            urlConnection.connect();
            File storage = mContext.getExternalFilesDir(null);
            File file = new File(storage, fName);
            FileOutputStream os = new FileOutputStream(file);
            InputStream is = urlConnection.getInputStream();
            byte[] buffer = new byte[1024];
            int bufferLength = 0;
            while ((bufferLength = is.read(buffer)) > 0) {
                os.write(buffer, 0, bufferLength);
            }
            os.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static String login() throws Exception {
        if (sid == null) {
            String login = ROLAPClientAux.loadProperties().getProperty("user");
            String password = ROLAPClientAux.loadProperties().getProperty("password");
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(password.getBytes());
            String password2 = asHexString(md.digest());
            String query = "/server/login?user=" + login + "&extern_password=" + password + "&password=" + password2;
            Vector<String> res = ROLAPClientAux.sendRequest(query);
            String vals[] = res.get(0).split(";");
            sid = vals[0];
        }
        return sid;
    }
public static void fileCopy(File src, File dest) throws IOException {
        IOException xforward = null;
        FileInputStream fis = null;
        FileOutputStream fos = null;
        FileChannel fcin = null;
        FileChannel fcout = null;
        try {
            fis = new FileInputStream(src);
            fos = new FileOutputStream(dest);
            fcin = fis.getChannel();
            fcout = fos.getChannel();
            final int MB32 = 32 * 1024 * 1024;
            long size = fcin.size();
            long position = 0;
            while (position < size) {
                position += fcin.transferTo(position, MB32, fcout);
            }
        } catch (IOException xio) {
            xforward = xio;
        } finally {
            if (fis != null) try {
                fis.close();
                fis = null;
            } catch (IOException xio) {
            }
            if (fos != null) try {
                fos.close();
                fos = null;
            } catch (IOException xio) {
            }
            if (fcin != null && fcin.isOpen()) try {
                fcin.close();
                fcin = null;
            } catch (IOException xio) {
            }
            if (fcout != null && fcout.isOpen()) try {
                fcout.close();
                fcout = null;
            } catch (IOException xio) {
            }
        }
        if (xforward != null) {
            throw xforward;
        }
    }
private String createDefaultRepoConf() throws IOException {
        InputStream confIn = getClass().getResourceAsStream(REPO_CONF_PATH);
        File tempConfFile = File.createTempFile("repository", "xml");
        tempConfFile.deleteOnExit();
        IOUtils.copy(confIn, new FileOutputStream(tempConfFile));
        return tempConfFile.getAbsolutePath();
    }
public Set<Plugin<?>> loadPluginMetaData() throws PluginRegistryException {
        try {
            final Enumeration<URL> urls = JavaSystemHelper.getResources(pluginMetaInfPath);
            pluginsSet.clear();
            if (urls != null) {
                while (urls.hasMoreElements()) {
                    final URL url = urls.nextElement();
                    echoMessages.add(PluginMessageBundle.getMessage("plugin.info.visitor.resource.found", "interfaces", url.getPath()));
                    InputStream resourceInput = null;
                    Reader reader = null;
                    BufferedReader buffReader = null;
                    String line;
                    try {
                        resourceInput = url.openStream();
                        reader = new InputStreamReader(resourceInput);
                        buffReader = new BufferedReader(reader);
                        line = buffReader.readLine();
                        while (line != null) {
                            try {
                                if (!StringHelper.isEmpty(line)) {
                                    echoMessages.add(PluginMessageBundle.getMessage("plugin.info.visitor.resource.processing", "interface", line));
                                    pluginsSet.add(inspectPlugin(Class.forName(line.trim())));
                                }
                                line = buffReader.readLine();
                            } catch (final ClassNotFoundException cnfe) {
                                throw new PluginRegistryException("plugin.error.load.classnotfound", cnfe, pluginMetaInfPath, line);
                            }
                        }
                    } catch (final IOException ioe) {
                        throw new PluginRegistryException("plugin.error.load.ioe", ioe, url.getFile() + "\n" + url.toString(), ioe.getMessage());
                    } finally {
                        if (buffReader != null) {
                            buffReader.close();
                        }
                        if (reader != null) {
                            reader.close();
                        }
                        if (resourceInput != null) {
                            resourceInput.close();
                        }
                    }
                }
            }
            return Collections.unmodifiableSet(pluginsSet);
        } catch (final IOException ioe) {
            throw new PluginRegistryException("plugin.error.load.ioe", ioe, pluginMetaInfPath, ioe.getMessage());
        }
    }
public Set<Plugin<?>> loadPluginImplementationMetaData() throws PluginRegistryException {
        try {
            final Enumeration<URL> urls = JavaSystemHelper.getResources(pluginImplementationMetaInfPath);
            pluginImplsSet.clear();
            if (urls != null) {
                while (urls.hasMoreElements()) {
                    final URL url = urls.nextElement();
                    echoMessages.add(PluginMessageBundle.getMessage("plugin.info.visitor.resource.found", "classes", url.getPath()));
                    InputStream resourceInput = null;
                    Reader reader = null;
                    BufferedReader buffReader = null;
                    String line;
                    try {
                        resourceInput = url.openStream();
                        reader = new InputStreamReader(resourceInput);
                        buffReader = new BufferedReader(reader);
                        line = buffReader.readLine();
                        while (line != null) {
                            try {
                                pluginImplsSet.add(inspectPluginImpl(Class.forName(line.trim())));
                                echoMessages.add(PluginMessageBundle.getMessage("plugin.info.visitor.resource.processing", "class", line));
                                line = buffReader.readLine();
                            } catch (final ClassNotFoundException cnfe) {
                                throw new PluginRegistryException("plugin.error.load.classnotfound", cnfe, pluginImplementationMetaInfPath, line);
                            } catch (final LinkageError ncfe) {
                                if (LOGGER.isDebugEnabled()) {
                                    echoMessages.add(PluginMessageBundle.getMessage("plugin.info.visitor.resource.linkageError", "class", line, ncfe.getMessage()));
                                }
                                line = buffReader.readLine();
                            }
                        }
                    } catch (final IOException ioe) {
                        throw new PluginRegistryException("plugin.error.load.ioe", ioe, url.getFile(), ioe.getMessage());
                    } finally {
                        if (buffReader != null) {
                            buffReader.close();
                        }
                        if (reader != null) {
                            reader.close();
                        }
                        if (resourceInput != null) {
                            resourceInput.close();
                        }
                    }
                }
            }
            return Collections.unmodifiableSet(pluginImplsSet);
        } catch (final IOException ioe) {
            throw new PluginRegistryException("plugin.error.load.ioe", ioe, pluginImplementationMetaInfPath, ioe.getMessage());
        }
    }
public static String createMD5(String str) {
        String sig = null;
        String strSalt = str + StaticBox.getsSalt();
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(strSalt.getBytes(), 0, strSalt.length());
            byte byteData[] = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }
            sig = sb.toString();
        } catch (NoSuchAlgorithmException e) {
            System.err.println("Can not use md5 algorithm");
        }
        return sig;
    }
public static InputStream getConfigIs(String path, String name) throws ProgrammerException, DesignerException, UserException {
        InputStream is = null;
        try {
            URL url = getConfigResource(new MonadUri(path).append(name));
            if (url != null) {
                is = url.openStream();
            }
        } catch (IOException e) {
            throw new ProgrammerException(e);
        }
        return is;
    }
private String md5(String value) {
        String md5Value = "1";
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(value.getBytes());
            md5Value = getHex(digest.digest());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return md5Value;
    }
@Override
    public void run() {
        try {
            URL url = new URL(this.uri);
            String data = "tags=" + this.tags + "&mbox=" + this.mbox + "&_method=put";
            HttpURLConnection huc = (HttpURLConnection) url.openConnection();
            huc.setRequestMethod("POST");
            huc.setDoOutput(true);
            huc.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
            huc.setRequestProperty("Content-Length", "" + data.length());
            huc.getOutputStream().write(data.getBytes());
            huc.getOutputStream().flush();
            huc.connect();
            if (huc.getResponseCode() == 200) {
                System.out.println("Harvested: " + this.uri);
            } else if (huc.getResponseCode() > 200) {
                System.out.println("Not Harvested: " + this.uri + " error: " + huc.getResponseCode());
            }
            huc.disconnect();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (ProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private void process(String zipFileName, String directory, String db, boolean quiet) throws SQLException {
        ArrayList<String> list = FileLister.getDatabaseFiles(directory, db, true);
        if (list.size() == 0) {
            if (!quiet) {
                printNoDatabaseFilesFound(directory, db);
            }
            return;
        }
        zipFileName = FileUtils.normalize(zipFileName);
        if (FileUtils.exists(zipFileName)) {
            FileUtils.delete(zipFileName);
        }
        OutputStream fileOut = null;
        try {
            fileOut = FileUtils.openFileOutputStream(zipFileName, false);
            ZipOutputStream zipOut = new ZipOutputStream(fileOut);
            String base = "";
            for (String fileName : list) {
                if (fileName.endsWith(Constants.SUFFIX_PAGE_FILE)) {
                    base = FileUtils.getParent(fileName);
                    break;
                } else if (fileName.endsWith(Constants.SUFFIX_DATA_FILE)) {
                    base = FileUtils.getParent(fileName);
                    break;
                }
            }
            for (String fileName : list) {
                String f = FileUtils.getAbsolutePath(fileName);
                if (!f.startsWith(base)) {
                    Message.throwInternalError(f + " does not start with " + base);
                }
                if (FileUtils.isDirectory(fileName)) {
                    continue;
                }
                f = f.substring(base.length());
                f = BackupCommand.correctFileName(f);
                ZipEntry entry = new ZipEntry(f);
                zipOut.putNextEntry(entry);
                InputStream in = null;
                try {
                    in = FileUtils.openFileInputStream(fileName);
                    IOUtils.copyAndCloseInput(in, zipOut);
                } catch (FileNotFoundException e) {
                } finally {
                    IOUtils.closeSilently(in);
                }
                zipOut.closeEntry();
                if (!quiet) {
                    out.println("Processed: " + fileName);
                }
            }
            zipOut.closeEntry();
            zipOut.close();
        } catch (IOException e) {
            throw Message.convertIOException(e, zipFileName);
        } finally {
            IOUtils.closeSilently(fileOut);
        }
    }
public static void copy(File fromFile, File toFile) throws IOException {
        String fromFilename = fromFile.getPath();
        String toFileName = toFile.getPath();
        if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFilename);
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFilename);
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFilename);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) throw new IOException("FileCopy: " + "destination file is unwriteable: " + toFileName);
            if (AppState.isVerbose()) System.out.print("Overwrite existing file " + toFile.getName() + "? (Y/N): ");
            System.out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String response = in.readLine();
            if (!response.equals("Y") && !response.equals("y")) throw new IOException("FileCopy: " + "existing file was not overwritten.");
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
            if (dir.isFile()) throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
            if (!dir.canWrite()) throw new IOException("FileCopy: " + "destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
private static String retrieveVersion(InputStream is) throws RepositoryException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        try {
            IOUtils.copy(is, buffer);
        } catch (IOException e) {
            throw new RepositoryException(exceptionLocalizer.format("device-repository-file-missing", DeviceRepositoryConstants.VERSION_FILENAME), e);
        }
        return buffer.toString().trim();
    }
public static String encriptar(String string) throws Exception {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new Exception("Algoritmo de Criptografia não encontrado.");
        }
        md.update(string.getBytes());
        BigInteger hash = new BigInteger(1, md.digest());
        String retorno = hash.toString(16);
        return retorno;
    }
public static void copyFile(File in, File out, boolean copyModified) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            int maxCount = (64 * 1024 * 1024) - (32 * 1024);
            long size = inChannel.size();
            long position = 0;
            while (position < size) {
                position += inChannel.transferTo(position, maxCount, outChannel);
            }
            if (copyModified) out.setLastModified(in.lastModified());
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
private void copyResourceToDir(String ondexDir, String resource) {
        InputStream inputStream = OndexGraphImpl.class.getClassLoader().getResourceAsStream(resource);
        try {
            FileWriter fileWriter = new FileWriter(new File(ondexDir, resource));
            IOUtils.copy(inputStream, fileWriter);
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            logger.error("Unable to copy '" + resource + "' file to " + ondexDir + "'");
        }
    }
public String encripta(String senha) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(senha.getBytes());
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(digest.digest());
        } catch (NoSuchAlgorithmException ns) {
            ns.printStackTrace();
            return senha;
        }
    }
public static void main(String args[]) throws Exception {
        File file = new File("D:/work/love.txt");
        @SuppressWarnings("unused") ZipFile zipFile = new ZipFile("D:/work/test1.zip");
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("D:/work/test1.zip"));
        zos.setEncoding("GBK");
        ZipEntry entry = null;
        if (file.isDirectory()) {
            entry = new ZipEntry(getAbsFileName(source, file) + "/");
        } else {
            entry = new ZipEntry(getAbsFileName(source, file));
        }
        entry.setSize(file.length());
        entry.setTime(file.lastModified());
        zos.putNextEntry(entry);
        int readLen = 0;
        byte[] buf = new byte[2048];
        if (file.isFile()) {
            InputStream in = new BufferedInputStream(new FileInputStream(file));
            while ((readLen = in.read(buf, 0, 2048)) != -1) {
                zos.write(buf, 0, readLen);
            }
            in.close();
        }
        zos.close();
    }
public void save(File f, AudioFileFormat.Type t) throws IOException {
        if (t.getExtension().equals("raw")) {
            IOUtils.copy(makeInputStream(), new FileOutputStream(f));
        } else {
            AudioSystem.write(makeStream(), t, f);
        }
    }