semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String generateMessageId(String plain) {
        byte[] cipher = new byte[35];
        String messageId = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(plain.getBytes());
            cipher = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < cipher.length; i++) {
                String hex = Integer.toHexString(0xff & cipher[i]);
                if (hex.length() == 1) sb.append('0');
                sb.append(hex);
            }
            StringBuffer pass = new StringBuffer();
            pass.append(sb.substring(0, 6));
            pass.append("H");
            pass.append(sb.substring(6, 11));
            pass.append("H");
            pass.append(sb.substring(11, 21));
            pass.append("H");
            pass.append(sb.substring(21));
            messageId = new String(pass);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return messageId;
    }
public static boolean reportException(Throwable ex, HashMap<String, String> suppl) {
        if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_CRASH_REPORTING)) {
            logger.debug("Report exception to devs...");
            String data = "reportType=exception&" + "message=" + ex.getMessage();
            data += "&build=" + Platform.getBundle("de.uni_mannheim.swt.codeconjurer").getHeaders().get("Bundle-Version");
            int ln = 0;
            for (StackTraceElement el : ex.getStackTrace()) {
                data += "&st_line_" + ++ln + "=" + el.getClassName() + "#" + el.getMethodName() + "<" + el.getLineNumber() + ">";
            }
            data += "&lines=" + ln;
            data += "&Suppl-Description=" + ex.toString();
            data += "&Suppl-Server=" + Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.P_SERVER);
            data += "&Suppl-User=" + Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.P_USERNAME);
            if (suppl != null) {
                for (String key : suppl.keySet()) {
                    data += "&Suppl-" + key + "=" + suppl.get(key);
                }
            }
            try {
                URL url = new URL("http://www.merobase.com:7777/org.code_conjurer.udc/CrashReport");
                URLConnection conn = url.openConnection();
                conn.setDoOutput(true);
                OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
                writer.write(data);
                writer.flush();
                StringBuffer answer = new StringBuffer();
                BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String line;
                while ((line = reader.readLine()) != null) {
                    answer.append(line + "\r\n");
                }
                writer.close();
                reader.close();
                logger.debug(answer.toString());
            } catch (Exception e) {
                logger.debug("Could not report exception");
                return false;
            }
            return true;
        } else {
            logger.debug("Reporting not wished!");
            return false;
        }
    }
public static String crypt(String password, String salt) throws java.security.NoSuchAlgorithmException {
        int saltEnd;
        int len;
        int value;
        int i;
        MessageDigest hash1;
        MessageDigest hash2;
        byte[] digest;
        byte[] passwordBytes;
        byte[] saltBytes;
        StringBuffer result;
        if (salt.startsWith(magic)) {
            salt = salt.substring(magic.length());
        }
        if ((saltEnd = salt.indexOf('$')) != -1) {
            salt = salt.substring(0, saltEnd);
        }
        if (salt.length() > 8) {
            salt = salt.substring(0, 8);
        }
        hash1 = MessageDigest.getInstance("MD5");
        hash1.update(password.getBytes());
        hash1.update(magic.getBytes());
        hash1.update(salt.getBytes());
        hash2 = MessageDigest.getInstance("MD5");
        hash2.update(password.getBytes());
        hash2.update(salt.getBytes());
        hash2.update(password.getBytes());
        digest = hash2.digest();
        for (len = password.length(); len > 0; len -= 16) {
            hash1.update(digest, 0, len > 16 ? 16 : len);
        }
        passwordBytes = password.getBytes();
        for (i = password.length(); i > 0; i >>= 1) {
            if ((i & 1) == 1) {
                hash1.update((byte) 0);
            } else {
                hash1.update(passwordBytes, 0, 1);
            }
        }
        result = new StringBuffer(magic);
        result.append(salt);
        result.append("$");
        digest = hash1.digest();
        saltBytes = salt.getBytes();
        for (i = 0; i < 1000; i++) {
            hash2.reset();
            if ((i & 1) == 1) {
                hash2.update(passwordBytes);
            } else {
                hash2.update(digest);
            }
            if (i % 3 != 0) {
                hash2.update(saltBytes);
            }
            if (i % 7 != 0) {
                hash2.update(passwordBytes);
            }
            if ((i & 1) != 0) {
                hash2.update(digest);
            } else {
                hash2.update(passwordBytes);
            }
            digest = hash2.digest();
        }
        value = ((digest[0] & 0xff) << 16) | ((digest[6] & 0xff) << 8) | (digest[12] & 0xff);
        result.append(to64(value, 4));
        value = ((digest[1] & 0xff) << 16) | ((digest[7] & 0xff) << 8) | (digest[13] & 0xff);
        result.append(to64(value, 4));
        value = ((digest[2] & 0xff) << 16) | ((digest[8] & 0xff) << 8) | (digest[14] & 0xff);
        result.append(to64(value, 4));
        value = ((digest[3] & 0xff) << 16) | ((digest[9] & 0xff) << 8) | (digest[15] & 0xff);
        result.append(to64(value, 4));
        value = ((digest[4] & 0xff) << 16) | ((digest[10] & 0xff) << 8) | (digest[5] & 0xff);
        result.append(to64(value, 4));
        value = digest[11] & 0xff;
        result.append(to64(value, 2));
        return result.toString();
    }
@SuppressWarnings("unused")
    private static int chkPasswd(final String sInputPwd, final String sSshaPwd) {
        assert sInputPwd != null;
        assert sSshaPwd != null;
        int r = ERR_LOGIN_ACCOUNT;
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] ba = decoder.decodeBuffer(sSshaPwd);
            assert ba.length >= FIXED_HASH_SIZE;
            byte[] hash = new byte[FIXED_HASH_SIZE];
            byte[] salt = new byte[FIXED_SALT_SIZE];
            System.arraycopy(ba, 0, hash, 0, FIXED_HASH_SIZE);
            System.arraycopy(ba, FIXED_HASH_SIZE, salt, 0, FIXED_SALT_SIZE);
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(sInputPwd.getBytes());
            md.update(salt);
            byte[] baPwdHash = md.digest();
            if (MessageDigest.isEqual(hash, baPwdHash)) {
                r = ERR_LOGIN_OK;
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        return r;
    }
public static String downloadWebVersionString(String address) {
        StringBuffer stb = new StringBuffer();
        URLConnection conn = null;
        InputStream in = null;
        try {
            URL url = new URL(address);
            conn = url.openConnection();
            in = conn.getInputStream();
            byte[] buffer = new byte[1024];
            int numRead;
            long numWritten = 0;
            while ((numRead = in.read(buffer)) != -1) {
                for (int i = 0; i < numRead; i++) {
                    stb.append((char) buffer[i]);
                }
                numWritten += numRead;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            return stb.toString();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ioe) {
            }
        }
        return stb.toString();
    }
public List<BadassEntry> parse() {
        mBadassEntries = new ArrayList<BadassEntry>();
        try {
            URL url = new URL(mUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setDoOutput(true);
            connection.connect();
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            boolean flag1 = false;
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (!flag1 && line.contains(START_PARSE)) flag1 = true;
                if (flag1 && line.contains(STOP_PARSE)) break;
                if (flag1) {
                    if (line.contains(ENTRY_HINT)) {
                        parseBadass(line);
                    }
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return mBadassEntries;
    }
public static InputStream downloadStream(URL url) {
        InputStream inputStream = null;
        try {
            URLConnection urlConnection = url.openConnection();
            if (urlConnection instanceof HttpURLConnection) {
                HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
                httpURLConnection.setFollowRedirects(true);
                httpURLConnection.setRequestMethod("GET");
                int responseCode = httpURLConnection.getResponseCode();
                if (responseCode != HttpURLConnection.HTTP_OK) return null;
            }
            return urlConnection.getInputStream();
        } catch (Exception ex) {
            try {
                inputStream.close();
            } catch (Exception ex1) {
            }
            return null;
        }
    }
public String setEncryptedPassword(String rawPassword) {
        String out = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(rawPassword.getBytes());
            byte raw[] = md.digest();
            out = new String();
            for (int x = 0; x < raw.length; x++) {
                String hex2 = Integer.toHexString((int) raw[x] & 0xFF);
                if (1 == hex2.length()) {
                    hex2 = "0" + hex2;
                }
                out += hex2;
                int a = 1;
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return out;
    }
void sortIds(int a[]) {
        ExecutionTimer t = new ExecutionTimer();
        t.start();
        for (int i = a.length; --i >= 0; ) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[j + 1]) {
                    int T = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = T;
                }
            }
        }
        t.end();
        TimerRecordFile timerFile = new TimerRecordFile("sort", "BufferSorting", "sortIds", t.duration());
    }
@Override
        protected Class<?> findClass(String name) throws ClassNotFoundException {
            String classFile = name.replace('.', '/') + ".class";
            InputStream classInputStream = null;
            for (JarFile java3DJar : this.java3DJars) {
                JarEntry jarEntry = java3DJar.getJarEntry(classFile);
                if (jarEntry != null) {
                    try {
                        classInputStream = java3DJar.getInputStream(jarEntry);
                    } catch (IOException ex) {
                        throw new ClassNotFoundException("Couldn't read class " + name, ex);
                    }
                }
            }
            if (classInputStream == null) {
                URL url = getResource(classFile);
                if (url == null) {
                    throw new ClassNotFoundException("Class " + name);
                }
                try {
                    classInputStream = url.openStream();
                } catch (IOException ex) {
                    throw new ClassNotFoundException("Couldn't read class " + name, ex);
                }
            }
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                BufferedInputStream in = new BufferedInputStream(classInputStream);
                byte[] buffer = new byte[8096];
                int size;
                while ((size = in.read(buffer)) != -1) {
                    out.write(buffer, 0, size);
                }
                in.close();
                return defineClass(name, out.toByteArray(), 0, out.size(), this.protectionDomain);
            } catch (IOException ex) {
                throw new ClassNotFoundException("Class " + name, ex);
            }
        }
public static String getTextFileFromURL(String urlName) {
        try {
            StringBuffer textFile = new StringBuffer("");
            String line = null;
            URL url = new URL(urlName);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((line = reader.readLine()) != null) textFile = textFile.append(line + "\n");
            reader.close();
            return textFile.toString();
        } catch (Exception e) {
            Debug.signal(Debug.ERROR, null, "Failed to open " + urlName + ", exception " + e);
            return null;
        }
    }
public boolean implies(Permission permission) {
        if (!permissionClass.isInstance(permission)) {
            return false;
        }
        GCFPermission perm = (GCFPermission) permission;
        int perm_low = perm.getMinPort();
        int perm_high = perm.getMaxPort();
        Enumeration search = permissions.elements();
        int count = permissions.size();
        int port_low[] = new int[count];
        int port_high[] = new int[count];
        int port_range_count = 0;
        while (search.hasMoreElements()) {
            GCFPermission cur_perm = (GCFPermission) search.nextElement();
            if (cur_perm.impliesByHost(perm)) {
                if (cur_perm.impliesByPorts(perm)) {
                    return true;
                }
                port_low[port_range_count] = cur_perm.getMinPort();
                port_high[port_range_count] = cur_perm.getMaxPort();
                port_range_count++;
            }
        }
        for (int i = 0; i < port_range_count; i++) {
            for (int j = 0; j < port_range_count - 1; j++) {
                if (port_low[j] > port_low[j + 1]) {
                    int tmp = port_low[j];
                    port_low[j] = port_low[j + 1];
                    port_low[j + 1] = tmp;
                    tmp = port_high[j];
                    port_high[j] = port_high[j + 1];
                    port_high[j + 1] = tmp;
                }
            }
        }
        int current_low = port_low[0];
        int current_high = port_high[0];
        for (int i = 1; i < port_range_count; i++) {
            if (port_low[i] > current_high + 1) {
                if (current_low <= perm_low && current_high >= perm_high) {
                    return true;
                }
                if (perm_low <= current_high) {
                    return false;
                }
                current_low = port_low[i];
                current_high = port_high[i];
            } else {
                if (current_high < port_high[i]) {
                    current_high = port_high[i];
                }
            }
        }
        return (current_low <= perm_low && current_high >= perm_high);
    }
@Override
    public void exec() {
        if (fileURI == null) return;
        InputStream is = null;
        try {
            if (fileURI.toLowerCase().startsWith("dbgp://")) {
                String uri = fileURI.substring(7);
                if (uri.toLowerCase().startsWith("file/")) {
                    uri = fileURI.substring(5);
                    is = new FileInputStream(new File(uri));
                } else {
                    XmldbURI pathUri = XmldbURI.create(URLDecoder.decode(fileURI.substring(15), "UTF-8"));
                    Database db = getJoint().getContext().getDatabase();
                    DBBroker broker = null;
                    try {
                        broker = db.getBroker();
                        DocumentImpl resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);
                        if (resource.getResourceType() == DocumentImpl.BINARY_FILE) {
                            is = broker.getBinaryResource((BinaryDocument) resource);
                        } else {
                            return;
                        }
                    } catch (EXistException e) {
                        exception = e;
                    } finally {
                        db.release(broker);
                    }
                }
            } else {
                URL url = new URL(fileURI);
                URLConnection conn = url.openConnection();
                is = conn.getInputStream();
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buf = new byte[256];
            int c;
            while ((c = is.read(buf)) > -1) {
                baos.write(buf, 0, c);
            }
            source = baos.toByteArray();
            success = true;
        } catch (MalformedURLException e) {
            exception = e;
        } catch (IOException e) {
            exception = e;
        } catch (PermissionDeniedException e) {
            exception = e;
        } finally {
            if (is != null) try {
                is.close();
            } catch (IOException e) {
                if (exception == null) exception = e;
            }
        }
    }
private static String encrypt(String password, String encryptType) {
        try {
            MessageDigest md = MessageDigest.getInstance(encryptType);
            md.update(password.getBytes());
            byte[] hash = md.digest();
            StringBuffer hexString = new StringBuffer();
            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]));
                }
            }
            password = hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return password.toUpperCase();
    }
public static void v2ljastaVeebileht(String s) throws IOException {
        URL url = new URL(s);
        InputStream is = url.openConnection().getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
    }
private void handleNodeUp(long eventID, long nodeID, String eventTime) {
        Category log = ThreadCategory.getInstance(OutageWriter.class);
        if (eventID == -1 || nodeID == -1) {
            log.warn(EventConstants.NODE_UP_EVENT_UEI + " ignored - info incomplete - eventid/nodeid: " + eventID + "/" + nodeID);
            return;
        }
        Connection dbConn = null;
        try {
            dbConn = DatabaseConnectionFactory.getInstance().getConnection();
            int count = 0;
            if (openOutageExists(dbConn, nodeID)) {
                try {
                    dbConn.setAutoCommit(false);
                } catch (SQLException sqle) {
                    log.error("Unable to change database AutoCommit to FALSE", sqle);
                    return;
                }
                PreparedStatement outageUpdater = dbConn.prepareStatement(OutageConstants.DB_UPDATE_OUTAGES_FOR_NODE);
                outageUpdater.setLong(1, eventID);
                outageUpdater.setTimestamp(2, convertEventTimeIntoTimestamp(eventTime));
                outageUpdater.setLong(3, nodeID);
                count = outageUpdater.executeUpdate();
                outageUpdater.close();
            } else {
                log.warn("\'" + EventConstants.NODE_UP_EVENT_UEI + "\' for " + nodeID + " no open record.");
            }
            try {
                dbConn.commit();
                if (log.isDebugEnabled()) log.debug("nodeUp closed " + count + " outages for nodeid " + nodeID + " in DB");
            } catch (SQLException se) {
                log.warn("Rolling back transaction, nodeUp could not be recorded  for nodeId: " + nodeID, se);
                try {
                    dbConn.rollback();
                } catch (SQLException sqle) {
                    log.warn("SQL exception during rollback, reason", sqle);
                }
            }
        } catch (SQLException se) {
            log.warn("SQL exception while handling \'nodeRegainedService\'", se);
        } finally {
            try {
                if (dbConn != null) dbConn.close();
            } catch (SQLException e) {
                log.warn("Exception closing JDBC connection", e);
            }
        }
    }
private void handleInterfaceUp(long eventID, long nodeID, String ipAddr, String eventTime) {
        Category log = ThreadCategory.getInstance(OutageWriter.class);
        if (eventID == -1 || nodeID == -1 || ipAddr == null) {
            log.warn(EventConstants.INTERFACE_UP_EVENT_UEI + " ignored - info incomplete - eventid/nodeid/ipAddr: " + eventID + "/" + nodeID + "/" + ipAddr);
            return;
        }
        Connection dbConn = null;
        try {
            dbConn = DatabaseConnectionFactory.getInstance().getConnection();
            if (openOutageExists(dbConn, nodeID, ipAddr)) {
                try {
                    dbConn.setAutoCommit(false);
                } catch (SQLException sqle) {
                    log.error("Unable to change database AutoCommit to FALSE", sqle);
                    return;
                }
                PreparedStatement outageUpdater = dbConn.prepareStatement(OutageConstants.DB_UPDATE_OUTAGES_FOR_INTERFACE);
                outageUpdater.setLong(1, eventID);
                outageUpdater.setTimestamp(2, convertEventTimeIntoTimestamp(eventTime));
                outageUpdater.setLong(3, nodeID);
                outageUpdater.setString(4, ipAddr);
                int count = outageUpdater.executeUpdate();
                outageUpdater.close();
                try {
                    dbConn.commit();
                    if (log.isDebugEnabled()) log.debug("handleInterfaceUp: interfaceUp closed " + count + " outages for nodeid/ip " + nodeID + "/" + ipAddr + " in DB");
                } catch (SQLException se) {
                    log.warn("Rolling back transaction, interfaceUp could not be recorded for nodeId/ipaddr: " + nodeID + "/" + ipAddr, se);
                    try {
                        dbConn.rollback();
                    } catch (SQLException sqle) {
                        log.warn("SQL exception during rollback, reason: ", sqle);
                    }
                }
            } else {
                log.warn("\'" + EventConstants.INTERFACE_UP_EVENT_UEI + "\' for " + nodeID + "/" + ipAddr + " ignored.");
            }
        } catch (SQLException se) {
            log.warn("SQL exception while handling \'interfaceUp\'", se);
        } finally {
            try {
                if (dbConn != null) dbConn.close();
            } catch (SQLException e) {
                log.warn("Exception closing JDBC connection", e);
            }
        }
    }