semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private Dataset(File f, Properties p, boolean ro) throws DatabaseException {
        folder = f;
        logger.debug("Opening dataset [" + ((ro) ? "readOnly" : "read/write") + " mode]");
        readOnly = ro;
        logger = Logger.getLogger(Dataset.class);
        logger.debug("Opening environment: " + f);
        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setTransactional(false);
        envConfig.setAllowCreate(!readOnly);
        envConfig.setReadOnly(readOnly);
        env = new Environment(f, envConfig);
        File props = new File(folder, "dataset.properties");
        if (!ro && p != null) {
            this.properties = p;
            try {
                FileOutputStream fos = new FileOutputStream(props);
                p.store(fos, null);
                fos.close();
            } catch (IOException e) {
                logger.warn("Error saving dataset properties", e);
            }
        } else {
            if (props.exists()) {
                try {
                    Properties pr = new Properties();
                    FileInputStream fis = new FileInputStream(props);
                    pr.load(fis);
                    fis.close();
                    this.properties = pr;
                } catch (IOException e) {
                    logger.warn("Error reading dataset properties", e);
                }
            }
        }
        getPaths();
        getNamespaces();
        getTree();
        pathDatabases = new HashMap();
        frequencyDatabases = new HashMap();
        lengthDatabases = new HashMap();
        clustersDatabases = new HashMap();
        pathMaps = new HashMap();
        frequencyMaps = new HashMap();
        lengthMaps = new HashMap();
        clustersMaps = new HashMap();
    }
private static byte[] baseHash(String name, String password) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.reset();
            digest.update(name.toLowerCase().getBytes());
            digest.update(password.getBytes());
            return digest.digest();
        } catch (NoSuchAlgorithmException ex) {
            d("MD5 algorithm not found!");
            throw new RuntimeException("MD5 algorithm not found! Unable to authenticate");
        }
    }
public void createFeed(Context ctx, URL url) {
        try {
            targetFlag = TARGET_FEED;
            droidDB = NewsDroidDB.getInstance(ctx);
            currentFeed.Url = url;
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(this);
            xr.parse(new InputSource(url.openStream()));
        } catch (IOException e) {
            Log.e(e.getMessage());
        } catch (SAXException e) {
            Log.e(e.getMessage());
        } catch (ParserConfigurationException e) {
            Log.e(e.getMessage());
        }
    }
private File download(String filename, URL url) {
        int size = -1;
        int received = 0;
        try {
            fireDownloadStarted(filename);
            File file = createFile(filename);
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
            System.out.println("������Դ��" + filename + ", url=" + url);
            InputStream bis = url.openStream();
            byte[] buf = new byte[1024];
            int count = 0;
            long lastUpdate = 0;
            size = bis.available();
            while ((count = bis.read(buf)) != -1) {
                bos.write(buf, 0, count);
                received += count;
                long now = System.currentTimeMillis();
                if (now - lastUpdate > 500) {
                    fireDownloadUpdate(filename, size, received);
                    lastUpdate = now;
                }
            }
            bos.close();
            System.out.println("��Դ������ϣ�" + filename);
            fireDownloadCompleted(filename);
            return file;
        } catch (IOException e) {
            System.out.println("������Դʧ�ܣ�" + filename + ", error=" + e.getMessage());
            fireDownloadInterrupted(filename);
            if (!(e instanceof FileNotFoundException)) {
                e.printStackTrace();
            }
        }
        return null;
    }
private void delay(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        String url = request.getRequestURL().toString();
        if (delayed.contains(url)) {
            delayed.remove(url);
            LOGGER.info(MessageFormat.format("Loading delayed resource at url = [{0}]", url));
            chain.doFilter(request, response);
        } else {
            LOGGER.info("Returning resource = [LoaderApplication.swf]");
            InputStream input = null;
            OutputStream output = null;
            try {
                input = getClass().getResourceAsStream("LoaderApplication.swf");
                output = response.getOutputStream();
                delayed.add(url);
                response.setHeader("Cache-Control", "no-cache");
                IOUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(output);
                IOUtils.closeQuietly(input);
            }
        }
    }
public TwilioRestResponse request(String path, String method, Map<String, String> vars) throws TwilioRestException {
        String encoded = "";
        if (vars != null) {
            for (String key : vars.keySet()) {
                try {
                    encoded += "&" + key + "=" + URLEncoder.encode(vars.get(key), "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            if (encoded.length() > 0) {
                encoded = encoded.substring(1);
            }
        }
        String url = this.endpoint + path;
        if (method.toUpperCase().equals("GET")) url += ((path.indexOf('?') == -1) ? "?" : "&") + encoded;
        try {
            URL resturl = new URL(url);
            HttpURLConnection con = (HttpURLConnection) resturl.openConnection();
            String userpass = this.accountSid + ":" + this.authToken;
            String encodeuserpass = new String(Base64.encodeToByte(userpass.getBytes(), false));
            con.setRequestProperty("Authorization", "Basic " + encodeuserpass);
            con.setDoOutput(true);
            if (method.toUpperCase().equals("GET")) {
                con.setRequestMethod("GET");
            } else if (method.toUpperCase().equals("POST")) {
                con.setRequestMethod("POST");
                OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
                out.write(encoded);
                out.close();
            } else if (method.toUpperCase().equals("PUT")) {
                con.setRequestMethod("PUT");
                OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
                out.write(encoded);
                out.close();
            } else if (method.toUpperCase().equals("DELETE")) {
                con.setRequestMethod("DELETE");
            } else {
                throw new TwilioRestException("Unknown method " + method);
            }
            BufferedReader in = null;
            try {
                if (con.getInputStream() != null) {
                    in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                }
            } catch (IOException e) {
                if (con.getErrorStream() != null) {
                    in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
                }
            }
            if (in == null) {
                throw new TwilioRestException("Unable to read response from server");
            }
            StringBuffer decodedString = new StringBuffer();
            String line;
            while ((line = in.readLine()) != null) {
                decodedString.append(line);
            }
            in.close();
            int responseCode = con.getResponseCode();
            return new TwilioRestResponse(url, decodedString.toString(), responseCode);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
public static void fileCopy(File source, File dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }
public void saveFile(final InputStream inputStream, final String fileName) {
        final File file = new File(System.getProperty("java.io.tmpdir") + File.separator + fileName);
        FileOutputStream fileOut = null;
        try {
            fileOut = new FileOutputStream(file);
            IOUtils.copy(inputStream, fileOut);
        } catch (FileNotFoundException e) {
            LOGGER.error("saveFile() - File Not Found." + e);
        } catch (IOException e) {
            LOGGER.error("saveFile() - Error while saving file." + e);
        } finally {
            try {
                inputStream.close();
                if (fileOut != null) {
                    fileOut.close();
                }
            } catch (IOException e) {
                LOGGER.error(e);
            }
        }
    }
public static void download(String address, String localFileName) {
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        try {
            URL url = new URL(address);
            out = new BufferedOutputStream(new FileOutputStream(localFileName));
            conn = url.openConnection();
            in = conn.getInputStream();
            byte[] buffer = new byte[1024];
            int numRead;
            long numWritten = 0;
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
                numWritten += numRead;
            }
            System.out.println(localFileName + "\t" + numWritten);
        } catch (Exception exception) {
            exception.printStackTrace();
        } finally {
            try {
                if (in != null) in.close();
                if (out != null) out.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }
public static void copyFileByNIO(File in, File out) throws IOException {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
@Override
    public void execute(IAlert alert, IReport report, Rule rule, Row row) {
        try {
            URL url = new URL(getUrl());
            URLConnection con = url.openConnection();
            con.setConnectTimeout(getTimeout());
            con.setDoOutput(true);
            OutputStream out = con.getOutputStream();
            out.write(formatOutput(report, alert, rule, row).getBytes());
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            StringBuilder input = new StringBuilder();
            String line = null;
            while ((line = in.readLine()) != null) {
                input.append(line);
                input.append('\n');
            }
            in.close();
            this.lastResult = input.toString();
        } catch (Throwable e) {
            logError("Error sending alert", e);
            if (!isHeadless()) {
                alert.setEnabled(false);
                JOptionPane.showMessageDialog(null, "Can't send alert " + e + "\n" + alert.getName() + " alert disabled.", "Action Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
private static String lastModified(URL url) {
        try {
            URLConnection conn = url.openConnection();
            return long2date(conn.getLastModified());
        } catch (Exception e) {
            SWGAide.printDebug("cach", 1, "SWGCraftCache:lastModified: " + e.getMessage());
        }
        return "0";
    }
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("H:\\FileServeUploader.java");
        HttpPost httppost = new HttpPost(postURL);
        httppost.setHeader("Cookie", langcookie + ";" + sessioncookie + ";" + mailcookie + ";" + namecookie + ";" + rolecookie + ";" + orderbycookie + ";" + directioncookie + ";");
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("files[]", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into wupload...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
    }
public static void loginWuploader() throws IOException {
        HttpParams params = new BasicHttpParams();
        params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);
        System.out.println("Trying to log in to Wupload");
        HttpPost httppost = new HttpPost("http://www.wupload.in/account/login");
        httppost.setHeader("Referer", "http://www.wupload.in/");
        httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("email", uname));
        formparams.add(new BasicNameValuePair("password", pwd));
        formparams.add(new BasicNameValuePair("redirect", "/"));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);
        System.out.println("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("PHPSESSID")) {
                sessioncookie = "PHPSESSID=" + escookie.getValue();
                System.out.println(sessioncookie);
            }
            if (escookie.getName().equalsIgnoreCase("email")) {
                mailcookie = "email=" + escookie.getValue();
                login = true;
                System.out.println(mailcookie);
            }
            if (escookie.getName().equalsIgnoreCase("nickname")) {
                namecookie = "nickname=" + escookie.getValue();
                System.out.println(namecookie);
            }
            if (escookie.getName().equalsIgnoreCase("isAffiliate")) {
                affiliatecookie = "isAffiliate=" + escookie.getValue();
                System.out.println(affiliatecookie);
            }
            if (escookie.getName().equalsIgnoreCase("role")) {
                rolecookie = "role=" + escookie.getValue();
                System.out.println(rolecookie);
            }
        }
        if (login) {
            System.out.println("Login Success");
            getFolderCookies();
        } else {
            System.out.println("Login failed");
        }
    }
public void reademi(Vector<String> descriptions, Vector<String> links, String linkaddress, String idmap) {
        InputStream is = null;
        URL url;
        ArrayList<String> keys = new ArrayList<String>();
        ArrayList<String> names = new ArrayList<String>();
        try {
            url = new URL(idmap);
            is = url.openStream();
            Scanner scanner = new Scanner(is);
            scanner.nextLine();
            String line = "";
            String id = "";
            while (scanner.hasNextLine()) {
                line = scanner.nextLine();
                Scanner linescanner = new Scanner(line);
                linescanner.useDelimiter("\t");
                id = linescanner.next();
                id = id.substring(0, id.length() - 2);
                keys.add(id);
                linescanner.next();
                linescanner.next();
                linescanner.next();
                linescanner.useDelimiter("\n");
                names.add(linescanner.next());
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(linkaddress).openStream()));
            String link = "";
            String key = "";
            String name = "";
            int counter = 0;
            while ((line = reader.readLine()) != null) {
                if (line.indexOf("style=raw") != -1) {
                    int linkstart = line.indexOf("http://www.ebi.ac.uk/cgi-bin/dbfetch?db");
                    int idstart = line.indexOf("id=") + 3;
                    int linkend = line.substring(linkstart).indexOf("\"") + linkstart;
                    link = line.substring(linkstart, linkend);
                    key = line.substring(idstart, linkend);
                    if (keys.indexOf(key) != -1) {
                        name = names.get(keys.indexOf(key));
                        counter++;
                        descriptions.add(counter + " " + key + " " + name);
                        links.add(link);
                    }
                }
            }
        } catch (MalformedURLException e) {
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public void readUNI(Vector<String> descriptions, String source) {
        InputStream is = null;
        try {
            URL url = new URL(source);
            is = url.openStream();
            Scanner scanner = new Scanner(is);
            scanner.nextLine();
            String line = "";
            String id = "";
            String desc = "";
            while (scanner.hasNextLine()) {
                line = scanner.nextLine();
                Scanner linescanner = new Scanner(line);
                linescanner.useDelimiter("\t");
                id = linescanner.next();
                linescanner.next();
                desc = linescanner.next();
                linescanner.useDelimiter("\n");
                linescanner.next();
                descriptions.add(id + " " + desc);
            }
        } catch (MalformedURLException e) {
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (is != null) try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
public void process(Group group, List resourcesName, List excludeResources, ServletContext servletContext, Writer out, String location) throws IOException {
        LOG.debug("Merging content of group : " + group.getName());
        for (Iterator iterator = group.getSubgroups().iterator(); iterator.hasNext(); ) {
            Group subGroup = (Group) iterator.next();
            String subLocation = subGroup.getBestLocation(location);
            ResourcesProcessor subGroupProcessor = null;
            if (subGroup.isMinimize() == null) subGroupProcessor = this; else subGroupProcessor = subGroup.getJSProcessor();
            subGroupProcessor.process(subGroup, subGroup.getJsNames(), excludeResources, servletContext, out, subLocation);
        }
        for (Iterator it = resourcesName.iterator(); it.hasNext(); ) {
            URL url = null;
            String path = (String) it.next();
            if (!excludeResources.contains(path)) {
                url = URLUtils.getLocalURL(path, servletContext);
                if (url == null) {
                    String webPath = URLUtils.concatUrlWithSlaches(group.getBestLocation(location), path);
                    url = URLUtils.getWebUrlResource(webPath);
                }
                if (url == null) {
                    throw new IOException("The resources '" + path + "' could not be found neither in the webapp folder nor in a jar");
                }
                InputStream in = null;
                try {
                    in = url.openStream();
                    IOUtils.copy(in, out, URLUtils.DEFAULT_ENCODING);
                    out.write("\n\n");
                } catch (Exception e) {
                    LOG.error("Merge failed for file " + path, e);
                } finally {
                    if (in != null) in.close();
                }
                excludeResources.add(path);
            }
        }
    }
public Set<String> getAvailableRoles() {
        if (availableRoles == null) {
            availableRoles = new HashSet<String>();
            try {
                Enumeration<URL> resources = org.springframework.util.ClassUtils.getDefaultClassLoader().getResources(ROLE_FILE_LOCATION);
                while (resources.hasMoreElements()) {
                    URL url = resources.nextElement();
                    InputStream is = null;
                    try {
                        URLConnection con = url.openConnection();
                        con.setUseCaches(false);
                        is = con.getInputStream();
                        List<String> lines = IOUtils.readLines(is, "ISO-8859-1");
                        if (lines != null) {
                            for (String line : lines) {
                                availableRoles.add(line.trim());
                            }
                        }
                    } finally {
                        if (is != null) {
                            is.close();
                        }
                    }
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return availableRoles;
    }
public static void copyFile(File in, File out) throws ObclipseException {
        try {
            FileChannel inChannel = null;
            FileChannel outChannel = null;
            try {
                inChannel = new FileInputStream(in).getChannel();
                outChannel = new FileOutputStream(out).getChannel();
                inChannel.transferTo(0, inChannel.size(), outChannel);
            } finally {
                if (inChannel != null) {
                    inChannel.close();
                }
                if (outChannel != null) {
                    outChannel.close();
                }
            }
        } catch (FileNotFoundException e) {
            Msg.error("The file ''{0}'' to copy does not exist!", e, in.getAbsolutePath());
        } catch (IOException e) {
            Msg.ioException(in, out, e);
        }
    }
public static String convertToSha1(final String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
public static String getHashedPasswordTc(String password) throws java.security.NoSuchAlgorithmException {
        java.security.MessageDigest d = java.security.MessageDigest.getInstance("MD5");
        d.reset();
        d.update(password.getBytes());
        byte[] buf = d.digest();
        char[] cbf = new char[buf.length * 2];
        for (int jj = 0, kk = 0; jj < buf.length; jj++) {
            cbf[kk++] = "0123456789abcdef".charAt((buf[jj] >> 4) & 0x0F);
            cbf[kk++] = "0123456789abcdef".charAt(buf[jj] & 0x0F);
        }
        return new String(cbf);
    }