semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String encodeMD5(String s) throws NoSuchAlgorithmException {
        MessageDigest m = null;
        String result = null;
        m = MessageDigest.getInstance("MD5");
        m.update(s.getBytes(), 0, s.length());
        result = new BigInteger(1, m.digest()).toString(16);
        if (result.length() == 31) {
            result = "0" + result;
        }
        return result;
    }
private boolean copyFile(BackupItem item) {
        try {
            FileChannel src = new FileInputStream(item.getDrive() + ":" + item.getPath()).getChannel();
            createFolderStructure(this.task.getDestinationPath() + "\\" + item.getDrive() + item.getPath());
            FileChannel dest = new FileOutputStream(this.task.getDestinationPath() + "\\" + item.getDrive() + item.getPath()).getChannel();
            dest.transferFrom(src, 0, src.size());
            src.close();
            dest.close();
            Logging.logMessage("file " + item.getDrive() + ":" + item.getPath() + " was backuped");
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
public static void copyFile(File in, File out) throws Exception {
        FileChannel sourceChannel = null;
        FileChannel destinationChannel = null;
        try {
            sourceChannel = new FileInputStream(in).getChannel();
            destinationChannel = new FileOutputStream(out).getChannel();
            sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        } finally {
            if (sourceChannel != null) sourceChannel.close();
            if (destinationChannel != null) destinationChannel.close();
        }
    }
public static void copyFile(final String src, final String dest) {
        Runnable r1 = new Runnable() {

            public void run() {
                try {
                    File inf = new File(dest);
                    if (!inf.exists()) {
                        inf.getParentFile().mkdirs();
                    }
                    FileChannel in = new FileInputStream(src).getChannel();
                    FileChannel out = new FileOutputStream(dest).getChannel();
                    out.transferFrom(in, 0, in.size());
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    System.err.println("Error copying file \n" + src + "\n" + dest);
                }
            }
        };
        Thread cFile = new Thread(r1, "copyFile");
        cFile.start();
    }
public void run() {
                try {
                    File inf = new File(dest);
                    if (!inf.exists()) {
                        inf.getParentFile().mkdirs();
                    }
                    FileChannel in = new FileInputStream(src).getChannel();
                    FileChannel out = new FileOutputStream(dest).getChannel();
                    out.transferFrom(in, 0, in.size());
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    System.err.println("Error copying file \n" + src + "\n" + dest);
                }
            }
public static synchronized String getMD5_Base64(final String input) {
        if (isInited == false) {
            isInited = true;
            try {
                digest = MessageDigest.getInstance("MD5");
            } catch (Exception ex) {
                logger.error("Cannot get MessageDigest. Application may fail to run correctly.", ex);
            }
        }
        if (digest == null) {
            return input;
        }
        try {
            digest.update(input.getBytes("UTF-8"));
        } catch (java.io.UnsupportedEncodingException ex) {
            logger.error("Assertion: This should never occur.");
        }
        byte[] rawData = digest.digest();
        byte[] encoded = Base64.encode(rawData);
        String retValue = new String(encoded);
        return retValue;
    }
public String runRawSearch(final String search) throws IOException {
        if (search == null) {
            return null;
        }
        StringBuilder urlString = new StringBuilder("http://ajax.googleapis.com/ajax/services/search/web?");
        if (version != null) {
            urlString.append("v=");
            urlString.append(version);
            urlString.append("&");
        }
        urlString.append("q=");
        urlString.append(StringEscapeUtils.escapeHtml(search));
        URL url = new URL(urlString.toString());
        Proxy proxy = null;
        final URLConnection connection;
        if (proxy != null) {
            connection = url.openConnection(proxy);
        } else {
            connection = url.openConnection();
        }
        if (referer != null) {
            connection.addRequestProperty("Referer", referer);
        }
        String line;
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        return builder.toString();
    }
public static List importSymbols(List symbols) throws ImportExportException {
        List quotes = new ArrayList();
        String URLString = constructURL(symbols);
        IDQuoteFilter filter = new YahooIDQuoteFilter();
        PreferencesManager.ProxyPreferences proxyPreferences = PreferencesManager.loadProxySettings();
        try {
            URL url = new URL(URLString);
            InputStreamReader input = new InputStreamReader(url.openStream());
            BufferedReader bufferedInput = new BufferedReader(input);
            String line;
            do {
                line = bufferedInput.readLine();
                if (line != null) {
                    try {
                        IDQuote quote = filter.toIDQuote(line);
                        quote.verify();
                        quotes.add(quote);
                    } catch (QuoteFormatException e) {
                    }
                }
            } while (line != null);
            bufferedInput.close();
        } catch (BindException e) {
            throw new ImportExportException(Locale.getString("UNABLE_TO_CONNECT_ERROR", e.getMessage()));
        } catch (ConnectException e) {
            throw new ImportExportException(Locale.getString("UNABLE_TO_CONNECT_ERROR", e.getMessage()));
        } catch (UnknownHostException e) {
            throw new ImportExportException(Locale.getString("UNKNOWN_HOST_ERROR", e.getMessage()));
        } catch (NoRouteToHostException e) {
            throw new ImportExportException(Locale.getString("DESTINATION_UNREACHABLE_ERROR", e.getMessage()));
        } catch (MalformedURLException e) {
            throw new ImportExportException(Locale.getString("INVALID_PROXY_ERROR", proxyPreferences.host, proxyPreferences.port));
        } catch (FileNotFoundException e) {
            throw new ImportExportException(Locale.getString("ERROR_DOWNLOADING_QUOTES"));
        } catch (IOException e) {
            throw new ImportExportException(Locale.getString("ERROR_DOWNLOADING_QUOTES"));
        }
        return quotes;
    }
public Boolean compress(String sSourceDir, ArrayList<String> aFiles, String sDestinationFilename) {
        logger.debug("compress(%s, %s, %s)", sSourceDir, aFiles, sDestinationFilename);
        BufferedInputStream oOrigin = null;
        FileOutputStream oDestination;
        ZipOutputStream oOutput = null;
        Iterator<String> oIterator;
        byte[] aData;
        try {
            oDestination = new FileOutputStream(sDestinationFilename);
            oOutput = new ZipOutputStream(new BufferedOutputStream(oDestination));
            aData = new byte[BUFFER_SIZE];
            oIterator = aFiles.iterator();
            while (oIterator.hasNext()) {
                try {
                    String sFilename = (String) oIterator.next();
                    FileInputStream fisInput = new FileInputStream(sSourceDir + File.separator + sFilename);
                    oOrigin = new BufferedInputStream(fisInput, BUFFER_SIZE);
                    ZipEntry oEntry = new ZipEntry(sFilename.replace('\\', '/'));
                    oOutput.putNextEntry(oEntry);
                    int iCount;
                    while ((iCount = oOrigin.read(aData, 0, BUFFER_SIZE)) != -1) oOutput.write(aData, 0, iCount);
                } finally {
                    StreamHelper.close(oOrigin);
                }
            }
        } catch (Exception oException) {
            logger.error(oException.getMessage(), oException);
            return false;
        } finally {
            StreamHelper.close(oOutput);
        }
        return true;
    }
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
        String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
        if (name != null && wanted.containsKey(name)) {
            FileOutputStream out = new FileOutputStream(wanted.get(name));
            IOUtils.copy(stream, out);
            out.close();
        } else {
            if (downstreamParser != null) {
                downstreamParser.parse(stream, handler, metadata, context);
            }
        }
    }
public static void saveAttachmentBody(Context context, Part part, Attachment localAttachment, long accountId) throws MessagingException, IOException {
        if (part.getBody() != null) {
            long attachmentId = localAttachment.mId;
            InputStream in = part.getBody().getInputStream();
            File saveIn = AttachmentProvider.getAttachmentDirectory(context, accountId);
            if (!saveIn.exists()) {
                saveIn.mkdirs();
            }
            File saveAs = AttachmentProvider.getAttachmentFilename(context, accountId, attachmentId);
            saveAs.createNewFile();
            FileOutputStream out = new FileOutputStream(saveAs);
            long copySize = IOUtils.copy(in, out);
            in.close();
            out.close();
            String contentUriString = AttachmentProvider.getAttachmentUri(accountId, attachmentId).toString();
            localAttachment.mSize = copySize;
            localAttachment.mContentUri = contentUriString;
            ContentValues cv = new ContentValues();
            cv.put(AttachmentColumns.SIZE, copySize);
            cv.put(AttachmentColumns.CONTENT_URI, contentUriString);
            Uri uri = ContentUris.withAppendedId(Attachment.CONTENT_URI, attachmentId);
            context.getContentResolver().update(uri, cv, null, null);
        }
    }
protected static void copyOrMove(File sourceLocation, File targetLocation, boolean move) throws IOException {
        String[] children;
        int i;
        InputStream in;
        OutputStream out;
        byte[] buf;
        int len;
        if (sourceLocation.isDirectory()) {
            if (!targetLocation.exists()) targetLocation.mkdir();
            children = sourceLocation.list();
            for (i = 0; i < children.length; i++) {
                copyOrMove(new File(sourceLocation, children[i]), new File(targetLocation, children[i]), move);
            }
            if (move) sourceLocation.delete();
        } else {
            in = new FileInputStream(sourceLocation);
            if (targetLocation.isDirectory()) out = new FileOutputStream(targetLocation.getAbsolutePath() + File.separator + sourceLocation.getName()); else out = new FileOutputStream(targetLocation);
            buf = new byte[1024];
            while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            in.close();
            out.close();
            if (move) sourceLocation.delete();
        }
    }
@Override
    public String encodePassword(String rawPass, Object salt) throws DataAccessException {
        try {
            MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
            digest.reset();
            digest.update(((String) salt).getBytes("UTF-8"));
            return new String(digest.digest(rawPass.getBytes("UTF-8")));
        } catch (Throwable e) {
            throw new DataAccessException("Error al codificar la contrase�a", e) {

                private static final long serialVersionUID = 3880106673612870103L;
            };
        }
    }
@Override
    public boolean isPasswordValid(String encPass, String rawPass, Object salt) throws DataAccessException {
        try {
            MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
            digest.reset();
            digest.update(((String) salt).getBytes("UTF-8"));
            String encodedRawPass = new String(digest.digest(rawPass.getBytes("UTF-8")));
            return encodedRawPass.equals(encPass);
        } catch (Throwable e) {
            throw new DataAccessException("Error al codificar la contrase�a", e) {

                private static final long serialVersionUID = -302443565702455874L;
            };
        }
    }
public static void addRecipe(String name, String instructions, int categoryId, String[][] ainekset) throws Exception {
        PreparedStatement pst1 = null;
        PreparedStatement pst2 = null;
        ResultSet rs = null;
        int retVal = -1;
        try {
            pst1 = conn.prepareStatement("INSERT INTO recipes (name, instructions, category_id) VALUES (?, ?, ?)");
            pst1.setString(1, name);
            pst1.setString(2, instructions);
            pst1.setInt(3, categoryId);
            if (pst1.executeUpdate() > 0) {
                pst2 = conn.prepareStatement("SELECT recipe_id FROM recipes WHERE name = ? AND instructions = ? AND category_id = ?");
                pst2.setString(1, name);
                pst2.setString(2, instructions);
                pst2.setInt(3, categoryId);
                rs = pst2.executeQuery();
                if (rs.next()) {
                    int id = rs.getInt(1);
                    System.out.println("Lis�t��n ainesosat");
                    String[] aines;
                    for (int i = 0; i < ainekset.length; ++i) {
                        aines = ainekset[i];
                        addIngredient(id, aines[0], aines[1], Integer.parseInt(aines[2]), Integer.parseInt(aines[3]));
                    }
                    retVal = id;
                } else {
                    retVal = -1;
                }
            } else {
                retVal = -1;
            }
            conn.commit();
        } catch (Exception e) {
            conn.rollback();
            throw new Exception("Reseptin lis�ys ep�onnistui. Poikkeus: " + e.getMessage());
        }
    }
private static void addIngredient(int recipeId, String name, String amount, int measureId, int shopFlag) throws Exception {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("INSERT INTO ingredients (recipe_id, name, amount, measure_id, shop_flag) VALUES (?,?,?,?,?)");
            pst.setInt(1, recipeId);
            pst.setString(2, name);
            pst.setString(3, amount);
            pst.setInt(4, measureId);
            pst.setInt(5, shopFlag);
            pst.executeUpdate();
            conn.commit();
        } catch (Exception e) {
            conn.rollback();
            throw new Exception("Ainesosan lis�ys ep�onnistui. Poikkeus: " + e.getMessage());
        }
    }
private static void loadParentProperties(Properties props, ClassLoader cl) throws IOException {
        String pName = props.getProperty(PARENT_PROPERTIES);
        if (pName == null) {
            return;
        }
        URL url = cl.getResource(pName);
        if (url == null) {
            return;
        }
        InputStream is = url.openStream();
        if (is != null) {
            Properties tmpProps = new Properties();
            tmpProps.load(is);
            is.close();
            loadParentProperties(tmpProps, cl);
            Iterator itr = tmpProps.entrySet().iterator();
            while (itr.hasNext()) {
                Map.Entry entry = (Map.Entry) itr.next();
                if (!props.containsKey(entry.getKey())) {
                    props.put(entry.getKey(), entry.getValue());
                }
            }
        }
    }
public String encrypt(String pwd) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            System.out.println("Error");
        }
        try {
            md5.update(pwd.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "That is not a valid encrpytion type");
        }
        byte raw[] = md5.digest();
        String empty = "";
        String hash = "";
        for (byte b : raw) {
            String tmp = empty + Integer.toHexString(b & 0xff);
            if (tmp.length() == 1) {
                tmp = 0 + tmp;
            }
            hash += tmp;
        }
        return hash;
    }
public void update() {
        try {
            String passwordMD5 = new String();
            if (this.password != null && this.password.length() > 0) {
                MessageDigest md = MessageDigest.getInstance("md5");
                md.update(this.password.getBytes());
                byte[] digest = md.digest();
                for (int i = 0; i < digest.length; i++) {
                    passwordMD5 += Integer.toHexString((digest[i] >> 4) & 0xf);
                    passwordMD5 += Integer.toHexString((digest[i] & 0xf));
                }
            }
            this.authCode = new String(Base64Encoder.encode(new String(this.username + ";" + passwordMD5).getBytes()));
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
public TableDirectory(RandomAccessFile raf) throws IOException {
        version = raf.readInt();
        numTables = raf.readShort();
        searchRange = raf.readShort();
        entrySelector = raf.readShort();
        rangeShift = raf.readShort();
        entries = new DirectoryEntry[numTables];
        for (int i = 0; i < numTables; i++) {
            entries[i] = new DirectoryEntry(raf);
        }
        boolean modified = true;
        while (modified) {
            modified = false;
            for (int i = 0; i < numTables - 1; i++) {
                if (entries[i].getOffset() > entries[i + 1].getOffset()) {
                    DirectoryEntry temp = entries[i];
                    entries[i] = entries[i + 1];
                    entries[i + 1] = temp;
                    modified = true;
                }
            }
        }
    }
public static boolean isLinkHtmlContent(String address) {
        boolean isHtml = false;
        URLConnection conn = null;
        try {
            if (!address.startsWith("http://")) {
                address = "http://" + address;
            }
            URL url = new URL(address);
            conn = url.openConnection();
            if (conn.getContentType().equals("text/html") && !conn.getHeaderField(0).contains("404")) {
                isHtml = true;
            }
        } catch (Exception e) {
            logger.error("Address attempted: " + conn.getURL());
            logger.error("Error Message: " + e.getMessage());
        }
        return isHtml;
    }
public static void printResponseHeaders(String address) {
        logger.info("Address: " + address);
        try {
            URL url = new URL(address);
            URLConnection conn = url.openConnection();
            for (int i = 0; ; i++) {
                String headerName = conn.getHeaderFieldKey(i);
                String headerValue = conn.getHeaderField(i);
                if (headerName == null && headerValue == null) {
                    break;
                }
                if (headerName == null) {
                    logger.info(headerValue);
                    continue;
                }
                logger.info(headerName + " " + headerValue);
            }
        } catch (Exception e) {
            logger.error("Exception Message: " + e.getMessage());
        }
    }
public static Map<String, List<String>> getResponseHeader(String address) {
        System.out.println(address);
        URLConnection conn = null;
        Map<String, List<String>> responseHeader = null;
        try {
            URL url = new URL(address);
            conn = url.openConnection();
            responseHeader = conn.getHeaderFields();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return responseHeader;
    }
public static int getContentLength(String address) {
        URLConnection conn = null;
        int contentLength = 0;
        try {
            URL url = new URL(address);
            conn = url.openConnection();
            contentLength = conn.getContentLength();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return contentLength;
    }
public static void main(String[] args) throws IOException {
        InputStream stream = null;
        FileOutputStream fos = null;
        File in = new File("in.txt");
        try {
            URL url = new URL(args[0]);
            stream = url.openStream();
            fos = new FileOutputStream(in);
            int i;
            while ((i = stream.read()) != -1) {
                fos.write(i);
            }
            fos.flush();
            fos.close();
            new FileRunner(in, new File("out.txt")).run();
            FileReader reader = new FileReader("out.txt");
            System.out.println(reader.toString());
        } finally {
            if (stream != null) stream.close();
        }
    }