semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void parse() {
        InputSource urlInputStream = null;
        SAXParserFactory spf = null;
        SAXParser sp = null;
        HttpURLConnection conn = null;
        try {
            URL url = new URL(this.urlString);
            _setProxy();
            conn = (HttpURLConnection) url.openConnection();
            urlInputStream = new InputSource(StreamUtils.inputStreamToReader(conn.getInputStream()));
            spf = SAXParserFactory.newInstance();
            if (spf != null) {
                sp = spf.newSAXParser();
                sp.parse(urlInputStream, this);
            }
        } catch (Exception e) {
            if (conn != null) {
                if (conn.getHeaderField("X-RateLimit-Limit") != null) {
                    String rateLimit = conn.getHeaderField("X-RateLimit-Limit");
                    String rateRemaining = conn.getHeaderField("X-RateLimit-Remaining");
                    long rateReset = Long.valueOf(conn.getHeaderField("X-RateLimit-Reset")) * 1000;
                    LOG.warn("Possible rate limits?  LIMIT:" + rateLimit + "  REMAINING:" + rateRemaining + "  RESET:" + new Date(rateReset));
                }
            }
            e.printStackTrace();
            LOG.warn("error parsing rss feed", e);
        } finally {
        }
    }
public static Document getXHTMLDocument(URL _url) throws IOException {
        final Tidy tidy = new Tidy();
        tidy.setQuiet(true);
        tidy.setShowWarnings(false);
        tidy.setXmlOut(true);
        final BufferedInputStream input_stream = new BufferedInputStream(_url.openStream());
        return tidy.parseDOM(input_stream, null);
    }
public void handleRequestInternal(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) throws ServletException, IOException {
        final String servetPath = httpServletRequest.getServletPath();
        final String previousToken = httpServletRequest.getHeader(IF_NONE_MATCH);
        final String currentToken = getETagValue(httpServletRequest);
        httpServletResponse.setHeader(ETAG, currentToken);
        final Date modifiedDate = new Date(httpServletRequest.getDateHeader(IF_MODIFIED_SINCE));
        final Calendar calendar = Calendar.getInstance();
        final Date now = calendar.getTime();
        calendar.setTime(modifiedDate);
        calendar.add(Calendar.MINUTE, getEtagExpiration());
        if (currentToken.equals(previousToken) && (now.getTime() < calendar.getTime().getTime())) {
            httpServletResponse.sendError(HttpServletResponse.SC_NOT_MODIFIED);
            httpServletResponse.setHeader(LAST_MODIFIED, httpServletRequest.getHeader(IF_MODIFIED_SINCE));
            if (LOG.isDebugEnabled()) {
                LOG.debug("ETag the same, will return 304");
            }
        } else {
            httpServletResponse.setDateHeader(LAST_MODIFIED, (new Date()).getTime());
            final String width = httpServletRequest.getParameter(Constants.WIDTH);
            final String height = httpServletRequest.getParameter(Constants.HEIGHT);
            final ImageNameStrategy imageNameStrategy = imageService.getImageNameStrategy(servetPath);
            String code = imageNameStrategy.getCode(servetPath);
            String fileName = imageNameStrategy.getFileName(servetPath);
            final String imageRealPathPrefix = getRealPathPrefix(httpServletRequest.getServerName().toLowerCase());
            String original = imageRealPathPrefix + imageNameStrategy.getFullFileNamePath(fileName, code);
            final File origFile = new File(original);
            if (!origFile.exists()) {
                code = Constants.NO_IMAGE;
                fileName = imageNameStrategy.getFileName(code);
                original = imageRealPathPrefix + imageNameStrategy.getFullFileNamePath(fileName, code);
            }
            String resizedImageFileName = null;
            if (width != null && height != null && imageService.isSizeAllowed(width, height)) {
                resizedImageFileName = imageRealPathPrefix + imageNameStrategy.getFullFileNamePath(fileName, code, width, height);
            }
            final File imageFile = getImageFile(original, resizedImageFileName, width, height);
            final FileInputStream fileInputStream = new FileInputStream(imageFile);
            IOUtils.copy(fileInputStream, httpServletResponse.getOutputStream());
            fileInputStream.close();
        }
    }
public void copyFile(String oldPath, String newPath) {
        try {
            int bytesum = 0;
            int byteread = 0;
            File oldfile = new File(oldPath);
            if (oldfile.exists()) {
                InputStream inStream = new FileInputStream(oldPath);
                FileOutputStream fs = new FileOutputStream(newPath);
                byte[] buffer = new byte[1444];
                while ((byteread = inStream.read(buffer)) != -1) {
                    bytesum += byteread;
                    System.out.println(bytesum);
                    fs.write(buffer, 0, byteread);
                }
                inStream.close();
            }
        } catch (Exception e) {
            System.out.println("复制单个文件操作出错");
            e.printStackTrace();
        }
    }
private void copyFile(File sourcefile, File targetfile) {
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {
            in = new BufferedInputStream(new FileInputStream(sourcefile));
            out = new BufferedOutputStream(new FileOutputStream(targetfile));
            byte[] buffer = new byte[4096];
            int bytesread = 0;
            while ((bytesread = in.read(buffer)) >= 0) {
                out.write(buffer, 0, bytesread);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
private void bubbleSort(int values[]) {
        PerfMonTimer timerOuter = PerfMonTimer.start("SortingTest.bubbleSort");
        try {
            int len = values.length - 1;
            for (int i = 0; i < len; i++) {
                for (int j = 0; j < len - i; j++) {
                    if (values[j] > values[j + 1]) {
                        int tmp = values[j];
                        values[j] = values[j + 1];
                        values[j + 1] = tmp;
                    }
                }
            }
        } finally {
            PerfMonTimer.stop(timerOuter);
        }
    }
public static SearchItem register(String... args) {
        SearchItem _return = new SearchItem();
        String line = null;
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(URL_REGISTER);
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
            nameValuePairs.add(new BasicNameValuePair("format", "xml"));
            nameValuePairs.add(new BasicNameValuePair("firtname", args[0]));
            nameValuePairs.add(new BasicNameValuePair("lastname", args[1]));
            nameValuePairs.add(new BasicNameValuePair("email", args[2]));
            nameValuePairs.add(new BasicNameValuePair("phone", args[3]));
            nameValuePairs.add(new BasicNameValuePair("password", args[4]));
            nameValuePairs.add(new BasicNameValuePair("confirmpassword", args[5]));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpClient.execute(httpPost);
            line = EntityUtils.toString(response.getEntity());
            Document document = XMLfunctions.XMLfromString(line);
            NodeList nodes = document.getElementsByTagName("response");
            Element e = (Element) nodes.item(0);
            _return.set(0, XMLfunctions.getValue(e, "success"));
            if ("false".endsWith(_return.get(0))) {
                _return.set(1, XMLfunctions.getValue(e, "error"));
            } else {
                _return.set(1, XMLfunctions.getValue(e, "message"));
            }
            return _return;
        } catch (Exception e) {
            line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
            line = null;
            _return.set(0, "false");
            _return.set(1, "");
        }
        return _return;
    }
public static SearchItem loadRecord(String id, boolean isContact) {
        String line = null;
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(isContact ? URL_RECORD_CONTACT : URL_RECORD_COMPANY);
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
            nameValuePairs.add(new BasicNameValuePair("format", "xml"));
            nameValuePairs.add(new BasicNameValuePair("token", Common.token));
            nameValuePairs.add(new BasicNameValuePair("id", id));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpClient.execute(httpPost);
            line = EntityUtils.toString(response.getEntity());
            Document document = XMLfunctions.XMLfromString(line);
            NodeList nodes = document.getElementsByTagName("response");
            Element e = (Element) nodes.item(0);
            String Name__Last__First_ = XMLfunctions.getValue(e, isContact ? "Name__Last__First_" : "Name");
            String phone = "";
            if (!isContact) phone = XMLfunctions.getValue(e, "Phone");
            String Email1 = XMLfunctions.getValue(e, isContact ? "Personal_Email" : "Email");
            String Home_Fax = XMLfunctions.getValue(e, isContact ? "Home_Fax" : "Fax1");
            String Address1 = XMLfunctions.getValue(e, "Address1");
            String Address2 = XMLfunctions.getValue(e, "Address2");
            String City = XMLfunctions.getValue(e, "City");
            String State = XMLfunctions.getValue(e, "State");
            String Zip = XMLfunctions.getValue(e, "Zip");
            String Country = XMLfunctions.getValue(e, "Country");
            String Profile = XMLfunctions.getValue(e, "Profile");
            String success = XMLfunctions.getValue(e, "success");
            String error = XMLfunctions.getValue(e, "error");
            SearchItem item = new SearchItem();
            item.set(1, Name__Last__First_);
            item.set(2, phone);
            item.set(3, phone);
            item.set(4, Email1);
            item.set(5, Home_Fax);
            item.set(6, Address1);
            item.set(7, Address2);
            item.set(8, City);
            item.set(9, State);
            item.set(10, Zip);
            item.set(11, Profile);
            item.set(12, Country);
            item.set(13, success);
            item.set(14, error);
            return item;
        } catch (Exception e) {
            line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
            line = null;
        }
        return null;
    }
public static RecordResponse loadRecord(RecordRequest recordRequest) {
        RecordResponse recordResponse = new RecordResponse();
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(recordRequest.isContact() ? URL_RECORD_CONTACT : URL_RECORD_COMPANY);
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
            nameValuePairs.add(new BasicNameValuePair("format", "xml"));
            nameValuePairs.add(new BasicNameValuePair("token", recordRequest.getToken()));
            nameValuePairs.add(new BasicNameValuePair("id", recordRequest.getId()));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpClient.execute(httpPost);
            String line = EntityUtils.toString(response.getEntity());
            Document document = XMLfunctions.XMLfromString(line);
            NodeList nodes = document.getElementsByTagName("response");
            Element e = (Element) nodes.item(0);
            String Name__Last__First_ = XMLfunctions.getValue(e, recordRequest.isContact() ? "Name__Last__First_" : "Name");
            String phone = "";
            if (!recordRequest.isContact()) phone = XMLfunctions.getValue(e, "Phone");
            String Email1 = XMLfunctions.getValue(e, recordRequest.isContact() ? "Personal_Email" : "Email");
            String Home_Fax = XMLfunctions.getValue(e, recordRequest.isContact() ? "Home_Fax" : "Fax1");
            String Address1 = XMLfunctions.getValue(e, "Address1");
            String Address2 = XMLfunctions.getValue(e, "Address2");
            String City = XMLfunctions.getValue(e, "City");
            String State = XMLfunctions.getValue(e, "State");
            String Zip = XMLfunctions.getValue(e, "Zip");
            String Country = XMLfunctions.getValue(e, "Country");
            String Profile = XMLfunctions.getValue(e, "Profile");
            String success = XMLfunctions.getValue(e, "success");
            String error = XMLfunctions.getValue(e, "error");
            recordResponse.setName(Name__Last__First_);
            recordResponse.setPhone(phone);
            recordResponse.setEmail(Email1);
            recordResponse.setHomeFax(Home_Fax);
            recordResponse.setAddress1(Address1);
            recordResponse.setAddress2(Address2);
            recordResponse.setCity(City);
            recordResponse.setState(State);
            recordResponse.setZip(Zip);
            recordResponse.setProfile(Profile);
            recordResponse.setCountry(Country);
            recordResponse.setSuccess(success);
            recordResponse.setError(error);
        } catch (Exception e) {
        }
        return recordResponse;
    }
public static void main(String[] args) throws IOException {
        System.out.println("Start filtering zgps...");
        final Config config = ConfigUtils.loadConfig(args[0]);
        final String CONFIG_MODULE = "GPSFilterZGPS";
        File sourceFileSelectedStages = new File(config.findParam(CONFIG_MODULE, "sourceFileSelectedStages"));
        File sourceFileZGPS = new File(config.findParam(CONFIG_MODULE, "sourceFileZGPS"));
        File targetFile = new File(config.findParam(CONFIG_MODULE, "targetFile"));
        System.out.println("Start reading selected stages...");
        FilterZGPSSelectedStages selectedStages = new FilterZGPSSelectedStages();
        selectedStages.createSelectedStages(sourceFileSelectedStages);
        System.out.println("Done. " + selectedStages.getSelectedStages().size() + " stages were stored");
        System.out.println("Start reading and writing zgps...");
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(sourceFileZGPS)));
            BufferedWriter out = new BufferedWriter(new FileWriter(targetFile));
            out.write(in.readLine());
            out.newLine();
            String lineFromInputFile;
            while ((lineFromInputFile = in.readLine()) != null) {
                String[] entries = lineFromInputFile.split("\t");
                if (selectedStages.containsStage(Integer.parseInt(entries[0]), Integer.parseInt(entries[1]), Integer.parseInt(entries[2]))) {
                    out.write(lineFromInputFile);
                    out.newLine();
                    out.flush();
                }
            }
            in.close();
            out.close();
        } catch (FileNotFoundException e) {
            System.out.println("Could not find source file for selected stages.");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("IO Exception while reading or writing zgps.");
            e.printStackTrace();
        }
        System.out.println("Done.");
    }
public static void copy(String from_name, String to_name) throws IOException {
        File from_file = new File(from_name);
        File to_file = new File(to_name);
        if (!from_file.exists()) abort("FileCopy: no such source file: " + from_name);
        if (!from_file.isFile()) abort("FileCopy: can't copy directory: " + from_name);
        if (!from_file.canRead()) abort("FileCopy: source file is unreadable: " + from_name);
        if (to_file.isDirectory()) to_file = new File(to_file, from_file.getName());
        String parent = to_file.getParent();
        if (parent == null) parent = System.getProperty("user.dir");
        File dir = new File(parent);
        if (!dir.exists()) abort("FileCopy: destination directory doesn't exist: " + parent);
        if (dir.isFile()) abort("FileCopy: destination is not a directory: " + parent);
        if (!dir.canWrite()) abort("FileCopy: destination directory is unwriteable: " + parent);
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(from_file);
            to = new FileOutputStream(to_file);
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) to.write(buffer, 0, bytes_read);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
public static String encriptarPassword(String aPassword) throws BusinessException {
        ILogger logger = LogFactory.getLogger(User.class);
        String methodId = "encriptarPassword";
        try {
            MessageDigest currentAlgorithm = MessageDigest.getInstance("MD5");
            currentAlgorithm.reset();
            currentAlgorithm.update(aPassword.getBytes());
            byte[] hash = currentAlgorithm.digest();
            String d = "";
            for (int i = 0; i < hash.length; i++) {
                int v = hash[i] & 0xFF;
                if (v < 16) d += "0";
                d += Integer.toString(v, 16).toUpperCase();
            }
            return d.toLowerCase();
        } catch (NoSuchAlgorithmException nsae) {
            logger.logError(methodId + "error al encriptar password:" + nsae, nsae);
            throw new BusinessException("Error al encriptar password");
        }
    }
public static ISimpleChemObjectReader createReader(URL url, String urlString, String type) throws CDKException {
        if (type == null) {
            type = "mol";
        }
        ISimpleChemObjectReader cor = null;
        try {
            Reader input = new BufferedReader(getReader(url));
            FormatFactory formatFactory = new FormatFactory(8192);
            IChemFormat format = formatFactory.guessFormat(input);
            if (format != null) {
                if (format instanceof RGroupQueryFormat) {
                    cor = new RGroupQueryReader();
                    cor.setReader(input);
                } else if (format instanceof CMLFormat) {
                    cor = new CMLReader(urlString);
                    cor.setReader(url.openStream());
                } else if (format instanceof MDLV2000Format) {
                    cor = new MDLV2000Reader(getReader(url));
                    cor.setReader(input);
                }
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        if (cor == null) {
            if (type.equals(JCPFileFilter.cml) || type.equals(JCPFileFilter.xml)) {
                cor = new CMLReader(urlString);
            } else if (type.equals(JCPFileFilter.sdf)) {
                cor = new MDLV2000Reader(getReader(url));
            } else if (type.equals(JCPFileFilter.mol)) {
                cor = new MDLV2000Reader(getReader(url));
            } else if (type.equals(JCPFileFilter.inchi)) {
                try {
                    cor = new INChIReader(new URL(urlString).openStream());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (type.equals(JCPFileFilter.rxn)) {
                cor = new MDLRXNV2000Reader(getReader(url));
            } else if (type.equals(JCPFileFilter.smi)) {
                cor = new SMILESReader(getReader(url));
            }
        }
        if (cor == null) {
            throw new CDKException(GT._("Could not determine file format"));
        }
        if (cor instanceof MDLV2000Reader) {
            try {
                BufferedReader in = new BufferedReader(getReader(url));
                String line;
                while ((line = in.readLine()) != null) {
                    if (line.equals("$$$$")) {
                        String message = GT._("It seems you opened a mol or sdf" + " file containing several molecules. " + "Only the first one will be shown");
                        JOptionPane.showMessageDialog(null, message, GT._("sdf-like file"), JOptionPane.INFORMATION_MESSAGE);
                        break;
                    }
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return cor;
    }
private Comic[] getAllComics() {
        try {
            URL comicURL = new URL(comicSite + "list");
            InputStream is = comicURL.openStream();
            BufferedReader buffread = new BufferedReader(new InputStreamReader(is));
            Vector tmplist = new Vector();
            while (buffread.ready()) {
                String comic = buffread.readLine();
                tmplist.add(comic);
            }
            Comic[] list = new Comic[tmplist.size()];
            activated = new boolean[tmplist.size()];
            titles = new String[tmplist.size()];
            for (int i = 0; i < tmplist.size(); i++) {
                try {
                    URL curl = new URL(comicSite + (String) tmplist.get(i));
                    BufferedInputStream bis = new BufferedInputStream(curl.openStream());
                    Properties cprop = new Properties();
                    cprop.load(bis);
                    Comic c = new Comic(cprop, false);
                    list[i] = c;
                    titles[i] = c.getName();
                    activated[i] = comicsmanager.isLoaded(c.getName());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            for (int i = 0; i < list.length; i++) {
                System.out.println(list[i]);
            }
            return list;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
private static InputStream connect(final String url) throws IOException {
        InputStream in = null;
        try {
            final URLConnection conn = new URL(url).openConnection();
            conn.setConnectTimeout(YahooGeocoding.connectTimeOut);
            conn.setReadTimeout(YahooGeocoding.readTimeOut);
            conn.setRequestProperty("User-Agent", YahooGeocoding.USER_AGENT);
            in = conn.getInputStream();
            return in;
        } catch (final IOException e) {
            Util.d("problems connecting to geonames url " + url + "Exception:" + e);
        }
        return in;
    }
public static String getSHA1Digest(String inputStr) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = null;
        byte[] sha1hash = null;
        md = MessageDigest.getInstance("SHA");
        sha1hash = new byte[40];
        md.update(inputStr.getBytes("iso-8859-1"), 0, inputStr.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }