semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String getHashedStringMD5(String value) throws java.security.NoSuchAlgorithmException {
        java.security.MessageDigest d = java.security.MessageDigest.getInstance("MD5");
        d.reset();
        d.update(value.getBytes());
        byte[] buf = d.digest();
        return new String(buf);
    }
public static void bubble(double[] a) {
        for (int i = a.length - 1; i > 0; i--) for (int j = 0; j < i; j++) if (a[j] > a[j + 1]) {
            double temp = a[j];
            a[j] = a[j + 1];
            a[j + 1] = temp;
        }
    }
public static String getRandomUserAgent() {
        if (USER_AGENT_CACHE == null) {
            Collection<String> userAgentsCache = new ArrayList<String>();
            try {
                URL url = Tools.getResource(UserAgent.class.getClassLoader(), "user-agents-browser.txt");
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                String str;
                while ((str = in.readLine()) != null) {
                    userAgentsCache.add(str);
                }
                in.close();
                USER_AGENT_CACHE = userAgentsCache.toArray(new String[userAgentsCache.size()]);
            } catch (Exception e) {
                System.err.println("Can not read file; using default user-agent; error message: " + e.getMessage());
                return DEFAULT_USER_AGENT;
            }
        }
        return USER_AGENT_CACHE[new Random().nextInt(USER_AGENT_CACHE.length)];
    }
public String contactService(String service, StringBuffer xmlRequest) throws Exception {
        Logger.debug(UPSConnections.class, "UPS CONNECTIONS ***** Started " + service + " " + new Date().toString() + " *****");
        HttpURLConnection connection;
        URL url;
        String response = "";
        try {
            Logger.debug(UPSConnections.class, "connect to " + protocol + "://" + hostname + "/" + URLPrefix + "/" + service);
            if (protocol.equalsIgnoreCase("https")) {
                java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
                System.getProperties().put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
                url = new URL(protocol + "://" + hostname + "/" + URLPrefix + "/" + service);
                connection = (HttpsURLConnection) url.openConnection();
            } else {
                url = new URL(protocol + "://" + hostname + "/" + URLPrefix + "/" + service);
                connection = (HttpURLConnection) url.openConnection();
            }
            Logger.debug(UPSConnections.class, "Establishing connection with " + url.toString());
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setUseCaches(false);
            OutputStream out = connection.getOutputStream();
            StringBuffer request = new StringBuffer();
            request.append(accessXMLRequest());
            request.append(xmlRequest);
            out.write((request.toString()).getBytes());
            Logger.debug(UPSConnections.class, "Transmission sent to " + url.toString() + ":\n" + xmlRequest);
            out.close();
            try {
                response = readURLConnection(connection);
            } catch (Exception e) {
                Logger.debug(UPSConnections.class, "Error in reading URL Connection" + e.getMessage());
                throw e;
            }
            Logger.debug(UPSConnections.class, "Response = " + response);
        } catch (Exception e1) {
            Logger.info(UPSConnections.class, "Error sending data to server" + e1.toString());
            Logger.debug(UPSConnections.class, "Error sending data to server" + e1.toString());
        } finally {
            Logger.info(UPSConnections.class, "****** Transmission Finished " + service + " " + new Date().toString() + " *********");
            Logger.debug(UPSConnections.class, "****** Transmission Finished " + service + " " + new Date().toString() + " *********");
        }
        return response;
    }
private static void loadQueryProcessorFactories() {
        qpFactoryMap = new HashMap<String, QueryProcessorFactoryIF>();
        Enumeration<URL> resources = null;
        try {
            resources = QueryUtils.class.getClassLoader().getResources(RESOURCE_STRING);
        } catch (IOException e) {
            log.error("Error while trying to look for " + "QueryProcessorFactoryIF implementations.", e);
        }
        while (resources != null && resources.hasMoreElements()) {
            URL url = resources.nextElement();
            InputStream is = null;
            try {
                is = url.openStream();
            } catch (IOException e) {
                log.warn("Error opening stream to QueryProcessorFactoryIF service description.", e);
            }
            if (is != null) {
                BufferedReader rdr = new BufferedReader(new InputStreamReader(is));
                String line;
                try {
                    while ((line = rdr.readLine()) != null) {
                        try {
                            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
                            Class<?> c = Class.forName(line, true, classLoader);
                            if (QueryProcessorFactoryIF.class.isAssignableFrom(c)) {
                                QueryProcessorFactoryIF factory = (QueryProcessorFactoryIF) c.newInstance();
                                qpFactoryMap.put(factory.getQueryLanguage().toUpperCase(), factory);
                            } else {
                                log.warn("Wrong entry for QueryProcessorFactoryIF service " + "description, '" + line + "' is not implementing the " + "correct interface.");
                            }
                        } catch (Exception e) {
                            log.warn("Could not create an instance for " + "QueryProcessorFactoryIF service '" + line + "'.");
                        }
                    }
                } catch (IOException e) {
                    log.warn("Could not read from QueryProcessorFactoryIF " + "service descriptor.", e);
                }
            }
        }
        if (!qpFactoryMap.containsKey(DEFAULT_LANGUAGE)) {
            qpFactoryMap.put(DEFAULT_LANGUAGE, new TologQueryProcessorFactory());
        }
    }
public static String md5String(String string) {
        try {
            MessageDigest msgDigest = MessageDigest.getInstance("MD5");
            msgDigest.update(string.getBytes("UTF-8"));
            byte[] digest = msgDigest.digest();
            String result = "";
            for (int i = 0; i < digest.length; i++) {
                int value = digest[i];
                if (value < 0) value += 256;
                result += Integer.toHexString(value);
            }
            return result;
        } catch (UnsupportedEncodingException error) {
            throw new IllegalArgumentException(error);
        } catch (NoSuchAlgorithmException error) {
            throw new IllegalArgumentException(error);
        }
    }
public static InputStream openURL(String url, ConnectData data) {
        try {
            URLConnection con = new URL(url).openConnection();
            con.setConnectTimeout(TIMEOUT);
            con.setReadTimeout(TIMEOUT);
            con.setUseCaches(false);
            con.setRequestProperty("Accept-Charset", "utf-8");
            setUA(con);
            if (data.cookie != null) con.setRequestProperty("Cookie", data.cookie);
            InputStream is = con.getInputStream();
            parseCookie(con, data);
            return new BufferedInputStream(is);
        } catch (IOException ioe) {
            Log.except("failed to open URL " + url, ioe);
        }
        return null;
    }
public static InputStream sendReq(String url, String content, ConnectData data) {
        try {
            URLConnection con = new URL(url).openConnection();
            con.setConnectTimeout(TIMEOUT);
            con.setReadTimeout(TIMEOUT);
            con.setUseCaches(false);
            setUA(con);
            con.setRequestProperty("Accept-Charset", "utf-8");
            con.setDoOutput(true);
            con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            if (data.cookie != null) con.setRequestProperty("Cookie", data.cookie);
            HttpURLConnection httpurl = (HttpURLConnection) con;
            httpurl.setRequestMethod("POST");
            Writer wr = new OutputStreamWriter(con.getOutputStream());
            wr.write(content);
            wr.flush();
            con.connect();
            InputStream is = con.getInputStream();
            is = new BufferedInputStream(is);
            wr.close();
            parseCookie(con, data);
            return is;
        } catch (IOException ioe) {
            Log.except("failed to send request " + url, ioe);
        }
        return null;
    }
private void reloadData(String dataSourceUrl) {
        try {
            URL url = new URL(dataSourceUrl);
            InputStream is = url.openStream();
            if (progressMonitor.isCanceled() == false) {
                progressMonitor.setNote("Building classifications...");
                progressMonitor.setProgress(2);
                mediator.loadClassificationTree(is);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static ArrayList<FriendInfo> downloadFriendsList(String username) {
        try {
            URL url;
            url = new URL(WS_URL + "/user/" + URLEncoder.encode(username, "UTF-8") + "/friends.xml");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            DocumentBuilderFactory dbFac = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbFac.newDocumentBuilder();
            Document doc = db.parse(is);
            NodeList friends = doc.getElementsByTagName("user");
            ArrayList<FriendInfo> result = new ArrayList<FriendInfo>();
            for (int i = 0; i < friends.getLength(); i++) try {
                result.add(new FriendInfo((Element) friends.item(i)));
            } catch (Utils.ParseException e) {
                Log.e(TAG, "in downloadFriendsList", e);
                return null;
            }
            return result;
        } catch (Exception e) {
            Log.e(TAG, "in downloadFriendsList", e);
            return null;
        }
    }
private ArrayList<XSPFTrackInfo> getPlaylist() {
        try {
            Log.d(TAG, "Getting playlist started");
            String urlString = "http://" + mBaseURL + "/xspf.php?sk=" + mSession + "&discovery=0&desktop=1.4.1.57486";
            if (mAlternateConn) {
                urlString += "&api_key=9d1bbaef3b443eb97973d44181d04e4b";
                Log.d(TAG, "Using alternate connection method");
            }
            URL url = new URL(urlString);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            DocumentBuilderFactory dbFac = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbFac.newDocumentBuilder();
            Document doc = db.parse(is);
            Element root = doc.getDocumentElement();
            NodeList titleNs = root.getElementsByTagName("title");
            String stationName = "<unknown station>";
            if (titleNs.getLength() > 0) {
                Element titleElement = (Element) titleNs.item(0);
                String res = "";
                for (int i = 0; i < titleElement.getChildNodes().getLength(); i++) {
                    Node item = titleElement.getChildNodes().item(i);
                    if (item.getNodeType() == Node.TEXT_NODE) res += item.getNodeValue();
                }
                stationName = URLDecoder.decode(res, "UTF-8");
            }
            NodeList tracks = doc.getElementsByTagName("track");
            ArrayList<XSPFTrackInfo> result = new ArrayList<XSPFTrackInfo>();
            for (int i = 0; i < tracks.getLength(); i++) try {
                result.add(new XSPFTrackInfo(stationName, (Element) tracks.item(i)));
            } catch (Utils.ParseException e) {
                Log.e(TAG, "in getPlaylist", e);
                return null;
            }
            Log.d(TAG, "Getting playlist successful");
            return result;
        } catch (Exception e) {
            Log.e(TAG, "in getPlaylist", e);
            return null;
        }
    }
private boolean adjust(String stationUrl) throws LastFMError {
        try {
            URL url = new URL("http://" + mBaseURL + "/adjust.php?session=" + mSession + "&url=" + URLEncoder.encode(stationUrl, "UTF-8"));
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            InputStreamReader reader = new InputStreamReader(is);
            BufferedReader stringReader = new BufferedReader(reader);
            Utils.OptionsParser options = new Utils.OptionsParser(stringReader);
            if (!options.parse()) options = null;
            stringReader.close();
            if ("OK".equals(options.get("response"))) {
                return true;
            } else {
                Log.e(TAG, "Adjust failed: \"" + options.get("response") + "\"");
                return false;
            }
        } catch (MalformedURLException e) {
            Log.e(TAG, "in adjust", e);
            throw new LastFMError("Adjust failed:" + e.toString());
        } catch (UnsupportedEncodingException e) {
            Log.e(TAG, "in adjust", e);
            throw new LastFMError("Adjust failed:" + e.toString());
        } catch (IOException e) {
            Log.e(TAG, "in adjust", e);
            throw new LastFMError("Station not found:" + stationUrl);
        }
    }
boolean checkIfUserExists(String username) throws IOException {
        try {
            URL url = new URL(WS_URL + "/user/" + URLEncoder.encode(username, "UTF-8") + "/profile.xml");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            is.close();
            return true;
        } catch (FileNotFoundException e) {
            return false;
        }
    }
static void xmlRpcCall(String method, String[] params) throws LastFMError {
        try {
            XmlPullParserFactory fac = XmlPullParserFactory.newInstance();
            XmlSerializer serializer = fac.newSerializer();
            URL url;
            url = new URL(XMLRPC_URL);
            URLConnection conn;
            conn = url.openConnection();
            conn.setRequestProperty("Content-Type", "text/xml");
            conn.setDoOutput(true);
            serializer.setOutput(conn.getOutputStream(), "UTF-8");
            serializer.startDocument("UTF-8", true);
            serializer.startTag(null, "methodCall");
            serializer.startTag(null, "methodName");
            serializer.text(method);
            serializer.endTag(null, "methodName");
            serializer.startTag(null, "params");
            for (String s : params) {
                serializer.startTag(null, "param");
                serializer.startTag(null, "value");
                serializer.startTag(null, "string");
                serializer.text(s);
                serializer.endTag(null, "string");
                serializer.endTag(null, "value");
                serializer.endTag(null, "param");
            }
            serializer.endTag(null, "params");
            serializer.endTag(null, "methodCall");
            serializer.flush();
            InputStream is = conn.getInputStream();
            DocumentBuilderFactory dbFac = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbFac.newDocumentBuilder();
            Document doc = db.parse(is);
            try {
                String res = Utils.getChildElement(doc.getDocumentElement(), new String[] { "params", "param", "value", "string" });
                if (!res.equals("OK")) {
                    Log.e(TAG, "while xmlrpc got " + res);
                    throw new LastFMXmlRpcError("XMLRPC Call failed: " + res);
                }
            } catch (ParseException e) {
                String faultString = Utils.getChildElement(doc.getDocumentElement(), new String[] { "params", "param", "value", "struct", "member[1]", "value", "string" });
                throw new LastFMXmlRpcError(faultString);
            }
        } catch (LastFMXmlRpcError e) {
            throw e;
        } catch (Exception e) {
            Log.e(TAG, "while xmlrpc", e);
            throw new LastFMError(e.toString());
        }
    }
public static Document getSkeleton() {
        Document doc = null;
        String filesep = System.getProperty("file.separator");
        try {
            java.net.URL url = Skeleton.class.getResource(filesep + "simplemassimeditor" + filesep + "resources" + filesep + "configskeleton.xml");
            InputStream input = url.openStream();
            DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            try {
                doc = parser.parse(input);
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return doc;
    }
public ICCColorSpaceExt createICCColorSpaceExt(BridgeContext ctx, Element paintedElement, String iccProfileName) {
        ICCColorSpaceExt cs = cache.request(iccProfileName.toLowerCase());
        if (cs != null) {
            return cs;
        }
        Document doc = paintedElement.getOwnerDocument();
        NodeList list = doc.getElementsByTagNameNS(SVG_NAMESPACE_URI, SVG_COLOR_PROFILE_TAG);
        int n = list.getLength();
        Element profile = null;
        for (int i = 0; i < n; i++) {
            Node node = list.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element profileNode = (Element) node;
                String nameAttr = profileNode.getAttributeNS(null, SVG_NAME_ATTRIBUTE);
                if (iccProfileName.equalsIgnoreCase(nameAttr)) {
                    profile = profileNode;
                }
            }
        }
        if (profile == null) return null;
        String href = XLinkSupport.getXLinkHref(profile);
        ICC_Profile p = null;
        if (href != null) {
            String baseURI = ((SVGOMDocument) doc).getURL();
            ParsedURL purl = new ParsedURL(baseURI, href);
            if (!purl.complete()) throw new BridgeException(paintedElement, ERR_URI_MALFORMED, new Object[] { href });
            try {
                ParsedURL pDocURL = null;
                if (baseURI != null) {
                    pDocURL = new ParsedURL(baseURI);
                }
                ctx.getUserAgent().checkLoadExternalResource(purl, pDocURL);
                p = ICC_Profile.getInstance(purl.openStream());
            } catch (IOException e) {
                throw new BridgeException(paintedElement, ERR_URI_IO, new Object[] { href });
            } catch (SecurityException e) {
                throw new BridgeException(paintedElement, ERR_URI_UNSECURE, new Object[] { href });
            }
        }
        if (p == null) {
            return null;
        }
        int intent = convertIntent(profile);
        cs = new ICCColorSpaceExt(p, intent);
        cache.put(iccProfileName.toLowerCase(), cs);
        return cs;
    }
private Properties loadPropertiesFromURL(String propertiesURL, Properties defaultProperties) {
        Properties properties = new Properties(defaultProperties);
        URL url;
        try {
            url = new URL(propertiesURL);
            URLConnection urlConnection = url.openConnection();
            properties.load(urlConnection.getInputStream());
        } catch (MalformedURLException e) {
            System.out.println("Error while loading url " + propertiesURL + " (" + e.getClass().getName() + ")");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("Error while loading url " + propertiesURL + " (" + e.getClass().getName() + ")");
            e.printStackTrace();
        }
        return properties;
    }
public boolean finish() {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName.getText());
        try {
            project.create(null);
            project.open(null);
            IProjectDescription desc = project.getDescription();
            desc.setNatureIds(new String[] { JavaCore.NATURE_ID });
            project.setDescription(desc, null);
            IJavaProject javaProject = JavaCore.create(project);
            IPath fitLib = project.getFullPath().append(FIT_LIBRARY);
            javaProject.setRawClasspath(createClassPathEntries(project, fitLib), null);
            copyLibrary(project);
            javaProject.setOutputLocation(createOutputFolder(project, DEFAULT_OUTPUT_FOLDER).getFullPath(), null);
            createOutputFolder(project, fitTests.getText());
            createOutputFolder(project, fitResults.getText());
            if (!DEFAULT_OUTPUT_FOLDER.equals(fitResults.getText())) {
                DefaultFolderProperties.setDefinedOutputLocation(project, fitResults.getText());
            }
            if (!DEFAULT_SOURCE_FOLDER.equals(fitFixtures.getText())) {
                DefaultFolderProperties.setDefinedSourceLocation(project, fitFixtures.getText());
            }
            if (includeExamplesCheck.getSelection()) {
                copySamples(project);
            }
        } catch (CoreException e) {
            handleError(getContainer().getShell(), project, "Could not create project:" + e.getMessage());
            return false;
        } catch (IOException e) {
            handleError(getContainer().getShell(), project, "Could not create project:" + e.getMessage());
            return false;
        }
        return true;
    }
protected File compress(File orig, IWrapCompression wrapper) throws IOException {
        File compressed = File.createTempFile("test.", ".gz");
        FileOutputStream fos = new FileOutputStream(compressed);
        OutputStream wos = wrapper.wrap(fos);
        FileInputStream fis = new FileInputStream(orig);
        IOUtils.copy(fis, wos);
        IOUtils.closeQuietly(fis);
        IOUtils.closeQuietly(wos);
        return compressed;
    }
@Override
    protected FTPClient ftpConnect() throws SocketException, IOException, NoSuchAlgorithmException {
        FilePathItem fpi = getFilePathItem();
        FTPClient f = new FTPSClient();
        f.connect(fpi.getHost());
        f.login(fpi.getUsername(), fpi.getPassword());
        return f;
    }