semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private boolean checkTypeChange(Class clazz, File wsdlFile) {
        if (!clazz.isPrimitive()) {
            ClassLoader cl = clazz.getClassLoader();
            if (cl instanceof AntClassLoader) {
                if (clazz.isArray()) return checkTypeChange(getArrayType(clazz), wsdlFile);
                String path = clazz.getName().replace('.', File.separatorChar) + ".class";
                File file = new File(builddir, path);
                long lastMod = Long.MAX_VALUE;
                if (!file.exists()) {
                    URL url = cl.getResource(path);
                    if (url == null) throw new BuildException("Can't get URL for webservice class '" + clazz.getName() + "' from jar file."); else {
                        try {
                            JarURLConnection con = (JarURLConnection) url.openConnection();
                            lastMod = con.getJarEntry().getTime();
                        } catch (IOException x) {
                            throw new BuildException("Can't get modification time for webservice class '" + clazz.getName() + "' from jar file.");
                        }
                    }
                } else {
                    lastMod = file.lastModified();
                }
                if (wsdlFile.lastModified() < lastMod) return true;
                if (clazz.isInterface()) {
                    Class[] itfs = clazz.getInterfaces();
                    for (int i = 0; i < itfs.length; i++) {
                        boolean changed = checkTypeChange(itfs[i], wsdlFile);
                        if (changed) return true;
                    }
                } else {
                    Class sup = clazz.getSuperclass();
                    boolean changed = checkTypeChange(sup, wsdlFile);
                    if (changed) return true;
                }
            }
        }
        return false;
    }
private static void copy(File source, File target) throws IOException {
        FileInputStream in = new FileInputStream(source);
        FileOutputStream out = new FileOutputStream(target);
        byte[] buffer = new byte[4096];
        int no = 0;
        try {
            while ((no = in.read(buffer)) != -1) out.write(buffer, 0, no);
        } finally {
            in.close();
            out.close();
        }
    }
public void run() {
            long id = 0;
            try {
                URL url = new URL(httpRequest + blockSize);
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                try {
                    String str = in.readLine();
                    if (str == null) {
                        throw new IllegalStateException("Parsing error");
                    }
                    if (str.matches(".*SUCCESS.*")) {
                        str = in.readLine();
                        if (str.matches(".*Start:.*")) {
                            str = in.readLine();
                            id = Long.parseLong(str);
                        } else {
                            throw new IllegalStateException("Invalid response for blocksize(" + blockSize + "):" + str);
                        }
                    } else {
                        throw new IllegalStateException("Invalid response for blocksize(" + blockSize + "):" + str);
                    }
                } finally {
                    in.close();
                }
                if (id <= 0) throw new IllegalStateException("Invalid GUID start value " + id);
                synchronized (ids) {
                    boolean absent = ids.add(new Long(id));
                    if (!absent) {
                        logErrorMessage(id + " already exists for thread " + Thread.currentThread().getName());
                    }
                }
            } catch (Exception e) {
                logErrorMessage("Unexpected IdGenerator thread failure" + e.getMessage());
                e.printStackTrace();
            } finally {
                synchronized (test) {
                    test.liveThreads--;
                    test.notify();
                }
            }
        }
private static String getSignature(String data) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            return "FFFFFFFFFFFFFFFF";
        }
        md.update(data.getBytes());
        StringBuffer sb = new StringBuffer();
        byte[] sign = md.digest();
        for (int i = 0; i < sign.length; i++) {
            byte b = sign[i];
            int in = (int) b;
            if (in < 0) in = 127 - b;
            String hex = Integer.toHexString(in).toUpperCase();
            if (hex.length() == 1) hex = "0" + hex;
            sb.append(hex);
        }
        return sb.toString();
    }
public void render(HttpServletRequest request, HttpServletResponse response, File file, final Throwable t, final String contentType, final String encoding) throws Exception {
        if (contentType != null) {
            response.setContentType(contentType);
        }
        if (encoding != null) {
            response.setCharacterEncoding(encoding);
        }
        if (file.length() > Integer.MAX_VALUE) {
            throw new IllegalArgumentException("Cannot send file greater than 2GB");
        }
        response.setContentLength((int) file.length());
        IOUtils.copy(new FileInputStream(file), response.getOutputStream());
    }
public void copyFile(File s, File t) {
        try {
            FileChannel in = (new FileInputStream(s)).getChannel();
            FileChannel out = (new FileOutputStream(t)).getChannel();
            in.transferTo(0, s.length(), out);
            in.close();
            out.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
public String preProcessHTML(String uri) {
        final StringBuffer buf = new StringBuffer();
        try {
            HTMLDocument doc = new HTMLDocument() {

                public HTMLEditorKit.ParserCallback getReader(int pos) {
                    return new HTMLEditorKit.ParserCallback() {

                        public void handleText(char[] data, int pos) {
                            buf.append(data);
                            buf.append('\n');
                        }
                    };
                }
            };
            URL url = new URI(uri).toURL();
            URLConnection conn = url.openConnection();
            Reader rd = new InputStreamReader(conn.getInputStream());
            new ParserDelegator().parse(rd, doc.getReader(0), Boolean.TRUE);
        } catch (MalformedURLException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        } catch (URISyntaxException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
        return buf.toString();
    }
public static void copyTo(File src, File dest) throws IOException {
        if (src.equals(dest)) throw new IOException("copyTo src==dest file");
        FileOutputStream fout = new FileOutputStream(dest);
        InputStream in = new FileInputStream(src);
        IOUtils.copyTo(in, fout);
        fout.flush();
        fout.close();
        in.close();
    }
private void getRandomGUID(boolean secure) throws NoSuchAlgorithmException {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Error: " + e);
            throw 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 void mode(String env) {
        String path = this.envs.get(env);
        InputStream in = null;
        try {
            URL url = ResourceUtil.getResourceNoException(path);
            if (url == null) {
                throw new IllegalEnvironmentException(env);
            }
            load(URLUtil.openStream(url));
        } catch (IOException e) {
            throw new IllegalEnvironmentException(env, e);
        } finally {
            StreamUtil.close(in);
        }
    }
private static void copyFile(String fromFile, String toFile) throws Exception {
        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 String md5(String pass) {
        StringBuffer enteredChecksum = new StringBuffer();
        byte[] digest;
        MessageDigest md5;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(pass.getBytes(), 0, pass.length());
            digest = md5.digest();
            for (int i = 0; i < digest.length; i++) {
                enteredChecksum.append(toHexString(digest[i]));
            }
        } catch (NoSuchAlgorithmException e) {
            log.error("Could not create MD5 hash!");
            log.error(e.getLocalizedMessage());
            log.error(e.getStackTrace());
        }
        return enteredChecksum.toString();
    }
public void createMd5Hash() {
        try {
            String vcardObject = new ContactToVcard(TimeZone.getTimeZone("UTC"), "UTF-8").convert(this);
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(vcardObject.getBytes());
            this.md5Hash = new BigInteger(m.digest()).toString();
            if (log.isTraceEnabled()) {
                log.trace("Hash is:" + this.md5Hash);
            }
        } catch (ConverterException ex) {
            log.error("Error creating hash:" + ex.getMessage());
        } catch (NoSuchAlgorithmException noSuchAlgorithmException) {
            log.error("Error creating hash:" + noSuchAlgorithmException.getMessage());
        }
    }
public static void createZipFromDataset(String localResourceId, File dataset, File metadata) {
        CommunicationLogger.warning("System entered ZipFactory");
        try {
            String tmpDir = System.getProperty("java.io.tmpdir");
            String outFilename = tmpDir + "/" + localResourceId + ".zip";
            CommunicationLogger.warning("File name: " + outFilename);
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
            byte[] buf = new byte[1024];
            FileInputStream in = new FileInputStream(dataset);
            out.putNextEntry(new ZipEntry(dataset.getName()));
            int len;
            while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            in = new FileInputStream(metadata);
            out.putNextEntry(new ZipEntry(metadata.getName()));
            while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            out.closeEntry();
            in.close();
            out.close();
        } catch (IOException e) {
            System.out.println("IO EXCEPTION: " + e.getMessage());
        }
    }
public boolean verify(String digest, String password) throws NoSuchAlgorithmException {
        String alg = null;
        int size = 0;
        if (digest.regionMatches(true, 0, "{CRYPT}", 0, 7)) {
            digest = digest.substring(7);
            return UnixCrypt.matches(digest, password);
        } else if (digest.regionMatches(true, 0, "{SHA}", 0, 5)) {
            digest = digest.substring(5);
            alg = "SHA-1";
            size = 20;
        } else if (digest.regionMatches(true, 0, "{SSHA}", 0, 6)) {
            digest = digest.substring(6);
            alg = "SHA-1";
            size = 20;
        } else if (digest.regionMatches(true, 0, "{MD5}", 0, 5)) {
            digest = digest.substring(5);
            alg = "MD5";
            size = 16;
        } else if (digest.regionMatches(true, 0, "{SMD5}", 0, 6)) {
            digest = digest.substring(6);
            alg = "MD5";
            size = 16;
        }
        MessageDigest msgDigest = MessageDigest.getInstance(alg);
        byte[][] hs = split(Base64.decode(digest.toCharArray()), size);
        byte[] hash = hs[0];
        byte[] salt = hs[1];
        msgDigest.reset();
        msgDigest.update(password.getBytes());
        msgDigest.update(salt);
        byte[] pwhash = msgDigest.digest();
        return msgDigest.isEqual(hash, pwhash);
    }
public String generateDigest(String password, String saltHex, String algorithm) throws NoSuchAlgorithmException {
        if (algorithm.equalsIgnoreCase("crypt")) {
            return "{CRYPT}" + UnixCrypt.crypt(password);
        } else if (algorithm.equalsIgnoreCase("sha")) {
            algorithm = "SHA-1";
        } else if (algorithm.equalsIgnoreCase("md5")) {
            algorithm = "MD5";
        }
        MessageDigest msgDigest = MessageDigest.getInstance(algorithm);
        byte[] salt = {};
        if (saltHex != null) {
            salt = fromHex(saltHex);
        }
        String label = null;
        if (algorithm.startsWith("SHA")) {
            label = (salt.length > 0) ? "{SSHA}" : "{SHA}";
        } else if (algorithm.startsWith("MD5")) {
            label = (salt.length > 0) ? "{SMD5}" : "{MD5}";
        }
        msgDigest.reset();
        msgDigest.update(password.getBytes());
        msgDigest.update(salt);
        byte[] pwhash = msgDigest.digest();
        StringBuffer digest = new StringBuffer(label);
        digest.append(Base64.encode(concatenate(pwhash, salt)));
        return digest.toString();
    }
public static Chunk updateLastSend(Chunk c) throws Exception {
        DBConnectionManager dbm = null;
        Connection conn = null;
        PreparedStatement stmt = null;
        Chunk ret = null;
        String SQL = "UPDATE CHUNK SET SENT=? WHERE FILEHASH=? AND STARTOFF=? AND LENGTH=?";
        log.debug("update chunk last sent for chunk " + c.getHash() + " startoff " + c.getStartOffset());
        try {
            dbm = DBConnectionManager.getInstance();
            conn = dbm.getConnection("satmule");
            stmt = conn.prepareStatement(SQL);
            stmt.setDate(1, new java.sql.Date(c.getLastSend().getTime()));
            stmt.setString(2, c.getHash());
            stmt.setLong(3, c.getStartOffset());
            stmt.setLong(4, c.getSize());
            stmt.executeUpdate();
            conn.commit();
            stmt.close();
            dbm.freeConnection("satmule", conn);
        } catch (Exception e) {
            log.error("Error while updating chunk " + c.getHash() + "offset:" + c.getStartOffset() + "SQL error: " + SQL, e);
            Exception excep;
            if (dbm == null) excep = new Exception("Could not obtain pool object DbConnectionManager"); else if (conn == null) excep = new Exception("The Db connection pool could not obtain a database connection"); else {
                conn.rollback();
                excep = new Exception("SQL Error : " + SQL + " error: " + e);
                dbm.freeConnection("satmule", conn);
            }
            throw excep;
        }
        return ret;
    }
public void addUser(String strUserName, String strPass) {
        String datetime = Function.getSysTime().toString();
        String time = datetime.substring(0, 4) + datetime.substring(5, 7) + datetime.substring(8, 10) + datetime.substring(11, 13) + datetime.substring(14, 16) + datetime.substring(17, 19) + datetime.substring(20, 22) + "0";
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbForumFactory.getConnection();
            con.setAutoCommit(false);
            int userID = DbSequenceManager.nextID(DbSequenceManager.USER);
            pstmt = con.prepareStatement(INSERT_USER);
            pstmt.setString(1, strUserName);
            pstmt.setString(2, SecurityUtil.md5ByHex(strPass));
            pstmt.setString(3, time);
            pstmt.setString(4, "");
            pstmt.setString(5, "");
            pstmt.setString(6, "");
            pstmt.setString(7, "");
            pstmt.setInt(8, userID);
            pstmt.executeUpdate();
            pstmt.clearParameters();
            pstmt = con.prepareStatement(INSERT_USERPROPS);
            pstmt.setString(1, "");
            pstmt.setString(2, "");
            pstmt.setString(3, "");
            pstmt.setInt(4, 0);
            pstmt.setString(5, "");
            pstmt.setInt(6, 0);
            pstmt.setInt(7, 0);
            pstmt.setString(8, "");
            pstmt.setString(9, "");
            pstmt.setString(10, "");
            pstmt.setInt(11, 0);
            pstmt.setInt(12, 0);
            pstmt.setInt(13, 0);
            pstmt.setInt(14, 0);
            pstmt.setString(15, "");
            pstmt.setString(16, "");
            pstmt.setString(17, "");
            pstmt.setString(18, "");
            pstmt.setString(19, "");
            pstmt.setString(20, "");
            pstmt.setString(21, "");
            pstmt.setString(22, "");
            pstmt.setString(23, "");
            pstmt.setInt(24, 0);
            pstmt.setInt(25, 0);
            pstmt.setInt(26, userID);
            pstmt.executeUpdate();
            pstmt.clearParameters();
            pstmt = con.prepareStatement(INSTER_USERGROUP);
            pstmt.setInt(1, 4);
            pstmt.setInt(2, userID);
            pstmt.setInt(3, 0);
            pstmt.executeUpdate();
            con.commit();
        } catch (Exception e) {
            try {
                con.rollback();
            } catch (SQLException e1) {
            }
            log.error("insert user Error: " + e.toString());
        } finally {
            DbForumFactory.closeDB(null, pstmt, null, con);
        }
    }
public void modify(String strName, String strNewPass) {
        String str = "update jb_user set V_PASSWORD =? where V_USERNAME =?";
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbForumFactory.getConnection();
            con.setAutoCommit(false);
            pstmt = con.prepareStatement(str);
            pstmt.setString(1, SecurityUtil.md5ByHex(strNewPass));
            pstmt.setString(2, strName);
            pstmt.executeUpdate();
            con.commit();
        } catch (Exception e) {
            e.printStackTrace();
            try {
                con.rollback();
            } catch (SQLException e1) {
            }
        } finally {
            try {
                DbForumFactory.closeDB(null, pstmt, null, con);
            } catch (Exception e) {
            }
        }
    }
public void addUser(String strUserName, String strPass, boolean isEncrypt) throws Exception {
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbForumFactory.getConnection();
            con.setAutoCommit(false);
            int userID = DbSequenceManager.nextID(DbSequenceManager.USER);
            pstmt = con.prepareStatement(INSERT_USER);
            pstmt.setString(1, strUserName);
            if (isEncrypt) {
                pstmt.setString(2, SecurityUtil.md5ByHex(strPass));
            } else {
                pstmt.setString(2, strPass);
            }
            pstmt.setString(3, "");
            pstmt.setString(4, "");
            pstmt.setString(5, "");
            pstmt.setString(6, "");
            pstmt.setString(7, "");
            pstmt.setInt(8, userID);
            pstmt.executeUpdate();
            pstmt.clearParameters();
            pstmt = con.prepareStatement(INSERT_USERPROPS);
            pstmt.setString(1, "");
            pstmt.setString(2, "");
            pstmt.setString(3, "");
            pstmt.setInt(4, 0);
            pstmt.setString(5, "");
            pstmt.setInt(6, 0);
            pstmt.setInt(7, 0);
            pstmt.setString(8, "");
            pstmt.setString(9, "");
            pstmt.setString(10, "");
            pstmt.setInt(11, 0);
            pstmt.setInt(12, 0);
            pstmt.setInt(13, 0);
            pstmt.setInt(14, 0);
            pstmt.setString(15, "");
            pstmt.setString(16, "");
            pstmt.setString(17, "");
            pstmt.setString(18, "");
            pstmt.setString(19, "");
            pstmt.setString(20, "");
            pstmt.setString(21, "");
            pstmt.setString(22, "");
            pstmt.setString(23, "");
            pstmt.setInt(24, 0);
            pstmt.setInt(25, 0);
            pstmt.setInt(26, userID);
            pstmt.executeUpdate();
            pstmt.clearParameters();
            pstmt = con.prepareStatement(INSTER_USERGROUP);
            pstmt.setInt(1, 4);
            pstmt.setInt(2, userID);
            pstmt.setInt(3, 0);
            pstmt.executeUpdate();
            con.commit();
        } catch (Exception e) {
            try {
                con.rollback();
            } catch (SQLException e1) {
            }
            log.error("insert user Error: " + e.toString());
        } finally {
            DbForumFactory.closeDB(null, pstmt, null, con);
        }
    }
public void fileCopy(File src, File dest) throws IOException {
        if (!dest.exists()) {
            final File parent = new File(dest.getParent());
            if (!parent.exists() && !parent.mkdirs()) {
                throw new IOException();
            }
            if (!dest.createNewFile()) {
            }
        }
        FileInputStream is = null;
        FileOutputStream os = null;
        try {
            is = new FileInputStream(src);
            os = new FileOutputStream(dest);
            final FileChannel srcChannel = is.getChannel();
            final FileChannel dstChannel = os.getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } finally {
                if (os != null) {
                    os.close();
                }
            }
        }
    }
private static boolean isUrlResourceExists(final URL url) {
        try {
            InputStream is = url.openStream();
            try {
                is.close();
            } catch (IOException ioe) {
            }
            return true;
        } catch (IOException ioe) {
            return false;
        }
    }