semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public String downloadToSdCard(String localFileName, String suffixFromHeader, String extension) {
        InputStream in = null;
        FileOutputStream fos = null;
        String absolutePath = null;
        try {
            Log.i(TAG, "Opening URL: " + url);
            StreamAndHeader inAndHeader = HTTPUtils.openWithHeader(url, suffixFromHeader);
            if (inAndHeader == null || inAndHeader.mStream == null) {
                return null;
            }
            in = inAndHeader.mStream;
            String sdcardpath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
            String headerValue = suffixFromHeader == null || inAndHeader.mHeaderValue == null ? "" : inAndHeader.mHeaderValue;
            headerValue = headerValue.replaceAll("[-:]*\\s*", "");
            String filename = sdcardpath + "/" + localFileName + headerValue + (extension == null ? "" : extension);
            mSize = in.available();
            Log.i(TAG, "Downloading " + filename + ", size: " + mSize);
            fos = new FileOutputStream(new File(filename));
            int buffersize = 1024;
            byte[] buffer = new byte[buffersize];
            int readsize = buffersize;
            mCount = 0;
            while (readsize != -1) {
                readsize = in.read(buffer, 0, buffersize);
                if (readsize > 0) {
                    Log.i(TAG, "Read " + readsize + " bytes...");
                    fos.write(buffer, 0, readsize);
                    mCount += readsize;
                }
            }
            fos.flush();
            fos.close();
            FileInputStream controlIn = new FileInputStream(filename);
            mSavedSize = controlIn.available();
            Log.v(TAG, "saved size: " + mSavedSize);
            mAbsolutePath = filename;
            done();
        } catch (Exception e) {
            Log.e(TAG, "LoadingWorker.run", e);
        } finally {
            HTTPUtils.close(in);
        }
        return mAbsolutePath;
    }
public static String encrypt(String str) {
        if (str == null || str.length() == 0) {
            throw new IllegalArgumentException("String to encript cannot be null or zero length");
        }
        StringBuffer hexString = new StringBuffer();
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        md.update(str.getBytes());
        byte[] hash = md.digest();
        for (int i = 0; i < hash.length; i++) {
            if ((0xff & hash[i]) < 0x10) {
                hexString.append("0" + Integer.toHexString((0xFF & hash[i])));
            } else {
                hexString.append(Integer.toHexString(0xFF & hash[i]));
            }
        }
        return hexString.toString();
    }
public static void copyFile(File inputFile, File outputFile) throws IOException {
        FileChannel inChannel = null;
        FileChannel outChannel = null;
        try {
            inChannel = new FileInputStream(inputFile).getChannel();
            outChannel = new FileOutputStream(outputFile).getChannel();
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            try {
                if (inChannel != null) {
                    inChannel.close();
                }
                if (outChannel != null) {
                    outChannel.close();
                }
            } catch (IOException e) {
                throw e;
            }
        }
    }
public void gzip(File from, File to) {
        OutputStream out_zip = null;
        ArchiveOutputStream os = null;
        try {
            try {
                out_zip = new FileOutputStream(to);
                os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out_zip);
                os.putArchiveEntry(new ZipArchiveEntry(from.getName()));
                IOUtils.copy(new FileInputStream(from), os);
                os.closeArchiveEntry();
            } finally {
                if (os != null) {
                    os.close();
                }
            }
            out_zip.close();
        } catch (IOException ex) {
            fatal("IOException", ex);
        } catch (ArchiveException ex) {
            fatal("ArchiveException", ex);
        }
    }
public static void copieFichier(File fichier1, File fichier2) {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(fichier1).getChannel();
            out = new FileOutputStream(fichier2).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }
    }
public static boolean insereCapitulo(final Connection con, Capitulo cap, Autor aut, Descricao desc) {
        try {
            con.setAutoCommit(false);
            Statement smt = con.createStatement();
            if (aut.getCodAutor() == 0) {
                GeraID.gerarCodAutor(con, aut);
                smt.executeUpdate("INSERT INTO autor VALUES(" + aut.getCodAutor() + ",'" + aut.getNome() + "','" + aut.getEmail() + "')");
            }
            GeraID.gerarCodDescricao(con, desc);
            GeraID.gerarCodCapitulo(con, cap);
            String text = desc.getTexto().replaceAll("[']", "\"");
            String titulo = cap.getTitulo().replaceAll("['\"]", "");
            String coment = cap.getComentario().replaceAll("[']", "\"");
            smt.executeUpdate("INSERT INTO descricao VALUES(" + desc.getCodDesc() + ",'" + text + "')");
            smt.executeUpdate("INSERT INTO capitulo VALUES(" + cap.getCodigo() + ",'" + titulo + "','" + coment + "'," + desc.getCodDesc() + ")");
            smt.executeUpdate("INSERT INTO cap_aut VALUES(" + cap.getCodigo() + "," + aut.getCodAutor() + ")");
            con.commit();
            return (true);
        } catch (SQLException e) {
            try {
                JOptionPane.showMessageDialog(null, "Rolling back transaction", "CAPITULO: Database error", JOptionPane.ERROR_MESSAGE);
                con.rollback();
            } catch (SQLException e1) {
                System.err.print(e1.getSQLState());
            }
            return (false);
        } finally {
            try {
                con.setAutoCommit(true);
            } catch (SQLException e2) {
                System.err.print(e2.getSQLState());
            }
        }
    }
public static boolean insereLicao(final Connection con, Licao lic, Autor aut, Descricao desc) {
        try {
            con.setAutoCommit(false);
            Statement smt = con.createStatement();
            if (aut.getCodAutor() == 0) {
                GeraID.gerarCodAutor(con, aut);
                smt.executeUpdate("INSERT INTO autor VALUES(" + aut.getCodAutor() + ",'" + aut.getNome() + "','" + aut.getEmail() + "')");
            }
            GeraID.gerarCodDescricao(con, desc);
            GeraID.gerarCodLicao(con, lic);
            String titulo = lic.getTitulo().replaceAll("['\"]", "");
            String coment = lic.getComentario().replaceAll("[']", "\"");
            String texto = desc.getTexto().replaceAll("[']", "\"");
            smt.executeUpdate("INSERT INTO descricao VALUES(" + desc.getCodDesc() + ",'" + texto + "')");
            smt.executeUpdate("INSERT INTO licao VALUES(" + lic.getCodigo() + ",'" + titulo + "','" + coment + "'," + desc.getCodDesc() + ")");
            smt.executeUpdate("INSERT INTO lic_aut VALUES(" + lic.getCodigo() + "," + aut.getCodAutor() + ")");
            con.commit();
            return (true);
        } catch (SQLException e) {
            try {
                JOptionPane.showMessageDialog(null, "Rolling back transaction", "LICAO: Database error", JOptionPane.ERROR_MESSAGE);
                con.rollback();
            } catch (SQLException e1) {
                System.err.print(e1.getSQLState());
            }
            return (false);
        } finally {
            try {
                con.setAutoCommit(true);
            } catch (SQLException e2) {
                System.err.print(e2.getSQLState());
            }
        }
    }
public static boolean insereMidia(final Connection con, Midia mid, Autor aut, Descricao desc) {
        try {
            con.setAutoCommit(false);
            Statement smt = con.createStatement();
            if (aut.getCodAutor() == 0) {
                GeraID.gerarCodAutor(con, aut);
                smt.executeUpdate("INSERT INTO autor VALUES(" + aut.getCodAutor() + ",'" + aut.getNome() + "','" + aut.getEmail() + "')");
            }
            GeraID.gerarCodMidia(con, mid);
            GeraID.gerarCodDescricao(con, desc);
            String titulo = mid.getTitulo().replaceAll("['\"]", "");
            String coment = mid.getComentario().replaceAll("[']", "\"");
            String texto = desc.getTexto().replaceAll("[']", "\"");
            smt.executeUpdate("INSERT INTO descricao VALUES(" + desc.getCodDesc() + ",'" + texto + "')");
            smt.executeUpdate("INSERT INTO midia VALUES(" + mid.getCodigo() + ", '" + titulo + "', '" + coment + "','" + mid.getUrl() + "', '" + mid.getTipo() + "', " + desc.getCodDesc() + ")");
            smt.executeUpdate("INSERT INTO mid_aut VALUES(" + mid.getCodigo() + "," + aut.getCodAutor() + ")");
            con.commit();
            return (true);
        } catch (SQLException e) {
            try {
                JOptionPane.showMessageDialog(null, "Rolling back transaction", "MIDIA: Database error", JOptionPane.ERROR_MESSAGE);
                System.err.print(e.getMessage());
                con.rollback();
            } catch (SQLException e1) {
                System.err.print(e1.getSQLState());
            }
            return (false);
        } finally {
            try {
                con.setAutoCommit(true);
            } catch (SQLException e2) {
                System.err.print(e2.getMessage());
            }
        }
    }
private static boolean insereTutorial(final Connection con, final Tutorial tut, final Autor aut, final Descricao desc) {
        try {
            con.setAutoCommit(false);
            Statement smt = con.createStatement();
            if (aut.getCodAutor() == 0) {
                GeraID.gerarCodAutor(con, aut);
                smt.executeUpdate("INSERT INTO autor VALUES(" + aut.getCodAutor() + ",'" + aut.getNome() + "','" + aut.getEmail() + "')");
            }
            GeraID.gerarCodDescricao(con, desc);
            GeraID.gerarCodTutorial(con, tut);
            String titulo = tut.getTitulo().replaceAll("['\"]", "");
            String coment = tut.getComentario().replaceAll("[']", "\"");
            String texto = desc.getTexto().replaceAll("[']", "\"");
            smt.executeUpdate("INSERT INTO descricao VALUES(" + desc.getCodDesc() + ",'" + texto + "')");
            smt.executeUpdate("INSERT INTO tutorial VALUES(" + tut.getCodigo() + ",'" + titulo + "','" + coment + "'," + desc.getCodDesc() + ")");
            smt.executeUpdate("INSERT INTO tut_aut VALUES(" + tut.getCodigo() + "," + aut.getCodAutor() + ")");
            con.commit();
            return (true);
        } catch (SQLException e) {
            try {
                JOptionPane.showMessageDialog(null, "Rolling back transaction", "TUTORIAL: Database error", JOptionPane.ERROR_MESSAGE);
                System.out.print(e.getMessage());
                con.rollback();
            } catch (SQLException e1) {
                System.err.print(e1.getSQLState());
            }
            return (false);
        } finally {
            try {
                con.setAutoCommit(true);
            } catch (SQLException e2) {
                System.err.print(e2.getSQLState());
            }
        }
    }
public void updateChecksum() {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            List<Parameter> sortedKeys = new ArrayList<Parameter>(parameter_instances.keySet());
            for (Parameter p : sortedKeys) {
                if (parameter_instances.get(p) != null && !(parameter_instances.get(p) instanceof OptionalDomain.OPTIONS) && !(parameter_instances.get(p).equals(FlagDomain.FLAGS.OFF))) {
                    md.update(parameter_instances.get(p).toString().getBytes());
                }
            }
            this.checksum = md.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
public static String toMD5String(String plainText) {
        if (TextUtils.isEmpty(plainText)) {
            plainText = "";
        }
        StringBuilder text = new StringBuilder();
        for (int i = plainText.length() - 1; i >= 0; i--) {
            text.append(plainText.charAt(i));
        }
        plainText = text.toString();
        MessageDigest mDigest;
        try {
            mDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            return plainText;
        }
        mDigest.update(plainText.getBytes());
        byte d[] = mDigest.digest();
        StringBuffer hash = new StringBuffer();
        for (int i = 0; i < d.length; i++) {
            hash.append(Integer.toHexString(0xFF & d[i]));
        }
        return hash.toString();
    }
public static String encrypt(String plainText) {
        if (TextUtils.isEmpty(plainText)) {
            plainText = "";
        }
        StringBuilder text = new StringBuilder();
        for (int i = plainText.length() - 1; i >= 0; i--) {
            text.append(plainText.charAt(i));
        }
        plainText = text.toString();
        MessageDigest mDigest;
        try {
            mDigest = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            return plainText;
        }
        mDigest.update(plainText.getBytes());
        byte d[] = mDigest.digest();
        StringBuffer hash = new StringBuffer();
        for (int i = 0; i < d.length; i++) {
            hash.append(Integer.toHexString(0xFF & d[i]));
        }
        return hash.toString();
    }
public static TopicMap getTopicMap(URL url) {
        String baseURI = url.toString();
        InputStream inputStream = null;
        try {
            inputStream = url.openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return getTopicMap(inputStream, baseURI);
    }
private static void copyFile(File sourceFile, File destFile) throws IOException {
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }
public void readDirectoryFrom(String urlString) throws Exception {
        URL url = new URL(urlString + DIR_INFO_FIENAME);
        PushbackInputStream in = new PushbackInputStream(new BufferedInputStream(url.openStream()));
        readDataFrom(in);
        TextToken t = TextToken.nextToken(in);
        while (t != null && t.isString()) {
            DirectoryInfoModel dir = addDirectory(new DirectoryInfo(t.getString()));
            dir.setUrl(urlString + t.getString() + '/');
            t = TextToken.nextToken(in);
        }
        in.close();
    }
public static HttpResponse query(DefaultHttpClient httpclient, Request request, Proxy proxy, Log log) throws ClientProtocolException, IOException, MojoExecutionException {
        log.debug("preparing " + request);
        if (proxy != null) {
            log.info("setting up " + proxy + " for request " + request);
            proxy.prepare(httpclient);
        }
        HttpRequestBase httpRequest = request.buildHttpRequestBase(httpclient, log);
        HttpHost targetHost = request.buildHttpHost(log);
        log.debug("HTTP " + request.getMethod() + " url=" + request.getFinalUrl());
        long responseTime = System.currentTimeMillis();
        HttpResponse response = httpclient.execute(targetHost, httpRequest);
        log.debug("received response (time=" + (System.currentTimeMillis() - responseTime) + "ms) for request [" + "HTTP " + request.getMethod() + " url=" + request.getFinalUrl() + "]");
        return response;
    }
protected File getFile() throws IOException {
        File home = new File(System.getProperty("user.dir"));
        String fileName = String.format("%s.txt", getFilePrefix());
        File file = new File(home, fileName);
        if (file.exists()) {
            return file;
        } else {
            URL url = LocalNameGenerator.class.getResource("/" + fileName);
            if (url == null) {
                throw new IllegalStateException(String.format("Cannot find resource at %s", fileName));
            } else {
                InputStream in = url.openStream();
                try {
                    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
                    try {
                        IOUtils.copy(in, out);
                    } finally {
                        out.close();
                    }
                } finally {
                    in.close();
                }
                return file;
            }
        }
    }
public static void copyFile(File src, File dst) throws IOException {
        FileChannel inChannel = new FileInputStream(src).getChannel();
        FileChannel outChannel = new FileOutputStream(dst).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } finally {
            if (inChannel != null) {
                inChannel.close();
            }
            if (outChannel != null) {
                outChannel.close();
            }
        }
    }
@Override
    public Response executeGet(String url) throws IOException {
        if (logger.isLoggable(INFO)) logger.info("Making a GET request to " + url);
        HttpURLConnection httpUrlConnection = null;
        InputStream inputStream = null;
        try {
            httpUrlConnection = openConnection(new URL(url));
            httpUrlConnection.setReadTimeout(DEFAULT_READ_TIMEOUT_IN_MS);
            httpUrlConnection.setUseCaches(false);
            customizeConnection(httpUrlConnection);
            httpUrlConnection.setRequestMethod("GET");
            httpUrlConnection.connect();
            if (logger.isLoggable(FINER)) logger.finer("Response headers: " + httpUrlConnection.getHeaderFields());
            try {
                inputStream = httpUrlConnection.getResponseCode() != HTTP_OK ? httpUrlConnection.getErrorStream() : httpUrlConnection.getInputStream();
            } catch (IOException e) {
                if (logger.isLoggable(WARNING)) logger.warning("An error occurred while making a GET request to " + url + ": " + e);
            }
            return new Response(httpUrlConnection.getResponseCode(), fromInputStream(inputStream));
        } finally {
            closeQuietly(httpUrlConnection);
        }
    }
public static void copyFile(File from, File to) throws FileNotFoundException, IOException {
        requireFile(from);
        requireFile(to);
        if (to.isDirectory()) {
            to = new File(to, getFileName(from));
        }
        FileChannel sourceChannel = new FileInputStream(from).getChannel();
        FileChannel destinationChannel = new FileOutputStream(to).getChannel();
        destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        sourceChannel.close();
        destinationChannel.close();
    }
private String hashPassword(String password) throws NoSuchAlgorithmException {
        String hash = null;
        MessageDigest md = MessageDigest.getInstance("SHA");
        log.debug("secure hash on password " + password);
        md.update(password.getBytes());
        hash = new String(Base64.encodeBase64(md.digest()));
        log.debug("returning hash " + hash);
        return hash;
    }
public void doImport(File f, boolean checkHosp) throws Exception {
        connector.getConnection().setAutoCommit(false);
        File base = f.getParentFile();
        ZipInputStream in = new ZipInputStream(new FileInputStream(f));
        ZipEntry entry;
        while ((entry = in.getNextEntry()) != null) {
            String outFileName = entry.getName();
            File outFile = new File(base, outFileName);
            OutputStream out = new FileOutputStream(outFile, false);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            out.close();
        }
        in.close();
        importDirectory(base, checkHosp);
        connector.getConnection().commit();
    }
private File newFile(File oldFile) throws IOException {
        int counter = 0;
        File nFile = new File(this.stateDirProvider.get() + File.separator + oldFile.getName());
        while (nFile.exists()) {
            nFile = new File(this.stateDirProvider.get() + File.separator + oldFile.getName() + "_" + counter);
        }
        IOUtils.copyFile(oldFile, nFile);
        return nFile;
    }
public static String encryptPassword(String password) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            LOG.error(e);
        }
        try {
            md.update(password.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            LOG.error(e);
        }
        return (new BASE64Encoder()).encode(md.digest());
    }
public void initialize() {
        if (shieldings == null) {
            try {
                URL url = ClassLoader.getSystemResource(RF);
                InputStreamReader isr = new InputStreamReader(url.openStream());
                BufferedReader br = new BufferedReader(isr);
                SharcReader sr1 = new SharcReader(br);
                shieldings = new Hashtable();
                while (sr1.hasNext()) {
                    SharcShielding ss1 = sr1.next();
                    shieldings.put(ss1.getMethod(), ss1);
                }
                String[] shieldingNames = new String[shieldings.size()];
                int i = 0;
                for (Enumeration k = shieldings.keys(); k.hasMoreElements(); ) {
                    shieldingNames[i] = (String) k.nextElement();
                    i++;
                }
                dialog = new SelectSharcReference(null, shieldingNames, true);
            } catch (Exception ex) {
                shieldings = null;
            }
        }
    }
protected static String encodePassword(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(password.getBytes());
            return HexString.bufferToHex(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }