semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void extractByParsingHtml(String refererURL, String requestURL) throws MalformedURLException, IOException {
        URL url = new URL(refererURL);
        InputStream is = url.openStream();
        mRefererURL = refererURL;
        if (requestURL.startsWith("http://www.")) {
            mRequestURLWWW = requestURL;
            mRequestURL = "http://" + mRequestURLWWW.substring(11);
        } else {
            mRequestURL = requestURL;
            mRequestURLWWW = "http://www." + mRequestURL.substring(7);
        }
        Parser parser = (new HTMLEditorKit() {

            public Parser getParser() {
                return super.getParser();
            }
        }).getParser();
        StringBuffer sb = new StringBuffer();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        try {
            String line = null;
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        } finally {
            br.close();
        }
        StringReader sr = new StringReader(sb.toString());
        parser.parse(sr, new LinkbackCallback(), true);
        if (mStart != 0 && mEnd != 0 && mEnd > mStart) {
            mExcerpt = sb.toString().substring(mStart, mEnd);
            mExcerpt = Utilities.removeHTML(mExcerpt);
            if (mExcerpt.length() > mMaxExcerpt) {
                mExcerpt = mExcerpt.substring(0, mMaxExcerpt) + "...";
            }
        }
        if (mTitle.startsWith(">") && mTitle.length() > 1) {
            mTitle = mTitle.substring(1);
        }
    }
public void copy(File s, File t) throws IOException {
            FileChannel in = (new FileInputStream(s)).getChannel();
            FileChannel out = (new FileOutputStream(t)).getChannel();
            in.transferTo(0, s.length(), out);
            in.close();
            out.close();
        }
public String upload() throws IOException {
        int idx = docIndex.incrementAndGet();
        String tmpName = "namefinder/doc_" + idx + "__" + fileFileName;
        File tmpFile = tmpFile(tmpName);
        if (tmpFile.exists()) {
            org.apache.commons.io.FileUtils.deleteQuietly(tmpFile);
        }
        org.apache.commons.io.FileUtils.touch(tmpFile);
        InputStream fileStream = new FileInputStream(file);
        OutputStream bos = new FileOutputStream(tmpFile);
        IOUtils.copy(fileStream, bos);
        bos.close();
        fileStream.close();
        return tmpUrl(tmpName);
    }
public static void main(String[] args) {
        try {
            MessageDigest sha1 = MessageDigest.getInstance("SHA1");
            sha1.update("Test".getBytes());
            byte[] digest = sha1.digest();
            for (int i = 0; i < digest.length; i++) {
                System.err.print(Integer.toHexString(0xFF & digest[i]));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
public static String MD5(String text) {
        MessageDigest md;
        try {
            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 (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
            return text;
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
            return text;
        }
    }
@Override
    public T[] sort(T[] values) {
        super.compareTimes = 0;
        for (int i = 0; i < values.length; i++) {
            for (int j = 0; j < values.length - i - 1; j++) {
                super.compareTimes++;
                if (values[j].compareTo(values[j + 1]) > 0) {
                    T temp = values[j];
                    values[j] = values[j + 1];
                    values[j + 1] = temp;
                }
            }
        }
        return values;
    }
@SuppressWarnings({ "serial", "unchecked" })
    private static IProject createCopyProject(IProject project, String pName, IWorkspace ws, IProgressMonitor pm) throws Exception {
        pm.beginTask("Creating temp project", 1);
        final IPath destination = new Path(pName);
        final IJavaProject oldJavaproj = JavaCore.create(project);
        final IClasspathEntry[] classPath = oldJavaproj.getRawClasspath();
        final IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(pName);
        newProject.create(null);
        newProject.open(null);
        final IProjectDescription desc = newProject.getDescription();
        desc.setNatureIds(new String[] { JavaCore.NATURE_ID });
        newProject.setDescription(desc, null);
        final List<IClasspathEntry> newClassPath = new ArrayList<IClasspathEntry>();
        for (final IClasspathEntry cEntry : classPath) {
            switch(cEntry.getEntryKind()) {
                case IClasspathEntry.CPE_SOURCE:
                    System.out.println("Source folder " + cEntry.getPath());
                    newClassPath.add(copySourceFolder(project, newProject, cEntry, destination));
                    break;
                case IClasspathEntry.CPE_LIBRARY:
                    System.out.println("library folder " + cEntry.getPath());
                    newClassPath.add(cEntry);
                    break;
                case IClasspathEntry.CPE_PROJECT:
                    System.out.println("project folder " + cEntry.getPath());
                    newClassPath.add(cEntry);
                    break;
                case IClasspathEntry.CPE_VARIABLE:
                    System.out.println("variable folder " + cEntry.getPath());
                    newClassPath.add(cEntry);
                    break;
                default:
                    System.out.println("container folder " + cEntry.getPath());
                    newClassPath.add(cEntry);
            }
        }
        copyDir(project.getLocation().toString(), "/translator", newProject.getLocation().toString(), "", new ArrayList<String>() {

            {
                add("generated");
                add("classes");
                add(".svn");
            }
        });
        newProject.refreshLocal(IResource.DEPTH_INFINITE, pm);
        newProject.build(IncrementalProjectBuilder.AUTO_BUILD, pm);
        newProject.touch(pm);
        final IJavaProject javaproj = JavaCore.create(newProject);
        javaproj.setOutputLocation(new Path("/" + newProject.getName() + "/classes/bin"), null);
        javaproj.setRawClasspath(newClassPath.toArray(new IClasspathEntry[newClassPath.size()]), pm);
        final Map opts = oldJavaproj.getOptions(true);
        javaproj.setOptions(opts);
        javaproj.makeConsistent(pm);
        javaproj.save(pm, true);
        return newProject;
    }
@Test
    public void testLoadHttpGzipped() throws Exception {
        String url = HTTP_GZIPPED;
        LoadingInfo loadingInfo = Utils.openFileObject(fsManager.resolveFile(url));
        InputStream contentInputStream = loadingInfo.getContentInputStream();
        byte[] actual = IOUtils.toByteArray(contentInputStream);
        byte[] expected = IOUtils.toByteArray(new GZIPInputStream(new URL(url).openStream()));
        assertEquals(expected.length, actual.length);
    }
public static synchronized BaseFont getL2BaseFont() {
        if (l2baseFont == null) {
            final ConfigProvider conf = ConfigProvider.getInstance();
            try {
                final ByteArrayOutputStream tmpBaos = new ByteArrayOutputStream();
                String fontPath = conf.getNotEmptyProperty("font.path", null);
                String fontName;
                String fontEncoding;
                InputStream tmpIs;
                if (fontPath != null) {
                    fontName = conf.getNotEmptyProperty("font.name", null);
                    if (fontName == null) {
                        fontName = new File(fontPath).getName();
                    }
                    fontEncoding = conf.getNotEmptyProperty("font.encoding", null);
                    if (fontEncoding == null) {
                        fontEncoding = BaseFont.WINANSI;
                    }
                    tmpIs = new FileInputStream(fontPath);
                } else {
                    fontName = Constants.L2TEXT_FONT_NAME;
                    fontEncoding = BaseFont.IDENTITY_H;
                    tmpIs = FontUtils.class.getResourceAsStream(Constants.L2TEXT_FONT_PATH);
                }
                IOUtils.copy(tmpIs, tmpBaos);
                tmpIs.close();
                tmpBaos.close();
                l2baseFont = BaseFont.createFont(fontName, fontEncoding, BaseFont.EMBEDDED, BaseFont.CACHED, tmpBaos.toByteArray(), null);
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    l2baseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
                } catch (Exception ex) {
                }
            }
        }
        return l2baseFont;
    }
protected File extractArchive(File archive) {
        byte buf[] = new byte[BUF_SIZE];
        ZipInputStream zis = null;
        File archiveDirectory = null;
        FileOutputStream fos;
        ZipEntry entry;
        File curEntry;
        int n;
        try {
            zis = new ZipInputStream(new FileInputStream(archive));
            while ((entry = zis.getNextEntry()) != null) {
                curEntry = new File(workingDir, entry.getName());
                if (entry.isDirectory()) {
                    getLogger().info("skip directory: " + entry.getName());
                    if (archiveDirectory == null) archiveDirectory = curEntry;
                    continue;
                }
                getLogger().info("zip-entry (file): " + entry.getName() + " ==> real path: " + curEntry.getAbsolutePath());
                if (!curEntry.getParentFile().exists()) curEntry.getParentFile().mkdirs();
                fos = new FileOutputStream(curEntry);
                while ((n = zis.read(buf, 0, buf.length)) > -1) fos.write(buf, 0, n);
                fos.close();
                zis.closeEntry();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            try {
                if (zis != null) zis.close();
            } catch (Throwable t) {
            }
        }
        return archiveDirectory;
    }
public HttpURLConnection getURLConnection() throws IOException {
        String url_str = getServerURL();
        URL url = new URL(url_str);
        HttpURLConnection urlConnection;
        if (url_str.toLowerCase().startsWith("https")) {
            HttpsURLConnection urlSConnection = (HttpsURLConnection) url.openConnection();
            urlSConnection.setHostnameVerifier(new HostnameVerifier() {

                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
            urlConnection = urlSConnection;
        } else urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("POST");
        if (useHTTPProxy && getProxyLogin() != null) {
            String authString = getProxyLogin() + ":" + getProxyPassword();
            String auth = "Basic " + new sun.misc.BASE64Encoder().encode(authString.getBytes());
            urlConnection.setRequestProperty("Proxy-Authorization", auth);
        }
        urlConnection.setDoOutput(true);
        if (useHTTPProxy) {
            System.getProperties().put("proxySet", "true");
            System.getProperties().put("proxyHost", proxyHost);
            System.getProperties().put("proxyPort", String.valueOf(proxyPort));
        }
        return urlConnection;
    }
@Override
    public void run() {
        File file;
        try {
            file = new File(filePath);
            if (!file.canWrite()) {
                Thread.sleep(5000);
                if (!file.canWrite()) {
                    logger.error("Filed to gain write access to file:" + filePath);
                    exitState = false;
                    return;
                }
            }
            fis = new BufferedInputStream(new FileInputStream(filePath));
        } catch (FileNotFoundException e) {
            logger.error("File not found:" + filePath);
            exitState = false;
            return;
        } catch (java.lang.InterruptedException ie) {
            logger.error("Upload thread halted or interrupted on file:" + filePath);
            exitState = false;
            return;
        }
        ftp = new FTPClient();
        ftp.setDefaultTimeout(20 * 1000);
        boolean uploadSuccessful = false;
        try {
            ftp.enterLocalPassiveMode();
            ftp.connect(ftpHostname);
            ftp.login(username, password);
            logger.trace("FTP Logged In and connected");
            if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                exitState = false;
                return;
            }
            ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
            logger.trace("FTP Timeout Set and File Type Set");
            ftp.changeWorkingDirectory(serverDirectory);
            ftp.storeUniqueFile(file.getName(), fis);
            logger.trace("File Uploaded");
            if (FTPReply.isPositiveIntermediate(ftp.getReplyCode())) {
                System.out.println("Completing pending command");
                ftp.completePendingCommand();
            }
            uploadSuccessful = true;
        } catch (Exception e) {
            try {
                ftp.disconnect();
            } catch (Exception de) {
                e.printStackTrace();
            }
            logger.error("Error uploading file:", e);
        } finally {
            try {
                fis.close();
                logger.trace("File closed");
                ftp.logout();
                logger.trace("FTP Logged Out");
                ftp.disconnect();
                logger.trace("FTP Disconnected");
                if (uploadSuccessful) {
                    logger.info("Deleting file:" + new File(filePath).getName());
                    if (!(new File(filePath)).delete()) {
                        logger.error("Can't delete file for some reason");
                    }
                    Thread.sleep(1000);
                    exitState = true;
                    return;
                }
            } catch (Exception e) {
                logger.error("Exception on file upload cleanup:", e);
                exitState = false;
                return;
            }
        }
        exitState = false;
        return;
    }
public static IChemModel readInChI(URL url) throws CDKException {
        IChemModel chemModel = new ChemModel();
        try {
            IMoleculeSet moleculeSet = new MoleculeSet();
            chemModel.setMoleculeSet(moleculeSet);
            StdInChIParser parser = new StdInChIParser();
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = in.readLine()) != null) {
                if (line.toLowerCase().startsWith("inchi=")) {
                    IAtomContainer atc = parser.parseInchi(line);
                    moleculeSet.addAtomContainer(atc);
                }
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new CDKException(e.getMessage());
        }
        return chemModel;
    }
public 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 void bubbleSort(int[] arr) {
        boolean swapped = true;
        int j = 0;
        int tmp;
        while (swapped) {
            swapped = false;
            j++;
            for (int i = 0; i < arr.length - j; i++) {
                if (arr[i] > arr[i + 1]) {
                    tmp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = tmp;
                    swapped = true;
                }
            }
        }
    }
public void getDownloadInfo(String _url) throws Exception {
        cl = new FTPClient();
        Authentication auth = new FTPAuthentication();
        cl.connect(getHostName());
        while (!cl.login(auth.getUser(), auth.getPassword())) {
            log.debug("getDownloadInfo() - login error state: " + Arrays.asList(cl.getReplyStrings()));
            ap.setSite(getSite());
            auth = ap.promptAuthentication();
            if (auth == null) throw new Exception("User Cancelled Auth Operation");
        }
        AuthManager.putAuth(getSite(), auth);
        cl.enterLocalPassiveMode();
        FTPFile file = cl.listFiles(new URL(_url).getFile())[0];
        setURL(_url);
        setLastModified(file.getTimestamp().getTimeInMillis());
        setSize(file.getSize());
        setResumable(cl.rest("0") == 350);
        setRangeEnd(getSize() - 1);
    }
public void initGet() throws Exception {
        cl = new FTPClient();
        cl.connect(getHostName());
        Authentication auth = AuthManager.getAuth(getSite());
        if (auth == null) auth = new FTPAuthentication(getSite());
        while (!cl.login(auth.getUser(), auth.getPassword())) {
            ap.setSite(getSite());
            auth = ap.promptAuthentication();
            if (auth == null) throw new Exception("User Cancelled Auth Operation");
        }
        cl.connect(getHostName());
        cl.login(auth.getUser(), auth.getPassword());
        cl.enterLocalPassiveMode();
        cl.setFileType(FTP.BINARY_FILE_TYPE);
        cl.setRestartOffset(getPosition());
        setInputStream(cl.retrieveFileStream(new URL(getURL()).getFile()));
    }
@SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception {
        PositionParser pp;
        Database.init("XIDResult");
        pp = new PositionParser("01:33:50.904+30:39:35.79");
        String url = "http://simbad.u-strasbg.fr/simbad/sim-script?submit=submit+script&script=";
        String script = "format object \"%IDLIST[%-30*]|-%COO(A)|%COO(D)|%OTYPELIST(S)\"\n";
        String tmp = "";
        script += pp.getPosition() + " radius=1m";
        url += URLEncoder.encode(script, "ISO-8859-1");
        URL simurl = new URL(url);
        BufferedReader in = new BufferedReader(new InputStreamReader(simurl.openStream()));
        String boeuf;
        boolean data_found = false;
        JSONObject retour = new JSONObject();
        JSONArray dataarray = new JSONArray();
        JSONArray colarray = new JSONArray();
        JSONObject jsloc = new JSONObject();
        jsloc.put("sTitle", "ID");
        colarray.add(jsloc);
        jsloc = new JSONObject();
        jsloc.put("sTitle", "Position");
        colarray.add(jsloc);
        jsloc = new JSONObject();
        jsloc.put("sTitle", "Type");
        colarray.add(jsloc);
        retour.put("aoColumns", colarray);
        int datasize = 0;
        while ((boeuf = in.readLine()) != null) {
            if (data_found) {
                String[] fields = boeuf.trim().split("\\|", -1);
                int pos = fields.length - 1;
                if (pos >= 3) {
                    String type = fields[pos];
                    pos--;
                    String dec = fields[pos];
                    pos--;
                    String ra = fields[pos];
                    String id = "";
                    for (int i = 0; i < pos; i++) {
                        id += fields[i];
                        if (i < (pos - 1)) {
                            id += "|";
                        }
                    }
                    if (id.length() <= 30) {
                        JSONArray darray = new JSONArray();
                        darray.add(id.trim());
                        darray.add(ra + " " + dec);
                        darray.add(type.trim());
                        dataarray.add(darray);
                        datasize++;
                    }
                }
            } else if (boeuf.startsWith("::data")) {
                data_found = true;
            }
        }
        retour.put("aaData", dataarray);
        retour.put("iTotalRecords", datasize);
        retour.put("iTotalDisplayRecords", datasize);
        System.out.println(retour.toJSONString());
        in.close();
    }
public static String encodePassword(String password) {
        try {
            MessageDigest messageDiegest = MessageDigest.getInstance("SHA-1");
            messageDiegest.update(password.getBytes("UTF-8"));
            return Base64.encodeToString(messageDiegest.digest(), false);
        } catch (NoSuchAlgorithmException e) {
            log.error("Exception while encoding password");
            throw new Error(e);
        } catch (UnsupportedEncodingException e) {
            log.error("Exception while encoding password");
            throw new Error(e);
        }
    }
public static void publish(String server, String id, String passwd, String path, String html) throws SocketException, IOException, LoginFailException {
        logger.info("Connect to FTP Server " + server);
        FTPClient f = new FTPClient();
        f.connect(server);
        if (f.login(id, passwd) == false) {
            logger.info("Fail to login with id=" + id);
            throw new LoginFailException(id, passwd);
        }
        f.changeWorkingDirectory(path);
        logger.info("Start to upload");
        f.storeFile("index.html", new ByteArrayInputStream(html.getBytes("utf-8")));
        logger.info("Upload index.html");
        f.storeFile("main.css", new FileInputStream("web/main.css"));
        logger.info("Upload main.css");
        f.storeFile("cafelibrary.js", new FileInputStream("web/cafelibrary.js"));
        logger.info("Upload cafelibrary.js");
        f.makeDirectory("img");
        f.changeWorkingDirectory("img");
        for (int i = 0; i <= 5; i++) {
            String fileName = "favorite_star_" + i + ".png";
            f.storeFile(fileName, new FileInputStream("web/img/" + fileName));
            logger.info("Upload " + fileName);
        }
        f.logout();
        f.disconnect();
    }