semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static synchronized Map<String, Object> getURLContentMap(String wwwurl) throws IOException, URISyntaxException {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        URI uri = new URI(wwwurl);
        URL url = new URL(uri.toASCIIString());
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10 * 1000);
        HttpURLConnection.setFollowRedirects(true);
        try {
            conn.setRequestMethod("GET");
            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110421 Red Hat/3.6-1.el5_6 Firefox/3.6.17");
            for (String key : conn.getHeaderFields().keySet()) {
                List<String> headerInfo = conn.getHeaderFields().get(key);
                if (headerInfo.size() > 0) {
                    resultMap.put(key, headerInfo.get(0));
                }
            }
            String contentType = conn.getContentType();
            if (!(contentType == null || contentType.toLowerCase().contains("text") || contentType.toLowerCase().contains("html"))) {
                return resultMap;
            }
            ByteArrayOutputStream outstream = new ByteArrayOutputStream();
            InputStream instream = conn.getInputStream();
            synchronized (instream) {
                int readSize = 0;
                int totalSize = 0;
                byte[] contentByte = null;
                byte[] buffer = new byte[1024];
                while ((readSize = instream.read(buffer)) > 0) {
                    outstream.write(buffer, 0, readSize);
                    totalSize += readSize;
                    if (totalSize >= MAX_CONTENT_SIZE) {
                        contentByte = ("[FAILD] content size is larger than " + MAX_CONTENT_SIZE + " byte.").getBytes();
                    }
                }
                if (contentByte == null) {
                    contentByte = outstream.toByteArray();
                }
                instream.close();
                outstream.close();
                resultMap.put(contentByteField, contentByte);
            }
        } finally {
        }
        return resultMap;
    }
private static void getPatronInfo(HttpClient client) throws Exception {
        HttpGet httpget = new HttpGet("http://libsys.arlingtonva.us/patroninfo~S1/1079675/items");
        HttpResponse response = client.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            System.out.println(EntityUtils.toString(entity));
        }
        EntityUtils.consume(entity);
    }
private static void login(HttpClient client, String token) throws Exception {
        HttpPost login = new HttpPost("https://libsys.arlingtonva.us/iii/cas/login?service=http&amp;scope=1");
        List<NameValuePair> formParams = new ArrayList<NameValuePair>();
        formParams.add(new BasicNameValuePair("code", "202002686286"));
        formParams.add(new BasicNameValuePair("pin", "3128"));
        formParams.add(new BasicNameValuePair("_eventId", "submit"));
        formParams.add(new BasicNameValuePair("lt", token));
        UrlEncodedFormEntity form = new UrlEncodedFormEntity(formParams, "UTF-8");
        login.setEntity(form);
        HttpResponse response = client.execute(login);
        EntityUtils.consume(response.getEntity());
        Header[] headers = response.getAllHeaders();
        System.out.println("HEADERS: ");
        for (Header hdr : headers) {
            System.out.println(hdr.getName() + ": " + hdr.getValue());
        }
    }
private static String getToken(HttpClient client) throws Exception {
        String token = null;
        HttpGet httpget = new HttpGet("https://libsys.arlingtonva.us/iii/cas/login?service=http&scope=1");
        HttpResponse response = client.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            entity = new BufferedHttpEntity(entity);
        }
        if (entity != null) {
            String resp = EntityUtils.toString(entity);
            EntityUtils.consume(entity);
            Pattern pattern = Pattern.compile("<input .*name=\"lt\".*value=\"(.*)\".*/>");
            Matcher matcher = pattern.matcher(resp);
            if (matcher.find()) {
                token = matcher.group(1);
            }
        }
        return token;
    }
private Map getBlackHoleData() throws Exception {
        File dataFile = new File(Kit.getDataDir() + BLACK_HOLE);
        if (dataFile.exists() && daysOld(dataFile) < 1) {
            return getStoredData(dataFile);
        }
        InputStream stream = null;
        try {
            String bh_url = "http://www.critique.org/users/critters/blackholes/sightdata.html";
            URL url = new URL(bh_url);
            stream = url.openStream();
        } catch (IOException e) {
            return getStoredData(dataFile);
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(stream));
        StringBuffer data = new StringBuffer();
        String line;
        while ((line = br.readLine()) != null) {
            data.append(line);
        }
        br.close();
        Pattern p = Pattern.compile(regexp);
        Matcher m = p.matcher(data);
        Map map = new THashMap();
        while (m.find()) {
            map.put(m.group(1).trim(), new ReplyTimeDatum(Integer.parseInt(m.group(3)), Integer.parseInt(m.group(4)), 0, Integer.parseInt(m.group(2))));
        }
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(dataFile));
        oos.writeObject(map);
        oos.close();
        return map;
    }
public static StringBuffer getCachedFile(String url) throws Exception {
        File urlCache = new File("tmp-cache/" + url.replace('/', '-'));
        new File("tmp-cache/").mkdir();
        if (urlCache.exists()) {
            BufferedReader in = new BufferedReader(new FileReader(urlCache));
            StringBuffer buffer = new StringBuffer();
            String input;
            while ((input = in.readLine()) != null) {
                buffer.append(input + "\n");
            }
            in.close();
            return buffer;
        } else {
            URL url2 = new URL(url.replace(" ", "%20"));
            BufferedReader in = new BufferedReader(new InputStreamReader(url2.openStream()));
            BufferedWriter cacheWriter = new BufferedWriter(new FileWriter(urlCache));
            StringBuffer buffer = new StringBuffer();
            String input;
            while ((input = in.readLine()) != null) {
                buffer.append(input + "\n");
                cacheWriter.write(input + "\n");
            }
            cacheWriter.close();
            in.close();
            return buffer;
        }
    }
public synchronized String encrypt(String plaintext) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = null;
        md = MessageDigest.getInstance("SHA");
        md.update(plaintext.getBytes("UTF-8"));
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
private void appendAndDelete(FileOutputStream outstream, String file) throws FileNotFoundException, IOException {
        FileInputStream input = new FileInputStream(file);
        byte[] buffer = new byte[65536];
        int l;
        while ((l = input.read(buffer)) != -1) outstream.write(buffer, 0, l);
        input.close();
        new File(file).delete();
    }
@Override
    protected void setUp() throws Exception {
        super.setUp();
        FTPConf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
        FTPConf.setServerTimeZoneId("GMT");
        FTP.configure(FTPConf);
        try {
            FTP.connect("tgftp.nws.noaa.gov");
            FTP.login("anonymous", "testing@apache.org");
            FTP.changeWorkingDirectory("SL.us008001/DF.an/DC.sflnd/DS.metar");
            FTP.enterLocalPassiveMode();
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
@LargeTest
    public void testThreadCheck() throws Exception {
        ContentResolver resolver = getContext().getContentResolver();
        GoogleHttpClient client = new GoogleHttpClient(resolver, "Test", false);
        try {
            HttpGet method = new HttpGet(mServerUrl);
            AndroidHttpClient.setThreadBlocked(true);
            try {
                client.execute(method);
                fail("\"thread forbids HTTP requests\" exception expected");
            } catch (RuntimeException e) {
                if (!e.toString().contains("forbids HTTP requests")) throw e;
            } finally {
                AndroidHttpClient.setThreadBlocked(false);
            }
            HttpResponse response = client.execute(method);
            assertEquals("/", EntityUtils.toString(response.getEntity()));
        } finally {
            client.close();
        }
    }
@MediumTest
    public void testUrlRewriteRules() throws Exception {
        ContentResolver resolver = getContext().getContentResolver();
        GoogleHttpClient client = new GoogleHttpClient(resolver, "Test", false);
        Settings.Gservices.putString(resolver, "url:test", "http://foo.bar/ rewrite " + mServerUrl + "new/");
        Settings.Gservices.putString(resolver, "digest", mServerUrl);
        try {
            HttpGet method = new HttpGet("http://foo.bar/path");
            HttpResponse response = client.execute(method);
            String body = EntityUtils.toString(response.getEntity());
            assertEquals("/new/path", body);
        } finally {
            client.close();
        }
    }
public void sort(int[] order, double[] values) {
        int temp = 0;
        boolean done = false;
        for (int i = 0; i < values.length; i++) {
            order[i] = i;
        }
        if (desendingValues) {
            while (!done) {
                done = true;
                for (int i = values.length - 2; i >= 0; i--) {
                    if (values[order[i]] < values[order[i + 1]]) {
                        done = false;
                        temp = order[i];
                        order[i] = order[i + 1];
                        order[i + 1] = temp;
                    }
                }
            }
        } else {
            while (!done) {
                done = true;
                for (int i = values.length - 2; i >= 0; i--) {
                    if (values[order[i]] > values[order[i + 1]]) {
                        done = false;
                        temp = order[i];
                        order[i] = order[i + 1];
                        order[i + 1] = temp;
                    }
                }
            }
        }
    }
@Override
    public void insert(Connection conn) throws SQLException {
        PreparedStatement objectInsert = null;
        String sqlString = null;
        int newID = 0;
        try {
            conn.setAutoCommit(false);
            sqlString = "SELECT NEXTVAL(OBJ_SEQ) AS NEXTVAL";
            objectInsert = conn.prepareStatement(sqlString);
            ResultSet r = objectInsert.executeQuery(sqlString);
            newID = r.getInt("NEXTVAL");
            sqlString = "INSERT INTO OBJECTS" + "(" + "OBJ_ID," + "OBJ_NAME," + "OBTY_CDE" + ")" + "VALUES" + "(" + "?," + "?," + "?" + ")" + "";
            objectInsert = conn.prepareStatement(sqlString);
            objectInsert.setInt(1, newID);
            objectInsert.setString(2, getRoomKey());
            objectInsert.setString(3, "ROOM");
            objectInsert.executeUpdate();
            sqlString = "INSERT INTO ROOMS" + "(" + "";
            conn.commit();
        } catch (SQLException e) {
            e.printStackTrace();
            if (conn != null) {
                try {
                    System.err.print("Transaction is being rolled back");
                    conn.rollback();
                } catch (SQLException excep) {
                    excep.printStackTrace();
                }
            }
        } finally {
            if (objectInsert != null) {
                objectInsert.close();
            }
            conn.setAutoCommit(true);
        }
    }
public static void saveFileData(File file, File destination, java.io.File newDataFile) throws Exception {
        String fileName = file.getFileName();
        String assetsPath = FileFactory.getRealAssetsRootPath();
        new java.io.File(assetsPath).mkdir();
        java.io.File workingFile = getAssetIOFile(file);
        DotResourceCache vc = CacheLocator.getVeloctyResourceCache();
        vc.remove(ResourceManager.RESOURCE_TEMPLATE + workingFile.getPath());
        if (destination != null && destination.getInode() > 0) {
            FileInputStream is = new FileInputStream(workingFile);
            FileChannel channelFrom = is.getChannel();
            java.io.File newVersionFile = getAssetIOFile(destination);
            FileChannel channelTo = new FileOutputStream(newVersionFile).getChannel();
            channelFrom.transferTo(0, channelFrom.size(), channelTo);
            channelTo.force(false);
            channelTo.close();
            channelFrom.close();
        }
        if (newDataFile != null) {
            FileChannel writeCurrentChannel = new FileOutputStream(workingFile).getChannel();
            writeCurrentChannel.truncate(0);
            FileChannel fromChannel = new FileInputStream(newDataFile).getChannel();
            fromChannel.transferTo(0, fromChannel.size(), writeCurrentChannel);
            writeCurrentChannel.force(false);
            writeCurrentChannel.close();
            fromChannel.close();
            if (UtilMethods.isImage(fileName)) {
                BufferedImage img = javax.imageio.ImageIO.read(workingFile);
                int height = img.getHeight();
                file.setHeight(height);
                int width = img.getWidth();
                file.setWidth(width);
            }
            String folderPath = workingFile.getParentFile().getAbsolutePath();
            Identifier identifier = IdentifierCache.getIdentifierFromIdentifierCache(file);
            java.io.File directory = new java.io.File(folderPath);
            java.io.File[] files = directory.listFiles((new FileFactory()).new ThumbnailsFileNamesFilter(identifier));
            for (java.io.File iofile : files) {
                try {
                    iofile.delete();
                } catch (SecurityException e) {
                    Logger.error(FileFactory.class, "EditFileAction._saveWorkingFileData(): " + iofile.getName() + " cannot be erased. Please check the file permissions.");
                } catch (Exception e) {
                    Logger.error(FileFactory.class, "EditFileAction._saveWorkingFileData(): " + e.getMessage());
                }
            }
        }
    }
public static void upper() throws Exception {
        File input = new File("dateiname");
        PostMethod post = new PostMethod("url");
        post.setRequestBody(new FileInputStream(input));
        if (input.length() < Integer.MAX_VALUE) post.setRequestContentLength((int) input.length()); else post.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
        post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859�1");
        HttpClient httpclient = new HttpClient();
        httpclient.executeMethod(post);
        post.releaseConnection();
        URL url = new URL("https://www.amazon.de/");
        URLConnection conn = url.openConnection();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            System.out.println(line);
        }
        rd.close();
    }
protected boolean testPort(String protocol, String server, int port, String file) {
        System.out.println("testPort[" + protocol + "," + server + ", " + port + ", " + file + "]");
        URL url = null;
        try {
            url = new URL(protocol, server, port, file);
        } catch (MalformedURLException ex) {
            log.severe("No URL for Protocol=" + protocol + ", Server=" + server + ": " + ex.getMessage());
            return false;
        }
        try {
            URLConnection c = url.openConnection();
            Object o = c.getContent();
            if (o == null) log.warning("In use=" + url); else log.warning("In Use=" + url);
        } catch (Exception ex) {
            log.fine("Not used=" + url);
            return false;
        }
        return true;
    }
public void invoke() throws IOException {
        String[] command = new String[files.length + options.length + 2];
        command[0] = chmod;
        System.arraycopy(options, 0, command, 1, options.length);
        command[1 + options.length] = perms;
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            command[2 + options.length + i] = file.getAbsolutePath();
        }
        Process p = Runtime.getRuntime().exec(command);
        try {
            p.waitFor();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        if (p.exitValue() != 0) {
            StringWriter writer = new StringWriter();
            IOUtils.copy(p.getErrorStream(), writer);
            throw new IOException("Unable to chmod files: " + writer.toString());
        }
    }
public static String getRefCatastral(String pURL) {
        String result = new String();
        String iniPC1 = "<pc1>";
        String iniPC2 = "<pc2>";
        String finPC1 = "</pc1>";
        String finPC2 = "</pc2>";
        String iniCuerr = "<cuerr>";
        String finCuerr = "</cuerr>";
        String iniDesErr = "<des>";
        String finDesErr = "</des>";
        boolean error = false;
        int ini, fin;
        try {
            URL url = new URL(pURL);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                if (str.contains(iniCuerr)) {
                    ini = str.indexOf(iniCuerr) + iniCuerr.length();
                    fin = str.indexOf(finCuerr);
                    if (Integer.parseInt(str.substring(ini, fin)) > 0) error = true;
                }
                if (error) {
                    if (str.contains(iniDesErr)) {
                        ini = str.indexOf(iniDesErr) + iniDesErr.length();
                        fin = str.indexOf(finDesErr);
                        throw (new Exception(str.substring(ini, fin)));
                    }
                } else {
                    if (str.contains(iniPC1)) {
                        ini = str.indexOf(iniPC1) + iniPC1.length();
                        fin = str.indexOf(finPC1);
                        result = str.substring(ini, fin);
                    }
                    if (str.contains(iniPC2)) {
                        ini = str.indexOf(iniPC2) + iniPC2.length();
                        fin = str.indexOf(finPC2);
                        result = result.concat(str.substring(ini, fin));
                    }
                }
            }
            in.close();
        } catch (Exception e) {
            System.err.println(e);
        }
        return result;
    }
public static Coordinate getCoordenadas(String RCoURL) {
        Coordinate coord = new Coordinate();
        String pURL;
        String iniPC1 = "<pc1>";
        String iniPC2 = "<pc2>";
        String finPC1 = "</pc1>";
        String finPC2 = "</pc2>";
        String iniX = "<xcen>";
        String iniY = "<ycen>";
        String finX = "</xcen>";
        String finY = "</ycen>";
        String iniCuerr = "<cuerr>";
        String finCuerr = "</cuerr>";
        String iniDesErr = "<des>";
        String finDesErr = "</des>";
        boolean error = false;
        int ini, fin;
        if (RCoURL.contains("/") || RCoURL.contains("\\") || RCoURL.contains(".")) pURL = RCoURL; else {
            if (RCoURL.length() > 14) pURL = baseURL[1].replace("<RC>", RCoURL.substring(0, 14)); else pURL = baseURL[1].replace("<RC>", RCoURL);
        }
        try {
            URL url = new URL(pURL);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                if (str.contains(iniCuerr)) {
                    ini = str.indexOf(iniCuerr) + iniCuerr.length();
                    fin = str.indexOf(finCuerr);
                    if (Integer.parseInt(str.substring(ini, fin)) > 0) error = true;
                }
                if (error) {
                    if (str.contains(iniDesErr)) {
                        ini = str.indexOf(iniDesErr) + iniDesErr.length();
                        fin = str.indexOf(finDesErr);
                        throw (new Exception(str.substring(ini, fin)));
                    }
                } else {
                    if (str.contains(iniPC1)) {
                        ini = str.indexOf(iniPC1) + iniPC1.length();
                        fin = str.indexOf(finPC1);
                        coord.setDescription(str.substring(ini, fin));
                    }
                    if (str.contains(iniPC2)) {
                        ini = str.indexOf(iniPC2) + iniPC2.length();
                        fin = str.indexOf(finPC2);
                        coord.setDescription(coord.getDescription().concat(str.substring(ini, fin)));
                    }
                    if (str.contains(iniX)) {
                        ini = str.indexOf(iniX) + iniX.length();
                        fin = str.indexOf(finX);
                        coord.setLongitude(Double.parseDouble(str.substring(ini, fin)));
                    }
                    if (str.contains(iniY)) {
                        ini = str.indexOf(iniY) + iniY.length();
                        fin = str.indexOf(finY);
                        coord.setLatitude(Double.parseDouble(str.substring(ini, fin)));
                    }
                }
            }
            in.close();
        } catch (Exception e) {
            System.err.println(e);
        }
        return coord;
    }
public static String getURLContent(String urlStr) throws MalformedURLException, IOException {
        URL url = new URL(urlStr);
        log.info("url: " + url);
        URLConnection conn = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuffer buf = new StringBuffer();
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            buf.append(inputLine);
        }
        in.close();
        return buf.toString();
    }
public String httpToStringStupid(String url) throws IllegalStateException, IOException, HttpException, InterruptedException, URISyntaxException {
        String pageDump = null;
        getParams().setParameter(ClientPNames.COOKIE_POLICY, org.apache.http.client.params.CookiePolicy.BROWSER_COMPATIBILITY);
        getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, getPreferenceService().getSearchSocketTimeout());
        HttpGet httpget = new HttpGet(url);
        httpget.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, getPreferenceService().getSearchSocketTimeout());
        HttpResponse response = execute(httpget);
        HttpEntity entity = response.getEntity();
        pageDump = IOUtils.toString(entity.getContent(), "UTF-8");
        return pageDump;
    }