semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private MediaWikiResult getFromUri(String url) throws OntologyServiceException {
        try {
            logger.info("getting " + url);
            HttpURLConnection connection = (java.net.HttpURLConnection) new URL(url).openConnection();
            connection.setRequestProperty("User-Agent", "OntoCat-" + Math.random());
            BufferedInputStream bin = new BufferedInputStream(connection.getInputStream());
            JAXBContext jaxbContext = JAXBContext.newInstance("uk.ac.ebi.ontocat.mediawiki.jaxb");
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            return (MediaWikiResult) unmarshaller.unmarshal(bin);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OntologyServiceException(e);
        }
    }
public final boolean login(String user, String pass) {
        if (user == null || pass == null) return false;
        connectionInfo.setData("com.tensegrity.palojava.pass#" + user, pass);
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(pass.getBytes());
            pass = asHexString(md.digest());
        } catch (NoSuchAlgorithmException ex) {
            throw new PaloException("Failed to create encrypted password for " + "user '" + user + "'!", ex);
        }
        connectionInfo.setUser(user);
        connectionInfo.setPassword(pass);
        return loginInternal(user, pass);
    }
public RegionInfo(String name, int databaseID, int units, float xMin, float xMax, float yMin, float yMax, float zMin, float zMax, String imageURL) {
        this.name = name;
        this.databaseID = databaseID;
        this.units = units;
        this.xMin = xMin;
        this.xMax = xMax;
        this.yMin = yMin;
        this.yMax = yMax;
        this.zMin = zMin;
        this.zMax = zMax;
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(this.name.getBytes());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream daos = new DataOutputStream(baos);
            daos.writeInt(this.databaseID);
            daos.writeInt(this.units);
            daos.writeDouble(this.xMin);
            daos.writeDouble(this.xMax);
            daos.writeDouble(this.yMin);
            daos.writeDouble(this.yMax);
            daos.writeDouble(this.zMin);
            daos.writeDouble(this.zMax);
            daos.flush();
            byte[] hashValue = digest.digest(baos.toByteArray());
            int hashCode = 0;
            for (int i = 0; i < hashValue.length; i++) {
                hashCode += (int) hashValue[i] << (i % 4);
            }
            this.hashcode = hashCode;
        } catch (Exception e) {
            throw new IllegalArgumentException("Error occurred while generating hashcode for region " + this.name);
        }
        if (imageURL != null) {
            URL url = null;
            try {
                url = new URL(imageURL);
            } catch (MalformedURLException murle) {
            }
            if (url != null) {
                BufferedImage tmpImage = null;
                try {
                    tmpImage = ImageIO.read(url);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                mapImage = tmpImage;
            } else this.mapImage = null;
        } else this.mapImage = null;
    }
public String md5(String phrase) {
        MessageDigest m;
        String coded = new String();
        try {
            m = MessageDigest.getInstance("MD5");
            m.update(phrase.getBytes(), 0, phrase.length());
            coded = (new BigInteger(1, m.digest()).toString(16)).toString();
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        if (coded.length() < 32) {
            coded = "0" + coded;
        }
        return coded;
    }
public static void copyURLToFile(URL source, File destination) throws IOException {
        InputStream input = source.openStream();
        try {
            FileOutputStream output = openOutputStream(destination);
            try {
                IOUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(output);
            }
        } finally {
            IOUtils.closeQuietly(input);
        }
    }
public boolean open(String mode) {
        if (source instanceof String) return false; else if (mode == null) mode = ""; else mode = mode.toLowerCase();
        boolean toread = false, towrite = false;
        if (mode.indexOf("r") >= 0) toread = true;
        if (mode.indexOf("w") >= 0) towrite = true;
        if (!toread && !towrite) toread = towrite = true;
        try {
            if (toread && input == null) {
                if (isDirectory()) return true; else if (reader != null) return true; else if (source instanceof File) input = new FileInputStream((File) source); else if (source instanceof Socket) input = ((Socket) source).getInputStream(); else if (source instanceof URL) return getUrlInfo(toread, towrite); else return false;
            }
            if (towrite && output == null) {
                if (isDirectory()) return false; else if (writer != null) return true; else if (source instanceof File) output = new FileOutputStream((File) source); else if (source instanceof Socket) output = ((Socket) source).getOutputStream(); else if (source instanceof URL) return getUrlInfo(toread, towrite); else return false;
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }
private String MD5Sum(String input) {
        String hashtext = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(input.getBytes());
            byte[] digest = md.digest();
            BigInteger bigInt = new BigInteger(1, digest);
            hashtext = bigInt.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return hashtext;
    }
private static Collection<String> createTopLevelFiles(Configuration configuration, Collections collections, Sets sets) throws FlickrException, SAXException, IOException, JDOMException, TransformerException {
        Collection<String> createdFiles = new HashSet<String>();
        File toplevelXmlFilename = getToplevelXmlFilename(configuration.photosBaseDirectory);
        Logger.getLogger(FlickrDownload.class).info("Creating XML file " + toplevelXmlFilename.getAbsolutePath());
        MediaIndexer indexer = new XmlMediaIndexer(configuration);
        Element toplevel = new Element("flickr").addContent(XmlUtils.createApplicationXml()).addContent(XmlUtils.createUserXml(configuration)).addContent(collections.createTopLevelXml()).addContent(sets.createTopLevelXml()).addContent(new Stats(sets).createStatsXml(indexer));
        createdFiles.addAll(indexer.writeIndex());
        XmlUtils.outputXmlFile(toplevelXmlFilename, toplevel);
        createdFiles.add(toplevelXmlFilename.getName());
        Logger.getLogger(FlickrDownload.class).info("Copying support files and performing XSLT transformations");
        IOUtils.copyToFileAndCloseStreams(XmlUtils.class.getResourceAsStream("xslt/" + PHOTOS_CSS_FILENAME), new File(configuration.photosBaseDirectory, PHOTOS_CSS_FILENAME));
        createdFiles.add(PHOTOS_CSS_FILENAME);
        IOUtils.copyToFileAndCloseStreams(XmlUtils.class.getResourceAsStream("xslt/" + PLAY_ICON_FILENAME), new File(configuration.photosBaseDirectory, PLAY_ICON_FILENAME));
        createdFiles.add(PLAY_ICON_FILENAME);
        XmlUtils.performXsltTransformation(configuration, "all_sets.xsl", toplevelXmlFilename, new File(configuration.photosBaseDirectory, ALL_SETS_HTML_FILENAME));
        createdFiles.add(ALL_SETS_HTML_FILENAME);
        XmlUtils.performXsltTransformation(configuration, "all_collections.xsl", toplevelXmlFilename, new File(configuration.photosBaseDirectory, ALL_COLLECTIONS_HTML_FILENAME));
        createdFiles.add(ALL_COLLECTIONS_HTML_FILENAME);
        createdFiles.add(Collections.COLLECTIONS_ICON_DIRECTORY);
        XmlUtils.performXsltTransformation(configuration, "stats.xsl", toplevelXmlFilename, new File(configuration.photosBaseDirectory, STATS_HTML_FILENAME));
        createdFiles.add(STATS_HTML_FILENAME);
        sets.performXsltTransformation();
        for (AbstractSet set : sets.getSets()) {
            createdFiles.add(set.getSetId());
        }
        return createdFiles;
    }
public static void copyFile(File source, File destination) throws IOException {
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(source));
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destination));
            byte[] buffer = new byte[4096];
            int read = -1;
            while ((read = in.read(buffer)) != -1) {
                out.write(buffer, 0, read);
            }
            out.flush();
            out.close();
            in.close();
        }
public static String sha1(String clearText, String seed) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update((seed + clearText).getBytes());
            return convertToHex(md.digest());
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
private static void downloadFile(String downloadFileName) throws Exception {
        URL getFileUrl = new URL("http://www.tegsoft.com/Tobe/getFile" + "?tegsoftFileName=" + downloadFileName);
        URLConnection getFileUrlConnection = getFileUrl.openConnection();
        InputStream is = getFileUrlConnection.getInputStream();
        String tobeHome = UiUtil.getParameter("RealPath.Context");
        OutputStream out = new FileOutputStream(tobeHome + "/setup/" + downloadFileName);
        IOUtils.copy(is, out);
        is.close();
        out.close();
    }
public void write(URL exportUrl, OutputStream output) throws Exception {
        if (exportUrl == null || output == null) {
            throw new RuntimeException("null passed in for required parameters");
        }
        MediaContent mc = new MediaContent();
        mc.setUri(exportUrl.toString());
        MediaSource ms = service.getMedia(mc);
        InputStream input = ms.getInputStream();
        IOUtils.copy(input, output);
    }
private String retrieveTemplate() throws Exception {
        if (cachedTemplate == null) {
            final URL url = new URL(blogEditor.getBlogInfo().getBlogUrl());
            final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            final StringBuilder result = new StringBuilder();
            String line;
            while ((line = in.readLine()) != null) {
                result.append(line);
            }
            in.close();
            cachedTemplate = result.toString();
        }
        return cachedTemplate;
    }
public ActionForward saveImageMap(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        log.debug("MapAction saveImageMap()");
        String imageURL = RequestUtil.getRequest(request, "imgUrl");
        DataInputStream di = null;
        FileOutputStream fo = null;
        byte[] b = new byte[1];
        URL url = new URL(imageURL);
        URLConnection urlConnection = url.openConnection();
        urlConnection.connect();
        response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment;filename=" + "map.png");
        OutputStream outstream = response.getOutputStream();
        byte abyte0[] = new byte[4096];
        try {
            BufferedInputStream instream = new BufferedInputStream(urlConnection.getInputStream());
            int i;
            while ((i = instream.read(abyte0, 0, 4096)) != -1) outstream.write(abyte0, 0, i);
            instream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
public static Test suite() throws Exception {
        java.net.URL url = ClassLoader.getSystemResource("host0.jndi.properties");
        java.util.Properties host0JndiProps = new java.util.Properties();
        host0JndiProps.load(url.openStream());
        java.util.Properties systemProps = System.getProperties();
        systemProps.putAll(host0JndiProps);
        System.setProperties(systemProps);
        TestSuite suite = new TestSuite();
        suite.addTest(new TestSuite(T06OTSInterpositionUnitTestCase.class));
        TestSetup wrapper = new JBossTestSetup(suite) {

            protected void setUp() throws Exception {
                super.setUp();
                deploy("dtmpassthrough2ots.jar");
            }

            protected void tearDown() throws Exception {
                undeploy("dtmpassthrough2ots.jar");
                super.tearDown();
            }
        };
        return wrapper;
    }
public static void copyToFileAndCloseStreams(InputStream istr, File destFile) throws IOException {
        OutputStream ostr = null;
        try {
            ostr = new FileOutputStream(destFile);
            IOUtils.copy(istr, ostr);
        } finally {
            if (ostr != null) ostr.close();
            if (istr != null) istr.close();
        }
    }
public IntactOntology parseOboFile(URL url, boolean keepTemporaryFile) throws PsiLoaderException {
        if (url == null) {
            throw new IllegalArgumentException("Please give a non null URL.");
        }
        StringBuffer buffer = new StringBuffer(1024 * 8);
        try {
            System.out.println("Loading URL: " + url);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()), 1024);
            String line;
            int lineCount = 0;
            while ((line = in.readLine()) != null) {
                lineCount++;
                buffer.append(line).append(NEW_LINE);
                if ((lineCount % 20) == 0) {
                    System.out.print(".");
                    System.out.flush();
                    if ((lineCount % 500) == 0) {
                        System.out.println("   " + lineCount);
                    }
                }
            }
            in.close();
            File tempDirectory = new File(System.getProperty("java.io.tmpdir", "tmp"));
            if (!tempDirectory.exists()) {
                if (!tempDirectory.mkdirs()) {
                    throw new IOException("Cannot create temp directory: " + tempDirectory.getAbsolutePath());
                }
            }
            System.out.println("Using temp directory: " + tempDirectory.getAbsolutePath());
            File tempFile = File.createTempFile("psimi.v25.", ".obo", tempDirectory);
            tempFile.deleteOnExit();
            tempFile.deleteOnExit();
            System.out.println("The OBO file is temporary store as: " + tempFile.getAbsolutePath());
            BufferedWriter out = new BufferedWriter(new FileWriter(tempFile), 1024);
            out.write(buffer.toString());
            out.flush();
            out.close();
            return parseOboFile(tempFile);
        } catch (IOException e) {
            throw new PsiLoaderException("Error while loading URL (" + url + ")", e);
        }
    }
private InputStream loadSource(String url) throws ClientProtocolException, IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(HTTP.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)");
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        return entity.getContent();
    }
public static String checkUpdate() {
        URL url = null;
        try {
            url = new URL("http://googlemeupdate.bravehost.com/");
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
        InputStream html = null;
        try {
            html = url.openStream();
            int c = 0;
            String Buffer = "";
            String Code = "";
            while (c != -1) {
                try {
                    c = html.read();
                } catch (IOException ex) {
                }
                Buffer = Buffer + (char) c;
            }
            return Buffer.substring(Buffer.lastIndexOf("Google.mE Version: ") + 19, Buffer.indexOf("||"));
        } catch (IOException ex) {
            ex.printStackTrace();
            return "";
        }
    }
public static String getWhatsNew(String ver) {
        URL url = null;
        try {
            url = new URL("http://googlemeupdate.bravehost.com/History.htm");
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
        InputStream html = null;
        try {
            html = url.openStream();
            int c = 0;
            String Buffer = "";
            String Code = "";
            while (c != -1) {
                try {
                    c = html.read();
                } catch (IOException ex) {
                }
                Buffer = Buffer + (char) c;
            }
            Buffer = Buffer.substring(Buffer.lastIndexOf(ver) + ver.length() + 2, Buffer.indexOf("end::")).replaceAll("||", "");
            return "<html>" + Buffer.substring(Buffer.indexOf("Google.mE Version: "));
        } catch (IOException ex) {
            ex.printStackTrace();
            return "";
        }
    }
public static void CreateBackupOfDataFile(String _src, String _dest) {
        try {
            File src = new File(_src);
            File dest = new File(_dest);
            if (new File(_src).exists()) {
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
                BufferedInputStream in = new BufferedInputStream(new FileInputStream(src));
                byte[] read = new byte[128];
                int len = 128;
                while ((len = in.read(read)) > 0) out.write(read, 0, len);
                out.flush();
                out.close();
                in.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static String BaiKe(String unknown) {
        String encodeurl = "";
        long sTime = System.currentTimeMillis();
        long eTime;
        try {
            String regEx = "\\#(.+)\\#";
            String searchText = "";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher(unknown);
            if (m.find()) {
                searchText = m.group(1);
            }
            System.out.println("searchText :  " + searchText);
            encodeurl = URLEncoder.encode(searchText, "UTF-8");
            String url = "http://www.hudong.com/wiki/" + encodeurl;
            HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
            conn.setConnectTimeout(10000);
            Parser parser = new Parser(conn);
            parser.setEncoding(parser.getEncoding());
            NodeFilter filtera = new TagNameFilter("DIV");
            NodeList nodes = parser.extractAllNodesThatMatch(filtera);
            String textInPage = "";
            if (nodes != null) {
                for (int i = 0; i < nodes.size(); i++) {
                    Node textnode = (Node) nodes.elementAt(i);
                    if ("div class=\"summary\"".equals(textnode.getText())) {
                        String temp = textnode.toPlainTextString();
                        textInPage += temp + "\n";
                    }
                }
            }
            String s = Replace(textInPage, searchText);
            eTime = System.currentTimeMillis();
            String time = "搜索[" + searchText + "]用时:" + (eTime - sTime) / 1000.0 + "s";
            System.out.println(s);
            return time + "\r\n" + s;
        } catch (Exception e) {
            e.printStackTrace();
            return "大姨妈来了";
        }
    }
private static String sort(final String item) {
        final char[] chars = item.toCharArray();
        for (int i = 1; i < chars.length; i++) {
            for (int j = 0; j < chars.length - 1; j++) {
                if (chars[j] > chars[j + 1]) {
                    final char temp = chars[j];
                    chars[j] = chars[j + 1];
                    chars[j + 1] = temp;
                }
            }
        }
        return String.valueOf(chars);
    }
public String encryptLdapPassword(String algorithm) {
        String sEncrypted = _password;
        if ((_password != null) && (_password.length() > 0)) {
            algorithm = Val.chkStr(algorithm);
            boolean bMD5 = algorithm.equalsIgnoreCase("MD5");
            boolean bSHA = algorithm.equalsIgnoreCase("SHA") || algorithm.equalsIgnoreCase("SHA1") || algorithm.equalsIgnoreCase("SHA-1");
            if (bSHA || bMD5) {
                String sAlgorithm = "MD5";
                if (bSHA) {
                    sAlgorithm = "SHA";
                }
                try {
                    MessageDigest md = MessageDigest.getInstance(sAlgorithm);
                    md.update(getPassword().getBytes("UTF-8"));
                    sEncrypted = "{" + sAlgorithm + "}" + (new BASE64Encoder()).encode(md.digest());
                } catch (NoSuchAlgorithmException e) {
                    sEncrypted = null;
                    e.printStackTrace(System.err);
                } catch (UnsupportedEncodingException e) {
                    sEncrypted = null;
                    e.printStackTrace(System.err);
                }
            }
        }
        return sEncrypted;
    }
public static void copyFile(File src, File dst) throws IOException {
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dst);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        in.close();
        out.close();
    }
public void bubble() {
        boolean test = false;
        int kars = 0, tas = 0;
        while (true) {
            for (int j = 0; j < dizi.length - 1; j++) {
                kars++;
                if (dizi[j] > dizi[j + 1]) {
                    int temp = dizi[j];
                    dizi[j] = dizi[j + 1];
                    dizi[j + 1] = temp;
                    test = true;
                    tas++;
                }
            }
            if (!test) {
                break;
            } else {
                test = false;
            }
        }
        System.out.print(kars + " " + tas);
    }
private void downloadTo(URL url, File out) throws IOException {
        URLConnection conn = url.openConnection();
        BufferedInputStream is = new BufferedInputStream(conn.getInputStream());
        BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(out));
        final int BLOCK_SIZE = 1024;
        byte[] buf = new byte[BLOCK_SIZE];
        int size;
        while ((size = is.read(buf, 0, BLOCK_SIZE)) > 0) os.write(buf, 0, size);
        is.close();
        os.close();
    }
public static String getTextFromUrl(final String url) {
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        try {
            final StringBuilder result = new StringBuilder();
            inputStreamReader = new InputStreamReader(new URL(url).openStream());
            bufferedReader = new BufferedReader(inputStreamReader);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                result.append(HtmlUtil.quoteHtml(line)).append("\r");
            }
            return result.toString();
        } catch (final IOException exception) {
            return exception.getMessage();
        } finally {
            InputOutputUtil.close(bufferedReader);
            InputOutputUtil.close(inputStreamReader);
        }
    }