semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void main(String[] args) {
        Stopwatch.start("");
        HtmlParser parser = new HtmlParser();
        try {
            Stopwatch.printTimeReset("", "> ParserDelegator");
            ParserDelegator del = new ParserDelegator();
            Stopwatch.printTimeReset("", "> url");
            URL url = new URL(args[0]);
            Stopwatch.printTimeReset("", "> openStrem");
            InputStream is = url.openStream();
            Stopwatch.printTimeReset("", "< parse");
            del.parse(new InputStreamReader(is), parser, true);
            Stopwatch.printTimeReset("", "< parse");
        } catch (Throwable t) {
            t.printStackTrace();
        }
        Stopwatch.printTimeReset("", "> traversal");
        TreeTraversal.traverse(parser.startTag, "eachChild", new Function() {

            String lastPath = null;

            public void apply(Object obj) {
                if (obj instanceof String) {
                    System.out.print(lastPath + ":");
                    System.out.println(obj);
                    return;
                }
                Tag t = (Tag) obj;
                lastPath = Utils.tagPath(t);
                System.out.println(lastPath);
            }
        });
        Stopwatch.printTimeReset("", "< traversal");
    }
void copyFile(String from, String to) throws IOException {
            File destFile = new File(to);
            if (!destFile.exists()) {
                destFile.createNewFile();
            }
            FileChannel source = null;
            FileChannel destination = null;
            try {
                source = new FileInputStream(from).getChannel();
                destination = new FileOutputStream(destFile).getChannel();
                destination.transferFrom(source, 0, source.size());
            } finally {
                if (source != null) {
                    source.close();
                }
                if (destination != null) {
                    destination.close();
                }
            }
        }
public static void main(String[] args) throws Exception {
        String codecClassname = args[0];
        Class<?> codecClass = Class.forName(codecClassname);
        Configuration conf = new Configuration();
        CompressionCodec codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf);
        CompressionOutputStream out = codec.createOutputStream(System.out);
        IOUtils.copyBytes(System.in, out, 4096, false);
        out.finish();
    }
public static void main(String args[]) {
        String url = "jdbc:mySubprotocol:myDataSource";
        Connection con = null;
        Statement stmt;
        PreparedStatement updateSales;
        PreparedStatement updateTotal;
        String updateString = "update COFFEES " + "set SALES = ? where COF_NAME = ?";
        String updateStatement = "update COFFEES " + "set TOTAL = TOTAL + ? where COF_NAME = ?";
        String query = "select COF_NAME, SALES, TOTAL from COFFEES";
        try {
            Class.forName("myDriver.ClassName");
        } catch (java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");
            System.err.println(e.getMessage());
        }
        try {
            con = DriverManager.getConnection(url, "myLogin", "myPassword");
            updateSales = con.prepareStatement(updateString);
            updateTotal = con.prepareStatement(updateStatement);
            int[] salesForWeek = { 175, 150, 60, 155, 90 };
            String[] coffees = { "Colombian", "French_Roast", "Espresso", "Colombian_Decaf", "French_Roast_Decaf" };
            int len = coffees.length;
            con.setAutoCommit(false);
            for (int i = 0; i < len; i++) {
                updateSales.setInt(1, salesForWeek[i]);
                updateSales.setString(2, coffees[i]);
                updateSales.executeUpdate();
                updateTotal.setInt(1, salesForWeek[i]);
                updateTotal.setString(2, coffees[i]);
                updateTotal.executeUpdate();
                con.commit();
            }
            con.setAutoCommit(true);
            updateSales.close();
            updateTotal.close();
            stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next()) {
                String c = rs.getString("COF_NAME");
                int s = rs.getInt("SALES");
                int t = rs.getInt("TOTAL");
                System.out.println(c + "     " + s + "    " + t);
            }
            stmt.close();
            con.close();
        } catch (SQLException ex) {
            System.err.println("SQLException: " + ex.getMessage());
            if (con != null) {
                try {
                    System.err.print("Transaction is being ");
                    System.err.println("rolled back");
                    con.rollback();
                } catch (SQLException excep) {
                    System.err.print("SQLException: ");
                    System.err.println(excep.getMessage());
                }
            }
        }
    }
private void testConnection(String address) throws Exception {
        URL url = new URL(address);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setUseCaches(false);
        try {
            con.connect();
            assertEquals(HttpURLConnection.HTTP_OK, con.getResponseCode());
        } finally {
            con.disconnect();
        }
    }
public static String getSHA1Hash(String plainText) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA1");
        md.update(plainText.getBytes());
        byte[] mdbytes = md.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < mdbytes.length; i++) {
            String hex = Integer.toHexString(0xFF & mdbytes[i]);
            if (hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString().toUpperCase();
    }
public static void getCoverFromUrl(URL url, String directory) {
        try {
            url.openConnection();
            InputStream is = url.openStream();
            System.out.flush();
            FileOutputStream fos = null;
            fos = new FileOutputStream(directory);
            int oneChar, count = 0;
            while ((oneChar = is.read()) != -1) {
                fos.write(oneChar);
                count++;
            }
            is.close();
            fos.close();
        } catch (MalformedURLException e) {
            System.err.println(" getCoverFromUrl " + e.toString());
            e.printStackTrace();
        } catch (IOException e) {
            System.err.println(" getCoverFromUrl " + e.toString());
            e.printStackTrace();
        }
    }
public static void main(String[] args) {
        FTPClient client = new FTPClient();
        try {
            File l_file = new File("C:/temp/testLoribel.html");
            String l_url = "http://www.loribel.com/index.html";
            GB_HttpTools.loadUrlToFile(l_url, l_file, ENCODING.ISO_8859_1);
            System.out.println("Try to connect...");
            client.connect("ftp://ftp.phpnet.org");
            System.out.println("Connected to server");
            System.out.println("Try to connect...");
            boolean b = client.login("fff", "ddd");
            System.out.println("Login: " + b);
            String[] l_names = client.listNames();
            GB_DebugTools.debugArray(GB_FtpDemo2.class, "names", l_names);
            b = client.makeDirectory("test02/toto");
            System.out.println("Mkdir: " + b);
            String l_remote = "test02/test.xml";
            InputStream l_local = new StringInputStream("Test111111111111111");
            b = client.storeFile(l_remote, l_local);
            System.out.println("Copy file: " + b);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
public void update(String target, String cfgVersion) throws MalformedURLException, FileNotFoundException, IOException {
        Debug.log("Config Updater", "Checking for newer configuration...");
        URL url = new URL(target);
        String[] urlSplit = target.split("/");
        this.fileName = urlSplit[urlSplit.length - 1];
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(Main.getHomeDir() + "tmp-" + this.fileName));
        URLConnection urlConnection = url.openConnection();
        InputStream in = urlConnection.getInputStream();
        byte[] buffer = new byte[1024];
        int numRead;
        int fileSize = 0;
        while ((numRead = in.read(buffer)) != -1) {
            out.write(buffer, 0, numRead);
            fileSize += numRead;
        }
        Debug.log("Config Updater", "Read latest configuration: " + fileSize + " bytes");
        in.close();
        out.close();
        XMLController xmlC = new XMLController();
        String newFileVersion = xmlC.readCfgVersion(Main.getHomeDir() + "tmp-" + this.fileName);
        if (new File(Main.getHomeDir() + this.fileName).exists()) {
            Debug.log("Config Updater", "Local configfile '" + Main.getHomeDir() + this.fileName + "' exists (version " + cfgVersion + ")");
            if (Double.parseDouble(newFileVersion) > Double.parseDouble(cfgVersion)) {
                Debug.log("Config Updater", "Removing old config and replacing it with version " + newFileVersion);
                new File(Main.getHomeDir() + this.fileName).delete();
                new File(Main.getHomeDir() + "tmp-" + this.fileName).renameTo(new File(Main.getHomeDir() + this.fileName));
                this.result = "ConfigFile upgraded to version " + newFileVersion;
            } else {
                new File(Main.getHomeDir() + "tmp-" + this.fileName).delete();
                Debug.log("Config Updater", "I already have the latest version " + cfgVersion);
            }
        } else {
            Debug.log("Config Updater", "Local config doesn't exist. Loading the new one, version " + newFileVersion);
            new File(Main.getHomeDir() + "tmp-" + this.fileName).renameTo(new File(Main.getHomeDir() + this.fileName));
            this.result = "ConfigFile upgraded to version " + newFileVersion;
        }
        Debug.log("Config Updater", "Update of configuration done");
    }
private static MappedObject sendHttpRequestToUrl(URL url, String method) throws Exception {
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod(method);
            connection.connect();
            InputStream is = connection.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder buffer = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
            }
            System.out.println("Read: " + buffer.toString());
            connection.disconnect();
            JAXBContext context = JAXBContext.newInstance(MappedObject.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            MappedObject mapped = (MappedObject) unmarshaller.unmarshal(new StringReader(buffer.toString()));
            return mapped;
        } catch (IOException e) {
            e.printStackTrace();
        }
        throw new Exception("Could not establish connection to " + url.toExternalForm());
    }
public static String installOvalDefinitions(final String xml_location) {
        InputStream in_stream = null;
        try {
            URL url = _toURL(xml_location);
            if (url == null) {
                in_stream = new FileInputStream(xml_location);
            } else {
                in_stream = url.openStream();
            }
        } catch (IOException ex) {
            throw new OvalException(ex);
        }
        Class<OvalDefinitions> type = OvalDefinitions.class;
        OvalDefinitions object = _unmarshalObject(type, in_stream);
        String pid = _getDatastore().save(type, object);
        return pid;
    }
public static String getPageSource(String url) throws ClientProtocolException, IOException {
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(url);
        HttpResponse response = client.execute(request);
        InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder source = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) source.append(line);
        in.close();
        return source.toString();
    }
public Object[] bubblesort(Object[] tosort) {
        Boolean sorting;
        int upperlimit = tosort.length - 1;
        do {
            sorting = false;
            for (int s0 = 0; s0 < upperlimit; s0++) {
                if (tosort[s0].toString().compareTo(tosort[s0 + 1].toString()) < 0) {
                } else if (tosort[s0].toString().compareTo(tosort[s0 + 1].toString()) == 0) {
                    Object[] tosortnew = new Object[tosort.length - 1];
                    for (int tmp = 0; tmp < s0; tmp++) {
                        tosortnew[tmp] = tosort[tmp];
                    }
                    for (int tmp = s0; tmp < tosortnew.length; tmp++) {
                        tosortnew[tmp] = tosort[tmp + 1];
                    }
                    tosort = tosortnew;
                    upperlimit = upperlimit - 1;
                    s0 = s0 - 1;
                } else if (tosort[s0].toString().compareTo(tosort[s0 + 1].toString()) > 0) {
                    String swap = (String) tosort[s0];
                    tosort[s0] = tosort[s0 + 1];
                    tosort[s0 + 1] = swap;
                    sorting = true;
                }
            }
            upperlimit = upperlimit - 1;
        } while (sorting);
        return tosort;
    }
public static String SHA1(String text) {
        byte[] sha1hash = new byte[40];
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(text.getBytes("iso-8859-1"), 0, text.length());
            sha1hash = md.digest();
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Converter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Converter.class.getName()).log(Level.SEVERE, null, ex);
        }
        return convertToHex(sha1hash);
    }
public byte[] generatePassword(String clave) {
        byte[] password = { 00 };
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(clave.getBytes());
            password = md5.digest();
            return password;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return password;
    }
public static final void connectExecuteDisconnect(String url, HttpProcess<?> process) throws IOException {
        URL urlObj = null;
        HttpURLConnection urlCon = null;
        try {
            urlObj = new URL(url);
            urlCon = (HttpURLConnection) urlObj.openConnection();
            process.apply(urlCon);
        } finally {
            disconnect(urlCon);
        }
    }
@Deprecated
    public static void getAndProcessContents(String videoPageURL, int bufsize, String charset, Closure<String> process) throws IOException {
        URL url = null;
        HttpURLConnection connection = null;
        InputStream is = null;
        InputStreamReader isr = null;
        BufferedReader br = null;
        try {
            url = new URL(videoPageURL);
            connection = (HttpURLConnection) url.openConnection();
            is = connection.getInputStream();
            isr = new InputStreamReader(is, charset);
            br = new BufferedReader(isr);
            for (String line = br.readLine(); line != null; line = br.readLine()) {
                process.exec(line);
            }
        } finally {
            Closeables.closeQuietly(br);
            Closeables.closeQuietly(isr);
            Closeables.closeQuietly(is);
            HttpUtils.disconnect(connection);
        }
    }
public String grabId(String itemName) throws Exception {
        StringBuffer modified = new StringBuffer(itemName);
        for (int i = 0; i <= modified.length() - 1; i++) {
            char ichar = modified.charAt(i);
            if (ichar == ' ') modified = modified.replace(i, i + 1, "+");
        }
        itemName = modified.toString();
        try {
            URL url = new URL(searchURL + itemName);
            InputStream urlStream = url.openStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream, "UTF-8"));
            while (reader.ready()) {
                String htmlLine = reader.readLine();
                int indexOfSearchStart = htmlLine.indexOf(searchForItemId);
                if (indexOfSearchStart != -1) {
                    int idStart = htmlLine.indexOf("=", indexOfSearchStart);
                    idStart++;
                    int idEnd = htmlLine.indexOf("'", idStart);
                    id = htmlLine.substring(idStart, idEnd);
                }
            }
            if (id == "") return null; else return id;
        } catch (Exception ex) {
            System.out.println("Exception in lookup: " + ex);
            throw (ex);
        }
    }
private void LoadLoginInfo() {
        m_PwdList.removeAllElements();
        String szTemp = null;
        int iIndex = 0;
        int iSize = m_UsrList.size();
        for (int i = 0; i < iSize; i++) m_PwdList.add("");
        try {
            if ((m_UsrList.size() > 0) && m_bSavePwd) {
                char[] MD5PWD = new char[80];
                java.util.Arrays.fill(MD5PWD, (char) 0);
                java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-1");
                String szPath = System.getProperty("user.home");
                szPath += System.getProperty("file.separator") + "MochaJournal" + System.getProperty("file.separator") + "user.dat";
                java.io.File file = new java.io.File(szPath);
                if (file.exists()) {
                    java.io.FileInputStream br = new java.io.FileInputStream(file);
                    byte[] szEncryptPwd = null;
                    int iLine = 0;
                    while (br.available() > 0) {
                        md.reset();
                        md.update(((String) m_UsrList.get(iLine)).getBytes());
                        byte[] DESUSR = md.digest();
                        byte alpha = 0;
                        for (int i2 = 0; i2 < DESUSR.length; i2++) alpha += DESUSR[i2];
                        iSize = br.read();
                        if (iSize > 0) {
                            szEncryptPwd = new byte[iSize];
                            br.read(szEncryptPwd);
                            char[] cPwd = new char[iSize];
                            for (int i = 0; i < iSize; i++) {
                                int iChar = (int) szEncryptPwd[i] - (int) alpha;
                                if (iChar < 0) iChar += 256;
                                cPwd[i] = (char) iChar;
                            }
                            m_PwdList.setElementAt(new String(cPwd), iLine);
                        }
                        iLine++;
                    }
                }
            }
        } catch (java.security.NoSuchAlgorithmException e) {
            System.err.println(e);
        } catch (java.io.IOException e3) {
            System.err.println(e3);
        }
    }
private void SaveLoginInfo() {
        int iSize;
        try {
            if (m_bSavePwd) {
                byte[] MD5PWD = new byte[80];
                java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-1");
                String szPath = System.getProperty("user.home");
                szPath += System.getProperty("file.separator") + "MochaJournal";
                java.io.File file = new java.io.File(szPath);
                if (!file.exists()) file.mkdirs();
                file = new java.io.File(file, "user.dat");
                if (!file.exists()) file.createNewFile();
                java.io.FileOutputStream pw = new java.io.FileOutputStream(file);
                iSize = m_PwdList.size();
                for (int iIndex = 0; iIndex < iSize; iIndex++) {
                    md.reset();
                    md.update(((String) m_UsrList.get(iIndex)).getBytes());
                    byte[] DESUSR = md.digest();
                    byte alpha = 0;
                    for (int i = 0; i < DESUSR.length; i++) alpha += DESUSR[i];
                    String pwd = (String) m_PwdList.get(iIndex);
                    if (pwd.length() > 0) {
                        java.util.Arrays.fill(MD5PWD, (byte) 0);
                        int iLen = pwd.length();
                        pw.write(iLen);
                        for (int i = 0; i < iLen; i++) {
                            int iDiff = (int) pwd.charAt(i) + (int) alpha;
                            int c = iDiff % 256;
                            MD5PWD[i] = (byte) c;
                            pw.write((byte) c);
                        }
                    } else pw.write(0);
                }
                pw.flush();
            }
        } catch (java.security.NoSuchAlgorithmException e) {
            System.err.println(e);
        } catch (java.io.IOException e3) {
            System.err.println(e3);
        }
    }
public void saveHiddenNames(HashSet names) throws SQLException {
        Connection conn = AppLayerDatabase.getInstance().getPooledConnection();
        PreparedStatement ps = null;
        try {
            conn.setAutoCommit(false);
            Statement stmt = conn.createStatement();
            stmt.executeUpdate("DELETE FROM HIDDENBOARDNAMES");
            stmt.close();
            stmt = null;
            ps = conn.prepareStatement("INSERT INTO HIDDENBOARDNAMES (boardname) VALUES (?)");
            for (Iterator i = names.iterator(); i.hasNext(); ) {
                String bName = (String) i.next();
                ps.setString(1, bName);
                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);
            try {
                if (ps != null) ps.close();
            } catch (Throwable t1) {
            }
            ;
        }
    }
public void alterar(Cliente cliente) throws Exception {
        Connection connection = criaConexao(false);
        String sql = "update cliente set nome = ?, sexo = ?, cod_cidade = ? where cod_cliente = ?";
        PreparedStatement stmt = null;
        try {
            stmt = connection.prepareStatement(sql);
            stmt.setString(1, cliente.getNome());
            stmt.setString(2, cliente.getSexo());
            stmt.setInt(3, cliente.getCidade().getCodCidade());
            stmt.setLong(4, cliente.getId());
            int retorno = stmt.executeUpdate();
            if (retorno == 0) {
                connection.rollback();
                throw new SQLException("Ocorreu um erro inesperado no momento de alterar dados de cliente no banco!");
            }
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            throw e;
        } finally {
            try {
                stmt.close();
                this.fechaConexao();
            } catch (SQLException e) {
                throw e;
            }
        }
    }