semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private InputStream getSearchInputStream(String name) {
        URL url = null;
        try {
            url = new URL(TheMovieDBXmlPullFeedParser.SEARCH_FEED_URL + URLEncoder.encode(name));
            Log.d(Constants.LOG_TAG, "Movie search URL: " + url);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        try {
            return url.openConnection().getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
private InputStream getInfoInputStream(String tmdbId) {
        URL url = null;
        try {
            url = new URL(TheMovieDBXmlPullFeedParser.INFO_FEED_URL + URLEncoder.encode(tmdbId));
            Log.d(Constants.LOG_TAG, "Movie info URL: " + url);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        try {
            return url.openConnection().getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
public static synchronized String getMD5_Base64(String input) {
        MessageDigest msgDigest = null;
        try {
            msgDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("System doesn't support MD5 algorithm.");
        }
        try {
            msgDigest.update(input.getBytes("UTF-8"));
        } catch (java.io.UnsupportedEncodingException ex) {
            throw new IllegalStateException("System doesn't support your  EncodingException.");
        }
        byte[] rawData = msgDigest.digest();
        byte[] encoded = Base64.encode(rawData);
        String retValue = new String(encoded);
        return retValue;
    }
public static final void copyFile(File source, File target) {
        try {
            FileChannel srcChannel = new FileInputStream(source).getChannel();
            FileChannel dstChannel = new FileOutputStream(target).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (java.io.IOException e) {
        }
    }
private void sortWhats(String[] labels, int[] whats, String simplifyString) {
        int n = whats.length;
        boolean swapped;
        do {
            swapped = false;
            for (int i = 0; i < n - 1; i++) {
                int i0_pos = simplifyString.indexOf(labels[whats[i]]);
                int i1_pos = simplifyString.indexOf(labels[whats[i + 1]]);
                if (i0_pos > i1_pos) {
                    int temp = whats[i];
                    whats[i] = whats[i + 1];
                    whats[i + 1] = temp;
                    swapped = true;
                }
            }
        } while (swapped);
    }
public void GetList() throws Exception {
        Authenticator.setDefault(new MyAuth(this._user, this._pwd));
        URL url = new URL(MyFanfou.PublicTimeLine);
        InputStream ins = url.openConnection().getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
        String json = "";
        String line;
        while ((line = reader.readLine()) != null) json += line;
        JSONArray array = new JSONArray(json);
        for (int i = 0; i < array.length(); i++) {
            JSONObject object = array.getJSONObject(i);
            String users = object.getString("user");
            JSONObject user = new JSONObject(users);
            System.out.println(object.getString("id") + ":" + user.getString("birthday"));
        }
    }
public static void copyFile(File file, File destination) throws Exception {
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {
            in = new BufferedInputStream(new FileInputStream(file));
            out = new BufferedOutputStream(new FileOutputStream(destination));
            int c;
            while ((c = in.read()) != -1) out.write(c);
        } finally {
            try {
                if (out != null) out.close();
            } catch (Exception e) {
            }
            try {
                if (in != null) in.close();
            } catch (Exception e) {
            }
        }
    }
public void visit(AuthenticationMD5Password message) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(((String) properties.get("password") + (String) properties.get("user")).getBytes("iso8859-1"));
            String newValue = toHexString(md5.digest()) + new String(message.getSalt(), "iso8859-1");
            md5.reset();
            md5.update(newValue.getBytes("iso8859-1"));
            newValue = toHexString(md5.digest());
            PasswordMessage mes = new PasswordMessage("md5" + newValue);
            byte[] data = encoder.encode(mes);
            out.write(data);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static OMElement createOMRequest(String file, int count, String[] documentIds) throws Exception {
        ObjectFactory factory = new ObjectFactory();
        SubmitDocumentRequest sdr = factory.createSubmitDocumentRequest();
        IdType pid = factory.createIdType();
        pid.setRoot("1.3.6.1.4.1.21367.2005.3.7.6fa11e467880478");
        sdr.setPatientId(pid);
        ClassLoader classLoader = JUnitHelper.class.getClassLoader();
        DocumentsType documents = factory.createDocumentsType();
        for (int i = 0; i < count; ++i) {
            DocumentType document = factory.createDocumentType();
            if ((documentIds != null) && (documentIds.length > i)) {
                document.setId(documentIds[i]);
            }
            CodeType type = factory.createCodeType();
            type.setCode("51855-5");
            type.setCodeSystem("2.16.840.1.113883.6.1");
            document.setType(type);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            InputStream is = classLoader.getResourceAsStream(file);
            assertNotNull(is);
            IOUtils.copy(is, bos);
            document.setContent(bos.toByteArray());
            documents.getDocument().add(document);
        }
        sdr.setDocuments(documents);
        QName qname = new QName(URIConstants.XDSBRIDGE_URI, "SubmitDocumentRequest");
        JAXBContext jc = JAXBContext.newInstance(SubmitDocumentRequest.class);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        JAXBElement element = new JAXBElement(qname, sdr.getClass(), sdr);
        StringWriter sw = new StringWriter();
        marshaller.marshal(element, sw);
        String xml = sw.toString();
        logger.debug(xml);
        OMElement result = AXIOMUtil.stringToOM(OMAbstractFactory.getOMFactory(), xml);
        List<OMElement> list = XPathHelper.selectNodes(result, "./ns:Documents/ns:Document/ns:Content", URIConstants.XDSBRIDGE_URI);
        for (OMElement contentNode : list) {
            OMText binaryNode = (OMText) contentNode.getFirstOMChild();
            if (binaryNode != null) {
                binaryNode.setOptimize(true);
            }
        }
        return result;
    }
@Override
    public void start() {
        try {
            ftp = new FTPClient();
            ftp.connect(this.url.getHost(), this.url.getPort() == -1 ? this.url.getDefaultPort() : this.url.getPort());
            String username = "anonymous";
            String password = "";
            if (this.url.getUserInfo() != null) {
                username = this.url.getUserInfo().split(":")[0];
                password = this.url.getUserInfo().split(":")[1];
            }
            ftp.login(username, password);
            long startPos = 0;
            if (getFile().exists()) startPos = getFile().length(); else getFile().createNewFile();
            ftp.download(this.url.getPath(), getFile(), startPos, new FTPDTImpl());
            ftp.disconnect(true);
        } catch (Exception ex) {
            ex.printStackTrace();
            speedTimer.cancel();
        }
    }
public void executeRequest(OperationContext context) throws Throwable {
        long t1 = System.currentTimeMillis();
        GetPortrayMapCapabilitiesParams params = context.getRequestOptions().getGetPortrayMapCapabilitiesOptions();
        String srvCfg = context.getRequestContext().getApplicationConfiguration().getCatalogConfiguration().getParameters().getValue("openls.portrayMap");
        String sUrl = srvCfg + "?f=json&pretty=true";
        URL url = new URL(sUrl);
        URLConnection conn = url.openConnection();
        String line = "";
        String sResponse = "";
        InputStream is = conn.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader rd = new BufferedReader(isr);
        while ((line = rd.readLine()) != null) {
            sResponse += line;
        }
        rd.close();
        parseResponse(params, sResponse);
        long t2 = System.currentTimeMillis();
        LOGGER.info("PERFORMANCE: " + (t2 - t1) + " ms spent performing service");
    }
public String digestPassword(String password) {
        StringBuffer hexString = new StringBuffer();
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(password.getBytes());
            byte[] messageDigest = algorithm.digest();
            for (byte b : messageDigest) {
                hexString.append(Integer.toHexString(0xFF & b));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return hexString.toString();
    }
public static void decompress(final File file, final File folder, final boolean deleteZipAfter) throws IOException {
        final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(file.getCanonicalFile())));
        ZipEntry ze;
        try {
            while (null != (ze = zis.getNextEntry())) {
                final File f = new File(folder.getCanonicalPath(), ze.getName());
                if (f.exists()) f.delete();
                if (ze.isDirectory()) {
                    f.mkdirs();
                    continue;
                }
                f.getParentFile().mkdirs();
                final OutputStream fos = new BufferedOutputStream(new FileOutputStream(f));
                try {
                    try {
                        final byte[] buf = new byte[8192];
                        int bytesRead;
                        while (-1 != (bytesRead = zis.read(buf))) fos.write(buf, 0, bytesRead);
                    } finally {
                        fos.close();
                    }
                } catch (final IOException ioe) {
                    f.delete();
                    throw ioe;
                }
            }
        } finally {
            zis.close();
        }
        if (deleteZipAfter) file.delete();
    }
private void post(String title, Document content, Set<String> tags) throws HttpException, IOException, TransformerException {
        PostMethod method = null;
        try {
            method = new PostMethod("http://www.blogger.com/feeds/" + this.blogId + "/posts/default");
            method.addRequestHeader("GData-Version", String.valueOf(GDataVersion));
            method.addRequestHeader("Authorization", "GoogleLogin auth=" + this.AuthToken);
            Document dom = this.domBuilder.newDocument();
            Element entry = dom.createElementNS(Atom.NS, "entry");
            dom.appendChild(entry);
            entry.setAttribute("xmlns", Atom.NS);
            Element titleNode = dom.createElementNS(Atom.NS, "title");
            entry.appendChild(titleNode);
            titleNode.setAttribute("type", "text");
            titleNode.appendChild(dom.createTextNode(title));
            Element contentNode = dom.createElementNS(Atom.NS, "content");
            entry.appendChild(contentNode);
            contentNode.setAttribute("type", "xhtml");
            contentNode.appendChild(dom.importNode(content.getDocumentElement(), true));
            for (String tag : tags) {
                Element category = dom.createElementNS(Atom.NS, "category");
                category.setAttribute("scheme", "http://www.blogger.com/atom/ns#");
                category.setAttribute("term", tag);
                entry.appendChild(category);
            }
            StringWriter out = new StringWriter();
            this.xml2ascii.transform(new DOMSource(dom), new StreamResult(out));
            method.setRequestEntity(new StringRequestEntity(out.toString(), "application/atom+xml", "UTF-8"));
            int status = getHttpClient().executeMethod(method);
            if (status == 201) {
                IOUtils.copyTo(method.getResponseBodyAsStream(), System.out);
            } else {
                throw new HttpException("post returned http-code=" + status + " expected 201 (CREATE)");
            }
        } catch (TransformerException err) {
            throw err;
        } catch (HttpException err) {
            throw err;
        } catch (IOException err) {
            throw err;
        } finally {
            if (method != null) method.releaseConnection();
        }
    }
public static void copyFromOffset(long offset, File exe, File cab) throws IOException {
        DataInputStream in = new DataInputStream(new FileInputStream(exe));
        FileOutputStream out = new FileOutputStream(cab);
        byte[] buffer = new byte[4096];
        int bytes_read;
        in.skipBytes((int) offset);
        while ((bytes_read = in.read(buffer)) != -1) out.write(buffer, 0, bytes_read);
        in.close();
        out.close();
        in = null;
        out = null;
    }
private void loadMascotLibrary() {
        if (isMascotLibraryLoaded) return;
        try {
            boolean isLinux = false;
            boolean isAMD64 = false;
            String mascotLibraryFile;
            if (Configurator.getOSName().toLowerCase().contains("linux")) {
                isLinux = true;
            }
            if (Configurator.getOSArch().toLowerCase().contains("amd64")) {
                isAMD64 = true;
            }
            if (isLinux) {
                if (isAMD64) {
                    mascotLibraryFile = "libmsparserj-64.so";
                } else {
                    mascotLibraryFile = "libmsparserj-32.so";
                }
            } else {
                if (isAMD64) {
                    mascotLibraryFile = "msparserj-64.dll";
                } else {
                    mascotLibraryFile = "msparserj-32.dll";
                }
            }
            logger.warn("Using: " + mascotLibraryFile);
            URL mascot_lib = MascotDAO.class.getClassLoader().getResource(mascotLibraryFile);
            if (mascot_lib != null) {
                logger.debug("Mascot library URL: " + mascot_lib);
                tmpMascotLibraryFile = File.createTempFile("libmascot.so.", ".tmp", new File(System.getProperty("java.io.tmpdir")));
                InputStream in = mascot_lib.openStream();
                OutputStream out = new FileOutputStream(tmpMascotLibraryFile);
                IOUtils.copy(in, out);
                in.close();
                out.close();
                System.load(tmpMascotLibraryFile.getAbsolutePath());
                isMascotLibraryLoaded = true;
            } else {
                throw new ConverterException("Could not load Mascot Library for system: " + Configurator.getOSName() + Configurator.getOSArch());
            }
        } catch (IOException e) {
            throw new ConverterException("Error loading Mascot library: " + e.getMessage(), e);
        }
    }
public static String analyze(List<String> stackLines) {
        final MessageDigest messageDigest;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
        final Iterator<String> iterator = stackLines.iterator();
        if (!iterator.hasNext()) {
            return null;
        }
        try {
            final String messageLine = iterator.next();
            final String exceptionClass = getExceptionClass(messageLine);
            messageDigest.update(exceptionClass.getBytes("UTF-8"));
            analyze(exceptionClass, iterator, messageDigest);
            final byte[] bytes = messageDigest.digest();
            final BigInteger bigInt = new BigInteger(1, bytes);
            final String ret = bigInt.toString(36);
            return ret;
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
public void runDynusT(final boolean cleanUp) {
        final String[] exeFiles = new String[] { "DynusT.exe", "DLL_ramp.dll", "Ramp_Meter_Fixed_CDLL.dll", "Ramp_Meter_Feedback_CDLL.dll", "Ramp_Meter_Feedback_FDLL.dll", "libifcoremd.dll", "libmmd.dll", "Ramp_Meter_Fixed_FDLL.dll", "libiomp5md.dll" };
        final String[] modelFiles = new String[] { "network.dat", "scenario.dat", "control.dat", "ramp.dat", "incident.dat", "movement.dat", "vms.dat", "origin.dat", "destination.dat", "StopCap4Way.dat", "StopCap2Way.dat", "YieldCap.dat", "WorkZone.dat", "GradeLengthPCE.dat", "leftcap.dat", "system.dat", "output_option.dat", "bg_demand_adjust.dat", "xy.dat", "TrafficFlowModel.dat", "parameter.dat" };
        log.info("Creating iteration-directory...");
        File iterDir = new File(this.tmpDir);
        if (!iterDir.exists()) {
            iterDir.mkdir();
        }
        log.info("Copying application files to iteration-directory...");
        for (String filename : exeFiles) {
            log.info("  Copying " + filename);
            IOUtils.copyFile(new File(this.dynusTDir + "/" + filename), new File(this.tmpDir + "/" + filename));
        }
        log.info("Copying model files to iteration-directory...");
        for (String filename : modelFiles) {
            log.info("  Copying " + filename);
            IOUtils.copyFile(new File(this.modelDir + "/" + filename), new File(this.tmpDir + "/" + filename));
        }
        for (File f : new File(this.modelDir).listFiles()) {
            if (f.getName().toLowerCase(Locale.ROOT).endsWith(".dws")) {
                log.info("  Copying " + f.getName());
                IOUtils.copyFile(f, new File(this.tmpDir + "/" + f.getName()));
            }
        }
        String logfileName = this.tmpDir + "/dynus-t.log";
        String cmd = this.tmpDir + "/DynusT.exe";
        log.info("running command: " + cmd + " in directory " + this.tmpDir);
        int timeout = 7200;
        int exitcode = ExeRunner.run(cmd, logfileName, timeout, this.tmpDir);
        if (exitcode != 0) {
            throw new RuntimeException("There was a problem running Dynus-T. exit code: " + exitcode);
        }
        if (cleanUp) {
            for (String filename : exeFiles) {
                log.info("  Deleting " + filename);
                new File(this.tmpDir + "/" + filename).delete();
            }
        }
    }
public static synchronized String encrypt(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(text.getBytes("UTF-8"));
        byte raw[] = md.digest();
        return new Base64(-1).encodeToString(raw);
    }
public InputSource resolveEntity(String pPublicId, String pSystemId) throws SAXException, IOException {
            try {
                URL url = new URL(pSystemId);
                String fileName = (String) urlMap.get(url);
                if (fileName != null) {
                    FileInputStream istream = new FileInputStream(new File(schemaDir, fileName));
                    InputSource isource = new InputSource(istream);
                    isource.setSystemId(url.toString());
                    return isource;
                }
                String file = url.getFile();
                if (file == null) {
                    file = "";
                } else {
                    int offset = file.lastIndexOf('/');
                    if (offset >= 0) {
                        file = file.substring(offset + 1);
                    }
                }
                if ("".equals(file)) {
                    file = "schema.xsd";
                }
                int offset = file.lastIndexOf('.');
                String prefix;
                String suffix;
                String numAsStr = "";
                if (offset > 0 && offset < file.length()) {
                    prefix = file.substring(0, offset);
                    suffix = file.substring(offset);
                } else {
                    prefix = file;
                    suffix = ".xsd";
                }
                File f;
                for (int num = 1; ; ++num) {
                    f = new File(schemaDir, prefix + numAsStr + suffix);
                    if (f.exists()) {
                        numAsStr = "_" + num;
                    } else {
                        break;
                    }
                }
                InputStream istream = url.openStream();
                schemaDir.mkdirs();
                FileOutputStream fos = new FileOutputStream(f);
                try {
                    byte[] buffer = new byte[1024];
                    for (; ; ) {
                        int res = istream.read(buffer);
                        if (res == -1) {
                            break;
                        } else if (res > 0) {
                            fos.write(buffer, 0, res);
                        }
                    }
                    istream.close();
                    fos.close();
                    fos = null;
                } finally {
                    if (fos != null) {
                        try {
                            f.delete();
                        } catch (Throwable ignore) {
                        }
                    }
                }
                urlMap.put(url, f.getName());
                InputSource isource = new InputSource(new FileInputStream(f));
                isource.setSystemId(url.toString());
                return isource;
            } catch (Exception e) {
                JaxMeServlet.this.log("Failed to resolve URL " + pSystemId, e);
            }
            return null;
        }
public Converter(String input, String output) {
        try {
            FileInputStream fis = new FileInputStream(new File(input));
            BufferedReader in = new BufferedReader(new InputStreamReader(fis, "SJIS"));
            FileOutputStream fos = new FileOutputStream(new File(output));
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos, "UTF8"));
            int len = 80;
            char buf[] = new char[len];
            int numRead;
            while ((numRead = in.read(buf, 0, len)) != -1) out.write(buf, 0, numRead);
            out.close();
            in.close();
        } catch (IOException e) {
            System.out.println("An I/O Exception Occurred: " + e);
        }
    }
public static void loadMessages(String filename, Map<String, String> map) throws FileNotFoundException, IOException {
        String line;
        URL url = CurrentLocale.class.getResource("MessagesBundle_" + filename + ".properties");
        InputStreamReader isr = new InputStreamReader(url.openStream());
        BufferedReader br = new BufferedReader(isr);
        while ((line = br.readLine()) != null) {
            String[] l = line.split("=", 2);
            map.put(l[0].trim(), l[1].trim());
        }
        br.close();
        isr.close();
    }