semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public Vector parse(String link) {
        addMessage("Parsing: " + link);
        links.removeAllElements();
        URLConnection conn = null;
        Reader rd = null;
        EditorKit kit = new HTMLEditorKit();
        Document doc = kit.createDefaultDocument();
        doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
        URL url = null;
        try {
            url = new URL(link);
        } catch (MalformedURLException err) {
            System.out.println("Malformed URL");
            return links;
        }
        try {
            conn = new URL(link).openConnection();
            rd = new InputStreamReader(conn.getInputStream());
        } catch (Exception err) {
            err.printStackTrace();
            return links;
        }
        try {
            kit.read(rd, doc, 0);
            ElementIterator it = new ElementIterator(doc);
            javax.swing.text.Element elem;
            while ((elem = it.next()) != null) {
                SimpleAttributeSet s = (SimpleAttributeSet) elem.getAttributes().getAttribute(HTML.Tag.A);
                if (s != null) {
                    if (s.toString().indexOf("script") >= 0) continue;
                    String lnk = "";
                    try {
                        lnk = s.getAttribute(HTML.Attribute.HREF).toString();
                    } catch (Exception err) {
                        continue;
                    }
                    int j = 0;
                    if ((j = lnk.indexOf('#')) >= 0) lnk = lnk.substring(0, j);
                    URL urlLink = new URL(url, lnk);
                    if (!url.getHost().equals(urlLink.getHost())) continue;
                    String str = urlLink.toString();
                    if (!str.startsWith("http")) continue;
                    if (str.endsWith(".pdf")) {
                        continue;
                    }
                    for (int i = 0; i < leaveSuffix.length; i++) {
                        if ((str.endsWith(leaveSuffix[i]))) continue;
                    }
                    boolean skip = false;
                    for (int i = 0; i < suffix.length; i++) {
                        if ((str.endsWith(suffix[i]))) skip = true;
                    }
                    if (!skip) {
                        try {
                            conn = urlLink.openConnection();
                        } catch (Exception err) {
                        }
                        String contentType = null;
                        if (contentType == null) contentType = conn.getContentType();
                        if (contentType.equals("application/pdf")) {
                            continue;
                        } else if (!contentType.equals("text/html")) {
                            continue;
                        }
                    }
                    if (!links.contains(urlLink.toString())) {
                        links.addElement(urlLink.toString());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return links;
    }
public void jsFunction_extract(ScriptableFile outputFile) throws IOException, FileSystemException, ArchiveException {
        InputStream is = file.jsFunction_createInputStream();
        OutputStream output = outputFile.jsFunction_createOutputStream();
        BufferedInputStream buf = new BufferedInputStream(is);
        ArchiveInputStream input = ScriptableZipArchive.getFactory().createArchiveInputStream(buf);
        try {
            long count = 0;
            while (input.getNextEntry() != null) {
                if (count == offset) {
                    IOUtils.copy(input, output);
                    break;
                }
                count++;
            }
        } finally {
            input.close();
            output.close();
            is.close();
        }
    }
public ServiceAdapterIfc deploy(String session, String name, byte jarBytes[], String jarName, String serviceClass, String serviceInterface) throws RemoteException, MalformedURLException, StartServiceException, SessionException {
        try {
            File jarFile = new File(jarName);
            jarName = jarFile.getName();
            String jarName2 = jarName;
            jarFile = new File(jarName2);
            int n = 0;
            while (jarFile.exists()) {
                jarName2 = jarName + n++;
                jarFile = new File(jarName2);
            }
            FileOutputStream fos = new FileOutputStream(jarName2);
            IOUtils.copy(new ByteArrayInputStream(jarBytes), fos);
            SCClassLoader cl = new SCClassLoader(new URL[] { new URL("file://" + jarFile.getAbsolutePath()) }, getMasterNode().getSCClassLoaderCounter());
            return startService(session, name, serviceClass, serviceInterface, cl);
        } catch (SessionException e) {
            throw e;
        } catch (Exception e) {
            throw new StartServiceException("Could not deploy service: " + e.getMessage(), e);
        }
    }
public static Object deployNewService(String scNodeRmiName, String userName, String password, String name, String jarName, String serviceClass, String serviceInterface, Logger log) throws RemoteException, MalformedURLException, StartServiceException, NotBoundException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, SessionException {
        try {
            SCNodeInterface node = (SCNodeInterface) Naming.lookup(scNodeRmiName);
            String session = node.login(userName, password);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IOUtils.copy(new FileInputStream(jarName), baos);
            ServiceAdapterIfc adapter = node.deploy(session, name, baos.toByteArray(), jarName, serviceClass, serviceInterface);
            if (adapter != null) {
                return new ExternalDomain(node, adapter, adapter.getUri(), log).getProxy(Thread.currentThread().getContextClassLoader());
            }
        } catch (Exception e) {
            log.warn("Could not send deploy command: " + e.getMessage(), e);
        }
        return null;
    }
private boolean copy(File in, File out) {
        try {
            FileInputStream fis = new FileInputStream(in);
            FileOutputStream fos = new FileOutputStream(out);
            FileChannel readableChannel = fis.getChannel();
            FileChannel writableChannel = fos.getChannel();
            writableChannel.truncate(0);
            writableChannel.transferFrom(readableChannel, 0, readableChannel.size());
            fis.close();
            fos.close();
            return true;
        } catch (IOException ioe) {
            System.out.println("Copy Error: IOException during copy\r\n" + ioe.getMessage());
            return false;
        }
    }
private File Gzip(File f) throws IOException {
        if (f == null || !f.exists()) return null;
        File dest_dir = f.getParentFile();
        String dest_filename = f.getName() + ".gz";
        File zipfile = new File(dest_dir, dest_filename);
        GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(zipfile));
        FileInputStream in = new FileInputStream(f);
        byte buf[] = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        out.finish();
        try {
            in.close();
        } catch (Exception e) {
        }
        try {
            out.close();
        } catch (Exception e) {
        }
        try {
            f.delete();
        } catch (Exception e) {
        }
        return zipfile;
    }
public static void getResponseAsStream(String _url, Object _stringOrStream, OutputStream _stream, Map _headers, Map _params, String _contentType, int _timeout) throws IOException {
        if (_url == null || _url.length() <= 0) throw new IllegalArgumentException("Url can not be null.");
        String temp = _url.toLowerCase();
        if (!temp.startsWith("http://") && !temp.startsWith("https://")) _url = "http://" + _url;
        HttpMethod method = null;
        if (_stringOrStream == null && (_params == null || _params.size() <= 0)) method = new GetMethod(_url); else method = new PostMethod(_url);
        HttpMethodParams params = ((HttpMethodBase) method).getParams();
        if (params == null) {
            params = new HttpMethodParams();
            ((HttpMethodBase) method).setParams(params);
        }
        if (_timeout < 0) params.setSoTimeout(0); else params.setSoTimeout(_timeout);
        if (_contentType != null && _contentType.length() > 0) {
            if (_headers == null) _headers = new HashMap();
            _headers.put("Content-Type", _contentType);
        }
        if (_headers != null) {
            Iterator iter = _headers.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                method.setRequestHeader((String) entry.getKey(), (String) entry.getValue());
            }
        }
        if (method instanceof PostMethod && (_params != null && _params.size() > 0)) {
            Iterator iter = _params.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                ((PostMethod) method).addParameter((String) entry.getKey(), (String) entry.getValue());
            }
        }
        if (method instanceof EntityEnclosingMethod && _stringOrStream != null) {
            if (_stringOrStream instanceof InputStream) {
                RequestEntity entity = new InputStreamRequestEntity((InputStream) _stringOrStream);
                ((EntityEnclosingMethod) method).setRequestEntity(entity);
            } else {
                RequestEntity entity = new StringRequestEntity(_stringOrStream.toString(), _contentType, null);
                ((EntityEnclosingMethod) method).setRequestEntity(entity);
            }
        }
        HttpClient httpClient = new HttpClient(new org.apache.commons.httpclient.SimpleHttpConnectionManager());
        try {
            int status = httpClient.executeMethod(method);
            if (status != HttpStatus.SC_OK) {
                if (status >= 500 && status < 600) throw new IOException("Remote service<" + _url + "> respose a error, status:" + status);
            }
            InputStream instream = method.getResponseBodyAsStream();
            IOUtils.copy(instream, _stream);
            instream.close();
        } catch (IOException err) {
            throw err;
        } finally {
            if (method != null) method.releaseConnection();
        }
    }
public static String getHash(String plaintext) {
        String hash = null;
        try {
            String text = plaintext;
            MessageDigest md = null;
            try {
                md = MessageDigest.getInstance("SHA-256");
                md.update(text.getBytes("UTF-8"));
                byte[] rawBytes = md.digest();
                hash = new BASE64Encoder().encode(rawBytes);
            } catch (NoSuchAlgorithmException e) {
            }
        } catch (IOException e) {
        }
        return hash;
    }
public String md5(Value request) throws FaultException {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(request.strValue().getBytes("UTF8"));
        } catch (UnsupportedEncodingException e) {
            throw new FaultException("UnsupportedOperation", e);
        } catch (NoSuchAlgorithmException e) {
            throw new FaultException("UnsupportedOperation", e);
        }
        int radix;
        if ((radix = request.getFirstChild("radix").intValue()) < 2) {
            radix = 16;
        }
        return new BigInteger(1, md.digest()).toString(radix);
    }
private boolean copyFile(File file) throws Exception {
        destination = new File(ServiceLocator.getSqliteDir(), file.getName());
        logger.debug("Writing to: " + destination);
        if (destination.exists()) {
            Frame.showMessage(ServiceLocator.getText("Error.file.exists") + file.getName(), null);
            logger.debug("File already exists: " + file);
            return false;
        }
        destination.createNewFile();
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(file);
            out = new FileOutputStream(destination);
            int read = 0;
            byte[] buffer = new byte[2048];
            while ((read = in.read(buffer)) > 0) {
                out.write(buffer, 0, read);
            }
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
        return true;
    }
private void bubbleSort(int[] mas) {
        boolean t = true;
        while (t) {
            t = false;
            for (int i = 0; i < mas.length - 1; i++) {
                if (mas[i] > mas[i + 1]) {
                    int temp = mas[i];
                    mas[i] = mas[i + 1];
                    mas[i + 1] = temp;
                    t = true;
                }
            }
        }
    }
public static String MD5(String text) {
        byte[] md5hash = new byte[32];
        try {
            MessageDigest md;
            md = MessageDigest.getInstance("MD5");
            md.update(text.getBytes("iso-8859-1"), 0, text.length());
            md5hash = md.digest();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertToHex(md5hash);
    }
public static ParsedXML parseXML(URL url) throws ParseException {
        try {
            InputStream is = url.openStream();
            ParsedXML px = parseXML(is);
            is.close();
            return px;
        } catch (IOException e) {
            throw new ParseException("could not read from URL" + url.toString());
        }
    }
private String getTextResponse(String address) throws Exception {
        URL url = new URL(address);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setUseCaches(false);
        BufferedReader in = null;
        try {
            con.connect();
            assertEquals(HttpURLConnection.HTTP_OK, con.getResponseCode());
            in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            StringBuilder builder = new StringBuilder();
            String inputLine = null;
            while ((inputLine = in.readLine()) != null) {
                builder.append(inputLine);
            }
            return builder.toString();
        } finally {
            if (in != null) {
                in.close();
            }
            con.disconnect();
        }
    }
@Override
    public void processSource() {
        try {
            URL url = new URL(this.mensa.getJsonUrl(weekNumber));
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            StringBuilder agentBuilder = new StringBuilder();
            agentBuilder.append(cxt.getString(R.string.app_name)).append(' ').append(cxt.getString(R.string.app_version)).append('|').append(Build.DISPLAY).append('|').append(VERSION.RELEASE).append('|').append(Build.ID).append('|').append(Build.MODEL).append('|').append(Locale.getDefault().getLanguage()).append('-').append(Locale.getDefault().getCountry());
            connection.setRequestProperty("User-Agent", agentBuilder.toString());
            InputStream inStream = connection.getInputStream();
            String response = getStringFromInputStream(inStream);
            JSONObject weekplanJsonObj = new JSONObject(response);
            this.menues = parseWeekplan(weekplanJsonObj);
            this.valuability = WeekPlan.VALUABLE;
        } catch (IOException ex) {
            this.valuability = WeekPlan.NOCON;
            this.menues = null;
        } catch (JSONException ex) {
            this.valuability = WeekPlan.ERROR;
            this.menues = null;
        }
    }
@Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String url = "http://jdkcn.com/checkUpdateNew.jsp?ver=" + blogFacade.getDatabaseSiteConfig().getAppVersion();
        response.setCharacterEncoding("UTF-8");
        URLConnection connection = new URL(url).openConnection();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder sb = new StringBuilder();
        String line = reader.readLine();
        while (line != null) {
            sb.append(line).append("\r\n");
            line = reader.readLine();
        }
        response.getWriter().println(sb.toString());
        return null;
    }
public void performOk(final IProject project, final TomcatPropertyPage page) {
            page.setPropertyValue("tomcat.jdbc.driver", c_drivers.getText());
            page.setPropertyValue("tomcat.jdbc.url", url.getText());
            page.setPropertyValue("tomcat.jdbc.user", username.getText());
            page.setPropertyValue("tomcat.jdbc.password", password.getText());
            File lib = new File(page.tomcatHome.getText(), "lib");
            if (!lib.exists()) {
                lib = new File(new File(page.tomcatHome.getText(), "common"), "lib");
                if (!lib.exists()) {
                    Logger.log(Logger.ERROR, "Not properly location of Tomcat Home at :: " + lib);
                    throw new IllegalStateException("Not properly location of Tomcat Home");
                }
            }
            final File conf = new File(page.tomcatHome.getText(), "conf/Catalina/localhost");
            if (!conf.exists()) {
                final boolean create = NexOpenUIActivator.getDefault().getTomcatConfProperty();
                if (create) {
                    if (Logger.getLog().isDebugEnabled()) {
                        Logger.getLog().debug("Create directory " + conf);
                    }
                    try {
                        conf.mkdirs();
                    } catch (final SecurityException se) {
                        Logger.getLog().error("Retrieved a Security exception creating " + conf, se);
                        Logger.log(Logger.ERROR, "Not created " + conf + " directory. Not enough privilegies. Message :: " + se.getMessage());
                    }
                }
            }
            String str_driverLibrary = LIBRARIES.get(c_drivers.getText());
            if ("<mysql_driver>".equals(str_driverLibrary)) {
                str_driverLibrary = NexOpenUIActivator.getDefault().getMySQLDriver();
            }
            final File driverLibrary = new File(lib, str_driverLibrary);
            if (!driverLibrary.exists()) {
                InputStream driver = null;
                FileOutputStream fos = null;
                try {
                    driver = AppServerPropertyPage.toInputStream(new Path("jdbc/" + str_driverLibrary));
                    fos = new FileOutputStream(driverLibrary);
                    IOUtils.copy(driver, fos);
                } catch (IOException e) {
                    Logger.log(Logger.ERROR, "Could not copy the driver jar file to Tomcat", e);
                } finally {
                    try {
                        if (driver != null) {
                            driver.close();
                            driver = null;
                        }
                        if (fos != null) {
                            fos.flush();
                            fos.close();
                            fos = null;
                        }
                    } catch (IOException e) {
                    }
                }
            }
            page.processTomcatCfg(c_drivers.getText(), url.getText(), username.getText(), password.getText());
        }
public boolean check(Object credentials) {
            try {
                byte[] digest = null;
                if (credentials instanceof Password || credentials instanceof String) {
                    synchronized (__TYPE) {
                        if (__md == null) __md = MessageDigest.getInstance("MD5");
                        __md.reset();
                        __md.update(credentials.toString().getBytes(StringUtil.__ISO_8859_1));
                        digest = __md.digest();
                    }
                    if (digest == null || digest.length != _digest.length) return false;
                    for (int i = 0; i < digest.length; i++) if (digest[i] != _digest[i]) return false;
                    return true;
                } else if (credentials instanceof MD5) {
                    MD5 md5 = (MD5) credentials;
                    if (_digest.length != md5._digest.length) return false;
                    for (int i = 0; i < _digest.length; i++) if (_digest[i] != md5._digest[i]) return false;
                    return true;
                } else if (credentials instanceof Credential) {
                    return ((Credential) credentials).check(this);
                } else {
                    log.warn("Can't check " + credentials.getClass() + " against MD5");
                    return false;
                }
            } catch (Exception e) {
                log.warn(LogSupport.EXCEPTION, e);
                return false;
            }
        }
public static String digest(String password) {
            try {
                byte[] digest;
                synchronized (__TYPE) {
                    if (__md == null) {
                        try {
                            __md = MessageDigest.getInstance("MD5");
                        } catch (Exception e) {
                            log.warn(LogSupport.EXCEPTION, e);
                            return null;
                        }
                    }
                    __md.reset();
                    __md.update(password.getBytes(StringUtil.__ISO_8859_1));
                    digest = __md.digest();
                }
                return __TYPE + TypeUtil.toString(digest, 16);
            } catch (Exception e) {
                log.warn(LogSupport.EXCEPTION, e);
                return null;
            }
        }
@Override
    public DataTable generateDataTable(Query query, HttpServletRequest request) throws DataSourceException {
        String url = request.getParameter(URL_PARAM_NAME);
        if (StringUtils.isEmpty(url)) {
            log.error("url parameter not provided.");
            throw new DataSourceException(ReasonType.INVALID_REQUEST, "url parameter not provided");
        }
        Reader reader;
        try {
            reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
        } catch (MalformedURLException e) {
            log.error("url is malformed: " + url);
            throw new DataSourceException(ReasonType.INVALID_REQUEST, "url is malformed: " + url);
        } catch (IOException e) {
            log.error("Couldn't read from url: " + url, e);
            throw new DataSourceException(ReasonType.INVALID_REQUEST, "Couldn't read from url: " + url);
        }
        DataTable dataTable = null;
        ULocale requestLocale = DataSourceHelper.getLocaleFromRequest(request);
        try {
            dataTable = CsvDataSourceHelper.read(reader, null, true, requestLocale);
        } catch (IOException e) {
            log.error("Couldn't read from url: " + url, e);
            throw new DataSourceException(ReasonType.INVALID_REQUEST, "Couldn't read from url: " + url);
        }
        return dataTable;
    }
public static XMLConfigurator loadFromDefaultSystemProperty() throws IOException {
        String urlStr = System.getProperty(DEFAULT_SYS_PROP_NAME);
        if (urlStr == null || urlStr.length() == 0) {
            return null;
        }
        InputStream in = null;
        DOMRetriever xmlDoc = null;
        try {
            URL url = new URL(urlStr);
            xmlDoc = new DOMRetriever(in = url.openStream());
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        } finally {
            if (in != null) in.close();
        }
        return newInstance(xmlDoc);
    }