semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void readURL() throws Exception {
        URL url = new URL("http://www.google.com");
        URLConnection c = url.openConnection();
        Map<String, List<String>> headers = c.getHeaderFields();
        for (String s : headers.keySet()) {
            System.out.println(s + ": " + headers.get(s));
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        reader.close();
    }
private static long saveAndClosePDFDocument(PDDocument document, OutputStreamProvider outProvider) throws IOException, COSVisitorException {
        File tempFile = null;
        InputStream in = null;
        OutputStream out = null;
        try {
            tempFile = File.createTempFile("temp", "pdf");
            OutputStream tempFileOut = new FileOutputStream(tempFile);
            tempFileOut = new BufferedOutputStream(tempFileOut);
            document.save(tempFileOut);
            document.close();
            tempFileOut.close();
            long length = tempFile.length();
            in = new BufferedInputStream(new FileInputStream(tempFile));
            out = new BufferedOutputStream(outProvider.getOutputStream());
            IOUtils.copy(in, out);
            return length;
        } finally {
            if (in != null) {
                IOUtils.closeQuietly(in);
            }
            if (out != null) {
                IOUtils.closeQuietly(out);
            }
            if (tempFile != null && !FileUtils.deleteQuietly(tempFile)) {
                tempFile.deleteOnExit();
            }
        }
    }
public static void main(String[] args) throws FileNotFoundException, IOException {
        String filePath = "/Users/francisbaril/Downloads/test-1.pdf";
        String testFilePath = "/Users/francisbaril/Desktop/testpdfbox/test.pdf";
        File file = new File(filePath);
        final File testFile = new File(testFilePath);
        if (testFile.exists()) {
            testFile.delete();
        }
        IOUtils.copy(new FileInputStream(file), new FileOutputStream(testFile));
        System.out.println(getLongProperty(new FileInputStream(testFile), PROPRIETE_ID_IGID));
    }
private boolean undefSeqLen = true;

    private boolean undefItemLen = true;

    private boolean fmi = true;

    /** Creates a new instance of Acr2Dcm */
    public Acr2Dcm() {
    }

    public void setStudyUID(String uid) {
        this.studyUID = uid;
    }

    public void setSeriesUID(String uid) {
        this.seriesUID = uid;
    }

    public void setInstUID(String uid) {
        this.instUID = uid;
    }

    public void setClassUID(String uid) {
        this.classUID = uid;
    }

    public void setSkipGroupLen(boolean skipGroupLen) {
protected void writeGZippedBytes(byte array[], TupleOutput out) {
        if (array == null || array.length == 0) {
            out.writeBoolean(false);
            writeBytes(array, out);
            return;
        }
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream(array.length);
            GZIPOutputStream gzout = new GZIPOutputStream(baos);
            ByteArrayInputStream bais = new ByteArrayInputStream(array);
            IOUtils.copyTo(bais, gzout);
            gzout.finish();
            gzout.close();
            bais.close();
            byte compressed[] = baos.toByteArray();
            if (compressed.length < array.length) {
                out.writeBoolean(true);
                writeBytes(compressed, out);
            } else {
                out.writeBoolean(false);
                writeBytes(array, out);
            }
        } catch (IOException err) {
            throw new RuntimeException(err);
        }
    }
protected byte[] readGZippedBytes(TupleInput in) {
        final boolean is_compressed = in.readBoolean();
        byte array[] = readBytes(in);
        if (array == null) return null;
        if (!is_compressed) {
            return array;
        }
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(array);
            GZIPInputStream gzin = new GZIPInputStream(bais);
            ByteArrayOutputStream baos = new ByteArrayOutputStream(array.length);
            IOUtils.copyTo(gzin, baos);
            gzin.close();
            bais.close();
            return baos.toByteArray();
        } catch (IOException err) {
            throw new RuntimeException(err);
        }
    }
private InputStream callService(String text) {
        InputStream in = null;
        try {
            URL url = new URL(SERVLET_URL);
            URLConnection conn = url.openConnection();
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setRequestMethod("POST");
            httpConn.setDoInput(true);
            httpConn.setDoOutput(true);
            httpConn.connect();
            DataOutputStream dataStream = new DataOutputStream(conn.getOutputStream());
            dataStream.writeBytes(text);
            dataStream.flush();
            dataStream.close();
            int responseCode = httpConn.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                in = httpConn.getInputStream();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return in;
    }
public String getMessageofTheDay(String id) {
        StringBuffer mod = new StringBuffer();
        int serverModId = 0;
        int clientModId = 0;
        BufferedReader input = null;
        try {
            URL url = new URL(FlyShareApp.BASE_WEBSITE_URL + "/mod.txt");
            input = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            inputLine = input.readLine();
            try {
                clientModId = Integer.parseInt(id);
                serverModId = Integer.parseInt(inputLine);
            } catch (NumberFormatException e) {
            }
            if (clientModId < serverModId || clientModId == 0) {
                mod.append(serverModId);
                mod.append('|');
                while ((inputLine = input.readLine()) != null) mod.append(inputLine);
            }
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        } finally {
            try {
                input.close();
            } catch (Exception e) {
            }
        }
        return mod.toString();
    }
public static void copyFile(File source, File dest) throws IOException {
        if (source.equals(dest)) return;
        FileChannel srcChannel = new FileInputStream(source).getChannel();
        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
public static void addClasses(final Checker checker, final ArrayList<Class<?>> list, final String packageName, final int levels, final URL url) {
        final File directory = new File(url.getFile());
        if (directory.exists()) addClasses(checker, list, packageName, levels, directory); else try {
            final JarURLConnection conn = (JarURLConnection) url.openConnection();
            addClasses(checker, list, levels, conn, packageName.replace('.', '/'));
        } catch (final IOException ioex) {
            System.err.println(ioex);
        }
    }
public static void main(String[] args) throws Exception {
        HttpClient httpclient = new DefaultHttpClient();
        InputStream is = CheckAvailability.class.getResourceAsStream("/isbns.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String isbn = null;
        HttpGet get = null;
        while ((isbn = br.readLine().split(" ")[0]) != null) {
            System.out.println("Target url: \n\t" + String.format(isbnSearchUrl, isbn));
            get = new HttpGet(String.format(isbnSearchUrl, isbn));
            HttpResponse resp = httpclient.execute(get);
            Scanner s = new Scanner(resp.getEntity().getContent());
            String pattern = s.findWithinHorizon("((\\d*) hold[s]? on first copy returned of (\\d*) )?[cC]opies", 0);
            if (pattern != null) {
                MatchResult match = s.match();
                if (match.groupCount() == 3) {
                    if (match.group(2) == null) {
                        System.out.println(isbn + ": copies available");
                    } else {
                        System.out.println(isbn + ": " + match.group(2) + " holds on " + match.group(3) + " copies");
                    }
                }
            } else {
                System.out.println(isbn + ": no match");
            }
            get.abort();
        }
    }
public void transport(File file) throws TransportException {
        FTPClient client = new FTPClient();
        try {
            client.connect(getOption("host"));
            client.login(getOption("username"), getOption("password"));
            client.changeWorkingDirectory(getOption("remotePath"));
            transportRecursive(client, file);
            client.disconnect();
        } catch (Exception e) {
            throw new TransportException(e);
        }
    }
public static boolean loadContentFromURL(String fromURL, String toFile) {
        try {
            URL url = new URL("http://bible-desktop.com/xml" + fromURL);
            File file = new File(toFile);
            URLConnection ucon = url.openConnection();
            InputStream is = ucon.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            ByteArrayBuffer baf = new ByteArrayBuffer(50);
            int current = 0;
            while ((current = bis.read()) != -1) {
                baf.append((byte) current);
            }
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(baf.toByteArray());
            fos.close();
        } catch (IOException e) {
            Log.e(TAG, e);
            return false;
        }
        return true;
    }
public static JSONArray getFriends(long[] uids) throws ClientProtocolException, IOException, JSONException {
        HttpClient client = new DefaultHttpClient(params);
        HttpPost post = new HttpPost(FRIENDS_URI);
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new BasicNameValuePair("uids", arrayToString(uids, ",")));
        post.setEntity(new UrlEncodedFormEntity(parameters));
        HttpResponse response = client.execute(post);
        if (response.getStatusLine().getStatusCode() == 200) {
            String res = EntityUtils.toString(response.getEntity());
            return new JSONArray(res);
        }
        throw new IOException("bad http response:" + response.getStatusLine().getReasonPhrase());
    }
public static JSONObject getFriend(long uid) throws ClientProtocolException, IOException, JSONException {
        HttpClient client = new DefaultHttpClient(params);
        HttpPost post = new HttpPost(FRIENDS_URI);
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new BasicNameValuePair("uids", arrayToString(new long[] { uid }, ",")));
        post.setEntity(new UrlEncodedFormEntity(parameters));
        HttpResponse response = client.execute(post);
        if (response.getStatusLine().getStatusCode() == 200) {
            String res = EntityUtils.toString(response.getEntity());
            JSONArray result = new JSONArray(res);
            return result.getJSONObject(0);
        }
        throw new IOException("bad http response:" + response.getStatusLine().getReasonPhrase());
    }
public static long[] getOnlineUids(String myUid) throws ClientProtocolException, IOException, JSONException {
        HttpClient client = new DefaultHttpClient(params);
        HttpGet get = new HttpGet(UIDS_ONLINE_URI);
        HttpResponse response = client.execute(get);
        if (response.getStatusLine().getStatusCode() == 200) {
            String res = EntityUtils.toString(response.getEntity());
            JSONArray result = new JSONArray(res);
            long[] friends = new long[result.length()];
            int uid = Integer.parseInt(myUid);
            for (int i = 0; i < result.length(); i++) {
                if (uid != result.getInt(i)) {
                    friends[i] = result.getInt(i);
                }
            }
            return friends;
        }
        throw new IOException("bad http response:" + response.getStatusLine().getReasonPhrase());
    }
public static long[] getUids(String myUid) throws ClientProtocolException, IOException, JSONException {
        HttpClient client = new DefaultHttpClient(params);
        HttpGet get = new HttpGet(UIDS_URI);
        HttpResponse response = client.execute(get);
        if (response.getStatusLine().getStatusCode() == 200) {
            String res = EntityUtils.toString(response.getEntity());
            JSONArray result = new JSONArray(res);
            long[] friends = new long[result.length()];
            long uid = Long.parseLong(myUid);
            for (int i = 0; i < result.length(); i++) {
                if (uid != result.getLong(i)) {
                    friends[i] = result.getLong(i);
                }
            }
            return friends;
        }
        throw new IOException("bad http response:" + response.getStatusLine().getReasonPhrase());
    }
public static long[] getUidsNearMe(String myUid, double lat, double lon) throws ClientProtocolException, IOException, JSONException {
        HttpClient client = new DefaultHttpClient(params);
        HttpPost post = new HttpPost(UIDS_NEARME_URI);
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new BasicNameValuePair("latitude", Double.toString(lat)));
        parameters.add(new BasicNameValuePair("longitude", Double.toString(lon)));
        post.setEntity(new UrlEncodedFormEntity(parameters));
        HttpResponse response = client.execute(post);
        if (response.getStatusLine().getStatusCode() == 200) {
            String res = EntityUtils.toString(response.getEntity());
            JSONArray result = new JSONArray(res);
            long[] friends = new long[result.length()];
            int uid = Integer.parseInt(myUid);
            for (int i = 0; i < result.length(); i++) {
                if (uid != result.getInt(i)) {
                    friends[i] = result.getInt(i);
                }
            }
            return friends;
        }
        throw new IOException("bad http response:" + response.getStatusLine().getReasonPhrase());
    }
public static JSONObject delete(String uid) throws ClientProtocolException, IOException, JSONException {
        HttpClient client = new DefaultHttpClient(params);
        HttpGet get = new HttpGet(DELETE_URI + "?uid=" + uid);
        HttpResponse response = client.execute(get);
        if (response.getStatusLine().getStatusCode() == 200) {
            String res = EntityUtils.toString(response.getEntity());
            return new JSONObject(res);
        }
        throw new IOException("bad http response:" + response.getStatusLine().getReasonPhrase());
    }
public static JSONObject update(String name, String uid, double lat, double lon, boolean online) throws ClientProtocolException, IOException, JSONException {
        HttpClient client = new DefaultHttpClient(params);
        HttpPost post = new HttpPost(UPDATE_URI);
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new BasicNameValuePair("name", name));
        parameters.add(new BasicNameValuePair("uid", uid));
        parameters.add(new BasicNameValuePair("latitude", Double.toString(lat)));
        parameters.add(new BasicNameValuePair("longitude", Double.toString(lon)));
        parameters.add(new BasicNameValuePair("online", Boolean.toString(online)));
        post.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8));
        HttpResponse response = client.execute(post);
        if (response.getStatusLine().getStatusCode() == 200) {
            String res = EntityUtils.toString(response.getEntity());
            return new JSONObject(res);
        }
        throw new IOException("bad http response:" + response.getStatusLine().getReasonPhrase());
    }
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
        GrammarPool grammarpool = (GrammarPool) config.getProperty(XMLReaderObjectFactory.GRAMMER_POOL);
        if (isCalledAs("clear-grammar-cache")) {
            Sequence result = new ValueSequence();
            int before = countTotalNumberOfGrammar(grammarpool);
            LOG.debug("Clearing " + before + " grammars");
            clearGrammarPool(grammarpool);
            int after = countTotalNumberOfGrammar(grammarpool);
            LOG.debug("Remained " + after + " grammars");
            int delta = before - after;
            result.add(new IntegerValue(delta));
            return result;
        } else if (isCalledAs("show-grammar-cache")) {
            MemTreeBuilder builder = context.getDocumentBuilder();
            NodeImpl result = writeReport(grammarpool, builder);
            return result;
        } else if (isCalledAs("pre-parse-grammar")) {
            if (args[0].isEmpty()) return Sequence.EMPTY_SEQUENCE;
            XMLGrammarPreparser parser = new XMLGrammarPreparser();
            parser.registerPreparser(TYPE_XSD, null);
            List<Grammar> allGrammars = new ArrayList<Grammar>();
            for (SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
                String url = i.nextItem().getStringValue();
                if (url.startsWith("/")) {
                    url = "xmldb:exist://" + url;
                }
                LOG.debug("Parsing " + url);
                try {
                    if (url.endsWith(".xsd")) {
                        InputStream is = new URL(url).openStream();
                        XMLInputSource xis = new XMLInputSource(null, url, url, is, null);
                        Grammar schema = parser.preparseGrammar(TYPE_XSD, xis);
                        is.close();
                        allGrammars.add(schema);
                    } else {
                        throw new XPathException(this, "Only XMLSchemas can be preparsed.");
                    }
                } catch (IOException ex) {
                    LOG.debug(ex);
                    throw new XPathException(this, ex);
                } catch (Exception ex) {
                    LOG.debug(ex);
                    throw new XPathException(this, ex);
                }
            }
            LOG.debug("Successfully parsed " + allGrammars.size() + " grammars.");
            Grammar grammars[] = new Grammar[allGrammars.size()];
            grammars = allGrammars.toArray(grammars);
            grammarpool.cacheGrammars(TYPE_XSD, grammars);
            ValueSequence result = new ValueSequence();
            for (Grammar one : grammars) {
                result.add(new StringValue(one.getGrammarDescription().getNamespace()));
            }
            return result;
        } else {
            LOG.error("function not found error");
            throw new XPathException(this, "function not found");
        }
    }
public WebFileInputStream(URL url, String userAgent) throws IOException {
        final java.net.URLConnection uconn = url.openConnection();
        if (!(uconn instanceof java.net.HttpURLConnection)) {
            throw new java.lang.IllegalArgumentException("URL protocol must be HTTP: " + url.toExternalForm());
        }
        final java.net.HttpURLConnection conn = (java.net.HttpURLConnection) uconn;
        conn.setConnectTimeout(10000);
        conn.setReadTimeout(10000);
        conn.setInstanceFollowRedirects(true);
        conn.setRequestProperty("User-agent", userAgent);
        conn.connect();
        responseHeader = conn.getHeaderFields();
        responseCode = conn.getResponseCode();
        if (responseCode != 200) {
            if (log.isDebugEnabled()) {
                log.debug(getErrors(conn));
            }
            if (responseCode == 404) {
                throw new IOException(MessageFormat.format(Messages.getString("WebFileInputStream.ERROR_404"), url.toExternalForm()));
            } else if (responseCode == 500) {
                throw new IOException(MessageFormat.format(Messages.getString("WebFileInputStream.ERROR_500"), url.toExternalForm()));
            } else if (responseCode == 403) {
                throw new IOException(MessageFormat.format(Messages.getString("WebFileInputStream.ERROR_403"), url.toExternalForm()));
            } else {
                throw new IOException(MessageFormat.format(Messages.getString("WebFileInputStream.ERROR_OTHER"), url.toExternalForm(), responseCode));
            }
        }
        final String type = conn.getContentType();
        if (type != null) {
            final String[] parts = type.split(";");
            MIMEtype = parts[0].trim();
            for (int i = 1; i < parts.length && charset == null; i++) {
                final String t = parts[i].trim();
                final int index = t.toLowerCase().indexOf("charset=");
                if (index != -1) {
                    charset = t.substring(index + 8);
                }
            }
        }
        Object c = conn.getContent();
        if (c instanceof InputStream) {
            content = (InputStream) c;
        } else {
            content = conn.getInputStream();
        }
    }
private String searchMetabolite(String name) {
        {
            BufferedReader in = null;
            try {
                String urlName = name;
                URL url = new URL(urlName);
                in = new BufferedReader(new InputStreamReader(url.openStream()));
                String inputLine;
                Boolean isMetabolite = false;
                while ((inputLine = in.readLine()) != null) {
                    if (inputLine.contains("Metabolite</h1>")) {
                        isMetabolite = true;
                    }
                    if (inputLine.contains("<td><a href=\"/Metabolites/") && isMetabolite) {
                        String metName = inputLine.substring(inputLine.indexOf("/Metabolites/") + 13, inputLine.indexOf("aspx\" target") + 4);
                        return "http://gmd.mpimp-golm.mpg.de/Metabolites/" + metName;
                    }
                }
                in.close();
                return name;
            } catch (IOException ex) {
                Logger.getLogger(GetGolmIDsTask.class.getName()).log(Level.SEVERE, null, ex);
                return null;
            }
        }
    }
public void connectUrl(String url) throws MalformedURLException, IOException {
        URLConnection connection = new URL(url).openConnection();
        connection.connect();
        connection.getInputStream().close();
        connection.getOutputStream().close();
    }
public void downloadQFromMinibix(int ticketNo) {
        String minibixDomain = Preferences.userRoot().node("Spectatus").get("MBAddr", "http://mathassess.caret.cam.ac.uk");
        String minibixPort = Preferences.userRoot().node("Spectatus").get("MBPort", "80");
        String url = minibixDomain + ":" + minibixPort + "/qtibank-webserv/deposits/all/" + ticketNo;
        File file = new File(tempdir + sep + "minibix.zip");
        try {
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(url);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream instream = entity.getContent();
                int l;
                byte[] tmp = new byte[2048];
                while ((l = instream.read(tmp)) != -1) {
                    out.write(tmp, 0, l);
                }
                out.close();
                instream.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }