semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String encrypt(String x) throws Exception {
        MessageDigest mdEnc = MessageDigest.getInstance("SHA-1");
        mdEnc.update(x.getBytes(), 0, x.length());
        String md5 = new BigInteger(1, mdEnc.digest()).toString(16);
        return md5;
    }
private void getRandomGUID(boolean secure) {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0;
            if (secure) {
                rand = mySecureRand.nextLong();
            } else {
                rand = random.nextLong();
            }
            sbValueBeforeMD5.append(sid);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            byte[] array = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; ++j) {
                int b = array[j] & 0xFF;
                if (b < 0x10) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
        }
    }
public static boolean downloadFile(String srcUri, String srcDest) {
        try {
            URL url = new URL(srcUri);
            InputStream is = url.openStream();
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(srcDest));
            byte[] buff = new byte[10000];
            int b;
            while ((b = is.read(buff)) > 0) bos.write(buff, 0, b);
            is.close();
            bos.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public static String getByUrl(String urlStr, String para) {
        URL url;
        StringBuffer html = new StringBuffer("");
        try {
            url = new URL(urlStr);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "8859_1");
            out.write(para);
            out.flush();
            out.close();
            System.out.println("para:" + para);
            InputStream is = url.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line = "";
            line = br.readLine();
            while (line != null) {
                html.append(line + "\n");
                line = br.readLine();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return html.toString();
    }
private String encode(String arg) {
        try {
            final MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(arg.getBytes());
            byte[] md5sum = digest.digest();
            final BigInteger bigInt = new BigInteger(1, md5sum);
            final String output = bigInt.toString(16);
            return output;
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("MD5 required: " + e.getMessage(), e);
        }
    }
private void getRandomGUID(boolean secure) {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Error: " + e);
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0;
            if (secure) {
                rand = mySecureRand.nextLong();
            } else {
                rand = myRand.nextLong();
            }
            sbValueBeforeMD5.append(s_id);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            byte[] array = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; ++j) {
                int b = array[j] & 0xFF;
                if (b < 0x10) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            System.out.println("Error:" + e);
        }
    }
public static Set<Class<?>> getClasses(String pack) {
        Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
        boolean recursive = true;
        String packageName = pack;
        String packageDirName = packageName.replace('.', '/');
        Enumeration<URL> dirs;
        try {
            dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
            while (dirs.hasMoreElements()) {
                URL url = dirs.nextElement();
                String protocol = url.getProtocol();
                if ("file".equals(protocol)) {
                    String filePath = URLDecoder.decode(url.getFile(), "UTF-8");
                    findAndAddClassesInPackageByFile(packageName, filePath, recursive, classes);
                } else if ("jar".equals(protocol)) {
                    JarFile jar;
                    try {
                        jar = ((JarURLConnection) url.openConnection()).getJarFile();
                        Enumeration<JarEntry> entries = jar.entries();
                        while (entries.hasMoreElements()) {
                            JarEntry entry = entries.nextElement();
                            String name = entry.getName();
                            if (name.charAt(0) == '/') {
                                name = name.substring(1);
                            }
                            if (name.startsWith(packageDirName)) {
                                int idx = name.lastIndexOf('/');
                                if (idx != -1) {
                                    packageName = name.substring(0, idx).replace('/', '.');
                                }
                                if ((idx != -1) || recursive) {
                                    if (name.endsWith(".class") && !entry.isDirectory()) {
                                        String className = name.substring(packageName.length() + 1, name.length() - 6);
                                        try {
                                            classes.add(Class.forName(packageName + '.' + className));
                                        } catch (ClassNotFoundException e) {
                                            System.out.println("添加用户自定义视图类错误 找不到此类的.class文件");
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            }
                        }
                    } catch (IOException e) {
                        System.out.println("在扫描用户定义视图时从jar包获取文件出错");
                        e.printStackTrace();
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return classes;
    }
@Override
    public void copy(final String fileName) throws FileIOException {
        final long savedCurrentPositionInFile = currentPositionInFile;
        if (opened) {
            closeImpl();
        }
        final FileInputStream fis;
        try {
            fis = new FileInputStream(file);
        } catch (FileNotFoundException exception) {
            throw HELPER_FILE_UTIL.fileIOException(FAILED_OPEN + file, file, exception);
        }
        final File destinationFile = new File(fileName);
        final FileOutputStream fos;
        try {
            fos = new FileOutputStream(destinationFile);
        } catch (FileNotFoundException exception) {
            throw HELPER_FILE_UTIL.fileIOException(FAILED_OPEN + destinationFile, destinationFile, exception);
        }
        try {
            final byte[] buf = new byte[1024];
            int readLength = 0;
            while ((readLength = fis.read(buf)) != -1) {
                fos.write(buf, 0, readLength);
            }
        } catch (IOException exception) {
            throw HELPER_FILE_UTIL.fileIOException("failed copy from " + file + " to " + destinationFile, null, exception);
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
            } catch (Exception exception) {
            }
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (Exception exception) {
            }
        }
        if (opened) {
            openImpl();
            seek(savedCurrentPositionInFile);
        }
    }
protected UnicodeList(URL url) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new GZIPInputStream(url.openStream())));
            String line;
            line = br.readLine();
            chars = new ArrayList();
            while ((line = br.readLine()) != null) {
                String[] parts = GUIHelper.split(line, ";");
                if (parts[0].length() >= 5) continue;
                if (parts.length < 2 || parts[0].length() != 4) {
                    System.out.println("Strange line: " + line);
                } else {
                    if (parts.length > 10 && parts[1].equals("<control>")) {
                        parts[1] = parts[1] + ": " + parts[10];
                    }
                    try {
                        Integer.parseInt(parts[0], 16);
                        chars.add(parts[0] + parts[1]);
                    } catch (NumberFormatException ex) {
                        System.out.println("No number: " + line);
                    }
                }
            }
            br.close();
        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
public void read(Model model, String url) {
        try {
            URLConnection conn = new URL(url).openConnection();
            String encoding = conn.getContentEncoding();
            if (encoding == null) {
                read(model, conn.getInputStream(), url);
            } else {
                read(model, new InputStreamReader(conn.getInputStream(), encoding), url);
            }
        } catch (IOException e) {
            throw new JenaException(e);
        }
    }
private File copyFile(File file, String newName, File folder) {
        File newFile = null;
        if (!file.exists()) {
            System.out.println("File " + file + " does not exist");
            return null;
        }
        if (file.isFile()) {
            BufferedOutputStream out = null;
            BufferedInputStream in = null;
            try {
                in = new BufferedInputStream(new FileInputStream(file));
                newFile = new File(folder, newName);
                if (!newFile.exists()) {
                    newFile.createNewFile();
                }
                out = new BufferedOutputStream(new FileOutputStream(newFile));
                int read;
                byte[] buffer = new byte[8192];
                while ((read = in.read(buffer)) != -1) {
                    out.write(buffer, 0, read);
                }
                updateTreeUI();
            } catch (IOException ex) {
                Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    if (in != null) {
                        in.close();
                    }
                    if (out != null) {
                        out.close();
                    }
                } catch (IOException ex) {
                    Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
                }
            }
        } else if (file.isDirectory()) {
            newFile = new File(folder, newName);
            if (!newFile.exists()) {
                newFile.mkdir();
            }
            for (File f : file.listFiles()) {
                copyFile(f, f.getName(), newFile);
            }
        }
        return newFile;
    }
public void saveSharedFiles(List<FrostSharedFileItem> sfFiles) throws SQLException {
        Connection conn = AppLayerDatabase.getInstance().getPooledConnection();
        try {
            conn.setAutoCommit(false);
            Statement s = conn.createStatement();
            s.executeUpdate("DELETE FROM SHAREDFILES");
            s.close();
            s = null;
            PreparedStatement ps = conn.prepareStatement("INSERT INTO SHAREDFILES (" + "path,size,fnkey,sha,owner,comment,rating,keywords," + "lastuploaded,uploadcount,reflastsent,requestlastreceived,requestsreceivedcount,lastmodified) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
            for (Iterator<FrostSharedFileItem> i = sfFiles.iterator(); i.hasNext(); ) {
                FrostSharedFileItem sfItem = i.next();
                int ix = 1;
                ps.setString(ix++, sfItem.getFile().getPath());
                ps.setLong(ix++, sfItem.getFileSize());
                ps.setString(ix++, sfItem.getChkKey());
                ps.setString(ix++, sfItem.getSha());
                ps.setString(ix++, sfItem.getOwner());
                ps.setString(ix++, sfItem.getComment());
                ps.setInt(ix++, sfItem.getRating());
                ps.setString(ix++, sfItem.getKeywords());
                ps.setLong(ix++, sfItem.getLastUploaded());
                ps.setInt(ix++, sfItem.getUploadCount());
                ps.setLong(ix++, sfItem.getRefLastSent());
                ps.setLong(ix++, sfItem.getRequestLastReceived());
                ps.setInt(ix++, sfItem.getRequestsReceived());
                ps.setLong(ix++, sfItem.getLastModified());
                ps.executeUpdate();
            }
            ps.close();
            conn.commit();
            conn.setAutoCommit(true);
        } catch (Throwable t) {
            logger.log(Level.SEVERE, "Exception during save", t);
            try {
                conn.rollback();
            } catch (Throwable t1) {
                logger.log(Level.SEVERE, "Exception during rollback", t1);
            }
            try {
                conn.setAutoCommit(true);
            } catch (Throwable t1) {
            }
        } finally {
            AppLayerDatabase.getInstance().givePooledConnection(conn);
        }
    }
public final void testT4CClientWriter() throws Exception {
        InputStream is = ClassLoader.getSystemResourceAsStream(this.testFileName);
        T4CClientReader reader = new T4CClientReader(is, rc);
        File tmpFile = File.createTempFile("barde", ".log", this.tmpDir);
        System.out.println("tmp=" + tmpFile.getAbsolutePath());
        T4CClientWriter writer = new T4CClientWriter(new FileOutputStream(tmpFile), rc);
        for (Message m = reader.read(); m != null; m = reader.read()) writer.write(m);
        writer.close();
        InputStream fa = ClassLoader.getSystemResourceAsStream(this.testFileName);
        FileInputStream fb = new FileInputStream(tmpFile);
		for (int ba = fa.read(); ba != -1; ba = fa.read()) assertEquals(ba, fb.read());
    }
public static void copy(String sourceFile, String targetFile) throws IOException {
        FileChannel sourceChannel = new FileInputStream(sourceFile).getChannel();
        FileChannel targetChannel = new FileOutputStream(targetFile).getChannel();
        targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        sourceChannel.close();
        targetChannel.close();
    }
public static synchronized String Encrypt(String plaintextPassword) throws Exception {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (Exception error) {
            throw new Exception(error.getMessage());
        }
        try {
            md.update(plaintextPassword.getBytes("UTF-8"));
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
public void setPilot(PilotData pilotData) throws UsernameNotValidException {
        try {
            if (pilotData.username.trim().equals("") || pilotData.password.trim().equals("")) throw new UsernameNotValidException(1, "Username or password missing");
            PreparedStatement psta;
            if (pilotData.id == 0) {
                psta = jdbc.prepareStatement("INSERT INTO pilot " + "(name, address1, address2, zip, city, state, country, birthdate, " + "pft_theory, pft, medical, passenger, instructor, loc_language, " + "loc_country, loc_variant, username, password, id) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,nextval('pilot_id_seq'))");
            } else {
                psta = jdbc.prepareStatement("UPDATE pilot SET " + "name = ?, address1 = ?, address2 = ?, " + "zip = ?, city = ?, state = ?, country = ?, birthdate = ?, pft_theory = ?," + "pft = ?, medical = ?, passenger = ?, instructor = ?, loc_language = ?, " + "loc_country = ?, loc_variant = ?, username = ?, password = ? " + "WHERE id = ?");
            }
            psta.setString(1, pilotData.name);
            psta.setString(2, pilotData.address1);
            psta.setString(3, pilotData.address2);
            psta.setString(4, pilotData.zip);
            psta.setString(5, pilotData.city);
            psta.setString(6, pilotData.state);
            psta.setString(7, pilotData.country);
            if (pilotData.birthdate != null) psta.setLong(8, pilotData.birthdate.getTime()); else psta.setNull(8, java.sql.Types.INTEGER);
            if (pilotData.pft_theory != null) psta.setLong(9, pilotData.pft_theory.getTime()); else psta.setNull(9, java.sql.Types.INTEGER);
            if (pilotData.pft != null) psta.setLong(10, pilotData.pft.getTime()); else psta.setNull(10, java.sql.Types.INTEGER);
            if (pilotData.medical != null) psta.setLong(11, pilotData.medical.getTime()); else psta.setNull(11, java.sql.Types.INTEGER);
            if (pilotData.passenger) psta.setString(12, "Y"); else psta.setString(12, "N");
            if (pilotData.instructor) psta.setString(13, "Y"); else psta.setString(13, "N");
            psta.setString(14, pilotData.loc_language);
            psta.setString(15, pilotData.loc_country);
            psta.setString(16, pilotData.loc_variant);
            psta.setString(17, pilotData.username);
            psta.setString(18, pilotData.password);
            if (pilotData.id != 0) {
                psta.setInt(19, pilotData.id);
            }
            psta.executeUpdate();
            jdbc.commit();
        } catch (SQLException sql) {
            jdbc.rollback();
            sql.printStackTrace();
            throw new UsernameNotValidException(2, "Username allready exist");
        }
    }
public void getFile(String url, String filepath) throws BggException {
        System.out.println(url);
        int retry = retryCount + 1;
        lastURL = url;
        for (retriedCount = 0; retriedCount < retry; retriedCount++) {
            int responseCode = -1;
            try {
                HttpURLConnection con = null;
                BufferedInputStream bis = null;
                OutputStream osw = null;
                try {
                    con = (HttpURLConnection) new URL(url).openConnection();
                    con.setDoInput(true);
                    setHeaders(con);
                    con.setRequestMethod("GET");
                    responseCode = con.getResponseCode();
                    bis = new BufferedInputStream(con.getInputStream());
                    int data;
                    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filepath));
                    while ((data = bis.read()) != -1) bos.write(data);
                    bos.flush();
                    bos.close();
                    break;
                } finally {
                    try {
                        bis.close();
                    } catch (Exception ignore) {
                    }
                    try {
                        osw.close();
                    } catch (Exception ignore) {
                    }
                    try {
                        con.disconnect();
                    } catch (Exception ignore) {
                    }
                }
            } catch (IOException ioe) {
                if (responseCode == UNAUTHORIZED || responseCode == FORBIDDEN) {
                    throw new BggException(ioe.getMessage(), responseCode);
                }
                if (retriedCount == retryCount) {
                    throw new BggException(ioe.getMessage(), responseCode);
                }
            }
            try {
                Thread.sleep(retryIntervalMillis);
            } catch (InterruptedException ignore) {
            }
        }
    }
private Response httpRequest(String url, String charset) throws BggException {
        int retry = retryCount + 1;
        Response res = null;
        lastURL = url;
        for (retriedCount = 0; retriedCount < retry; retriedCount++) {
            int responseCode = -1;
            try {
                HttpURLConnection con = null;
                InputStream is = null;
                OutputStream osw = null;
                try {
                    con = (HttpURLConnection) new URL(url).openConnection();
                    con.setDoInput(true);
                    setHeaders(con);
                    con.setRequestMethod("GET");
                    responseCode = con.getResponseCode();
                    is = con.getInputStream();
                    if (charset != null) {
                        res = new Response(con.getResponseCode(), is, charset);
                    } else {
                        res = new Response(con.getResponseCode(), is);
                    }
                    break;
                } finally {
                    try {
                        is.close();
                    } catch (Exception ignore) {
                    }
                    try {
                        osw.close();
                    } catch (Exception ignore) {
                    }
                    try {
                        con.disconnect();
                    } catch (Exception ignore) {
                    }
                }
            } catch (IOException ioe) {
                if (responseCode == UNAUTHORIZED || responseCode == FORBIDDEN) {
                    throw new BggException(ioe.getMessage(), responseCode);
                }
                if (retriedCount == retryCount) {
                    throw new BggException(ioe.getMessage(), responseCode);
                }
            }
            try {
                Thread.sleep(retryIntervalMillis);
            } catch (InterruptedException ignore) {
            }
        }
        return res;
    }