semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void testStopPoll() throws Exception {
        for (int i = 0; i < 500; i++) index(masterClient, "id", i, "name", "name = " + i);
        masterClient.commit();
        NamedList masterQueryRsp = query("*:*", masterClient);
        SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
        assertEquals(500, masterQueryResult.getNumFound());
        Thread.sleep(3000);
        NamedList slaveQueryRsp = query("*:*", slaveClient);
        SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
        assertEquals(500, slaveQueryResult.getNumFound());
        String cmp = TestDistributedSearch.compare(masterQueryResult, slaveQueryResult, 0, null);
        assertEquals(null, cmp);
        String masterUrl = "http://localhost:" + slaveJetty.getLocalPort() + "/solr/replication?command=disablepoll";
        URL url = new URL(masterUrl);
        InputStream stream = url.openStream();
        try {
            stream.close();
        } catch (IOException e) {
        }
        index(masterClient, "id", 501, "name", "name = " + 501);
        masterClient.commit();
        Thread.sleep(3000);
        slaveQueryRsp = query("*:*", slaveClient);
        slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
        assertEquals(500, slaveQueryResult.getNumFound());
        slaveQueryRsp = query("*:*", masterClient);
        slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
        assertEquals(501, slaveQueryResult.getNumFound());
    }
public void testSnapPullWithMasterUrl() throws Exception {
        copyFile(new File(CONF_DIR + "solrconfig-slave1.xml"), new File(slave.getConfDir(), "solrconfig.xml"));
        slaveJetty.stop();
        slaveJetty = createJetty(slave);
        slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
        for (int i = 0; i < 500; i++) index(masterClient, "id", i, "name", "name = " + i);
        masterClient.commit();
        NamedList masterQueryRsp = query("*:*", masterClient);
        SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
        assertEquals(500, masterQueryResult.getNumFound());
        String masterUrl = "http://localhost:" + slaveJetty.getLocalPort() + "/solr/replication?command=fetchindex&masterUrl=";
        masterUrl += "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication";
        URL url = new URL(masterUrl);
        InputStream stream = url.openStream();
        try {
            stream.close();
        } catch (IOException e) {
        }
        Thread.sleep(3000);
        NamedList slaveQueryRsp = query("*:*", slaveClient);
        SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
        assertEquals(500, slaveQueryResult.getNumFound());
        String cmp = TestDistributedSearch.compare(masterQueryResult, slaveQueryResult, 0, null);
        assertEquals(null, cmp);
    }
public void testReplicateAfterWrite2Slave() throws Exception {
        int nDocs = 50;
        for (int i = 0; i < nDocs; i++) {
            index(masterClient, "id", i, "name", "name = " + i);
        }
        String masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=disableReplication";
        URL url = new URL(masterUrl);
        InputStream stream = url.openStream();
        try {
            stream.close();
        } catch (IOException e) {
        }
        masterClient.commit();
        NamedList masterQueryRsp = query("*:*", masterClient);
        SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
        assertEquals(nDocs, masterQueryResult.getNumFound());
        Thread.sleep(100);
        index(slaveClient, "id", 551, "name", "name = " + 551);
        slaveClient.commit(true, true);
        index(slaveClient, "id", 552, "name", "name = " + 552);
        slaveClient.commit(true, true);
        index(slaveClient, "id", 553, "name", "name = " + 553);
        slaveClient.commit(true, true);
        index(slaveClient, "id", 554, "name", "name = " + 554);
        slaveClient.commit(true, true);
        index(slaveClient, "id", 555, "name", "name = " + 555);
        slaveClient.commit(true, true);
        NamedList slaveQueryRsp = query("id:555", slaveClient);
        SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
        assertEquals(1, slaveQueryResult.getNumFound());
        masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=enableReplication";
        url = new URL(masterUrl);
        stream = url.openStream();
        try {
            stream.close();
        } catch (IOException e) {
        }
        Thread.sleep(3000);
        slaveQueryRsp = query("id:555", slaveClient);
        slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
        assertEquals(0, slaveQueryResult.getNumFound());
    }
public void run() {
                String masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=" + ReplicationHandler.CMD_BACKUP;
                URL url;
                InputStream stream = null;
                try {
                    url = new URL(masterUrl);
                    stream = url.openStream();
                    stream.close();
                } catch (Exception e) {
                    fail = e.getMessage();
                } finally {
                    IOUtils.closeQuietly(stream);
                }
            }
public void run() {
                String masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=" + ReplicationHandler.CMD_DETAILS;
                URL url;
                InputStream stream = null;
                try {
                    url = new URL(masterUrl);
                    stream = url.openStream();
                    response = IOUtils.toString(stream);
                    if (response.contains("<str name=\"status\">success</str>")) {
                        success = true;
                    }
                    stream.close();
                } catch (Exception e) {
                    fail = e.getMessage();
                } finally {
                    IOUtils.closeQuietly(stream);
                }
            }
private String cookieString(String url, String ip) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
            md.update((url + "&&" + ip + "&&" + salt.toString()).getBytes());
            java.math.BigInteger hash = new java.math.BigInteger(1, md.digest());
            return hash.toString(16);
        } catch (NoSuchAlgorithmException e) {
            filterConfig.getServletContext().log(this.getClass().getName() + " error " + e);
            return null;
        }
    }
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("FileCopy: " + "no such source file: " + fromFileName);
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFileName);
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFileName);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) throw new IOException("FileCopy: " + "destination file is unwriteable: " + toFileName);
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) dir.mkdir();
            if (dir.isFile()) throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
            if (!dir.canWrite()) throw new IOException("FileCopy: " + "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) {
                ;
            }
        }
    }
public static String stringOfUrl(String addr) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        System.out.println("test");
        URL url = new URL(addr);
        System.out.println("test2");
        IOUtils.copy(url.openStream(), output);
        return output.toString();
    }
public int openUrl(String url, String method, Bundle params) {
        int result = 0;
        try {
            if (method.equals("GET")) {
                url = url + "?" + Utility.encodeUrl(params);
            }
            String response = "";
            HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
            conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " RenrenAndroidSDK");
            if (!method.equals("GET")) {
                conn.setRequestMethod("POST");
                conn.setDoOutput(true);
                conn.getOutputStream().write(Utility.encodeUrl(params).getBytes("UTF-8"));
            }
            response = Utility.read(conn.getInputStream());
            JSONObject json = new JSONObject(response);
            try {
                int code = json.getInt("result");
                if (code > 0) result = 1;
            } catch (Exception e) {
                result = json.getInt("error_code");
                errmessage = json.getString("error_msg");
            }
        } catch (Exception e) {
            result = -1;
        }
        return result;
    }
public void loginSendSpace() throws Exception {
        loginsuccessful = false;
        HttpParams params = new BasicHttpParams();
        params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);
        NULogger.getLogger().info("Trying to log in to sendspace");
        HttpPost httppost = new HttpPost("http://www.sendspace.com/login.html");
        httppost.setHeader("Cookie", sidcookie + ";" + ssuicookie);
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("action", "login"));
        formparams.add(new BasicNameValuePair("submit", "login"));
        formparams.add(new BasicNameValuePair("target", "%252F"));
        formparams.add(new BasicNameValuePair("action_type", "login"));
        formparams.add(new BasicNameValuePair("remember", "1"));
        formparams.add(new BasicNameValuePair("username", getUsername()));
        formparams.add(new BasicNameValuePair("password", getPassword()));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);
        NULogger.getLogger().info("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("ssal")) {
                ssalcookie = escookie.getName() + "=" + escookie.getValue();
                NULogger.getLogger().info(ssalcookie);
                loginsuccessful = true;
            }
        }
        if (loginsuccessful) {
            username = getUsername();
            password = getPassword();
            NULogger.getLogger().info("SendSpace login success :)");
        } else {
            NULogger.getLogger().info("SendSpace login failed :(");
            loginsuccessful = false;
            username = "";
            password = "";
            JOptionPane.showMessageDialog(NeembuuUploader.getInstance(), "<html><b>" + HOSTNAME + "</b> " + TranslationProvider.get("neembuuuploader.accounts.loginerror") + "</html>", HOSTNAME, JOptionPane.WARNING_MESSAGE);
            AccountsManager.getInstance().setVisible(true);
        }
    }
private static byte[] createHash(EHashType hashType, String string) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance(hashType.getJavaHashType());
            md.reset();
            md.update(string.getBytes());
            byte[] byteResult = md.digest();
            return byteResult;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
public void run(String srcf, String dst) {
        final Path srcPath = new Path("./" + srcf);
        final Path desPath = new Path(dst);
        try {
            Path[] srcs = FileUtil.stat2Paths(hdfs.globStatus(srcPath), srcPath);
            OutputStream out = FileSystem.getLocal(conf).create(desPath);
            for (int i = 0; i < srcs.length; i++) {
                System.out.println(srcs[i]);
                InputStream in = hdfs.open(srcs[i]);
                IOUtils.copyBytes(in, out, conf, false);
                in.close();
            }
            out.close();
        } catch (IOException ex) {
            System.err.print(ex.getMessage());
        }
    }
public void copy(File aSource, File aDestDir) throws IOException {
        FileInputStream myInFile = new FileInputStream(aSource);
        FileOutputStream myOutFile = new FileOutputStream(new File(aDestDir, aSource.getName()));
        FileChannel myIn = myInFile.getChannel();
        FileChannel myOut = myOutFile.getChannel();
        boolean end = false;
        while (true) {
            int myBytes = myIn.read(theBuffer);
            if (myBytes != -1) {
                theBuffer.flip();
                myOut.write(theBuffer);
                theBuffer.clear();
            } else break;
        }
        myIn.close();
        myOut.close();
        myInFile.close();
        myOutFile.close();
        long myEnd = System.currentTimeMillis();
    }
private void getRandomGuid(boolean secure) {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Error: " + e);
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0;
            if (secure) {
                rand = secureRandom.nextLong();
            } else {
                rand = random.nextLong();
            }
            sbValueBeforeMD5.append(id);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            byte[] array = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; ++j) {
                int b = array[j] & 0xFF;
                if (b < 0x10) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            System.out.println("Error:" + e);
        }
    }
public String translate(String before, int translateType) throws CoreException {
        if (before == null) throw new IllegalArgumentException("before is null.");
        if ((translateType != ENGLISH_TO_JAPANESE) && (translateType != JAPANESE_TO_ENGLISH)) {
            throw new IllegalArgumentException("Invalid translateType. value=" + translateType);
        }
        try {
            URL url = new URL(config.getTranslatorSiteUrl());
            URLConnection connection = url.openConnection();
            sendTranslateRequest(before, translateType, connection);
            String afterContents = receiveTranslatedResponse(connection);
            String afterStartKey = config.getTranslationResultStart();
            String afterEndKey = config.getTranslationResultEnd();
            int startLength = afterStartKey.length();
            int startPos = afterContents.indexOf(afterStartKey);
            if (startPos != -1) {
                int endPos = afterContents.indexOf(afterEndKey, startPos);
                if (endPos != -1) {
                    String after = afterContents.substring(startPos + startLength, endPos);
                    after = replaceEntities(after);
                    return after;
                } else {
                    throwCoreException(ERROR_END_KEYWORD_NOT_FOUND, "End keyword not found.", null);
                }
            } else {
                throwCoreException(ERROR_START_KEYWORD_NOT_FOUND, "Start keyword not found.", null);
            }
        } catch (IOException e) {
            throwCoreException(ERROR_IO, e.getMessage(), e);
        }
        throw new IllegalStateException("CoreException not occurd.");
    }
public static String getResponseText(String url) throws MalformedURLException, IOException {
        URL m_url = new URL(url);
        URLConnection urlCconn = m_url.openConnection();
        urlCconn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16");
        urlCconn.setRequestProperty("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        urlCconn.setRequestProperty("Accept-Language", "en-us,en;q=0.5");
        urlCconn.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
        urlCconn.setRequestProperty("Keep-Alive", "300");
        urlCconn.setRequestProperty("Connection", "keep-alive");
        return IOUtil.toString(urlCconn.getInputStream());
    }
private void copyFile(File from, File to) throws IOException {
        FileUtils.ensureParentDirectoryExists(to);
        byte[] buffer = new byte[1024];
        int read;
        FileInputStream is = new FileInputStream(from);
        FileOutputStream os = new FileOutputStream(to);
        while ((read = is.read(buffer)) > 0) {
            os.write(buffer, 0, read);
        }
        is.close();
        os.close();
    }
private void writeAndCheckFile(DataFileReader reader, String base, String path, String hash, Reference ref, boolean hashall) throws Exception {
        Data data = ref.data;
        File file = new File(base + path);
        file.getParentFile().mkdirs();
        if (Debug.level > 1) System.err.println("read file " + data.file + " at index " + data.index);
        OutputStream output = new FileOutputStream(file);
        if (hashall) output = new DigestOutputStream(output, MessageDigest.getInstance("MD5"));
        reader.read(output, data.index, data.file);
        output.close();
        if (hashall) {
            String filehash = StringUtils.toHex(((DigestOutputStream) output).getMessageDigest().digest());
            if (!hash.equals(filehash)) throw new RuntimeException("hash wasn't equal for " + file);
        }
        file.setLastModified(ref.lastmod);
        if (file.length() != data.size) throw new RuntimeException("corrupted file " + file);
    }
protected Object serveFile(MyServerSocket socket, String filenm, URL url) {
        PrintStream out = null;
        InputStream in = null;
        long len = 0;
        try {
            out = new PrintStream(socket.getOutputStream());
            in = url.openStream();
            len = in.available();
        } catch (IOException e) {
            HttpHelper.httpWrap(HttpHelper.EXC, e.toString(), 0);
        }
        if (HttpHelper.isImage(filenm)) {
            out.print(HttpHelper.httpWrapPic(filenm, len));
        } else if (filenm.endsWith(".html")) {
            Comms.copyStreamSED(in, out, MPRES);
        } else if (HttpHelper.isOtherFile(filenm)) {
            out.print(HttpHelper.httpWrapOtherFile(filenm, len));
        } else {
            String type = MimeUtils.getMimeType(filenm);
            if (type.equals(MimeUtils.UNKNOWN_MIME_TYPE)) {
                out.print(HttpHelper.httpWrapMimeType(type, len));
            } else {
                out.print(HttpHelper.httpWrapMimeType(type, len));
            }
        }
        if (in == null) {
            Log.logThis("THE INPUT STREAM IS NULL...url=" + url);
        } else Files.copyStream(in, out);
        return null;
    }
public static void copy(String path1, String path2) throws IOException {
        FileReader in = new FileReader(path1);
        FileWriter out = new FileWriter(path2);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
    }
private RatingServiceSelectionResponseType contactService(String xmlInputString) throws Exception {
        OutputStream outputStream = null;
        RatingServiceSelectionResponseType rType = null;
        try {
            URL url = new URL(ENDPOINT_URL);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setUseCaches(false);
            outputStream = connection.getOutputStream();
            outputStream.write(xmlInputString.getBytes());
            outputStream.flush();
            outputStream.close();
            rType = readURLConnection(connection);
            connection.disconnect();
        } catch (Exception e) {
            throw e;
        } finally {
            if (outputStream != null) {
                outputStream.close();
                outputStream = null;
            }
        }
        return rType;
    }