semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
static final String md5(String text) throws RtmApiException {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
            byte[] md5hash = new byte[32];
            md.update(text.getBytes("UTF-8"), 0, text.length());
            md5hash = md.digest();
            return convertToHex(md5hash);
        } catch (NoSuchAlgorithmException e) {
            throw new RtmApiException("Md5 error: NoSuchAlgorithmException - " + e.getMessage());
        } catch (UnsupportedEncodingException e) {
            throw new RtmApiException("Md5 error: UnsupportedEncodingException - " + e.getMessage());
        }
    }
private static String doHash(String frase, String algorithm) {
        try {
            String ret;
            MessageDigest md = MessageDigest.getInstance(algorithm);
            md.update(frase.getBytes());
            BigInteger bigInt = new BigInteger(1, md.digest());
            ret = bigInt.toString(16);
            return ret;
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
protected boolean writeFile(Interest outstandingInterest) throws IOException {
        File fileToWrite = ccnNameToFilePath(outstandingInterest.name());
        Log.info("CCNFileProxy: extracted request for file: " + fileToWrite.getAbsolutePath() + " exists? ", fileToWrite.exists());
        if (!fileToWrite.exists()) {
            Log.warning("File {0} does not exist. Ignoring request.", fileToWrite.getAbsoluteFile());
            return false;
        }
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(fileToWrite);
        } catch (FileNotFoundException fnf) {
            Log.warning("Unexpected: file we expected to exist doesn't exist: {0}!", fileToWrite.getAbsolutePath());
            return false;
        }
        CCNTime modificationTime = new CCNTime(fileToWrite.lastModified());
        ContentName versionedName = VersioningProfile.addVersion(new ContentName(_prefix, outstandingInterest.name().postfix(_prefix).components()), modificationTime);
        CCNFileOutputStream ccnout = new CCNFileOutputStream(versionedName, _handle);
        ccnout.addOutstandingInterest(outstandingInterest);
        byte[] buffer = new byte[BUF_SIZE];
        int read = fis.read(buffer);
        while (read >= 0) {
            ccnout.write(buffer, 0, read);
            read = fis.read(buffer);
        }
        fis.close();
        ccnout.close();
        return true;
    }
public static String hash(String plainText) throws Exception {
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.update(plainText.getBytes(), 0, plainText.length());
        String hash = new BigInteger(1, m.digest()).toString(16);
        if (hash.length() == 31) {
            hash = "0" + hash;
        }
        return hash;
    }
public static void messageDigestTest() {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update("computer".getBytes());
            md.update("networks".getBytes());
            System.out.println(new String(md.digest()));
            System.out.println(new String(md.digest("computernetworks".getBytes())));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static InputStream getStreamFromSystemIdentifier(String systemId, EntityResolver resolver) throws Exception {
        InputSource source = null;
        InputStream stream = null;
        if (resolver != null) {
            try {
                source = resolver.resolveEntity(null, systemId);
            } catch (Exception e) {
                LogService.instance().log(LogService.ERROR, "DocumentFactory: Unable to resolve '" + systemId + "'");
                LogService.instance().log(LogService.ERROR, e);
            }
        }
        if (source != null) {
            try {
                stream = source.getByteStream();
            } catch (Exception e) {
                LogService.instance().log(LogService.ERROR, "DocumentFactory: Unable to get bytestream from '" + source.getSystemId() + "'");
                LogService.instance().log(LogService.ERROR, e);
            }
        }
        if (stream == null) {
            URL url = new URL(systemId);
            stream = url.openStream();
        }
        return stream;
    }
public void run() {
        try {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Checking for updates at " + checkUrl);
            }
            URL url = new URL(checkUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.connect();
            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                StringBuffer content = new StringBuffer();
                String s = reader.readLine();
                while (s != null) {
                    content.append(s);
                    s = reader.readLine();
                }
                LOGGER.info("update-available", content.toString());
            } else if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("No update available (Response code " + connection.getResponseCode() + ")");
            }
        } catch (Throwable e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Update check failed", e);
            }
        }
    }
public RFC1345List(URL url) {
        if (url == null) return;
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new GZIPInputStream(url.openStream())));
            final String linePattern = " XX???????      HHHH    X";
            String line;
            mnemos = new HashMap();
            nextline: while ((line = br.readLine()) != null) {
                if (line.length() < 9) continue nextline;
                if (line.charAt(7) == ' ' || line.charAt(8) != ' ') {
                    line = line.substring(0, 8) + "        " + line.substring(8);
                }
                if (line.length() < linePattern.length()) continue nextline;
                for (int i = 0; i < linePattern.length(); i++) {
                    char c = line.charAt(i);
                    switch(linePattern.charAt(i)) {
                        case ' ':
                            if (c != ' ') continue nextline;
                            break;
                        case 'X':
                            if (c == ' ') continue nextline;
                            break;
                        case '?':
                            break;
                        case 'H':
                            if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')) ; else continue nextline;
                            break;
                        default:
                            throw new RuntimeException("Pattern broken!");
                    }
                }
                char c = (char) Integer.parseInt(line.substring(16, 20), 16);
                String mnemo = line.substring(1, 16).trim();
                if (mnemo.length() < 2) throw new RuntimeException();
                mnemos.put(mnemo, new Character(c));
            }
            br.close();
        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
private void generateDeviceUUID() {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(deviceType.getBytes());
            md5.update(internalId.getBytes());
            md5.update(bindAddress.getHostName().getBytes());
            StringBuffer hexString = new StringBuffer();
            byte[] digest = md5.digest();
            for (int i = 0; i < digest.length; i++) {
                hexString.append(Integer.toHexString(0xFF & digest[i]));
            }
            uuid = hexString.toString().toUpperCase();
        } catch (Exception ex) {
            RuntimeException runTimeEx = new RuntimeException("Unexpected error during MD5 hash creation, check your JRE");
            runTimeEx.initCause(ex);
            throw runTimeEx;
        }
    }
public void write(HttpServletRequest req, HttpServletResponse res, Object bean) throws IntrospectionException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
        res.setContentType(contentType);
        final Object r;
        if (HttpRpcServer.HttpRpcOutput.class.isAssignableFrom(bean.getClass())) {
            HttpRpcServer.HttpRpcOutput output = (HttpRpcServer.HttpRpcOutput) bean;
            r = output.getResult();
        } else r = bean;
        if (r != null) {
            if (File.class.isAssignableFrom(r.getClass())) {
                File file = (File) r;
                InputStream in = null;
                try {
                    in = new FileInputStream(file);
                    IOUtils.copy(in, res.getOutputStream());
                } finally {
                    if (in != null) in.close();
                }
            } else if (InputStream.class.isAssignableFrom(r.getClass())) {
                InputStream in = null;
                try {
                    in = (InputStream) r;
                    IOUtils.copy(in, res.getOutputStream());
                } finally {
                    if (in != null) in.close();
                }
            } else if (XFile.class.isAssignableFrom(r.getClass())) {
                XFile file = (XFile) r;
                InputStream in = null;
                try {
                    in = new XFileInputStream(file);
                    IOUtils.copy(in, res.getOutputStream());
                } finally {
                    if (in != null) in.close();
                }
            }
            res.getOutputStream().flush();
        }
    }
private static void generateFile(String inputFilename, String outputFilename) throws Exception {
        File inputFile = new File(inputFilename);
        if (inputFile.exists() == false) {
            throw new Exception(Messages.getString("ScriptDocToBinary.Input_File_Does_Not_Exist") + inputFilename);
        }
        Environment environment = new Environment();
        environment.initBuiltInObjects();
        NativeObjectsReader reader = new NativeObjectsReader(environment);
        InputStream input = new FileInputStream(inputFile);
        System.out.println(Messages.getString("ScriptDocToBinary.Reading_Documentation") + inputFilename);
        reader.loadXML(input);
        checkFile(outputFilename);
        File binaryFile = new File(outputFilename);
        FileOutputStream outputStream = new FileOutputStream(binaryFile);
        TabledOutputStream output = new TabledOutputStream(outputStream);
        reader.getScriptDoc().write(output);
        output.close();
        System.out.println(Messages.getString("ScriptDocToBinary.Finished"));
        System.out.println();
    }
public void onItem(FeedParserState state, String title, String link, String description, String permalink) throws FeedParserException {
                if (counter >= MAX_FEEDS) {
                    throw new FeedPollerCancelException("Maximum number of items reached");
                }
                boolean canAnnounce = false;
                try {
                    if (lastDigest == null) {
                        MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
                        md.update(title.getBytes());
                        lastDigest = md.digest();
                        canAnnounce = true;
                    } else {
                        MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
                        md.update(title.getBytes());
                        byte[] currentDigest = md.digest();
                        if (!MessageDigest.isEqual(currentDigest, lastDigest)) {
                            lastDigest = currentDigest;
                            canAnnounce = true;
                        }
                    }
                    if (canAnnounce) {
                        String shortTitle = title;
                        if (shortTitle.length() > TITLE_MAX_LEN) {
                            shortTitle = shortTitle.substring(0, TITLE_MAX_LEN) + " ...";
                        }
                        String shortLink = IOUtil.getTinyUrl(link);
                        Log.debug("Link:" + shortLink);
                        for (Channel channel : channels) {
                            channel.say(String.format("%s, %s", shortTitle, shortLink));
                        }
                    }
                } catch (Exception e) {
                    throw new FeedParserException(e);
                }
                counter++;
            }
private Source getStylesheetSource(String stylesheetResource) throws ApplicationContextException {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Loading XSLT stylesheet from " + stylesheetResource);
        }
        try {
            URL url = this.getClass().getClassLoader().getResource(stylesheetResource);
            String urlPath = url.toString();
            String systemId = urlPath.substring(0, urlPath.lastIndexOf('/') + 1);
            return new StreamSource(url.openStream(), systemId);
        } catch (IOException e) {
            throw new RuntimeException("Can't load XSLT stylesheet from " + stylesheetResource, e);
        }
    }
public URLConnection getConnection() throws IOException {
        URLConnection con = url.openConnection();
        con.setConnectTimeout(30 * 1000);
        if (username == null || "".equals(username) || password == null || "".equals(password)) return con;
        if (wsseMode) {
            con.setRequestProperty("X-WSSE", getWsseHeaderValue());
            return con;
        }
        Authenticator.setDefault(new Authenticator() {

            protected PasswordAuthentication getPasswordAuthentication() {
                PasswordAuthentication auth = null;
                if (username != null && password != null) {
                    auth = new PasswordAuthentication(username, password.toCharArray());
                }
                return auth;
            }
        });
        return con;
    }
private void copyReportFile(ServletRequest req, String reportName, Report report) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException, FileNotFoundException, IOException {
        String reportFileName = (String) Class.forName("org.eclipse.birt.report.utility.ParameterAccessor").getMethod("getReport", new Class[] { HttpServletRequest.class, String.class }).invoke(null, new Object[] { req, reportName });
        ByteArrayInputStream bais = new ByteArrayInputStream(report.getReportContent());
        FileOutputStream fos = new FileOutputStream(new File(reportFileName));
        IOUtils.copy(bais, fos);
        bais.close();
        fos.close();
    }
public static boolean copy(FileSystem srcFS, Path src, FileSystem dstFS, Path dst, boolean deleteSource, boolean overwrite, Configuration conf) throws IOException {
        LOG.debug("[sgkim] copy - start");
        dst = checkDest(src.getName(), dstFS, dst, overwrite);
        if (srcFS.getFileStatus(src).isDir()) {
            checkDependencies(srcFS, src, dstFS, dst);
            if (!dstFS.mkdirs(dst)) {
                return false;
            }
            FileStatus contents[] = srcFS.listStatus(src);
            for (int i = 0; i < contents.length; i++) {
                copy(srcFS, contents[i].getPath(), dstFS, new Path(dst, contents[i].getPath().getName()), deleteSource, overwrite, conf);
            }
        } else if (srcFS.isFile(src)) {
            InputStream in = null;
            OutputStream out = null;
            try {
                LOG.debug("[sgkim] srcFS: " + srcFS + ", src: " + src);
                in = srcFS.open(src);
                LOG.debug("[sgkim] dstFS: " + dstFS + ", dst: " + dst);
                out = dstFS.create(dst, overwrite);
                LOG.debug("[sgkim] copyBytes - start");
                IOUtils.copyBytes(in, out, conf, true);
                LOG.debug("[sgkim] copyBytes - end");
            } catch (IOException e) {
                IOUtils.closeStream(out);
                IOUtils.closeStream(in);
                throw e;
            }
        } else {
            throw new IOException(src.toString() + ": No such file or directory");
        }
        LOG.debug("[sgkim] copy - end");
        if (deleteSource) {
            return srcFS.delete(src, true);
        } else {
            return true;
        }
    }
public static boolean copyMerge(FileSystem srcFS, Path srcDir, FileSystem dstFS, Path dstFile, boolean deleteSource, Configuration conf, String addString) throws IOException {
        dstFile = checkDest(srcDir.getName(), dstFS, dstFile, false);
        if (!srcFS.getFileStatus(srcDir).isDir()) return false;
        OutputStream out = dstFS.create(dstFile);
        try {
            FileStatus contents[] = srcFS.listStatus(srcDir);
            for (int i = 0; i < contents.length; i++) {
                if (!contents[i].isDir()) {
                    InputStream in = srcFS.open(contents[i].getPath());
                    try {
                        IOUtils.copyBytes(in, out, conf, false);
                        if (addString != null) out.write(addString.getBytes("UTF-8"));
                    } finally {
                        in.close();
                    }
                }
            }
        } finally {
            out.close();
        }
        if (deleteSource) {
            return srcFS.delete(srcDir, true);
        } else {
            return true;
        }
    }
public static boolean copy(File src, FileSystem dstFS, Path dst, boolean deleteSource, Configuration conf) throws IOException {
        dst = checkDest(src.getName(), dstFS, dst, false);
        if (src.isDirectory()) {
            if (!dstFS.mkdirs(dst)) {
                return false;
            }
            File contents[] = src.listFiles();
            for (int i = 0; i < contents.length; i++) {
                copy(contents[i], dstFS, new Path(dst, contents[i].getName()), deleteSource, conf);
            }
        } else if (src.isFile()) {
            InputStream in = null;
            OutputStream out = null;
            try {
                in = new FileInputStream(src);
                out = dstFS.create(dst);
                IOUtils.copyBytes(in, out, conf);
            } catch (IOException e) {
                IOUtils.closeStream(out);
                IOUtils.closeStream(in);
                throw e;
            }
        } else {
            throw new IOException(src.toString() + ": No such file or directory");
        }
        if (deleteSource) {
            return FileUtil.fullyDelete(src);
        } else {
            return true;
        }
    }
public static boolean copy(FileSystem srcFS, Path src, File dst, boolean deleteSource, Configuration conf) throws IOException {
        if (srcFS.getFileStatus(src).isDir()) {
            if (!dst.mkdirs()) {
                return false;
            }
            FileStatus contents[] = srcFS.listStatus(src);
            for (int i = 0; i < contents.length; i++) {
                copy(srcFS, contents[i].getPath(), new File(dst, contents[i].getPath().getName()), deleteSource, conf);
            }
        } else if (srcFS.isFile(src)) {
            InputStream in = srcFS.open(src);
            IOUtils.copyBytes(in, new FileOutputStream(dst), conf);
        } else {
            throw new IOException(src.toString() + ": No such file or directory");
        }
        if (deleteSource) {
            return srcFS.delete(src, true);
        } else {
            return true;
        }
    }
private static String fetch(String urltxt, String cookie) {
        try {
            URL url = new URL(urltxt);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            InputStream source = url.openStream();
            String data = new Scanner(source).useDelimiter("\\A").next();
            Pattern p = Pattern.compile("form action=\"(.*)\" method=\"post\"");
            Matcher m = p.matcher(data);
            if (!m.find()) return "";
            urltxt = m.group(1);
            url = new URL(urltxt);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestProperty("Cookie", cookie);
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
            out.write("dl.start=PREMIUM");
            out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuffer sb = new StringBuffer();
            while ((data = in.readLine()) != null) sb.append(data + System.getProperty("line.separator"));
            data = urltxt.substring(urltxt.lastIndexOf("/") + 1);
            p = Pattern.compile("<tr><td><a href=\"(.*?)" + data);
            m = p.matcher(sb.toString());
            data = (m.find()) ? (m.group(1) + data + System.getProperty("line.separator")) : "";
            return data;
        } catch (Exception e) {
            return "";
        }
    }
private static String saveCookie(String username, String password) {
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
            }
        } };
        try {
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            URL url = new URL("https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi");
            HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
            out.write("login=" + username + "&password=" + password);
            out.flush();
            String cookie = conn.getHeaderField("Set-Cookie");
            cookie = cookie.substring(0, cookie.indexOf(";"));
            out.close();
            conn.disconnect();
            return cookie;
        } catch (Exception e) {
            return "";
        }
    }