semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static Image getImage(String urlChartString) throws IOException, JGoogleChartException {
        Image image = null;
        HttpURLConnection urlConn = null;
        URL url = new URL(urlChartString);
        urlConn = (HttpURLConnection) url.openConnection();
        urlConn.setDoInput(true);
        urlConn.setDoOutput(true);
        urlConn.setUseCaches(false);
        urlConn.setRequestMethod("GET");
        urlConn.setAllowUserInteraction(false);
        urlConn.setRequestProperty("HTTP-Version", "HTTP/1.1");
        urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        int responseCode = urlConn.getResponseCode();
        if (responseCode != 200) {
            throw new JGoogleChartException(JGoogleChartException.MSG_HTTP_ERROR_CODE + responseCode + " (" + urlConn.getResponseMessage());
        }
        InputStream istream = urlConn.getInputStream();
        image = ImageIO.read(istream);
        return image;
    }
private URLConnection openPostConnection(StringBuffer sb) throws IOException, IOException, MalformedURLException {
        URL url = new URL(m_gatewayAddress);
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        connection.setUseCaches(false);
        OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
        wr.write(sb.toString());
        wr.flush();
        wr.close();
        return connection;
    }
private URLConnection openGetConnection(StringBuffer sb) throws IOException, IOException, MalformedURLException {
        URL url = new URL(m_gatewayAddress + "?" + sb.toString());
        URLConnection connection = url.openConnection();
        connection.setUseCaches(false);
        return connection;
    }
public byte[] scramblePassword(String password, String seed) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] stage1 = md.digest(password.getBytes());
        md.reset();
        byte[] stage2 = md.digest(stage1);
        md.reset();
        md.update(seed.getBytes());
        md.update(stage2);
        byte[] result = md.digest();
        for (int i = 0; i < result.length; i++) {
            result[i] ^= stage1[i];
        }
        return result;
    }
public void gzipCompress(String file) {
        try {
            File inputFile = new File(file);
            FileInputStream fileinput = new FileInputStream(inputFile);
            File outputFile = new File(file.substring(0, file.length() - 1) + "z");
            FileOutputStream stream = new FileOutputStream(outputFile);
            GZIPOutputStream gzipstream = new GZIPOutputStream(stream);
            BufferedInputStream bis = new BufferedInputStream(fileinput);
            int bytes_read = 0;
            byte[] buf = new byte[READ_BUFFER_SIZE];
            while ((bytes_read = bis.read(buf, 0, BLOCK_SIZE)) != -1) {
                gzipstream.write(buf, 0, bytes_read);
            }
            bis.close();
            inputFile.delete();
            gzipstream.finish();
            gzipstream.close();
        } catch (FileNotFoundException fnfe) {
            System.out.println("Compressor: Cannot find file " + fnfe.getMessage());
        } catch (SecurityException se) {
            System.out.println("Problem saving file " + se.getMessage());
        } catch (IOException ioe) {
            System.out.println("Problem saving file " + ioe.getMessage());
        }
    }
private String choosePivotVertex() throws ProcessorExecutionException {
        String result = null;
        Graph src;
        Graph dest;
        Path tmpDir;
        System.out.println("##########>" + _dirMgr.getSeqNum() + " Choose the pivot vertex");
        src = new Graph(Graph.defaultGraph());
        src.setPath(_curr_path);
        dest = new Graph(Graph.defaultGraph());
        try {
            tmpDir = _dirMgr.getTempDir();
        } catch (IOException e) {
            throw new ProcessorExecutionException(e);
        }
        dest.setPath(tmpDir);
        GraphAlgorithm choose_pivot = new PivotChoose();
        choose_pivot.setConf(context);
        choose_pivot.setSource(src);
        choose_pivot.setDestination(dest);
        choose_pivot.setMapperNum(getMapperNum());
        choose_pivot.setReducerNum(getReducerNum());
        choose_pivot.execute();
        try {
            Path the_file = new Path(tmpDir.toString() + "/part-00000");
            FileSystem client = FileSystem.get(context);
            if (!client.exists(the_file)) {
                throw new ProcessorExecutionException("Did not find the chosen vertex in " + the_file.toString());
            }
            FSDataInputStream input_stream = client.open(the_file);
            ByteArrayOutputStream output_stream = new ByteArrayOutputStream();
            IOUtils.copyBytes(input_stream, output_stream, context, false);
            String the_line = output_stream.toString();
            result = the_line.substring(PivotChoose.KEY_PIVOT.length()).trim();
            input_stream.close();
            output_stream.close();
            System.out.println("##########> Chosen pivot id = " + result);
        } catch (IOException e) {
            throw new ProcessorExecutionException(e);
        }
        return result;
    }
private final synchronized Vector<Class<?>> findSubclasses(URL location, String packageName, Class<?> superClass) {
        Map<Class<?>, URL> thisResult = new TreeMap<Class<?>, URL>(CLASS_COMPARATOR);
        Vector<Class<?>> v = new Vector<Class<?>>();
        String fqcn = searchClass.getName();
        List<URL> knownLocations = new ArrayList<URL>();
        knownLocations.add(location);
        for (int loc = 0; loc < knownLocations.size(); loc++) {
            URL url = knownLocations.get(loc);
            File directory = new File(url.getFile());
            if (directory.exists()) {
                String[] files = directory.list();
                for (int i = 0; i < files.length; i++) if (files[i].endsWith(".class")) {
                    String classname = files[i].substring(0, files[i].length() - 6);
                    try {
                        Class<?> c = Class.forName(packageName + "." + classname);
                        if (superClass.isAssignableFrom(c) && !fqcn.equals(packageName + "." + classname)) thisResult.put(c, url);
                    } catch (ClassNotFoundException cnfex) {
                        errors.add(cnfex);
                    } catch (Exception ex) {
                        errors.add(ex);
                    }
                }
            } else try {
                JarURLConnection conn = (JarURLConnection) url.openConnection();
                JarFile jarFile = conn.getJarFile();
                Enumeration<JarEntry> e = jarFile.entries();
                while (e.hasMoreElements()) {
                    JarEntry entry = e.nextElement();
                    String entryname = entry.getName();
                    if (!entry.isDirectory() && entryname.endsWith(".class")) {
                        String classname = entryname.substring(0, entryname.length() - 6);
                        if (classname.startsWith("/")) classname = classname.substring(1);
                        classname = classname.replace('/', '.');
                        System.err.println("Trying " + classname);
                        try {
                            Class c = Class.forName(classname);
                            if (superClass.isAssignableFrom(c) && !fqcn.equals(classname)) thisResult.put(c, url);
                        } catch (ClassNotFoundException cnfex) {
                            errors.add(cnfex);
                        } catch (NoClassDefFoundError ncdfe) {
                            errors.add(ncdfe);
                        } catch (UnsatisfiedLinkError ule) {
                            errors.add(ule);
                        } catch (Exception exception) {
                            errors.add(exception);
                        } catch (Error error) {
                            errors.add(error);
                        }
                    }
                }
            } catch (IOException ioex) {
                errors.add(ioex);
            }
        }
        results.putAll(thisResult);
        Iterator<Class<?>> it = thisResult.keySet().iterator();
        while (it.hasNext()) v.add(it.next());
        return v;
    }
private void copyResourceToFile(final String resourceFilename, final String destinationFilename) throws IOException {
        InputStream inStream = null;
        OutputStream outStream = null;
        try {
            inStream = MatsimResource.getAsInputStream(resourceFilename);
            outStream = new FileOutputStream(destinationFilename);
            IOUtils.copyStream(inStream, outStream);
        } finally {
            if (inStream != null) {
                try {
                    inStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outStream != null) {
                try {
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public static String md5(String text, String charset) {
        MessageDigest msgDigest = null;
        try {
            msgDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("System doesn't support MD5 algorithm.");
        }
        msgDigest.update(text.getBytes());
        byte[] bytes = msgDigest.digest();
        byte tb;
        char low;
        char high;
        char tmpChar;
        String md5Str = new String();
        for (int i = 0; i < bytes.length; i++) {
            tb = bytes[i];
            tmpChar = (char) ((tb >>> 4) & 0x000f);
            if (tmpChar >= 10) {
                high = (char) (('a' + tmpChar) - 10);
            } else {
                high = (char) ('0' + tmpChar);
            }
            md5Str += high;
            tmpChar = (char) (tb & 0x000f);
            if (tmpChar >= 10) {
                low = (char) (('a' + tmpChar) - 10);
            } else {
                low = (char) ('0' + tmpChar);
            }
            md5Str += low;
        }
        return md5Str;
    }
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException {
        LOGGER.debug("DOWNLOAD - Send content: " + realFile.getAbsolutePath());
        LOGGER.debug("Output stream: " + out.toString());
        if (ServerConfiguration.isDynamicSEL()) {
            LOGGER.error("IS DINAMIC SEL????");
        } else {
        }
        if (".tokens".equals(realFile.getName()) || ".response".equals(realFile.getName()) || ".request".equals(realFile.getName()) || isAllowedClient) {
            FileInputStream in = null;
            try {
                in = new FileInputStream(realFile);
                int bytes = IOUtils.copy(in, out);
                LOGGER.debug("System resource or Allowed Client wrote bytes:  " + bytes);
                out.flush();
            } catch (Exception e) {
                LOGGER.error("Error while downloading over encryption system " + realFile.getName() + " file", e);
            } finally {
                IOUtils.closeQuietly(in);
            }
        } else {
        }
    }
private static File createTempWebXml(Class portletClass, File portletDir, String appName, String portletName) throws IOException, FileNotFoundException {
        File pathToWebInf = new File(portletDir, "WEB-INF");
        File tempWebXml = File.createTempFile("web", ".xml", pathToWebInf);
        tempWebXml.deleteOnExit();
        OutputStream webOutputStream = new FileOutputStream(tempWebXml);
        PortletUnitWebXmlStream streamSource = WEB_XML_STREAM_FACTORY;
        IOUtils.copy(streamSource.createStream(portletClass, appName, portletName), webOutputStream);
        webOutputStream.close();
        return tempWebXml;
    }
public void downloadFrinika() throws Exception {
        if (!frinikaFile.exists()) {
            String urlString = remoteURLPath + frinikaFileName;
            showMessage("Connecting to " + urlString);
            URLConnection uc = new URL(urlString).openConnection();
            progressBar.setIndeterminate(false);
            showMessage("Downloading from " + urlString);
            progressBar.setValue(0);
            progressBar.setMinimum(0);
            progressBar.setMaximum(fileSize);
            InputStream is = uc.getInputStream();
            FileOutputStream fos = new FileOutputStream(frinikaFile);
            byte[] b = new byte[BUFSIZE];
            int c;
            while ((c = is.read(b)) != -1) {
                fos.write(b, 0, c);
                progressBar.setValue(progressBar.getValue() + c);
            }
            fos.close();
        }
    }
public void extractFrinika() throws Exception {
        FileInputStream fis = new FileInputStream(frinikaFile);
        progressBar.setIndeterminate(true);
        ZipInputStream zis = new ZipInputStream(fis);
        ZipEntry ze = zis.getNextEntry();
        while (ze != null) {
            showMessage("Extracting: " + ze.getName());
            File file = new File(installDirName + "/" + ze.getName());
            if (ze.isDirectory()) file.mkdir(); else {
                FileOutputStream fos = new FileOutputStream(file);
                byte[] b = new byte[BUFSIZE];
                int c;
                while ((c = zis.read(b)) != -1) fos.write(b, 0, c);
                fos.close();
            }
            ze = zis.getNextEntry();
        }
    }
public static File unGzip(File infile, boolean deleteGzipfileOnSuccess) throws IOException {
        GZIPInputStream gin = new GZIPInputStream(new FileInputStream(infile));
        File outFile = new File(infile.getParent(), infile.getName().replaceAll("\\.gz$", ""));
        FileOutputStream fos = new FileOutputStream(outFile);
        byte[] buf = new byte[100000];
        int len;
        while ((len = gin.read(buf)) > 0) fos.write(buf, 0, len);
        gin.close();
        fos.close();
        if (deleteGzipfileOnSuccess) infile.delete();
        return outFile;
    }
public int create(BusinessObject o) throws DAOException {
        int insert = 0;
        int id = 0;
        Contact contact = (Contact) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("INSERT_CONTACT"));
            pst.setString(1, contact.getName());
            pst.setString(2, contact.getFirstname());
            pst.setString(3, contact.getPhone());
            pst.setString(4, contact.getEmail());
            if (contact.getAccount() == 0) {
                pst.setNull(5, java.sql.Types.INTEGER);
            } else {
                pst.setInt(5, contact.getAccount());
            }
            insert = pst.executeUpdate();
            if (insert <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (insert > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("select max(id) from contact");
            rs.next();
            id = rs.getInt(1);
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return id;
    }
public int delete(BusinessObject o) throws DAOException {
        int delete = 0;
        Contact contact = (Contact) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("DELETE_CONTACT"));
            pst.setInt(1, contact.getId());
            delete = pst.executeUpdate();
            if (delete <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (delete > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return delete;
    }
public int update(BusinessObject o) throws DAOException {
        int update = 0;
        Contact contact = (Contact) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("UPDATE_CONTACT"));
            pst.setString(1, contact.getName());
            pst.setString(2, contact.getFirstname());
            pst.setString(3, contact.getPhone());
            pst.setString(4, contact.getEmail());
            if (contact.getAccount() == 0) {
                pst.setNull(5, java.sql.Types.INTEGER);
            } else {
                pst.setInt(5, contact.getAccount());
            }
            pst.setBoolean(6, contact.isArchived());
            pst.setInt(7, contact.getId());
            update = pst.executeUpdate();
            if (update <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (update > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return update;
    }
public String getSummaryText() {
        if (summaryText == null) {
            for (Iterator iter = xdcSources.values().iterator(); iter.hasNext(); ) {
                XdcSource source = (XdcSource) iter.next();
                File packageFile = new File(source.getFile().getParentFile(), "xdc-package.html");
                if (packageFile.exists()) {
                    Reader in = null;
                    try {
                        in = new FileReader(packageFile);
                        StringWriter out = new StringWriter();
                        IOUtils.copy(in, out);
                        StringBuffer buf = out.getBuffer();
                        int pos1 = buf.indexOf("<body>");
                        int pos2 = buf.lastIndexOf("</body>");
                        if (pos1 >= 0 && pos1 < pos2) {
                            summaryText = buf.substring(pos1 + 6, pos2);
                        } else {
                            summaryText = "";
                        }
                    } catch (FileNotFoundException e) {
                        LOG.error(e.getMessage(), e);
                        summaryText = "";
                    } catch (IOException e) {
                        LOG.error(e.getMessage(), e);
                        summaryText = "";
                    } finally {
                        if (in != null) {
                            try {
                                in.close();
                            } catch (IOException e) {
                                LOG.error(e.getMessage(), e);
                            }
                        }
                    }
                    break;
                } else {
                    summaryText = "";
                }
            }
        }
        return summaryText;
    }
public static String getProgramVersion() {
        String s = "0";
        try {
            URL url;
            URLConnection urlConn;
            DataInputStream dis;
            url = new URL("http://www.dombosfest.org.yu/log/yamiversion.dat");
            urlConn = url.openConnection();
            urlConn.setDoInput(true);
            urlConn.setUseCaches(false);
            dis = new DataInputStream(urlConn.getInputStream());
            while ((dis.readUTF()) != null) {
                s = dis.readUTF();
            }
            dis.close();
        } catch (MalformedURLException mue) {
            System.out.println("mue:" + mue.getMessage());
        } catch (IOException ioe) {
            System.out.println("ioe:" + ioe.getMessage());
        }
        return s;
    }
public static String mdFive(String string) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] array = new byte[32];
        md.update(string.getBytes("iso-8859-1"), 0, string.length());
        array = md.digest();
        return convertToHex(array);
    }
protected void copy(File src, File dest) throws IOException {
        if (src.isDirectory() && dest.isFile()) throw new IOException("Cannot copy a directory to a file");
        if (src.isDirectory()) {
            File newDir = new File(dest, src.getName());
            if (!newDir.mkdirs()) throw new IOException("Cannot create a new Directory");
            File[] entries = src.listFiles();
            for (int i = 0; i < entries.length; ++i) copy(entries[i], newDir);
            return;
        }
        if (dest.isDirectory()) {
            File newFile = new File(dest, src.getName());
            newFile.createNewFile();
            copy(src, newFile);
            return;
        }
        try {
            if (src.length() == 0) {
                dest.createNewFile();
                return;
            }
            FileChannel fc = new FileInputStream(src).getChannel();
            FileChannel dstChannel = new FileOutputStream(dest).getChannel();
            long transfered = 0;
            long totalLength = src.length();
            while (transfered < totalLength) {
                long num = fc.transferTo(transfered, totalLength - transfered, dstChannel);
                if (num == 0) throw new IOException("Error while copying");
                transfered += num;
            }
            dstChannel.close();
            fc.close();
        } catch (IOException e) {
            if (os.equals("Unix")) {
                _logger.fine("Trying to use cp to copy file...");
                File cp = new File("/usr/bin/cp");
                if (!cp.exists()) cp = new File("/bin/cp");
                if (!cp.exists()) cp = new File("/usr/local/bin/cp");
                if (!cp.exists()) cp = new File("/sbin/cp");
                if (!cp.exists()) cp = new File("/usr/sbin/cp");
                if (!cp.exists()) cp = new File("/usr/local/sbin/cp");
                if (cp.exists()) {
                    Process cpProcess = Runtime.getRuntime().exec(cp.getAbsolutePath() + " '" + src.getAbsolutePath() + "' '" + dest.getAbsolutePath() + "'");
                    int errCode;
                    try {
                        errCode = cpProcess.waitFor();
                    } catch (java.lang.InterruptedException ie) {
                        throw e;
                    }
                    return;
                }
            }
            throw e;
        }
    }