semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void testConvert() throws IOException, ConverterException {
        InputStreamReader reader = new InputStreamReader(new FileInputStream("test" + File.separator + "input" + File.separator + "A0851ohneex.dat"), CharsetUtil.forName("x-PICA"));
        FileWriter writer = new FileWriter("test" + File.separator + "output" + File.separator + "ddbInterToMarcxmlTest.out");
        Converter c = context.getConverter("ddb-intern", "MARC21-xml", "x-PICA", "UTF-8");
        ConversionParameters params = new ConversionParameters();
        params.setSourceCharset("x-PICA");
        params.setTargetCharset("UTF-8");
        params.setAddCollectionHeader(true);
        params.setAddCollectionFooter(true);
        c.convert(reader, writer, params);
    }
@SuppressWarnings("static-access")
    public FastCollection<String> load(Link link) {
        URL url = null;
        FastCollection<String> links = new FastList<String>();
        FTPClient ftp = null;
        try {
            String address = link.getURI();
            address = JGetFileUtils.removeTrailingString(address, "/");
            url = new URL(address);
            host = url.getHost();
            String folder = url.getPath();
            logger.info("Traversing: " + address);
            ftp = new FTPClient(host);
            if (!ftp.connected()) {
                ftp.connect();
            }
            ftp.login("anonymous", "me@mymail.com");
            logger.info("Connected to " + host + ".");
            logger.debug("changing dir to " + folder);
            ftp.chdir(folder);
            String[] files = ftp.dir();
            for (String file : files) {
                links.add(address + "/" + file);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            logger.debug(e.getStackTrace());
        } finally {
            try {
                ftp.quit();
            } catch (Exception e) {
                logger.error("Failed to logout or disconnect from the ftp server: ftp://" + host);
            }
        }
        return links;
    }
public static Properties parse() {
        try {
            String userHome = System.getProperty("user.home");
            File dsigFolder = new File(userHome, ".dsig");
            if (!dsigFolder.exists() && !dsigFolder.mkdir()) {
                throw new IOException("Could not create .dsig folder in user home directory");
            }
            File settingsFile = new File(dsigFolder, "settings.properties");
            if (!settingsFile.exists()) {
                InputStream is = UserHomeSettingsParser.class.getResourceAsStream("/defaultSettings.properties");
                if (is != null) {
                    IOUtils.copy(is, new FileOutputStream(settingsFile));
                }
            }
            if (settingsFile.exists()) {
                Properties p = new Properties();
                FileInputStream fis = new FileInputStream(settingsFile);
                p.load(fis);
                IOUtils.closeQuietly(fis);
                return p;
            }
        } catch (IOException e) {
            logger.warn("Error while initialize settings", e);
        }
        return null;
    }
private static FacesBean.Type _createType() {
        try {
            ClassLoader cl = _getClassLoader();
            URL url = cl.getResource("META-INF/faces-bean-type.properties");
            if (url != null) {
                Properties properties = new Properties();
                InputStream is = url.openStream();
                try {
                    properties.load(is);
                    String className = (String) properties.get(UIXComponentBase.class.getName());
                    return (FacesBean.Type) cl.loadClass(className).newInstance();
                } finally {
                    is.close();
                }
            }
        } catch (Exception e) {
            _LOG.severe("CANNOT_LOAD_TYPE_PROPERTIES", e);
        }
        return new FacesBean.Type();
    }
public HttpURLConnection openConnection(String url) throws IOException {
        if (isDebugMode()) System.out.println("open: " + url);
        URL u = new URL(url);
        HttpURLConnection urlConnection;
        if (proxy != null) urlConnection = (HttpURLConnection) u.openConnection(proxy); else urlConnection = (HttpURLConnection) u.openConnection();
        urlConnection.setRequestProperty("User-Agent", userAgent);
        return urlConnection;
    }
public Result request(URL url) {
        try {
            return xmlUtil.unmarshall(urlOpener.openStream(url));
        } catch (FileNotFoundException e) {
            log.info("File not found: " + url);
        } catch (IOException e) {
            log.error("Failed to read from url: " + url + ". " + e.getMessage(), e);
        }
        return null;
    }
public static void parseConfigV2(List rootList, InputStream is, javax.servlet.ServletContext context, List configFileList) throws Exception {
        URL configUrl = CompositePageUtil.class.getResource("/cuttleConfigurationV2.xml");
        if (configUrl == null) configUrl = CompositePageUtil.class.getClassLoader().getResource("/cuttleConfigurationV2.xml");
        URL dtdUrl = CompositePageUtil.class.getResource("/dtd/cuttleConfiguration.dtd");
        if (dtdUrl == null) dtdUrl = CompositePageUtil.class.getClassLoader().getResource("/dtd/cuttleConfiguration.dtd");
        Digester digester = DigesterLoader.createDigester(configUrl);
        digester.setValidating(false);
        digester.register("-//Cuttle MVC Framework//DTD Cuttle Configuration 1.0//EN", dtdUrl.toString());
        XMLCuttleConfiguration cuttleConfiguration = (XMLCuttleConfiguration) digester.parse(is);
        ConfigureDigester.setXmlCuttleConfiguration(cuttleConfiguration);
        if (configFileList != null) {
            for (int i = 0; i < configFileList.size(); i++) {
                String file = (String) configFileList.get(i);
                URL url2 = CompositePageUtil.class.getResource(file);
                if (url2 == null) url2 = CompositePageUtil.class.getClassLoader().getResource(file);
                if (url2 == null) {
                    logger.error("file path:" + file + " not found!");
                }
                XMLRoot root = (XMLRoot) ConfigureDigester.parseXMLToObject(url2.openStream());
                rootList.add(root);
            }
        } else {
            for (int i = 0; i < cuttleConfiguration.getActionConfigs().size(); i++) {
                XMLActionConfig config = (XMLActionConfig) cuttleConfiguration.getActionConfigs().get(i);
                URL url2 = context.getResource(config.getResource());
                if (url2 == null) {
                    logger.error("file path:" + config.getResource() + " not found!");
                }
                XMLRoot root = (XMLRoot) ConfigureDigester.parseXMLToObject(url2.openStream());
                rootList.add(root);
            }
        }
        compositeXMLRoot(rootList);
        XMLCuttleConfiguration config = ConfigureDigester.getXmlCuttleConfiguration();
        if (config != null) {
            List processUnits = config.getProcessUnits();
            if (processUnits != null) {
                for (int i = 0; i < processUnits.size(); i++) {
                    XMLProcessUnit processUnit = (XMLProcessUnit) processUnits.get(i);
                    if (processUnit.getSpringMapping() == null || processUnit.getSpringMapping().equals("")) {
                        Class businessClass = Class.forName(processUnit.getClazz());
                        Object business = businessClass.newInstance();
                        ConfigureDigester.addObjectToPool(business);
                    }
                }
            }
        }
    }
public static void initConfigurationV2(String cuttleConfiguration, javax.servlet.ServletContext context, List configFileList) throws Exception {
        ConfigureDigester.clearMap();
        List rootList = new ArrayList();
        InputStream is = null;
        if (cuttleConfiguration == null) {
            URL url = CompositePageUtil.class.getResource("/cuttle.xml");
            if (url == null) url = CompositePageUtil.class.getClassLoader().getResource("/cuttle.xml");
            is = url.openStream();
        } else {
            is = context.getResourceAsStream(cuttleConfiguration);
        }
        parseConfigV2(rootList, is, context, configFileList);
        if (ConfigureDigester.getXmlCuttleConfiguration() != null && ConfigureDigester.getXmlCuttleConfiguration().getPlugins() != null) {
            for (int i = 0; i < ConfigureDigester.getXmlCuttleConfiguration().getPlugins().size(); i++) {
                XMLPlugin plugin = (XMLPlugin) ConfigureDigester.getXmlCuttleConfiguration().getPlugins().get(i);
                if (plugin.getConfigurePlugable() != null && !plugin.getConfigurePlugable().equals("")) {
                    Class pluginable = Class.forName(plugin.getConfigurePlugable());
                    ConfigurePlugable pluginableObj = (ConfigurePlugable) pluginable.newInstance();
                    pluginableObj.initConfiguration(plugin.getConfigurationPath(), context);
                }
            }
        }
    }
public static InputStream getFileInputStream(String path) throws IOException {
        InputStream is = null;
        File file = new File(path);
        if (file.exists()) is = new BufferedInputStream(new FileInputStream(file));
        if (is == null) {
            URL url = FileUtils.class.getClassLoader().getResource(path);
            is = (url == null) ? null : url.openStream();
        }
        return is;
    }
public Document getDocument(String urlString) {
        Document doc = null;
        URLConnection conn = null;
        InputStream in = null;
        try {
            SAXBuilder sxbuild = new SAXBuilder();
            if (Osmolt.debug) {
                outputInterface.printDebugMessage("ProcessOSM", "url: " + urlString);
                in = new FileInputStream(new File(System.getProperty("user.home") + "/data.osm"));
                outputInterface.processSetStatus("getting data from " + System.getProperty("user.home") + "/data.osm");
            } else {
                URL url = new URL(urlString);
                outputInterface.printDebugMessage("ProcessOSM", "url: " + urlString);
                outputInterface.processSetStatus("connecting Server");
                conn = url.openConnection();
                outputInterface.processSetStatus("loading Data");
                in = conn.getInputStream();
            }
            doc = sxbuild.build(in);
        } catch (java.net.UnknownHostException e) {
            outputInterface.printError("Unknown Host: " + urlString);
        } catch (java.net.SocketTimeoutException e) {
            outputInterface.printError("Timeout: Server does not response");
        } catch (java.net.ConnectException e) {
            outputInterface.printError("Error Server response: " + e.getMessage());
        } catch (java.net.SocketException e) {
            outputInterface.printError("Error Server response: " + e.getMessage());
        } catch (JDOMException e) {
            outputInterface.printError(e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            outputInterface.printError(e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            outputInterface.printError(e.getMessage());
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ioe) {
            }
        }
        return doc;
    }
public static String EncryptString(String method, String input) {
        MessageDigest md = null;
        byte[] byteHash = null;
        StringBuffer resultString = new StringBuffer();
        if (method.equals("SHA1") || method.equals("MD5")) {
            try {
                md = MessageDigest.getInstance(method);
            } catch (NoSuchAlgorithmException e) {
                System.out.println("NoSuchAlgorithmException caught!");
                return null;
            }
        } else {
            return null;
        }
        md.reset();
        md.update(input.getBytes());
        byteHash = md.digest();
        for (int i = 0; i < byteHash.length; i++) {
            String tmp = Integer.toHexString(0xff & byteHash[i]);
            if (tmp.length() < 2) tmp = "0" + tmp;
            resultString.append(tmp);
        }
        return (resultString.toString());
    }
public static String md5sum(String s, String alg) {
        try {
            MessageDigest md = MessageDigest.getInstance(alg);
            md.update(s.getBytes(), 0, s.length());
            StringBuffer sb = new StringBuffer();
            synchronized (sb) {
                for (byte b : md.digest()) sb.append(pad(Integer.toHexString(0xFF & b), ZERO.charAt(0), 2, true));
            }
            return sb.toString();
        } catch (Exception ex) {
            log(ex);
        }
        return null;
    }
public static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        System.out.println("Login form get: " + response.getStatusLine());
        if (entity != null) {
            entity.consumeContent();
        }
        System.out.println("Initial set of cookies:");
        List<Cookie> cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }
        }
        HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" + "org=self_registered_users&" + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("IDToken1", "username"));
        nvps.add(new BasicNameValuePair("IDToken2", "password"));
        httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        response = httpclient.execute(httpost);
        entity = response.getEntity();
        System.out.println("Login form get: " + response.getStatusLine());
        if (entity != null) {
            entity.consumeContent();
        }
        System.out.println("Post logon cookies:");
        cookies = httpclient.getCookieStore().getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }
        }
    }
public static boolean copyFile(File source, File dest) {
        FileChannel srcChannel = null;
        FileChannel dstChannel = null;
        try {
            srcChannel = new FileInputStream(source).getChannel();
            dstChannel = new FileOutputStream(dest).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        } catch (IOException e) {
            return false;
        } finally {
            try {
                if (srcChannel != null) {
                    srcChannel.close();
                }
            } catch (IOException e) {
            }
            try {
                if (dstChannel != null) {
                    dstChannel.close();
                }
            } catch (IOException e) {
            }
        }
        return true;
    }
public Logging() throws Exception {
        File home = new File(System.getProperty("user.home"), ".jorgan");
        if (!home.exists()) {
            home.mkdirs();
        }
        File logging = new File(home, "logging.properties");
        if (!logging.exists()) {
            InputStream input = getClass().getResourceAsStream("logging.properties");
            OutputStream output = null;
            try {
                output = new FileOutputStream(logging);
                IOUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(input);
                IOUtils.closeQuietly(output);
            }
        }
        FileInputStream input = null;
        try {
            input = new FileInputStream(logging);
            LogManager.getLogManager().readConfiguration(input);
        } finally {
            IOUtils.closeQuietly(input);
        }
    }
public static FTPClient getFtpClient(TopAnalysisConfig topAnalyzerConfig) throws SocketException, IOException {
        FTPClient ftp = new FTPClient();
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
        ftp.connect(topAnalyzerConfig.getFtpServer());
        int reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            throw new java.lang.RuntimeException("PullFileJobWorker connect ftp error!");
        }
        if (!ftp.login(topAnalyzerConfig.getFtpUserName(), topAnalyzerConfig.getFtpPassWord())) {
            ftp.logout();
            throw new java.lang.RuntimeException("PullFileJobWorker login ftp error!");
        }
        logger.info("Remote system is " + ftp.getSystemName());
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        if (topAnalyzerConfig.isLocalPassiveMode()) ftp.enterLocalPassiveMode();
        return ftp;
    }
public OOXMLSignatureService(InputStream documentInputStream, OutputStream documentOutputStream, SignatureFacet signatureFacet, String role, IdentityDTO identity, byte[] photo, RevocationDataService revocationDataService, TimeStampService timeStampService, DigestAlgo signatureDigestAlgo) throws IOException {
        super(signatureDigestAlgo);
        this.temporaryDataStorage = new HttpSessionTemporaryDataStorage();
        this.documentOutputStream = documentOutputStream;
        this.tmpFile = File.createTempFile("eid-dss-", ".ooxml");
        FileOutputStream fileOutputStream;
        fileOutputStream = new FileOutputStream(this.tmpFile);
        IOUtils.copy(documentInputStream, fileOutputStream);
        addSignatureFacet(signatureFacet);
        addSignatureFacet(new XAdESXLSignatureFacet(timeStampService, revocationDataService, getSignatureDigestAlgorithm()));
        XAdESSignatureFacet xadesSignatureFacet = super.getXAdESSignatureFacet();
        xadesSignatureFacet.setRole(role);
        if (null != identity) {
            IdentitySignatureFacet identitySignatureFacet = new IdentitySignatureFacet(identity, photo, getSignatureDigestAlgorithm());
            addSignatureFacet(identitySignatureFacet);
        }
    }
private static String hashPassword(String password, String customsalt) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        password = SALT1 + password;
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(password.getBytes(), 0, password.length());
        password += convertToHex(md5.digest()) + SALT2 + customsalt;
        MessageDigest md = MessageDigest.getInstance("SHA-512");
        byte[] sha1hash = new byte[40];
        md.update(password.getBytes("UTF-8"), 0, password.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash) + "|" + customsalt;
    }
public static String unsecureHashConstantSalt(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        password = SALT3 + password;
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(password.getBytes(), 0, password.length());
        password += convertToHex(md5.digest()) + SALT4;
        MessageDigest md = MessageDigest.getInstance("SHA-512");
        byte[] sha1hash = new byte[40];
        md.update(password.getBytes("UTF-8"), 0, password.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
public static boolean checkUrl(CmsObject cms, String check) {
        URI uri = null;
        try {
            uri = new CmsUriSplitter(check, true).toURI();
        } catch (URISyntaxException exc) {
            return false;
        }
        try {
            if (!uri.isAbsolute()) {
                return cms.existsResource(cms.getRequestContext().removeSiteRoot(uri.getPath()));
            } else {
                URL url = uri.toURL();
                if ("http".equals(url.getProtocol())) {
                    HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
                    return (httpcon.getResponseCode() == 200);
                } else {
                    return true;
                }
            }
        } catch (MalformedURLException mue) {
            return false;
        } catch (Exception ex) {
            return false;
        }
    }
@SuppressWarnings("unchecked")
        private void doService(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
            final String url = request.getRequestURL().toString();
            if (url.endsWith("/favicon.ico")) {
                response.setStatus(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
            if (url.contains("/delay")) {
                final String delay = StringUtils.substringBetween(url, "/delay", "/");
                final int ms = Integer.parseInt(delay);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Sleeping for " + ms + " before to deliver " + url);
                }
                Thread.sleep(ms);
            }
            final URL requestedUrl = new URL(url);
            final WebRequest webRequest = new WebRequest(requestedUrl);
            webRequest.setHttpMethod(HttpMethod.valueOf(request.getMethod()));
            for (final Enumeration<String> en = request.getHeaderNames(); en.hasMoreElements(); ) {
                final String headerName = en.nextElement();
                final String headerValue = request.getHeader(headerName);
                webRequest.setAdditionalHeader(headerName, headerValue);
            }
            final List<NameValuePair> requestParameters = new ArrayList<NameValuePair>();
            for (final Enumeration<String> paramNames = request.getParameterNames(); paramNames.hasMoreElements(); ) {
                final String name = paramNames.nextElement();
                final String[] values = request.getParameterValues(name);
                for (final String value : values) {
                    requestParameters.add(new NameValuePair(name, value));
                }
            }
            if ("PUT".equals(request.getMethod()) && request.getContentLength() > 0) {
                final byte[] buffer = new byte[request.getContentLength()];
                request.getInputStream().readLine(buffer, 0, buffer.length);
                webRequest.setRequestBody(new String(buffer));
            } else {
                webRequest.setRequestParameters(requestParameters);
            }
            final WebResponse resp = MockConnection_.getResponse(webRequest);
            response.setStatus(resp.getStatusCode());
            for (final NameValuePair responseHeader : resp.getResponseHeaders()) {
                response.addHeader(responseHeader.getName(), responseHeader.getValue());
            }
            if (WriteContentAsBytes_) {
                IOUtils.copy(resp.getContentAsStream(), response.getOutputStream());
            } else {
                final String newContent = getModifiedContent(resp.getContentAsString());
                final String contentCharset = resp.getContentCharset();
                response.setCharacterEncoding(contentCharset);
                response.getWriter().print(newContent);
            }
            response.flushBuffer();
        }