semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected EntailmentType invokeHttp(String stuff) {
        String data = encode("theory") + "=" + encode(stuff);
        URL url;
        EntailmentType result = EntailmentType.unkown;
        try {
            url = new URL(httpAddress);
        } catch (MalformedURLException e) {
            throw new RuntimeException("FOL Reasoner not correclty configured: '" + httpAddress + "' is not an URL");
        }
        log.debug("sending theory to endpoint: " + url);
        try {
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                log.debug("resultline: " + line);
                if (line.contains("Proof found")) {
                    result = EntailmentType.entailed;
                }
                if (line.contains("Ran out of time")) {
                    result = EntailmentType.unkown;
                }
                if (line.contains("Completion found")) {
                    result = EntailmentType.notEntailed;
                }
            }
            wr.close();
            rd.close();
        } catch (IOException io) {
            throw new RuntimeException("the remote reasoner did not respond:" + io, io);
        }
        return result;
    }
public static void loginSkyDrive() throws Exception {
        System.out.println("login ");
        u = new URL(loginurl);
        uc = (HttpURLConnection) u.openConnection();
        uc.setRequestProperty("Cookie", msprcookie + ";" + mspokcookie);
        uc.setDoOutput(true);
        uc.setRequestMethod("POST");
        uc.setInstanceFollowRedirects(false);
        pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream()), true);
        pw.print("login=dinesh007007%40hotmail.com&passwd=&SI=Sign+in&type=11&LoginOptions=3&NewUser=1&MEST=&PPSX=Passpor&PPFT=" + ppft + "&PwdPad=&sso=&i1=&i2=1&i3=10524&i4=&i12=1&i13=&i14=437&i15=624&i16=3438");
        pw.flush();
        pw.close();
        System.out.println(uc.getResponseCode());
        Map<String, List<String>> headerFields = uc.getHeaderFields();
        if (headerFields.containsKey("Set-Cookie")) {
            List<String> header = headerFields.get("Set-Cookie");
            for (int i = 0; i < header.size(); i++) {
                tmp = header.get(i);
                System.out.println(tmp);
            }
        }
        location = uc.getHeaderField("Location");
        System.out.println("Location : " + location);
        System.out.println("going to open paaport page");
        DefaultHttpClient d = new DefaultHttpClient();
        HttpGet hg = new HttpGet("https://skydrive.live.com");
        hg.setHeader("Cookie", msprcookie + ";" + mspokcookie);
        HttpResponse execute = d.execute(hg);
        HttpEntity entity = execute.getEntity();
        System.out.println(EntityUtils.toString(entity));
        System.out.println(execute.getStatusLine());
        Header[] allHeaders = execute.getAllHeaders();
        for (int i = 0; i < allHeaders.length; i++) {
            System.out.println(allHeaders[i].getName() + " : " + allHeaders[i].getValue());
        }
    }
protected void zipFile(File from, File to) throws IOException {
        FileInputStream in = new FileInputStream(from);
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(to));
        byte[] buffer = new byte[4096];
        int bytes_read;
        while ((bytes_read = in.read(buffer)) != -1) out.write(buffer, 0, bytes_read);
        in.close();
        out.close();
    }
protected void zipDirectory(File dir, File zipfile) throws IOException, IllegalArgumentException {
        if (!dir.isDirectory()) throw new IllegalArgumentException("Compress: not a directory:  " + dir);
        String[] entries = dir.list();
        byte[] buffer = new byte[4096];
        int bytes_read;
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
        for (int i = 0; i < entries.length; i++) {
            File f = new File(dir, entries[i]);
            if (f.isDirectory()) continue;
            FileInputStream in = new FileInputStream(f);
            ZipEntry entry = new ZipEntry(f.getPath());
            out.putNextEntry(entry);
            while ((bytes_read = in.read(buffer)) != -1) out.write(buffer, 0, bytes_read);
            in.close();
        }
        out.close();
    }
private String GetStringFromURL(String URL) {
        InputStream in = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        String outstring = "";
        try {
            java.net.URL url = new java.net.URL(URL);
            in = url.openStream();
            inputStreamReader = new InputStreamReader(in);
            bufferedReader = new BufferedReader(inputStreamReader);
            StringBuffer out = new StringBuffer("");
            String nextLine;
            String newline = System.getProperty("line.separator");
            while ((nextLine = bufferedReader.readLine()) != null) {
                out.append(nextLine);
                out.append(newline);
            }
            outstring = new String(out);
        } catch (IOException e) {
            System.out.println("Failed to read from " + URL);
            outstring = "";
        } finally {
            try {
                bufferedReader.close();
                inputStreamReader.close();
            } catch (Exception e) {
            }
        }
        return outstring;
    }
private void installBinaryFile(File source, File destination) {
        byte[] buffer = new byte[8192];
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(source);
            fos = new FileOutputStream(destination);
            int read;
            while ((read = fis.read(buffer)) != -1) {
                fos.write(buffer, 0, read);
            }
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
            new ProjectCreateException(e, "Failed to read binary file: %1$s", source.getAbsolutePath());
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                }
            }
        }
    }
public static byte[] encode(String origin, String algorithm) throws NoSuchAlgorithmException {
        String resultStr = null;
        resultStr = new String(origin);
        MessageDigest md = MessageDigest.getInstance(algorithm);
        md.update(resultStr.getBytes());
        return md.digest();
    }
public static boolean checkEncode(String origin, byte[] mDigest, String algorithm) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance(algorithm);
        md.update(origin.getBytes());
        if (MessageDigest.isEqual(mDigest, md.digest())) {
            return true;
        } else {
            return false;
        }
    }
public synchronized String encrypt(String plaintext) throws Exception {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            throw new Exception(e.getMessage());
        }
        try {
            md.update(plaintext.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new Exception(e.getMessage());
        }
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
public boolean copyTo(String targetFilePath) {
        try {
            FileInputStream srcFile = new FileInputStream(filePath);
            FileOutputStream target = new FileOutputStream(targetFilePath);
            byte[] buff = new byte[1024];
            int readed = -1;
            while ((readed = srcFile.read(buff)) > 0) target.write(buff, 0, readed);
            srcFile.close();
            target.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
private Concept fetchDataNeeded(String conceptUri) {
        if (cache.size() > MAX_CACHE) cache.clear();
        if (cache.containsKey(conceptUri)) return this.cache.get(conceptUri);
        try {
            URL url = new URL(conceptUri);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setInstanceFollowRedirects(true);
            connection.setRequestProperty("Accept", "application/rdf+xml");
            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK && connection.getContentType().contains("application/rdf+xml")) {
                InputStream is = connection.getInputStream();
                HashMap<String, String> parameters = new HashMap<String, String>();
                parameters.put("uri", conceptUri);
                Transformer tf = this.templates.getDAOTransformer(keyTemplates, parameters);
                DOMResult outputTarget = new DOMResult();
                tf.transform(new StreamSource(is), outputTarget);
                Concept concept = ConceptXMLBind.getInstance().restoreConcept(outputTarget.getNode());
                this.cache.put(conceptUri, concept);
                return concept;
            } else {
                logger.error("Unable to get a representation of the resource: " + connection.getResponseCode() + " => " + connection.getContentType());
                throw new RuntimeException("Unable to get a representation of the resource");
            }
        } catch (Exception e) {
            logger.error("Unable to fetch data for concept " + conceptUri, e);
            throw new RuntimeException(e);
        }
    }
public void fetchFile(String ID) {
        String url = "http://www.nal.usda.gov/cgi-bin/agricola-ind?bib=" + ID + "&conf=010000++++++++++++++&screen=MA";
        System.out.println(url);
        try {
            PrintWriter pw = new PrintWriter(new FileWriter("MARC" + ID + ".txt"));
            if (!id.contains("MARC" + ID + ".txt")) {
                id.add("MARC" + ID + ".txt");
            }
            in = new BufferedReader(new InputStreamReader((new URL(url)).openStream()));
            in.readLine();
            String inputLine, stx = "";
            StringBuffer sb = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                if (inputLine.startsWith("<TR><TD><B>")) {
                    String sts = (inputLine.substring(inputLine.indexOf("B>") + 2, inputLine.indexOf("</")));
                    int i = 0;
                    try {
                        i = Integer.parseInt(sts);
                    } catch (NumberFormatException nfe) {
                    }
                    if (i > 0) {
                        stx = stx + "\n" + sts + " - ";
                    } else {
                        stx += sts;
                    }
                }
                if (!(inputLine.startsWith("<") || inputLine.startsWith(" <") || inputLine.startsWith(">"))) {
                    String tx = inputLine.trim();
                    stx += tx;
                }
            }
            pw.println(stx);
            pw.close();
        } catch (Exception e) {
            System.out.println("Couldn't open stream");
            System.out.println(e);
        }
    }
protected Class findClass(String name) throws ClassNotFoundException {
        String classFile = name.replace('.', '/') + ".class";
        InputStream classInputStream = null;
        if (this.extensionJars != null) {
            for (int i = 0; i < this.extensionJars.length; i++) {
                JarFile extensionJar = this.extensionJars[i];
                JarEntry jarEntry = extensionJar.getJarEntry(classFile);
                if (jarEntry != null) {
                    try {
                        classInputStream = extensionJar.getInputStream(jarEntry);
                    } catch (IOException ex) {
                        throw new ClassNotFoundException("Couldn't read class " + name, ex);
                    }
                }
            }
        }
        if (classInputStream == null) {
            URL url = getResource(classFile);
            if (url == null) {
                throw new ClassNotFoundException("Class " + name);
            }
            try {
                classInputStream = url.openStream();
            } catch (IOException ex) {
                throw new ClassNotFoundException("Couldn't read class " + name, ex);
            }
        }
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            BufferedInputStream in = new BufferedInputStream(classInputStream);
            byte[] buffer = new byte[8096];
            int size;
            while ((size = in.read(buffer)) != -1) {
                out.write(buffer, 0, size);
            }
            in.close();
            return defineClass(name, out.toByteArray(), 0, out.size(), this.protectionDomain);
        } catch (IOException ex) {
            throw new ClassNotFoundException("Class " + name, ex);
        }
    }
public static byte[] hash(final byte[] saltBefore, final String content, final byte[] saltAfter, final int repeatedHashingCount) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        if (content == null) return null;
        final MessageDigest digest = MessageDigest.getInstance(DIGEST);
        if (digestLength == -1) digestLength = digest.getDigestLength();
        for (int i = 0; i < repeatedHashingCount; i++) {
            if (i > 0) digest.update(digest.digest());
            digest.update(saltBefore);
            digest.update(content.getBytes(WebCastellumFilter.DEFAULT_CHARACTER_ENCODING));
            digest.update(saltAfter);
        }
        return digest.digest();
    }
void queryFile(String rendezvousProgram, String rendezvousMD5) {
        try {
            XMLConfigParser.readUrlHost();
            String url = XMLConfigParser.urlHost;
            String query;
            String param1 = "op=query";
            String param2 = "program=" + rendezvousProgram;
            String param3 = "md5=" + rendezvousMD5;
            query = String.format("%s&%s&%s", param1, param2, param3);
            openConnection(query, url);
            String line = br.readLine();
            NetworkLog.logMsg(NetworkLog.LOG_DEBUG, this, "(Query) Response of the server: " + line);
            br.close();
        } catch (MalformedURLException e) {
            NetworkLog.logMsg(NetworkLog.LOG_ERROR, this, "Error" + e);
        } catch (IOException e) {
            NetworkLog.logMsg(NetworkLog.LOG_ERROR, this, e.getMessage());
        }
    }
void queryInactive() {
        try {
            XMLConfigParser.readUrlHost();
            String url = XMLConfigParser.urlHost;
            Date currenttime = new Date();
            String query;
            String param1 = "op=queryinactive";
            String param2 = "time=" + currenttime.getTime();
            query = String.format("%s&%s", param1, param2);
            openConnection(query, url);
            String line = br.readLine();
            NetworkLog.logMsg(NetworkLog.LOG_DEBUG, this, "(Query inactive)Response of the server: " + line);
            br.close();
        } catch (MalformedURLException e) {
            NetworkLog.logMsg(NetworkLog.LOG_ERROR, this, "Error" + e);
        } catch (IOException e) {
            NetworkLog.logMsg(NetworkLog.LOG_ERROR, this, e.getMessage());
        }
    }
private String getPayLoadWithCookie(String url) {
        StringBuffer sb = new StringBuffer();
        if (this.cookie != null) {
            try {
                Log.debug("Requesting url ==> " + url);
                URLConnection con = new URL(url).openConnection();
                con.setDoOutput(true);
                con.addRequestProperty("Cookie", this.cookie);
                BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String line = "";
                while ((line = br.readLine()) != null) {
                    sb.append(line + "\n");
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }
public static void copy(File source, File destination) throws IOException {
        InputStream in = new FileInputStream(source);
        OutputStream out = new FileOutputStream(destination);
        byte[] buffer = new byte[1024];
        int len;
        while ((len = in.read(buffer)) > 0) out.write(buffer, 0, len);
        in.close();
        out.close();
    }
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);
            System.out.print("Overwrite existing file " + toFile.getName() + "? (Y/N): ");
            System.out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String response = in.readLine();
            if (!response.equals("Y") && !response.equals("y")) throw new IOException("FileCopy: " + "existing file was not overwritten.");
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
            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 final String getContent(String address) {
        String content = "";
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        try {
            URL url = new URL(address);
            out = new ByteArrayOutputStream();
            conn = url.openConnection();
            in = conn.getInputStream();
            byte[] buffer = new byte[1024];
            int numRead;
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
            }
            content = out.toString();
        } catch (Exception exception) {
            exception.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException ioe) {
            }
        }
        return content;
    }
public static void copyFromFileToFileUsingNIO(File inputFile, File outputFile) throws FileNotFoundException, IOException {
        FileChannel inputChannel = new FileInputStream(inputFile).getChannel();
        FileChannel outputChannel = new FileOutputStream(outputFile).getChannel();
        try {
            inputChannel.transferTo(0, inputChannel.size(), outputChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inputChannel != null) inputChannel.close();
            if (outputChannel != null) outputChannel.close();
        }
    }
public void setContentMD5() {
        MessageDigest messagedigest = null;
        try {
            messagedigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            contentMD5 = null;
        }
        messagedigest.update(content.getBytes());
        byte digest[] = messagedigest.digest();
        String chk = "";
        for (int i = 0; i < digest.length; i++) {
            String s = Integer.toHexString(digest[i] & 0xFF);
            chk += ((s.length() == 1) ? "0" + s : s);
        }
        contentMD5 = chk;
    }
public static void checkForUpdate(String version) {
        try {
            URL url = new URL(WiimoteWhiteboard.getProperty("updateURL"));
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            final String current = in.readLine();
            if (compare(version, current)) showUpdateNotification(version, current);
            in.close();
        } catch (Exception e) {
        }
    }