semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static PointGeomReader[] loadResourceList(final String resourceName, ClassLoader loader) {
        if (loader == null) loader = ClassLoader.getSystemClassLoader();
        final FastSet<PointGeomReader> result = FastSet.newInstance();
        try {
            final Enumeration<URL> resources = loader.getResources(resourceName);
            if (resources != null) {
                while (resources.hasMoreElements()) {
                    final URL url = resources.nextElement();
                    final Properties mapping;
                    InputStream urlIn = null;
                    try {
                        urlIn = url.openStream();
                        mapping = new Properties();
                        mapping.load(urlIn);
                    } catch (IOException ioe) {
                        continue;
                    } finally {
                        if (urlIn != null) try {
                            urlIn.close();
                        } catch (Exception ignore) {
                        }
                    }
                    for (Enumeration keys = mapping.propertyNames(); keys.hasMoreElements(); ) {
                        final String format = (String) keys.nextElement();
                        final String implClassName = mapping.getProperty(format);
                        result.add(loadResource(implClassName, loader));
                    }
                }
            }
        } catch (IOException ignore) {
        }
        PointGeomReader[] resultArr = result.toArray(new PointGeomReader[result.size()]);
        Arrays.sort(resultArr, FastComparator.DEFAULT);
        FastSet.recycle(result);
        return resultArr;
    }
protected void onlyFileCopy(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            int maxCount = (1024 * 1024 * 64) - (1024 * 32);
            long size = inChannel.size();
            long pos = 0;
            while (pos < size) {
                pos += inChannel.transferTo(pos, maxCount, outChannel);
            }
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
public void dorequest(Map<String, String> ps, String method) throws IOException {
        StringBuffer httpResponse = new StringBuffer();
        URL ourl = new URL(url);
        HttpURLConnection httpConnection = (HttpURLConnection) ourl.openConnection();
        httpConnection.setRequestMethod(method);
        httpConnection.setDoOutput(true);
        this.setCookie(httpConnection);
        OutputStream httpOutputStream = httpConnection.getOutputStream();
        StringBuffer postParams = new StringBuffer("");
        for (Entry<String, String> entry : ps.entrySet()) {
            postParams.append(entry.getKey());
            postParams.append("=");
            postParams.append(entry.getValue());
            postParams.append("&");
        }
        httpOutputStream.write(postParams.toString().getBytes());
        BufferedReader httpBufferedReader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
        httpResponse.append(this.readBufferedContent(httpBufferedReader));
        text = httpResponse.toString();
        this.readCookie(httpConnection);
    }
@Override
    public JSONObject runCommand(JSONObject payload, HttpSession session) throws DefinedException {
        String sessionId = session.getId();
        log.debug("Login -> runCommand SID: " + sessionId);
        JSONObject toReturn = new JSONObject();
        boolean isOK = true;
        String username = null;
        try {
            username = payload.getString(ComConstants.LogIn.Request.USERNAME);
        } catch (JSONException e) {
            log.error("SessionId=" + sessionId + ", Missing username parameter", e);
            throw new DefinedException(StatusCodesV2.PARAMETER_ERROR);
        }
        String password = null;
        if (isOK) {
            try {
                password = payload.getString(ComConstants.LogIn.Request.PASSWORD);
            } catch (JSONException e) {
                log.error("SessionId=" + sessionId + ", Missing password parameter", e);
                throw new DefinedException(StatusCodesV2.PARAMETER_ERROR);
            }
        }
        if (isOK) {
            MessageDigest m = null;
            try {
                m = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
                log.error("SessionId=" + sessionId + ", MD5 algorithm does not exist", e);
                e.printStackTrace();
                throw new DefinedException(StatusCodesV2.INTERNAL_SYSTEM_FAILURE);
            }
            m.update(password.getBytes(), 0, password.length());
            password = new BigInteger(1, m.digest()).toString(16);
            UserSession userSession = pli.login(username, password);
            try {
                if (userSession != null) {
                    session.setAttribute("user", userSession);
                    toReturn.put(ComConstants.Response.STATUS_CODE, StatusCodesV2.LOGIN_OK.getStatusCode());
                    toReturn.put(ComConstants.Response.STATUS_MESSAGE, StatusCodesV2.LOGIN_OK.getStatusMessage());
                } else {
                    log.error("SessionId=" + sessionId + ", Login failed: username=" + username + " not found");
                    toReturn.put(ComConstants.Response.STATUS_CODE, StatusCodesV2.LOGIN_USER_OR_PASSWORD_INCORRECT.getStatusCode());
                    toReturn.put(ComConstants.Response.STATUS_MESSAGE, StatusCodesV2.LOGIN_USER_OR_PASSWORD_INCORRECT.getStatusMessage());
                }
            } catch (JSONException e) {
                log.error("SessionId=" + sessionId + ", JSON exception occured in response", e);
                e.printStackTrace();
                throw new DefinedException(StatusCodesV2.INTERNAL_SYSTEM_FAILURE);
            }
        }
        log.debug("Login <- runCommand SID: " + sessionId);
        return toReturn;
    }
private String getData(String myurl) throws Exception {
        URL url = new URL(myurl);
        uc = (HttpURLConnection) url.openConnection();
        br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        String temp = "", k = "";
        while ((temp = br.readLine()) != null) {
            k += temp;
        }
        br.close();
        return k;
    }
private void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        if (zShareAccount.loginsuccessful) {
            httppost.setHeader("Cookie", zShareAccount.getSidcookie() + ";" + zShareAccount.getMysessioncookie());
        } else {
            httppost.setHeader("Cookie", sidcookie + ";" + mysessioncookie);
        }
        generateZShareID();
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        mpEntity.addPart("", new MonitoredFileBody(file, uploadProgress));
        mpEntity.addPart("TOS", new StringBody("1"));
        httppost.setEntity(mpEntity);
        NULogger.getLogger().log(Level.INFO, "executing request {0}", httppost.getRequestLine());
        status = UploadStatus.UPLOADING;
        NULogger.getLogger().info("Now uploading your file into zshare.net");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        NULogger.getLogger().info(response.getStatusLine().toString());
        if (resEntity != null) {
            uploadresponse = EntityUtils.toString(resEntity);
        }
        uploadresponse = uploadresponse.replaceAll("\n", "");
        uploadresponse = uploadresponse.substring(uploadresponse.indexOf("index2.php"));
        uploadresponse = uploadresponse.substring(0, uploadresponse.indexOf("\">here"));
        uploadresponse = uploadresponse.replaceAll("amp;", "");
        if (zShareAccount.loginsuccessful) {
            uploadresponse = zShareAccount.getZsharelink() + uploadresponse;
        } else {
            uploadresponse = zsharelink + uploadresponse;
        }
        uploadresponse = uploadresponse.replaceAll(" ", "%20");
        NULogger.getLogger().log(Level.INFO, "resp : {0}", uploadresponse);
        httpclient.getConnectionManager().shutdown();
    }
private void getDownloadLink() throws Exception {
        status = UploadStatus.GETTINGLINK;
        NULogger.getLogger().info("Now Getting Download link...");
        HttpClient client = new DefaultHttpClient();
        HttpGet h = new HttpGet(uploadresponse);
        h.setHeader("Referer", postURL);
        if (zShareAccount.loginsuccessful) {
            h.setHeader("Cookie", zShareAccount.getSidcookie() + ";" + zShareAccount.getMysessioncookie());
        } else {
            h.setHeader("Cookie", sidcookie + ";" + mysessioncookie);
        }
        HttpResponse res = client.execute(h);
        HttpEntity entity = res.getEntity();
        linkpage = EntityUtils.toString(entity);
        linkpage = linkpage.replaceAll("\n", "");
        downloadlink = CommonUploaderTasks.parseResponse(linkpage, "value=\"", "\"");
        deletelink = CommonUploaderTasks.parseResponse(linkpage, "delete.html?", "\"");
        deletelink = "http://www.zshare.net/delete.html?" + deletelink;
        downURL = downloadlink;
        delURL = deletelink;
        NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
        NULogger.getLogger().log(Level.INFO, "Delete Link : {0}", deletelink);
        uploadFinished();
    }
public static boolean encodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            closeQuietly(in);
            closeQuietly(out);
        }
        return success;
    }
public static boolean decodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.DECODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            closeQuietly(in);
            closeQuietly(out);
        }
        return success;
    }
public String selectFROM() throws Exception {
        BufferedReader in = null;
        String data = null;
        try {
            HttpClient httpclient = new DefaultHttpClient();
            URI uri = new URI("http://**.**.**.**/OctopusManager/index2.php");
            HttpGet request = new HttpGet();
            request.setURI(uri);
            HttpResponse httpresponse = httpclient.execute(request);
            HttpEntity httpentity = httpresponse.getEntity();
            in = new BufferedReader(new InputStreamReader(httpentity.getContent()));
            StringBuffer sb = new StringBuffer("");
            String line = "";
            while ((line = in.readLine()) != null) {
                sb.append(line);
            }
            in.close();
            data = sb.toString();
            return data;
        } finally {
            if (in != null) {
                try {
                    in.close();
                    return data;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
@Override
    public User saveUser(User user) {
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(user.getPassword().getBytes("UTF-8"));
            byte[] hash = digest.digest();
            BigInteger bigInt = new BigInteger(1, hash);
            String hashtext = bigInt.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            user.setPassword(hashtext);
            user.setDataRegjistrimit(new Date());
            return em.merge(user);
        } catch (Exception e) {
            throw new NestedException(e.getMessage(), e);
        }
    }
@Override
    public User login(String username, String password) {
        User user = null;
        try {
            user = (User) em.createQuery("Select o from User o where o.username = :username").setParameter("username", username).getSingleResult();
        } catch (NoResultException e) {
            throw new NestedException(e.getMessage(), e);
        }
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(password.getBytes("UTF-8"));
            byte[] hash = digest.digest();
            BigInteger bigInt = new BigInteger(1, hash);
            String hashtext = bigInt.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            if (hashtext.equals(user.getPassword())) return user;
        } catch (Exception e) {
            throw new NestedException(e.getMessage(), e);
        }
        return null;
    }
public void createFile(File src, String filename) throws IOException {
        try {
            FileInputStream fis = new FileInputStream(src);
            OutputStream fos = this.fileResourceManager.writeResource(this.txId, filename);
            IOUtils.copy(fis, fos);
            fos.close();
            fis.close();
        } catch (ResourceManagerException e) {
            LOGGER.error(e);
        }
    }
public boolean download(URL url, File file) {
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        try {
            out = new BufferedOutputStream(new FileOutputStream(file));
            conn = url.openConnection();
            in = conn.getInputStream();
            byte[] buffer = new byte[4096];
            int numRead;
            long numWritten = 0;
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
                numWritten += numRead;
            }
        } catch (Exception e) {
            System.out.println(e);
            return false;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException ioe) {
                return false;
            }
        }
        return true;
    }
public static Reader getReader(String rPath) {
        try {
            URL url = getResource(rPath);
            if (url != null) return new InputStreamReader(url.openStream());
            File file = new File(rPath);
            if (file.canRead()) return new FileReader(file);
        } catch (Exception ex) {
            System.out.println("could not create reader for " + rPath);
        }
        return null;
    }
void testFileObject(JavaFileObject fo) throws Exception {
        URI uri = fo.toUri();
        System.err.println("uri: " + uri);
        URLConnection urlconn = uri.toURL().openConnection();
        if (urlconn instanceof JarURLConnection) {
            JarURLConnection jarconn = (JarURLConnection) urlconn;
            File f = new File(jarconn.getJarFile().getName());
            foundJars.add(f.getName());
        }
        try {
            byte[] uriData = read(urlconn.getInputStream());
            byte[] foData = read(fo.openInputStream());
            if (!Arrays.equals(uriData, foData)) {
                if (uriData.length != foData.length) throw new Exception("data size differs: uri data " + uriData.length + " bytes, fo data " + foData.length + " bytes");
                for (int i = 0; i < uriData.length; i++) {
                    if (uriData[i] != foData[i]) throw new Exception("unexpected data returned at offset " + i + ", uri data " + uriData[i] + ", fo data " + foData[i]);
                }
                throw new AssertionError("cannot find difference");
            }
        } finally {
            if (urlconn instanceof JarURLConnection) {
                JarURLConnection jarconn = (JarURLConnection) urlconn;
                jarconn.getJarFile().close();
            }
        }
    }
private String MD5(String text) {
        try {
            MessageDigest md;
            md = MessageDigest.getInstance("MD5");
            byte[] md5hash = new byte[32];
            md.update(text.getBytes("iso-8859-1"), 0, text.length());
            md5hash = md.digest();
            return convertToHex(md5hash);
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        return null;
    }
public static void pingSearchEngine(String engineURL) throws MalformedURLException, UnsupportedEncodingException {
        if ((ConfigurationManager.getProperty("http.proxy.host") != null) && (ConfigurationManager.getProperty("http.proxy.port") != null)) {
            System.setProperty("proxySet", "true");
            System.setProperty("proxyHost", ConfigurationManager.getProperty("http.proxy.host"));
            System.getProperty("proxyPort", ConfigurationManager.getProperty("http.proxy.port"));
        }
        String sitemapURL = ConfigurationManager.getProperty("dspace.url") + "/sitemap";
        URL url = new URL(engineURL + URLEncoder.encode(sitemapURL, "UTF-8"));
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuffer resp = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                resp.append(inputLine).append("\n");
            }
            in.close();
            if (connection.getResponseCode() == 200) {
                log.info("Pinged " + url.toString() + " successfully");
            } else {
                log.warn("Error response pinging " + url.toString() + ":\n" + resp);
            }
        } catch (IOException e) {
            log.warn("Error pinging " + url.toString(), e);
        }
    }
private BibtexDatabase parseBibtexDatabase(List<String> id, boolean abs) throws IOException {
        if (id.isEmpty()) {
            return null;
        }
        URL url;
        URLConnection conn;
        try {
            url = new URL(importUrl);
            conn = url.openConnection();
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        }
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("Referer", searchUrl);
        PrintWriter out = new PrintWriter(conn.getOutputStream());
        String recordIds = "";
        Iterator<String> iter = id.iterator();
        while (iter.hasNext()) {
            recordIds += iter.next() + " ";
        }
        recordIds = recordIds.trim();
        String citation = abs ? "citation-abstract" : "citation-only";
        String content = "recordIds=" + recordIds.replaceAll(" ", "%20") + "&fromPageName=&citations-format=" + citation + "&download-format=download-bibtex";
        System.out.println(content);
        out.write(content);
        out.flush();
        out.close();
        BufferedReader bufr = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuffer sb = new StringBuffer();
        char[] buffer = new char[256];
        while (true) {
            int bytesRead = bufr.read(buffer);
            if (bytesRead == -1) {
                break;
            }
            for (int i = 0; i < bytesRead; i++) {
                sb.append((char) buffer[i]);
            }
        }
        System.out.println(sb.toString());
        ParserResult results = new BibtexParser(bufr).parse();
        bufr.close();
        return results.getDatabase();
    }
@SuppressWarnings("unchecked")
    public HttpResponse putFile(String root, String to_path, File file_obj) throws DropboxException {
        String path = "/files/" + root + to_path;
        try {
            Path targetPath = new Path(path);
            String target = buildFullURL(secureProtocol, content_host, port, buildURL(targetPath.removeLastSegments(1).addTrailingSeparator().toString(), API_VERSION, null));
            HttpClient client = getClient(target);
            HttpPost req = new HttpPost(target);
            List nvps = new ArrayList();
            nvps.add(new BasicNameValuePair("file", targetPath.lastSegment()));
            req.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
            auth.sign(req);
            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            FileBody bin = new FileBody(file_obj, targetPath.lastSegment(), "application/octet-stream", null);
            entity.addPart("file", bin);
            req.setEntity(entity);
            HttpResponse resp = client.execute(req);
            resp.getEntity().consumeContent();
            return resp;
        } catch (Exception e) {
            throw new DropboxException(e);
        }
    }
private static URL lookForDefaultThemeFile(String aFilename) {
        try {
            XPathFactory fabrique = XPathFactory.newInstance();
            XPath environnement = fabrique.newXPath();
            URL url = new URL("file:" + aFilename);
            InputSource source = new InputSource(url.openStream());
            XPathExpression expression;
            expression = environnement.compile("/alloy/instance/@filename");
            String resultat = expression.evaluate(source);
            AlloyPlugin.getDefault().logInfo("Solution coming from " + resultat);
            IPath path = new Path(resultat);
            IPath themePath = path.removeFileExtension().addFileExtension("thm");
            File themeFile = themePath.toFile();
            if (themeFile.exists()) {
                AlloyPlugin.getDefault().logInfo("Found default theme " + themeFile);
                return themeFile.toURI().toURL();
            }
        } catch (MalformedURLException e) {
            AlloyPlugin.getDefault().log(e);
        } catch (IOException e) {
            AlloyPlugin.getDefault().log(e);
        } catch (XPathExpressionException e) {
            AlloyPlugin.getDefault().log(e);
        }
        return null;
    }
private void writeData(IBaseType dataType, Writer writer) throws XMLStreamException {
        InputStream isData;
        DataType data = (DataType) baseType;
        if (data.isSetInputStream()) {
            isData = data.getInputStream();
            try {
                IOUtils.copy(isData, writer);
            } catch (IOException e) {
                throw new XMLStreamException("DataType fail writing streaming data ", e);
            }
        } else if (data.isSetOutputStream()) {
            throw new XMLStreamException("DataType only can write streaming input, its an output stream (only for reading) ");
        } else {
            new CharactersEventImpl(startElement.getLocation(), String.valueOf(baseType.asData()), false).writeAsEncodedUnicode(writer);
        }
    }