semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public DataSetInfo(String request) throws AddeURLException {
        URLConnection urlc;
        BufferedReader reader;
        debug = debug || request.indexOf("debug=true") >= 0;
        try {
            URL url = new URL(request);
            urlc = url.openConnection();
            reader = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
        } catch (AddeURLException ae) {
            status = -1;
            throw new AddeURLException("No datasets found");
        } catch (Exception e) {
            status = -1;
            throw new AddeURLException("Error opening connection: " + e);
        }
        int numBytes = ((AddeURLConnection) urlc).getInitialRecordSize();
        if (debug) System.out.println("DataSetInfo: numBytes = " + numBytes);
        if (numBytes == 0) {
            status = -1;
            throw new AddeURLException("No datasets found");
        } else {
            data = new char[numBytes];
            try {
                int start = 0;
                while (start < numBytes) {
                    int numRead = reader.read(data, start, (numBytes - start));
                    if (debug) System.out.println("bytes read = " + numRead);
                    start += numRead;
                }
            } catch (IOException e) {
                status = -1;
                throw new AddeURLException("Error reading dataset info:" + e);
            }
            int numNames = data.length / 80;
            descriptorTable = new Hashtable(numNames);
            if (debug) System.out.println("Number of descriptors = " + numNames);
            for (int i = 0; i < numNames; i++) {
                String temp = new String(data, i * 80, 80);
                if (debug) System.out.println("Parsing: >" + temp + "<");
                if (temp.trim().equals("")) continue;
                String descriptor = temp.substring(0, 12).trim();
                if (debug) System.out.println("Descriptor = " + descriptor);
                String comment = descriptor;
                int pos = temp.indexOf('"');
                if (debug) System.out.println("Found quote at " + pos);
                if (pos >= 23) {
                    comment = temp.substring(pos + 1).trim();
                    if (comment.equals("")) comment = descriptor;
                }
                if (debug) System.out.println("Comment = " + comment);
                descriptorTable.put(comment, descriptor);
            }
        }
    }
public static void copy(String fromFileName, String toFileName) throws IOException {
        File fromFile = new File(fromFileName);
        File toFile = new File(toFileName);
        if (!fromFile.exists()) throw new IOException("Copy: no such source file: " + fromFileName);
        if (!fromFile.canRead()) throw new IOException("Copy: source file is unreadable: " + fromFileName);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) throw new IOException("Copy: destination file is unwriteable: " + toFileName);
            if (JOptionPane.showConfirmDialog(null, "Overwrite File ?", "Overwrite File", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return;
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) throw new IOException("Copy: destination directory doesn't exist: " + parent);
            if (dir.isFile()) throw new IOException("Copy: destination is not a directory: " + parent);
            if (!dir.canWrite()) throw new IOException("Copy: destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
@Override
    public void copy(final String fileName) throws FileIOException {
        try {
            if (opened) {
                fileChannel.position(0);
            } else {
                fileChannel = new FileInputStream(file).getChannel();
            }
            FileChannel dstChannel = null;
            try {
                dstChannel = new FileOutputStream(fileName).getChannel();
                dstChannel.transferFrom(fileChannel, 0, fileChannel.size());
            } finally {
                try {
                    if (dstChannel != null) {
                        dstChannel.close();
                    }
                } catch (Exception exception) {
                }
            }
            if (opened) {
                fileChannel.position(currentPositionInFile);
            } else {
                fileChannel.close();
            }
        } catch (IOException exception) {
            throw HELPER_FILE_UTIL.fileIOException("failed copy " + file + " to " + fileName, null, exception);
        }
    }
public static void test(String args[]) {
        int trace;
        int bytes_read = 0;
        int last_contentLenght = 0;
        try {
            BufferedReader reader;
            URL url;
            url = new URL(args[0]);
            URLConnection istream = url.openConnection();
            last_contentLenght = istream.getContentLength();
            reader = new BufferedReader(new InputStreamReader(istream.getInputStream()));
            System.out.println(url.toString());
            String line;
            trace = t2pNewTrace();
            while ((line = reader.readLine()) != null) {
                bytes_read = bytes_read + line.length() + 1;
                t2pProcessLine(trace, line);
            }
            t2pHandleEventPairs(trace);
            t2pSort(trace, 0);
            t2pExportTrace(trace, new String("pngtest2.png"), 1000, 700, (float) 0, (float) 33);
            t2pExportTrace(trace, new String("pngtest3.png"), 1000, 700, (float) 2.3, (float) 2.44);
            System.out.println("Press any key to contiune read from stream !!!");
            System.out.println(t2pGetProcessName(trace, 0));
            System.in.read();
            istream = url.openConnection();
            if (last_contentLenght != istream.getContentLength()) {
                istream = url.openConnection();
                istream.setRequestProperty("Range", "bytes=" + Integer.toString(bytes_read) + "-");
                System.out.println(Integer.toString(istream.getContentLength()));
                reader = new BufferedReader(new InputStreamReader(istream.getInputStream()));
                while ((line = reader.readLine()) != null) {
                    System.out.println(line);
                    t2pProcessLine(trace, line);
                }
            } else System.out.println("File not changed !");
            t2pDeleteTrace(trace);
        } catch (MalformedURLException e) {
            System.out.println("MalformedURLException !!!");
        } catch (IOException e) {
            System.out.println("File not found " + args[0]);
        }
        ;
    }
@Override
    public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException {
        if (TDebug.TraceAudioFileReader) {
            TDebug.out("getAudioFileFormat(URL url)");
        }
        InputStream inputStream = url.openStream();
        try {
            return getAudioFileFormat(inputStream);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }
public int[] do_it(final int[] x) {
        int temp = 0;
        int j = x.length;
        while (j > 0) {
            for (int i = 0; i < j - 1; i++) {
                if (x[i] > x[i + 1]) {
                    temp = x[i];
                    x[i] = x[i + 1];
                    x[i + 1] = temp;
                }
                ;
            }
            ;
            j--;
        }
        ;
        return x;
    }
public static String getDigest(String user, String realm, String password, String method, String uri, String nonce) {
        String digest1 = user + ":" + realm + ":" + password;
        String digest2 = method + ":" + uri;
        try {
            MessageDigest digestOne = MessageDigest.getInstance("md5");
            digestOne.update(digest1.getBytes());
            String hexDigestOne = getHexString(digestOne.digest());
            MessageDigest digestTwo = MessageDigest.getInstance("md5");
            digestTwo.update(digest2.getBytes());
            String hexDigestTwo = getHexString(digestTwo.digest());
            String digest3 = hexDigestOne + ":" + nonce + ":" + hexDigestTwo;
            MessageDigest digestThree = MessageDigest.getInstance("md5");
            digestThree.update(digest3.getBytes());
            String hexDigestThree = getHexString(digestThree.digest());
            return hexDigestThree;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
public static String getDigest(String user, String realm, String password, String method, String uri, String nonce, String nc, String cnonce, String qop) {
        String digest1 = user + ":" + realm + ":" + password;
        String digest2 = method + ":" + uri;
        try {
            MessageDigest digestOne = MessageDigest.getInstance("md5");
            digestOne.update(digest1.getBytes());
            String hexDigestOne = getHexString(digestOne.digest());
            MessageDigest digestTwo = MessageDigest.getInstance("md5");
            digestTwo.update(digest2.getBytes());
            String hexDigestTwo = getHexString(digestTwo.digest());
            String digest3 = hexDigestOne + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + hexDigestTwo;
            MessageDigest digestThree = MessageDigest.getInstance("md5");
            digestThree.update(digest3.getBytes());
            String hexDigestThree = getHexString(digestThree.digest());
            return hexDigestThree;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
static void getFileClient(String fsName, String id, File[] localPath) throws IOException {
        byte[] buf = new byte[BUFFER_SIZE];
        StringBuffer str = new StringBuffer("http://" + fsName + "/getimage?");
        str.append(id);
        URL url = new URL(str.toString());
        URLConnection connection = url.openConnection();
        InputStream stream = connection.getInputStream();
        FileOutputStream[] output = null;
        try {
            if (localPath != null) {
                output = new FileOutputStream[localPath.length];
                for (int i = 0; i < output.length; i++) {
                    output[i] = new FileOutputStream(localPath[i]);
                }
            }
            int num = 1;
            while (num > 0) {
                num = stream.read(buf);
                if (num > 0 && localPath != null) {
                    for (int i = 0; i < output.length; i++) {
                        output[i].write(buf, 0, num);
                    }
                }
            }
        } finally {
            stream.close();
            if (output != null) {
                for (int i = 0; i < output.length; i++) {
                    if (output[i] != null) {
                        output[i].close();
                    }
                }
            }
        }
    }
private void bokActionPerformed(java.awt.event.ActionEvent evt) {
        if (this.tfGeneralSubDivision.getText().trim().equals("")) {
            this.showWarningMessage("Enter general sub division");
        } else {
            String[] patlib = newgen.presentation.NewGenMain.getAppletInstance().getPatronLibraryIds();
            String xmlreq = newgen.presentation.administration.AdministrationXMLGenerator.getInstance().saveGeneralSubDivision("1", this.tfGeneralSubDivision.getText(), patlib);
            System.out.println(xmlreq);
            try {
                java.net.URL url = new java.net.URL(ResourceBundle.getBundle("Administration").getString("ServerURL") + ResourceBundle.getBundle("Administration").getString("ServletSubPath") + "SubDivisionServlet");
                java.net.URLConnection urlconn = (java.net.URLConnection) url.openConnection();
                urlconn.setDoOutput(true);
                java.io.OutputStream dos = urlconn.getOutputStream();
                dos.write(xmlreq.getBytes());
                java.io.InputStream ios = urlconn.getInputStream();
                SAXBuilder saxb = new SAXBuilder();
                Document retdoc = saxb.build(ios);
                Element rootelement = retdoc.getRootElement();
                if (rootelement.getChild("Error") == null) {
                    this.showInformationMessage(ResourceBundle.getBundle("Administration").getString("DataSavedInDatabase"));
                } else {
                    this.showErrorMessage(ResourceBundle.getBundle("Administration").getString("ErrorPleaseContactTheVendor"));
                }
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }
private static boolean hasPackageInfo(URL url) {
        if (url == null) return false;
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = br.readLine()) != null) {
                if (line.startsWith("Specification-Title: ") || line.startsWith("Specification-Version: ") || line.startsWith("Specification-Vendor: ") || line.startsWith("Implementation-Title: ") || line.startsWith("Implementation-Version: ") || line.startsWith("Implementation-Vendor: ")) return true;
            }
        } catch (IOException ioe) {
        } finally {
            if (br != null) try {
                br.close();
            } catch (IOException e) {
            }
        }
        return false;
    }
@Test(dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER)
    public void shouldGreetUser(@ArquillianResource URL baseURL) throws IOException {
        final String name = "Earthlings";
        final URL url = new URL(baseURL, "Foo.action");
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        reader.close();
        LOGGER.info("Returned response: " + builder.toString());
        Assert.assertEquals(builder.toString(), FooService.GREETING + name);
    }
public void copyFile(File source, File destination, boolean lazy) {
        if (!source.exists()) {
            return;
        }
        if (lazy) {
            String oldContent = null;
            try {
                oldContent = read(source);
            } catch (Exception e) {
                return;
            }
            String newContent = null;
            try {
                newContent = read(destination);
            } catch (Exception e) {
            }
            if ((oldContent == null) || !oldContent.equals(newContent)) {
                copyFile(source, destination, false);
            }
        } else {
            if ((destination.getParentFile() != null) && (!destination.getParentFile().exists())) {
                destination.getParentFile().mkdirs();
            }
            try {
                FileChannel srcChannel = new FileInputStream(source).getChannel();
                FileChannel dstChannel = new FileOutputStream(destination).getChannel();
                dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                srcChannel.close();
                dstChannel.close();
            } catch (IOException ioe) {
                _log.error(ioe.getMessage());
            }
        }
    }
public void createIndex(File indexDir) throws SearchLibException, IOException {
        if (!indexDir.mkdir()) throw new SearchLibException("directory creation failed (" + indexDir + ")");
        InputStream is = null;
        FileWriter target = null;
        for (String resource : resources) {
            String res = rootPath + '/' + resource;
            is = getClass().getResourceAsStream(res);
            if (is == null) is = getClass().getResourceAsStream("common" + '/' + resource);
            if (is == null) throw new SearchLibException("Unable to find resource " + res);
            try {
                File f = new File(indexDir, resource);
                if (f.getParentFile() != indexDir) f.getParentFile().mkdirs();
                target = new FileWriter(f);
                IOUtils.copy(is, target);
            } finally {
                if (target != null) target.close();
                if (is != null) is.close();
            }
        }
    }
public File download(Show s) throws Exception {
        Collection<String> exclude = Util.toCollection((List<String>) this.exclude.clone(), Util.nonNullString(s.getExclude()).split(","));
        URL url = new URL("http://v3.newzbin.com/search/" + buildQuery(s));
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        while ((line = in.readLine()) != null) {
            if (!Util.containsNone(line, exclude)) continue;
            String id = line.split("\",\"", 3)[1];
            File downloaded = download(s, id);
            if (downloaded != null) return downloaded;
        }
        return null;
    }
private static MapEntry<String, Properties> loadFpmConf() throws ConfigurationReadException {
        MapEntry<String, Properties> ret = null;
        Scanner sc = new Scanner(CONF_PATHS).useDelimiter(SEP_P);
        String prev = "";
        while (sc.hasNext() && !hasLoaded) {
            Properties fpmConf = null;
            boolean relative = false;
            String path = sc.next();
            if (path.startsWith(PREV_P)) {
                path = path.replace(PREV_P, prev.substring(0, prev.length() - 1));
            } else if (path.startsWith(REL_P)) {
                path = path.replace(REL_P + FS, "");
                relative = true;
            } else if (path.contains(HOME_P)) {
                path = path.replace(HOME_P, USER_HOME);
            }
            prev = path;
            path = path.concat(MAIN_CONF_FILE);
            try {
                InputStream is = null;
                if (relative) {
                    is = ClassLoader.getSystemResourceAsStream(path);
                    path = getSystemConfDir();
                    Strings.getOne().createPath(path);
                    path += MAIN_CONF_FILE;
                    FileOutputStream os = new FileOutputStream(path);
                    IOUtils.copy(is, os);
                    os.flush();
                    os.close();
                    os = null;
                } else {
                    is = new FileInputStream(path);
                }
                fpmConf = new Properties();
                fpmConf.load(is);
                if (fpmConf.isEmpty()) {
                    throw new ConfigurationReadException();
                }
                ret = new MapEntry<String, Properties>(path, fpmConf);
                hasLoaded = true;
            } catch (FileNotFoundException e) {
                fpmConf = null;
                singleton = null;
                hasLoaded = false;
            } catch (IOException e) {
                throw new ConfigurationReadException();
            }
        }
        return ret;
    }
@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String rewrittenQueryString = URLDecoder.decode(request.getRequestURI(), "UTF-8").replaceFirst("^.*?\\/(id:.*)\\/.*?$", "$1");
        logger.debug("rewrittenQueryString: " + rewrittenQueryString);
        URL rewrittenUrl = new URL(fedoraUrl + rewrittenQueryString);
        logger.debug("rewrittenUrl: " + rewrittenUrl.getProtocol() + "://" + rewrittenUrl.getHost() + ":" + rewrittenUrl.getPort() + rewrittenUrl.getFile());
        HttpURLConnection httpURLConnection = (HttpURLConnection) rewrittenUrl.openConnection();
        HttpURLConnection.setFollowRedirects(false);
        httpURLConnection.connect();
        response.setStatus(httpURLConnection.getResponseCode());
        logger.debug("[status=" + httpURLConnection.getResponseCode() + "]");
        logger.debug("[headers]");
        for (Entry<String, List<String>> header : httpURLConnection.getHeaderFields().entrySet()) {
            if (header.getKey() != null) {
                for (String value : header.getValue()) {
                    if (value != null) {
                        logger.debug(header.getKey() + ": " + value);
                        if (!header.getKey().equals("Server") && !header.getKey().equals("Transfer-Encoding")) {
                            response.addHeader(header.getKey(), value);
                        }
                    }
                }
            }
        }
        logger.debug("[/headers]");
        InputStream inputStream = httpURLConnection.getInputStream();
        OutputStream outputStream = response.getOutputStream();
        IOUtils.copy(inputStream, outputStream);
    }
private String readFile(String urlFileString) throws IOException {
        URL url = new URL(urlFileString);
        VizDebugUtils.debug("url: " + url.toString());
        InputStream stream = url.openStream();
        Reader reader = new InputStreamReader(stream, "iso-8859-1");
        StringWriter writer = new StringWriter();
        StreamUtils.transfer(reader, writer);
        stream.close();
        return writer.toString();
    }
public static String md5Encode16(String s) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(s.getBytes("utf-8"));
            byte b[] = md.digest();
            int i;
            StringBuilder buf = new StringBuilder("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0) i += 256;
                if (i < 16) buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString().substring(8, 24);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }