semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public HostRecord addressForHost(String domainName) throws Exception {
        String fullUrl = requestUrlStub + domainName;
        URL url = new URL(fullUrl);
        HttpURLConnection connection = null;
        connection = null;
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setDoOutput(true);
        connection.setReadTimeout(10000);
        connection.connect();
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String inputLine;
        HostRecord result = new HostRecord(domainName);
        byte parts[] = new byte[4];
        while ((inputLine = in.readLine()) != null) {
            String pat1 = "<span class='orange'>";
            String pat2 = "</span>";
            int index1 = inputLine.indexOf(pat1);
            int index2 = inputLine.indexOf(pat2);
            if ((index1 > 0) && (index2 > 0)) {
                String ipStr = inputLine.substring(index1 + pat1.length(), index2);
                String[] s = ipStr.split("\\.");
                for (int i = 0; i < s.length; i++) parts[i] = (byte) Integer.parseInt(s[i]);
            }
        }
        IPAddress ipAddress = new IPAddress(parts);
        result.addIpAddress(ipAddress);
        in.close();
        return result;
    }
private void saveFile(InputStream in, String fullPath) {
        try {
            File sysfile = new File(fullPath);
            if (!sysfile.exists()) {
                sysfile.createNewFile();
            }
            java.io.OutputStream out = new FileOutputStream(sysfile);
            org.apache.commons.io.IOUtils.copy(in, out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public InputStream getResourceAsStream(String name) {
        try {
            URL url = getResource(name);
            System.out.println("Loading \"" + url + "\"...");
            URLConnection urlConnection = url.openConnection();
            if (urlConnection instanceof HttpURLConnection) {
                HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
                httpURLConnection.setFollowRedirects(true);
                httpURLConnection.setRequestMethod("GET");
                int responseCode = httpURLConnection.getResponseCode();
                System.out.println(httpURLConnection.getResponseMessage() + ", " + httpURLConnection.getContentLength() + " bytes" + ", " + new Date(httpURLConnection.getDate()) + ", " + new Date(httpURLConnection.getLastModified()));
                if (responseCode != HttpURLConnection.HTTP_OK) {
                    return null;
                }
            }
            return urlConnection.getInputStream();
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
public static String hash(String toEncripty) {
        if (toEncripty != null) {
            try {
                synchronized (toEncripty) {
                    MessageDigest md = MessageDigest.getInstance("MD5");
                    md.update(toEncripty.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]));
                    }
                    toEncripty = hexString.toString();
                }
            } catch (Exception e) {
                e.getMessage();
            }
        }
        return toEncripty;
    }
public String getNextObjectId() throws SQLException {
        long nextserial = 1;
        String s0 = "lock table serials in exclusive mode";
        String s1 = "SELECT nextserial FROM serials WHERE tablename = 'SERVER_OIDS'";
        String s2;
        try {
            Statement stmt = dbconnect.connection.createStatement();
            stmt.executeUpdate(s0);
            ResultSet rs = stmt.executeQuery(s1);
            if (!rs.next()) {
                s2 = "insert into serials (tablename,nextserial) values ('SERVER_OIDS', " + (nextserial) + ")";
            } else {
                nextserial = rs.getLong(1) + 1;
                s2 = "update serials set nextserial=" + (nextserial) + " where tablename='SERVER_OIDS'";
            }
            stmt.executeUpdate(s2);
            dbconnect.connection.commit();
            rs.close();
            stmt.close();
            return "" + nextserial;
        } catch (SQLException e) {
            dbconnect.connection.rollback();
            throw e;
        }
    }
private byte[] hash(String toHash) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5", "BC");
            md5.update(toHash.getBytes("ISO-8859-1"));
            return md5.digest();
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
public static void copy(File src, File dst) throws IOException {
        FileChannel srcChannel = new FileInputStream(src).getChannel();
        FileChannel dstChannel = new FileOutputStream(dst).getChannel();
        try {
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        } finally {
            try {
                srcChannel.close();
            } finally {
                dstChannel.close();
            }
        }
    }
public ProgramProfilingMessageSymbol createNewProfilingMessageSymbol(int configID, int programMessageSymbolID) throws AdaptationException {
        ProgramProfilingMessageSymbol profilingMessageSymbol = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            String query = "INSERT INTO ProgramProfilingMessageSymbols" + "(projectDeploymentConfigurationID, programMessageSymbolID)" + " VALUES (" + configID + ", " + programMessageSymbolID + ")";
            connection = DriverManager.getConnection(CONN_STR);
            statement = connection.createStatement();
            statement.executeUpdate(query);
            query = "SELECT * FROM ProgramProfilingMessageSymbols WHERE " + "projectDeploymentConfigurationID = " + configID + " AND " + "programMessageSymbolID           = " + programMessageSymbolID;
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to create program profiling message " + "symbol failed.";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            profilingMessageSymbol = getProfilingMessageSymbol(resultSet);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in createNewProfilingMessageSymbol";
            log.error(msg, ex);
            throw new AdaptationException(msg, ex);
        } finally {
            try {
                resultSet.close();
            } catch (Exception ex) {
            }
            try {
                statement.close();
            } catch (Exception ex) {
            }
            try {
                connection.close();
            } catch (Exception ex) {
            }
        }
        return profilingMessageSymbol;
    }
public ProgramProfilingMessageSymbol deleteProfilingMessageSymbol(int id) throws AdaptationException {
        ProgramProfilingMessageSymbol profilingMessageSymbol = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            String query = "SELECT * FROM ProgramProfilingMessageSymbols " + "WHERE id = " + id;
            connection = DriverManager.getConnection(CONN_STR);
            statement = connection.createStatement();
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to delete program profiling message " + "symbol failed.";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            profilingMessageSymbol = getProfilingMessageSymbol(resultSet);
            query = "DELETE FROM ProgramProfilingMessageSymbols " + "WHERE id = " + id;
            statement.executeUpdate(query);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in deleteProfilingMessageSymbol";
            log.error(msg, ex);
            throw new AdaptationException(msg, ex);
        } finally {
            try {
                resultSet.close();
            } catch (Exception ex) {
            }
            try {
                statement.close();
            } catch (Exception ex) {
            }
            try {
                connection.close();
            } catch (Exception ex) {
            }
        }
        return profilingMessageSymbol;
    }
public File getFile(String file) {
        DirProperties dp;
        List files = new ArrayList();
        for (int i = 0; i < locs.size(); i++) {
            dp = (DirProperties) locs.get(i);
            if (dp.isReadable()) {
                File g = new File(dp.getLocation() + slash() + file);
                if (g.exists()) files.add(g);
            }
        }
        if (files.size() == 0) {
            throw new UnsupportedOperationException("at least one DirProperty should get 'read=true'");
        } else if (files.size() == 1) {
            return (File) files.get(0);
        } else {
            File fromFile = (File) files.get(files.size() - 2);
            File toFile = (File) files.get(files.size() - 1);
            byte reading[] = new byte[2024];
            try {
                FileInputStream stream = new FileInputStream(fromFile);
                FileOutputStream outStr = new FileOutputStream(toFile);
                while (stream.read(reading) != -1) {
                    outStr.write(reading);
                }
            } catch (FileNotFoundException ex) {
                getLogger().severe("FileNotFound: while copying from " + fromFile + " to " + toFile);
            } catch (IOException ex) {
                getLogger().severe("IOException: while copying from " + fromFile + " to " + toFile);
            }
            return toFile;
        }
    }
public static String encodeFromFile(String filename) throws java.io.IOException, URISyntaxException {
        String encodedData = null;
        Base641.InputStream bis = null;
        File file;
        try {
            URL url = new URL(filename);
            URLConnection conn = url.openConnection();
            file = new File("myfile.doc");
            java.io.InputStream inputStream = (java.io.InputStream) conn.getInputStream();
            FileOutputStream out = new FileOutputStream(file);
            byte buf[] = new byte[1024];
            int len;
            while ((len = inputStream.read(buf)) > 0) out.write(buf, 0, len);
            out.close();
            inputStream.close();
            byte[] buffer = new byte[Math.max((int) (file.length() * 1.4), 40)];
            int length = 0;
            int numBytes = 0;
            bis = new Base641.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)), Base641.ENCODE);
            while ((numBytes = bis.read(buffer, length, 4096)) >= 0) {
                length += numBytes;
            }
            encodedData = new String(buffer, 0, length, Base641.PREFERRED_ENCODING);
        } catch (java.io.IOException e) {
            throw e;
        } finally {
            try {
                bis.close();
            } catch (Exception e) {
            }
        }
        return encodedData;
    }
public int doEndTag() throws JspException {
        JspWriter saida = pageContext.getOut();
        HttpURLConnection urlConnection = null;
        try {
            URL requisicao = new URL(((HttpServletRequest) pageContext.getRequest()).getRequestURL().toString());
            URL link = new URL(requisicao, url);
            urlConnection = (HttpURLConnection) link.openConnection();
            BufferedReader entrada = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "ISO-8859-1"));
            String linha = entrada.readLine();
            while (linha != null) {
                saida.write(linha + "\n");
                linha = entrada.readLine();
            }
            entrada.close();
        } catch (Exception e) {
            try {
                saida.write("Erro ao incluir o conte�do da URL \"" + url + "\"");
            } catch (IOException e1) {
            }
        } finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
        }
        return super.doEndTag();
    }
private void putAlgosFromJar(File jarfile, AlgoDir dir, Model model) throws FileNotFoundException, IOException {
        URLClassLoader urlLoader = new URLClassLoader(new URL[] { jarfile.toURI().toURL() });
        JarInputStream jis = new JarInputStream(new FileInputStream(jarfile));
        JarEntry entry = jis.getNextJarEntry();
        String name = null;
        String tmpdir = System.getProperty("user.dir") + File.separator + Application.getProperty("dir.tmp") + File.separator;
        byte[] buffer = new byte[1000];
        while (entry != null) {
            name = entry.getName();
            if (name.endsWith(".class")) {
                name = name.substring(0, name.length() - 6);
                name = name.replace('/', '.');
                try {
                    Class<?> cls = urlLoader.loadClass(name);
                    if (IAlgorithm.class.isAssignableFrom(cls) && !cls.isInterface() && ((cls.getModifiers() & Modifier.ABSTRACT) == 0)) {
                        dir.addAlgorithm(cls);
                        model.putClass(cls.getName(), cls);
                    } else if (ISerializable.class.isAssignableFrom(cls)) {
                        model.putClass(cls.getName(), cls);
                    }
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } else if (Constants.isAllowedImageType(name)) {
                int lastSep = name.lastIndexOf("/");
                if (lastSep != -1) {
                    String dirs = tmpdir + name.substring(0, lastSep);
                    File d = new File(dirs);
                    if (!d.exists()) d.mkdirs();
                }
                String filename = tmpdir + name;
                File f = new File(filename);
                if (!f.exists()) {
                    f.createNewFile();
                    FileOutputStream fos = new FileOutputStream(f);
                    int read = -1;
                    while ((read = jis.read(buffer)) != -1) {
                        fos.write(buffer, 0, read);
                    }
                    fos.close();
                }
            }
            entry = jis.getNextJarEntry();
        }
    }
public static void copyFile(File sourceFile, File destFile) throws IOException {
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }
public String login() {
        String authSuccess = "false";
        try {
            String errorMesg = "";
            int error;
            if ((error = utils.stringIsNull(passwd)) != -1) {
                errorMesg += rb.getString("passwdField") + ": " + utils.errors[error] + " ";
            } else if ((error = utils.stringIsEmpty(passwd)) != -1) {
                errorMesg += rb.getString("passwdField") + ": " + utils.errors[error] + " ";
            }
            if ((error = utils.stringIsNull(login)) != -1) {
                errorMesg += rb.getString("loginField") + ": " + utils.errors[error] + " ";
            } else if ((error = utils.stringIsEmpty(login)) != -1) {
                errorMesg += rb.getString("loginField") + ": " + utils.errors[error] + " ";
            }
            String[] admins = conf.getProperty("admin").split("\\s");
            boolean admin = false;
            for (int i = 0; i < admins.length; i++) {
                if (admins[i].equals(login)) {
                    admin = true;
                }
            }
            if (!admin) {
                errorMesg += rb.getString("noAdmin");
                session.invalidate();
            } else {
                session.setAttribute("conf", conf);
            }
            if (errorMesg.length() > 0) {
                status = errorMesg;
                System.out.println(status);
                FacesContext context = FacesContext.getCurrentInstance();
                context.renderResponse();
            } else {
                MessageDigest md5 = MessageDigest.getInstance("MD5");
                md5.reset();
                md5.update(passwd.getBytes());
                byte[] result = md5.digest();
                StringBuffer hexString = new StringBuffer();
                for (int i = 0; i < result.length; i++) {
                    String hex = Integer.toHexString(0xFF & result[i]);
                    if (hex.length() == 1) {
                        hexString.append('0');
                    }
                    hexString.append(hex);
                }
                authSuccess = (sqlManager.getPassword(login).equals(hexString.toString())) ? "true" : "false";
                if (authSuccess.equals("false")) session.invalidate();
            }
        } catch (NoSuchAlgorithmException nsae) {
            utils.catchExp(nsae);
            status = utils.getStatus();
            if (stacktrace) {
                stackTrace = utils.getStackTrace();
            }
            FacesContext.getCurrentInstance().renderResponse();
        } catch (SQLException sqle) {
            utils.catchExp(sqle);
            status = utils.getStatus();
            if (stacktrace) {
                stackTrace = utils.getStackTrace();
            }
            FacesContext.getCurrentInstance().renderResponse();
        }
        return authSuccess;
    }
public static String getEncodedHex(String text) {
        MessageDigest md = null;
        String encodedString = null;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(text.getBytes());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        Hex hex = new Hex();
        encodedString = new String(hex.encode(md.digest()));
        md.reset();
        return encodedString;
    }
private boolean copyFile(File inFile, File outFile) {
        BufferedReader reader = null;
        BufferedWriter writer = null;
        try {
            reader = new BufferedReader(new FileReader(inFile));
            writer = new BufferedWriter(new FileWriter(outFile));
            while (reader.ready()) {
                writer.write(reader.read());
            }
            writer.flush();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                    return false;
                }
            }
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException ex) {
                    return false;
                }
            }
        }
        return true;
    }
private String generateHash(String key, String data) throws ChiropteraException {
        try {
            MessageDigest md = MessageDigest.getInstance(Constants.Connection.Auth.MD5);
            md.update(key.getBytes());
            byte[] raw = md.digest();
            String s = toHexString(raw);
            SecretKey skey = new SecretKeySpec(s.getBytes(), Constants.Connection.Auth.HMACMD5);
            Mac mac = Mac.getInstance(skey.getAlgorithm());
            mac.init(skey);
            byte digest[] = mac.doFinal(data.getBytes());
            String digestB64 = BaculaBase64.binToBase64(digest);
            return digestB64.substring(0, digestB64.length());
        } catch (NoSuchAlgorithmException e) {
            throw new ChiropteraException(Constants.Chiroptera.Errors.HASH, e.getMessage(), e);
        } catch (InvalidKeyException e) {
            throw new ChiropteraException(Constants.Chiroptera.Errors.HASH, e.getMessage(), e);
        }
    }
public static String hash(String string, String algorithm, String encoding) throws UnsupportedEncodingException {
        try {
            MessageDigest digest = MessageDigest.getInstance(algorithm);
            digest.update(string.getBytes(encoding));
            byte[] encodedPassword = digest.digest();
            return new BigInteger(1, encodedPassword).toString(16);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
public static String mysqlPasswordHash(String string) {
        try {
            MessageDigest digest = MessageDigest.getInstance(HashAlgorithms.SHA1);
            try {
                digest.update(string.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
            byte[] encodedPassword = digest.digest();
            digest.update(encodedPassword);
            encodedPassword = digest.digest();
            String hash = new BigInteger(1, encodedPassword).toString(16).toUpperCase();
            while (hash.length() < 40) {
                hash = "0" + hash;
            }
            return "*" + hash;
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
public String readPage(boolean ignoreComments) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String inputLine;
        String html = "";
        if (ignoreComments) {
            while ((inputLine = in.readLine()) != null) {
                if (inputLine.length() > 0) {
                    if (inputLine.substring(0, 1).compareTo("#") != 0) {
                        html = html + inputLine + "\n";
                    }
                }
            }
        } else {
            while ((inputLine = in.readLine()) != null) {
                html = html + inputLine + "\n";
            }
        }
        in.close();
        return html;
    }
public boolean updatenum(int num, String pid) {
        boolean flag = false;
        Connection conn = null;
        PreparedStatement pm = null;
        try {
            conn = Pool.getConnection();
            conn.setAutoCommit(false);
            pm = conn.prepareStatement("update addwuliao set innum=? where pid=?");
            pm.setInt(1, num);
            pm.setString(2, pid);
            int a = pm.executeUpdate();
            if (a == 0) {
                flag = false;
            } else {
                flag = true;
            }
            conn.commit();
            Pool.close(pm);
            Pool.close(conn);
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            Pool.close(pm);
            Pool.close(conn);
        } finally {
            Pool.close(pm);
            Pool.close(conn);
        }
        return flag;
    }