semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void main(String[] args) throws IOException {
        String zipPath = "C:\\test.zip";
        CZipInputStream zip_in = null;
        try {
            byte[] c = new byte[1024];
            int slen;
            zip_in = new CZipInputStream(new FileInputStream(zipPath), "utf-8");
            do {
                ZipEntry file = zip_in.getNextEntry();
                if (file == null) break;
                String fileName = file.getName();
                System.out.println(fileName);
                String ext = fileName.substring(fileName.lastIndexOf("."));
                long seed = new Date(System.currentTimeMillis()).getTime();
                String newFileName = Long.toString(seed) + ext;
                FileOutputStream out = new FileOutputStream(newFileName);
                while ((slen = zip_in.read(c, 0, c.length)) != -1) out.write(c, 0, slen);
                out.close();
            } while (true);
        } catch (ZipException zipe) {
            zipe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            zip_in.close();
        }
    }
char[] DigestCalcHA1(String algorithm, String userName, String realm, String password, String nonce, String clientNonce) throws SaslException {
        byte[] hash;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(userName.getBytes("UTF-8"));
            md.update(":".getBytes("UTF-8"));
            md.update(realm.getBytes("UTF-8"));
            md.update(":".getBytes("UTF-8"));
            md.update(password.getBytes("UTF-8"));
            hash = md.digest();
            if ("md5-sess".equals(algorithm)) {
                md.update(hash);
                md.update(":".getBytes("UTF-8"));
                md.update(nonce.getBytes("UTF-8"));
                md.update(":".getBytes("UTF-8"));
                md.update(clientNonce.getBytes("UTF-8"));
                hash = md.digest();
            }
        } catch (NoSuchAlgorithmException e) {
            throw new SaslException("No provider found for MD5 hash", e);
        } catch (UnsupportedEncodingException e) {
            throw new SaslException("UTF-8 encoding not supported by platform.", e);
        }
        return convertToHex(hash);
    }
char[] DigestCalcResponse(char[] HA1, String serverNonce, String nonceCount, String clientNonce, String qop, String method, String digestUri, boolean clientResponseFlag) throws SaslException {
        byte[] HA2;
        byte[] respHash;
        char[] HA2Hex;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            if (clientResponseFlag) md.update(method.getBytes("UTF-8"));
            md.update(":".getBytes("UTF-8"));
            md.update(digestUri.getBytes("UTF-8"));
            if ("auth-int".equals(qop)) {
                md.update(":".getBytes("UTF-8"));
                md.update("00000000000000000000000000000000".getBytes("UTF-8"));
            }
            HA2 = md.digest();
            HA2Hex = convertToHex(HA2);
            md.update(new String(HA1).getBytes("UTF-8"));
            md.update(":".getBytes("UTF-8"));
            md.update(serverNonce.getBytes("UTF-8"));
            md.update(":".getBytes("UTF-8"));
            if (qop.length() > 0) {
                md.update(nonceCount.getBytes("UTF-8"));
                md.update(":".getBytes("UTF-8"));
                md.update(clientNonce.getBytes("UTF-8"));
                md.update(":".getBytes("UTF-8"));
                md.update(qop.getBytes("UTF-8"));
                md.update(":".getBytes("UTF-8"));
            }
            md.update(new String(HA2Hex).getBytes("UTF-8"));
            respHash = md.digest();
        } catch (NoSuchAlgorithmException e) {
            throw new SaslException("No provider found for MD5 hash", e);
        } catch (UnsupportedEncodingException e) {
            throw new SaslException("UTF-8 encoding not supported by platform.", e);
        }
        return convertToHex(respHash);
    }
static final void executeUpdate(Collection<String> queries, DBConnector connector) throws IOException {
        Connection con = null;
        Statement st = null;
        try {
            con = connector.getDB();
            con.setAutoCommit(false);
            st = con.createStatement();
            for (String s : queries) st.executeUpdate(s);
            con.commit();
        } catch (SQLException e) {
            try {
                con.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            throw new IOException(e.getMessage());
        } finally {
            if (st != null) {
                try {
                    st.close();
                } catch (SQLException ignore) {
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException ignore) {
                }
            }
        }
    }
private void downloadFile(String directory, String fileName) {
        URL url = null;
        String urlstr = updateURL + directory + fileName;
        int position = 0;
        try {
            Logger.msg(threadName + "Download new file from " + urlstr);
            url = new URL(urlstr);
            URLConnection conn = url.openConnection();
            BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(updateDirectory + System.getProperty("file.separator") + fileName));
            int i = in.read();
            while (i != -1) {
                if (isInterrupted()) {
                    setWasInterrupted();
                    in.close();
                    out.flush();
                    out.close();
                    interrupt();
                    return;
                }
                out.write(i);
                i = in.read();
                position += 1;
                if (position % 1000 == 0) {
                    Enumeration<DownloadFilesListener> en = listener.elements();
                    while (en.hasMoreElements()) {
                        DownloadFilesListener currentListener = en.nextElement();
                        currentListener.progress(1000);
                    }
                }
            }
            Enumeration<DownloadFilesListener> en = listener.elements();
            while (en.hasMoreElements()) {
                DownloadFilesListener currentListener = en.nextElement();
                currentListener.progress(1000);
            }
            in.close();
            out.flush();
            out.close();
            Logger.msg(threadName + "Saved file " + fileName + " to " + updateDirectory + System.getProperty("file.separator") + fileName);
        } catch (Exception e) {
            Logger.err(threadName + "Error (" + e.toString() + ")");
        }
    }
public static String read(URL url) throws Exception {
        String filename = Integer.toString(url.toString().hashCode());
        boolean cached = false;
        File dir = new File(Config.CACHE_PATH);
        for (File file : dir.listFiles()) {
            if (!file.isFile()) continue;
            if (file.getName().equals(filename)) {
                filename = file.getName();
                cached = true;
                break;
            }
        }
        File file = new File(Config.CACHE_PATH, filename);
        if (Config.USE_CACHE && cached) return read(file);
        System.out.println(">> CACHE HIT FAILED.");
        InputStream in = null;
        try {
            in = url.openStream();
        } catch (Exception e) {
            System.out.println(">> OPEN STREAM FAILED: " + url.toString());
            return null;
        }
        String content = read(in);
        save(file, content);
        return content;
    }
public boolean saveVideoXMLOnWebserver() {
        String text = "";
        boolean erg = false;
        try {
            URL url = new URL("http://localhost:8080/virtPresenterVerwalter/videofile.jsp?id=" + this.getId());
            HttpURLConnection http = (HttpURLConnection) url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(http.getInputStream()));
            String zeile = "";
            while ((zeile = in.readLine()) != null) {
                text += zeile + "\n";
            }
            in.close();
            http.disconnect();
            erg = saveVideoXMLOnWebserver(text);
            System.err.println("Job " + this.getId() + " erfolgreich bearbeitet!");
        } catch (MalformedURLException e) {
            System.err.println("Job " + this.getId() + ": Konnte video.xml nicht erstellen. Verbindung konnte nicht aufgebaut werden.");
            return false;
        } catch (IOException e) {
            System.err.println("Job " + this.getId() + ": Konnte video.xml nicht erstellen. Konnte Daten nicht lesen/schreiben.");
            return false;
        }
        return erg;
    }
public boolean saveVideoXMLOnWebserver(String text) {
        boolean error = false;
        FTPClient ftp = new FTPClient();
        try {
            int reply;
            ftp.connect(this.getWebserver().getUrl());
            System.out.println("Connected to " + this.getWebserver().getUrl() + ".");
            System.out.print(ftp.getReplyString());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
                return false;
            }
            if (!ftp.login(this.getWebserver().getFtpBenutzer(), this.getWebserver().getFtpPasswort())) {
                System.err.println("FTP server: Login incorrect");
            }
            String tmpSeminarID = this.getSeminarID();
            if (tmpSeminarID == null) tmpSeminarID = "unbekannt";
            try {
                ftp.changeWorkingDirectory(this.getWebserver().getDefaultPath() + "/" + tmpSeminarID + "/lectures/" + this.getId() + "/data");
            } catch (Exception e) {
                ftp.makeDirectory(this.getWebserver().getDefaultPath() + "/" + tmpSeminarID + "/lectures/" + this.getId() + "/data");
                ftp.changeWorkingDirectory(this.getWebserver().getDefaultPath() + "/" + tmpSeminarID + "/lectures/" + this.getId() + "/data");
            }
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ByteArrayInputStream videoIn = new ByteArrayInputStream(text.getBytes());
            ftp.enterLocalPassiveMode();
            ftp.storeFile("video.xml", videoIn);
            videoIn.close();
            ftp.logout();
            ftp.disconnect();
        } catch (IOException e) {
            System.err.println("Job " + this.getId() + ": Datei video.xml konnte nicht auf Webserver kopiert werden.");
            error = true;
            e.printStackTrace();
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException ioe) {
                }
            }
        }
        return error;
    }
public boolean saveLecturerecordingsXMLOnWebserver() {
        boolean error = false;
        FTPClient ftp = new FTPClient();
        String lecture = "";
        try {
            URL url = new URL("http://localhost:8080/virtPresenterVerwalter/lecturerecordings.jsp?seminarid=" + this.getSeminarID());
            HttpURLConnection http = (HttpURLConnection) url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(http.getInputStream()));
            String zeile = "";
            while ((zeile = in.readLine()) != null) {
                lecture += zeile + "\n";
            }
            in.close();
            http.disconnect();
        } catch (Exception e) {
            System.err.println("Konnte lecturerecordings.xml nicht lesen.");
        }
        try {
            int reply;
            ftp.connect(this.getWebserver().getUrl());
            System.out.println("Connected to " + this.getWebserver().getUrl() + ".");
            System.out.print(ftp.getReplyString());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
                return false;
            }
            if (!ftp.login(this.getWebserver().getFtpBenutzer(), this.getWebserver().getFtpPasswort())) {
                System.err.println("FTP server: Login incorrect");
            }
            String tmpSeminarID = this.getSeminarID();
            if (tmpSeminarID == null) tmpSeminarID = "unbekannt";
            try {
                ftp.changeWorkingDirectory(this.getWebserver().getDefaultPath() + "/" + tmpSeminarID + "/lectures/");
            } catch (Exception e) {
                ftp.makeDirectory(this.getWebserver().getDefaultPath() + "/" + tmpSeminarID + "/lectures/");
                ftp.changeWorkingDirectory(this.getWebserver().getDefaultPath() + "/" + tmpSeminarID + "/lectures/");
            }
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ByteArrayInputStream lectureIn = new ByteArrayInputStream(lecture.getBytes());
            System.err.println("FTP Verzeichnis: " + ftp.printWorkingDirectory());
            ftp.storeFile("lecturerecordings.xml", lectureIn);
            lectureIn.close();
            ftp.logout();
            ftp.disconnect();
        } catch (IOException e) {
            System.err.println("Job " + this.getId() + ": Datei lecturerecordings.xml konnte nicht auf Webserver kopiert werden.");
            error = true;
            e.printStackTrace();
        } catch (NullPointerException e) {
            System.err.println("Job " + this.getId() + ": Datei lecturerecordings.xml konnte nicht auf Webserver kopiert werden. (Kein Webserver zugewiesen)");
            error = true;
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException ioe) {
                }
            }
        }
        return error;
    }
public String loadGeneratorXML() {
        FTPClient ftp = new FTPClient();
        try {
            int reply;
            ftp.connect(this.getFolienKonvertierungsServer().getUrl());
            System.out.println("Connected to " + this.getFolienKonvertierungsServer().getUrl() + ".");
            System.out.print(ftp.getReplyString());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
                return null;
            }
            if (!ftp.login(this.getFolienKonvertierungsServer().getFtpBenutzer(), this.getFolienKonvertierungsServer().getFtpPasswort())) {
                System.err.println("FTP server: Login incorrect");
            }
            String path;
            if (this.getFolienKonvertierungsServer().getDefaultPath().length() > 0) {
                path = "/" + this.getFolienKonvertierungsServer().getDefaultPath() + "/" + this.getId() + "/";
            } else {
                path = "/" + this.getId() + "/";
            }
            if (!ftp.changeWorkingDirectory(path)) System.err.println("Konnte Verzeichnis nicht wechseln: " + path);
            System.err.println("Arbeitsverzeichnis: " + ftp.printWorkingDirectory());
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ftp.enterLocalPassiveMode();
            InputStream inStream = ftp.retrieveFileStream("generator.xml");
            if (inStream == null) {
                System.err.println("Job " + this.getId() + ": Datei generator.xml wurde nicht gefunden");
                return null;
            }
            BufferedReader in = new BufferedReader(new InputStreamReader(inStream));
            generatorXML = "";
            String zeile = "";
            while ((zeile = in.readLine()) != null) {
                generatorXML += zeile + "\n";
            }
            in.close();
            ftp.logout();
            ftp.disconnect();
        } catch (IOException e) {
            System.err.println("Job " + this.getId() + ": Datei generator.xml konnte nicht vom Webserver kopiert werden.");
            e.printStackTrace();
        } catch (Exception e) {
            System.err.println("Job " + this.getId() + ": Datei generator.xml konnte nicht vom Webserver kopiert werden.");
            e.printStackTrace();
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException ioe) {
                }
            }
        }
        if (generatorXML != null && generatorXML.length() == 0) {
            generatorXML = null;
        }
        return generatorXML;
    }
public Object next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        this.currentGafFilePath = this.url;
        try {
            if (this.httpURL != null) {
                LOG.info("Reading URL :" + httpURL);
                InputStream is = this.httpURL.openStream();
                int index = this.httpURL.toString().lastIndexOf('/');
                String file = this.httpURL.toString().substring(index + 1);
                File downloadLocation = new File(GoConfigManager.getInstance().getGafUploadDir(), "tmp-" + file);
                OutputStream out = new FileOutputStream(downloadLocation);
                IOUtils.copy(is, out);
                out.close();
                is = new FileInputStream(downloadLocation);
                if (url.endsWith(".gz")) {
                    is = new GZIPInputStream(is);
                }
                this.currentGafFile = this.currentGafFilePath.substring(this.currentGafFilePath.lastIndexOf("/") + 1);
                this.httpURL = null;
                return is;
            } else {
                String file = files[counter++].getName();
                this.currentGafFile = file;
                if (!this.currentGafFilePath.endsWith(file)) currentGafFilePath += file;
                LOG.info("Returning input stream for the file: " + file);
                _connect();
                ftpClient.changeWorkingDirectory(path);
                InputStream is = ftpClient.retrieveFileStream(file);
                File downloadLocation = new File(GoConfigManager.getInstance().getGafUploadDir(), file);
                OutputStream out = new FileOutputStream(downloadLocation);
                IOUtils.copy(is, out);
                out.close();
                System.out.println("Download complete.....");
                is = new FileInputStream(downloadLocation);
                if (file.endsWith(".gz")) {
                    is = new GZIPInputStream(is);
                }
                return is;
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
private void _connect() throws SocketException, IOException {
        try {
            ftpClient.disconnect();
        } catch (Exception ex) {
        }
        ftpClient.connect(host, port);
        ftpClient.login("anonymous", "");
        ftpClient.enterLocalActiveMode();
    }
private String digest(String input) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] md5hash = new byte[64];
        md.update(input.getBytes("iso-8859-1"), 0, input.length());
        md5hash = md.digest();
        return this.convertToHex(md5hash);
    }
@Override
    public InputStream getDataStream(int bufferSize) throws IOException {
        InputStream in = manager == null ? url.openStream() : manager.getResourceInputStream(this);
        if (in instanceof ByteArrayInputStream || in instanceof BufferedInputStream) {
            return in;
        }
        return bufferSize == 0 ? new BufferedInputStream(in) : new BufferedInputStream(in, bufferSize);
    }
public static String post(String strUrl, String strPostString) {
        NoMuleRuntime.showDebug("POST : " + strUrl + "(" + strPostString + ")");
        try {
            URL url = new URL(strUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(true);
            conn.setAllowUserInteraction(true);
            HttpURLConnection.setFollowRedirects(true);
            conn.setInstanceFollowRedirects(true);
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            DataOutputStream out = new DataOutputStream(conn.getOutputStream());
            out.writeBytes(strPostString);
            out.flush();
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String s = "";
            StringBuffer sRet = new StringBuffer();
            while ((s = in.readLine()) != null) {
                sRet.append(s);
            }
            in.close();
            return sRet.toString();
        } catch (MalformedURLException e) {
            NoMuleRuntime.showError("Internal Error. Malformed URL.");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("Internal I/O Error.");
            e.printStackTrace();
        }
        return "";
    }
public static String get(String strUrl) {
        if (NoMuleRuntime.DEBUG) System.out.println("GET : " + strUrl);
        try {
            URL url = new URL(strUrl);
            URLConnection conn = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String s = "";
            String sRet = "";
            while ((s = in.readLine()) != null) {
                sRet += s;
            }
            NoMuleRuntime.showDebug("ANSWER: " + sRet);
            return sRet;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
private static Result request(AbstractHttpClient client, HttpUriRequest request) throws ClientProtocolException, IOException {
        HttpResponse response = client.execute(request);
        HttpEntity entity = response.getEntity();
        Result result = new Result();
        result.setStatusCode(response.getStatusLine().getStatusCode());
        result.setHeaders(response.getAllHeaders());
        result.setCookie(assemblyCookie(client.getCookieStore().getCookies()));
        result.setHttpEntity(entity);
        return result;
    }