semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
void loadImage(final int runnumber, final String surl, final StatusCallback status) {
        Runnable run = new Runnable() {

            public void run() {
                try {
                    if (sync == SyncType.SyncSpaced || sync == SyncType.Spaced) {
                        Thread.sleep(spaceMillis);
                    }
                    URL url = new URL(surl + "&requestId=" + runnumber);
                    long t0 = System.currentTimeMillis();
                    InputStream in = url.openStream();
                    transfer(in, new FileOutputStream(new File(outputFolder, "" + runnumber + ".png")));
                    BufferedImage image = ImageIO.read(new File(outputFolder, "" + runnumber + ".png"));
                    status.score(runnumber, System.currentTimeMillis() - t0);
                    ImageIO.write(image, "png", new FileOutputStream(new File(outputFolder, "" + runnumber + ".png")));
                    if (false) {
                        int whiteCount = 0;
                        for (int i = 0; i < image.getWidth(); i++) {
                            for (int j = 0; j < image.getHeight(); j++) {
                                whiteCount += image.getRGB(i, j) == -1 ? 1 : 0;
                            }
                        }
                        System.err.println("##" + runnumber + "#: " + whiteCount);
                        if (whiteCount < 227564) {
                            System.err.println("whiteCount fails!!!!");
                            System.err.println("whiteCount fails!!!!");
                            System.exit(0);
                        }
                    }
                } catch (Exception ex) {
                    System.err.println("##" + runnumber + "#: Exception!!! ###");
                    ex.printStackTrace();
                    status.score(runnumber, -999);
                }
            }
        };
        if (sync == SyncType.SyncSpaced || sync == SyncType.Sync) {
            run.run();
        } else {
            new Thread(run).start();
        }
    }
public void run() {
                try {
                    if (sync == SyncType.SyncSpaced || sync == SyncType.Spaced) {
                        Thread.sleep(spaceMillis);
                    }
                    URL url = new URL(surl + "&requestId=" + runnumber);
                    long t0 = System.currentTimeMillis();
                    InputStream in = url.openStream();
                    transfer(in, new FileOutputStream(new File(outputFolder, "" + runnumber + ".png")));
                    BufferedImage image = ImageIO.read(new File(outputFolder, "" + runnumber + ".png"));
                    status.score(runnumber, System.currentTimeMillis() - t0);
                    ImageIO.write(image, "png", new FileOutputStream(new File(outputFolder, "" + runnumber + ".png")));
                    if (false) {
                        int whiteCount = 0;
                        for (int i = 0; i < image.getWidth(); i++) {
                            for (int j = 0; j < image.getHeight(); j++) {
                                whiteCount += image.getRGB(i, j) == -1 ? 1 : 0;
                            }
                        }
                        System.err.println("##" + runnumber + "#: " + whiteCount);
                        if (whiteCount < 227564) {
                            System.err.println("whiteCount fails!!!!");
                            System.err.println("whiteCount fails!!!!");
                            System.exit(0);
                        }
                    }
                } catch (Exception ex) {
                    System.err.println("##" + runnumber + "#: Exception!!! ###");
                    ex.printStackTrace();
                    status.score(runnumber, -999);
                }
            }
@SuppressWarnings("unused")
    private String getMD5(String value) {
        MessageDigest md5;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            return "";
        }
        md5.reset();
        md5.update(value.getBytes());
        byte[] messageDigest = md5.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
        }
        String hashedPassword = hexString.toString();
        return hashedPassword;
    }
public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Specify name of the file, just one entry per line");
            System.exit(0);
        }
        File inFile = new File(args[0]);
        BufferedReader myBR = null;
        File outFile = new File(args[0] + ".xml");
        BufferedWriter myBW = null;
        try {
            myBR = new BufferedReader(new FileReader(inFile));
            myBW = new BufferedWriter(new FileWriter(outFile));
        } catch (Exception ex) {
            System.out.println("IN: " + inFile.getAbsolutePath());
            System.out.println("OUT: " + outFile.getAbsolutePath());
            ex.printStackTrace();
            System.exit(0);
        }
        try {
            String readLine;
            while ((readLine = myBR.readLine()) != null) {
                myBW.write("<dbColumn name=\"" + readLine + "\" display=\"" + readLine + "\" panel=\"CENTER\"  >");
                myBW.write("\n");
                myBW.write("<dbType name=\"text\" maxVal=\"10\" defaultVal=\"\" sizeX=\"5\"/>");
                myBW.write("\n");
                myBW.write("</dbColumn>");
                myBW.write("\n");
            }
            myBW.close();
            myBR.close();
        } catch (Exception ex) {
            ex.printStackTrace();
            System.exit(0);
        }
        System.out.println("OUT: " + outFile.getAbsolutePath());
        System.out.println("erzeugt");
    }
protected URLConnection getConnection(String uri, String data) throws MalformedURLException, IOException {
        URL url = new URL(uri);
        URLConnection conn = url.openConnection();
        conn.setConnectTimeout((int) MINUTE / 2);
        conn.setReadTimeout((int) MINUTE / 2);
        return conn;
    }
void acessResource(ClassLoader cl, String resource) throws IOException {
        URL url = cl.getResource(resource);
        if (url == null) {
            println("Ups can't find resource " + resource);
        } else {
            println("URL OK " + resource + " ->" + url);
            InputStream is = url.openStream();
            try {
                is.read();
            } finally {
                is.close();
            }
            println("Read OK " + resource + " ->" + url);
        }
    }
private List<String[]> retrieveData(String query) {
        List<String[]> data = new Vector<String[]>();
        query = query.replaceAll("\\s", "+");
        String q = "http://www.uniprot.org/uniprot/?query=" + query + "&format=tab&columns=id,protein%20names,organism";
        try {
            URL url = new URL(q);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = "";
            reader.readLine();
            while ((line = reader.readLine()) != null) {
                String[] st = line.split("\t");
                String[] d = new String[] { st[0], st[1], st[2] };
                data.add(d);
            }
            reader.close();
            if (data.size() == 0) {
                JOptionPane.showMessageDialog(this, "No data found for query");
            }
        } catch (MalformedURLException e) {
            System.err.println("Query " + q + " caused exception: ");
            e.printStackTrace();
        } catch (Exception e) {
            System.err.println("Query " + q + " caused exception: ");
            e.printStackTrace();
        }
        return data;
    }
public void add(Site site) throws Exception {
        DBOperation dbo = null;
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            String sqlStr = "insert into t_ip_site (id,name,description,ascii_name,site_path,remark_number,increment_index,use_status,appserver_id) VALUES(?,?,?,?,?,?,?,?,?)";
            dbo = createDBOperation();
            connection = dbo.getConnection();
            connection.setAutoCommit(false);
            preparedStatement = connection.prepareStatement(sqlStr);
            preparedStatement.setInt(1, site.getSiteID());
            preparedStatement.setString(2, site.getName());
            preparedStatement.setString(3, site.getDescription());
            preparedStatement.setString(4, site.getAsciiName());
            preparedStatement.setString(5, site.getPath());
            preparedStatement.setInt(6, site.getRemarkNumber());
            preparedStatement.setString(7, site.getIncrementIndex().trim());
            preparedStatement.setString(8, String.valueOf(site.getUseStatus()));
            preparedStatement.setString(9, String.valueOf(site.getAppserverID()));
            preparedStatement.executeUpdate();
            String[] path = new String[1];
            path[0] = site.getPath();
            selfDefineAdd(path, site, connection, preparedStatement);
            connection.commit();
            int resID = site.getSiteID() + Const.SITE_TYPE_RES;
            String resName = site.getName();
            int resTypeID = Const.RES_TYPE_ID;
            int operateTypeID = Const.OPERATE_TYPE_ID;
            String remark = "";
            AuthorityManager am = new AuthorityManager();
            am.createExtResource(Integer.toString(resID), resName, resTypeID, operateTypeID, remark);
            site.wirteFile();
        } catch (SQLException ex) {
            connection.rollback();
            log.error("����վ��ʧ��!", ex);
            throw ex;
        } finally {
            close(resultSet, null, preparedStatement, connection, dbo);
        }
    }
public void delete(Site site) throws Exception {
        DBOperation dbo = null;
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            String chkSql = "select id from t_ip_doc where channel_path=?";
            dbo = createDBOperation();
            connection = dbo.getConnection();
            connection.setAutoCommit(false);
            String[] selfDefinePath = getSelfDefinePath(site.getPath(), "1", connection, preparedStatement, resultSet);
            selfDefineDelete(selfDefinePath, connection, preparedStatement);
            preparedStatement = connection.prepareStatement(chkSql);
            preparedStatement.setString(1, site.getPath());
            resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                throw new Exception("ɾ��ʧ�ܣ�" + site.getName() + "���Ѿ����ĵ����ڣ�");
            } else {
                String sqlStr = "delete from t_ip_site where site_path=?";
                dbo = createDBOperation();
                connection = dbo.getConnection();
                preparedStatement = connection.prepareStatement(sqlStr);
                preparedStatement.setString(1, site.getPath());
                preparedStatement.executeUpdate();
            }
            connection.commit();
        } catch (SQLException ex) {
            connection.rollback();
            throw ex;
        } finally {
            close(resultSet, null, preparedStatement, connection, dbo);
        }
    }
public void update(Site site) throws Exception {
        DBOperation dbo = null;
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String exp = site.getExtendParent();
        String path = site.getPath();
        try {
            String sqlStr = "update t_ip_site set id=?,name=?,description=?,ascii_name=?,remark_number=?,increment_index=?,use_status=?,appserver_id=? where id=?";
            dbo = createDBOperation();
            connection = dbo.getConnection();
            connection.setAutoCommit(false);
            String[] selfDefinePath = getSelfDefinePath(path, exp, connection, preparedStatement, resultSet);
            selfDefineDelete(selfDefinePath, connection, preparedStatement);
            selfDefineAdd(selfDefinePath, site, connection, preparedStatement);
            preparedStatement = connection.prepareStatement(sqlStr);
            preparedStatement.setInt(1, site.getSiteID());
            preparedStatement.setString(2, site.getName());
            preparedStatement.setString(3, site.getDescription());
            preparedStatement.setString(4, site.getAsciiName());
            preparedStatement.setInt(5, site.getRemarkNumber());
            preparedStatement.setString(6, site.getIncrementIndex().trim());
            preparedStatement.setString(7, String.valueOf(site.getUseStatus()));
            preparedStatement.setString(8, String.valueOf(site.getAppserverID()));
            preparedStatement.setInt(9, site.getSiteID());
            preparedStatement.executeUpdate();
            connection.commit();
            int resID = site.getSiteID() + Const.SITE_TYPE_RES;
            StructResource sr = new StructResource();
            sr.setResourceID(Integer.toString(resID));
            sr.setOperateID(Integer.toString(1));
            sr.setOperateTypeID(Const.OPERATE_TYPE_ID);
            sr.setTypeID(Const.RES_TYPE_ID);
            StructAuth sa = new AuthorityManager().getExternalAuthority(sr);
            int authID = sa.getAuthID();
            if (authID == 0) {
                String resName = site.getName();
                int resTypeID = Const.RES_TYPE_ID;
                int operateTypeID = Const.OPERATE_TYPE_ID;
                String remark = "";
                AuthorityManager am = new AuthorityManager();
                am.createExtResource(Integer.toString(resID), resName, resTypeID, operateTypeID, remark);
            }
            site.wirteFile();
        } catch (SQLException ex) {
            connection.rollback();
            log.error("����վ������ʧ��!", ex);
            throw ex;
        } finally {
            close(resultSet, null, preparedStatement, connection, dbo);
        }
    }
public static void downloadURLNow(URL url, File to, SHA1Sum sha1, boolean force) throws Exception {
        {
            String sep = System.getProperty("file.separator");
            String folders = to.getPath();
            String path = "";
            for (int i = 0; i < folders.length(); i++) {
                path += folders.charAt(i);
                if (path.endsWith(sep)) {
                    File f = new File(path);
                    if (!f.exists()) f.mkdir();
                    if (!f.isDirectory()) {
                        Out.error(URLDownloader.class, path + " is not a directory!");
                        return;
                    }
                }
            }
        }
        Out.info(URLDownloader.class, "Downloading " + url.toExternalForm());
        URLConnection uc = url.openConnection();
        DataInputStream is = new DataInputStream(new BufferedInputStream(uc.getInputStream()));
        FileOutputStream os = new FileOutputStream(to);
        byte[] b = new byte[1024];
        int fileLength = uc.getHeaderFieldInt("Content-Length", 0) / b.length;
        Task task = null;
        if (fileLength > 0) task = TaskManager.createTask(url.toExternalForm(), fileLength, "kB");
        do {
            int c = is.read(b);
            if (c == -1) break;
            os.write(b, 0, c);
            if (task != null) task.advanceProgress();
        } while (true);
        if (task != null) task.complete();
        os.close();
        is.close();
    }
public String encrypt(String password) {
        if (password.length() == 40) {
            return password;
        }
        if (salt != null) {
            password = password + salt;
        }
        MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
        messageDigest.reset();
        messageDigest.update(password.getBytes());
        final byte[] bytes = messageDigest.digest();
        String encrypted = new BigInteger(1, bytes).toString(16);
        if (encrypted.length() < 40) {
            final StringBuilder builder = new StringBuilder(encrypted);
            while (builder.length() < 40) {
                builder.insert(0, '0');
            }
            encrypted = builder.toString();
        }
        return encrypted;
    }
@Test
    public void testWriteAndRead() throws Exception {
        JCFS.configureLoopback(dir);
        RFile file = new RFile("testreadwrite.txt");
        RFileOutputStream out = new RFileOutputStream(file);
        out.write("test".getBytes("utf-8"));
        out.close();
        RFileInputStream in = new RFileInputStream(file);
        byte[] buffer = new byte[4];
        int readCount = in.read(buffer);
        in.close();
        assertEquals(4, readCount);
        String resultRead = new String(buffer, "utf-8");
        assertEquals("test", resultRead);
    }
public static String encriptaSenha(String string) throws ApplicationException {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(string.getBytes());
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(digest.digest());
        } catch (NoSuchAlgorithmException ns) {
            ns.printStackTrace();
            throw new ApplicationException("Erro ao Encriptar Senha");
        }
    }
private void download(String address, String localFileName) throws UrlNotFoundException, Exception {
        String ext = G_File.getExtensao(address);
        if (ext.equals("jsp")) {
            throw new Exception("Erro ao baixar pagina JSP, tipo negado." + address);
        }
        File temp = new File(localFileName + ".tmp");
        if (temp.exists()) temp.delete();
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        try {
            try {
                URL url = new URL(address);
                conn = url.openConnection();
                in = conn.getInputStream();
            } catch (FileNotFoundException e2) {
                throw new UrlNotFoundException();
            }
            out = new BufferedOutputStream(new FileOutputStream(temp));
            byte[] buffer = new byte[1024];
            int numRead;
            long numWritten = 0;
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
                numWritten += numRead;
            }
        } catch (UrlNotFoundException exception) {
            throw exception;
        } catch (Exception exception) {
            throw exception;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException ioe) {
            }
        }
        File oldArq = new File(localFileName);
        if (oldArq.exists()) {
            oldArq.delete();
        }
        oldArq = null;
        File nomeFinal = new File(localFileName);
        temp.renameTo(nomeFinal);
    }
private int[] sort(int n) {
        int[] mas = new int[n];
        Random rand = new Random();
        for (int i = 0; i < n; i++) {
            mas[i] = rand.nextInt(10) + 1;
        }
        boolean t = true;
        int tmp = 0;
        while (t) {
            t = false;
            for (int i = 0; i < mas.length - 1; i++) {
                if (mas[i] > mas[i + 1]) {
                    tmp = mas[i];
                    mas[i] = mas[i + 1];
                    mas[i + 1] = tmp;
                    t = true;
                }
            }
        }
        return mas;
    }
public boolean Load_Clickable_Peaks_Source_File(String tam) {
        if (tam == null) return false;
        try {
            URL url = new URL(getDocumentBase(), tam);
            InputStream stream = url.openStream();
            DataInputStream fichier = new DataInputStream(stream);
            texte = new Vector();
            String s;
            while ((s = fichier.readLine()) != null) {
                texte.addElement(s);
            }
            My_ZoneVisu.Nb_Clickable_Peaks = texte.size();
        } catch (Exception e) {
            return false;
        }
        My_ZoneVisu.Peak_Start = new double[My_ZoneVisu.Nb_Clickable_Peaks];
        My_ZoneVisu.Peak_Stop = new double[My_ZoneVisu.Nb_Clickable_Peaks];
        My_ZoneVisu.Peak_Html = new String[My_ZoneVisu.Nb_Clickable_Peaks];
        int cpt_tokens = 0;
        int i = 0;
        StringTokenizer mon_token;
        while (cpt_tokens < My_ZoneVisu.Nb_Clickable_Peaks) {
            do {
                String mysub = (String) texte.elementAt(cpt_tokens);
                mon_token = new StringTokenizer(mysub, " ");
                cpt_tokens++;
            } while (cpt_tokens < My_ZoneVisu.Nb_Clickable_Peaks && mon_token.hasMoreTokens() == false);
            if (mon_token.hasMoreTokens() == true) {
                My_ZoneVisu.Peak_Start[i] = Double.valueOf(mon_token.nextToken()).doubleValue();
                My_ZoneVisu.Peak_Stop[i] = Double.valueOf(mon_token.nextToken()).doubleValue();
                if (My_ZoneVisu.Peak_Start[i] > My_ZoneVisu.Peak_Stop[i]) {
                    double temp = My_ZoneVisu.Peak_Start[i];
                    My_ZoneVisu.Peak_Start[i] = My_ZoneVisu.Peak_Stop[i];
                    My_ZoneVisu.Peak_Stop[i] = temp;
                }
                My_ZoneVisu.Peak_Html[i] = (String) mon_token.nextToken();
            }
            i++;
        }
        return true;
    }
public static String email_get_public_hash(String email) {
        try {
            if (email != null) {
                email = email.trim().toLowerCase();
                CRC32 crc32 = new CRC32();
                crc32.reset();
                crc32.update(email.getBytes());
                MessageDigest md5 = MessageDigest.getInstance("MD5");
                md5.reset();
                return crc32.getValue() + " " + new String(md5.digest(email.getBytes()));
            }
        } catch (Exception e) {
        }
        return "";
    }
public static void main(String[] args) {
        File container = new File(ArchiveFeature.class.getProtectionDomain().getCodeSource().getLocation().toURI());
        if (container == null) {
            throw new RuntimeException("this use-case isn't being invoked from the executable jar");
        }
        JarFile jarFile = new JarFile(container);
        String artifactName = PROJECT_DIST_ARCHIVE + ".tar.gz";
        File artifactFile = new File(".", artifactName);
        ZipEntry artifactEntry = jarFile.getEntry(artifactName);
        InputStream source = jarFile.getInputStream(artifactEntry);
        try {
            FileOutputStream dest = new FileOutputStream(artifactFile);
            try {
                IOUtils.copy(source, dest);
            } finally {
                IOUtils.closeQuietly(dest);
            }
        } finally {
            IOUtils.closeQuietly(source);
        }
        Project project = new Project();
        project.setName("project");
        project.init();
        Target target = new Target();
        target.setName("target");
        project.addTarget(target);
        project.addBuildListener(new Log4jListener());
        Untar untar = new Untar();
        untar.setTaskName("untar");
        untar.setSrc(artifactFile);
        untar.setDest(new File("."));
        Untar.UntarCompressionMethod method = new Untar.UntarCompressionMethod();
        method.setValue("gzip");
        untar.setCompression(method);
        untar.setProject(project);
        untar.setOwningTarget(target);
        target.addTask(untar);
        untar.execute();
    }