semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static Set<Street> getVias(String pURL) {
        Set<Street> result = new HashSet<Street>();
        String iniCuerr = "<cuerr>";
        String finCuerr = "</cuerr>";
        String iniDesErr = "<des>";
        String finDesErr = "</des>";
        String iniVia = "<calle>";
        String finVia = "</calle>";
        String iniCodVia = "<cv>";
        String finCodVia = "</cv>";
        String iniTipoVia = "<tv>";
        String finTipoVia = "</tv>";
        String iniNomVia = "<nv>";
        String finNomVia = "</nv>";
        boolean error = false;
        int ini, fin;
        try {
            URL url = new URL(pURL);
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            Street via;
            while ((str = br.readLine()) != null) {
                if (str.contains(iniCuerr)) {
                    ini = str.indexOf(iniCuerr) + iniCuerr.length();
                    fin = str.indexOf(finCuerr);
                    if (Integer.parseInt(str.substring(ini, fin)) > 0) error = true;
                }
                if (error) {
                    if (str.contains(iniDesErr)) {
                        ini = str.indexOf(iniDesErr) + iniDesErr.length();
                        fin = str.indexOf(finDesErr);
                        throw (new Exception(str.substring(ini, fin)));
                    }
                } else {
                    if (str.contains(iniVia)) {
                        via = new Street();
                        while ((str = br.readLine()) != null && !str.contains(finVia)) {
                            if (str.contains(iniCodVia)) {
                                ini = str.indexOf(iniCodVia) + iniCodVia.length();
                                fin = str.indexOf(finCodVia);
                                via.setCodeStreet(Integer.parseInt(str.substring(ini, fin)));
                            }
                            if (str.contains(iniTipoVia)) {
                                TypeStreet tipo = new TypeStreet();
                                if (!str.contains(finTipoVia)) tipo.setCodetpStreet(""); else {
                                    ini = str.indexOf(iniTipoVia) + iniTipoVia.length();
                                    fin = str.indexOf(finTipoVia);
                                    tipo.setCodetpStreet(str.substring(ini, fin));
                                }
                                tipo.setDescription(getDescripcionTipoVia(tipo.getCodetpStreet()));
                                via.setTypeStreet(tipo);
                            }
                            if (str.contains(iniNomVia)) {
                                ini = str.indexOf(iniNomVia) + iniNomVia.length();
                                fin = str.indexOf(finNomVia);
                                via.setStreetName(str.substring(ini, fin).trim());
                            }
                        }
                        result.add(via);
                    }
                }
            }
            br.close();
        } catch (Exception e) {
            System.err.println(e);
        }
        return result;
    }
public static String hash(String str) {
        if (str == null || str.length() == 0) {
            throw new CaptureSecurityException("String to encript cannot be null or zero length");
        }
        StringBuilder hexString = new StringBuilder();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            byte[] hash = md.digest();
            for (byte element : hash) {
                if ((0xff & element) < 0x10) {
                    hexString.append('0').append(Integer.toHexString((0xFF & element)));
                } else {
                    hexString.append(Integer.toHexString(0xFF & element));
                }
            }
        } catch (NoSuchAlgorithmException e) {
            throw new CaptureSecurityException(e);
        }
        return hexString.toString();
    }
public final void navigate(final URL url) {
        try {
            EncogLogging.log(EncogLogging.LEVEL_INFO, "Navigating to page:" + url);
            final URLConnection connection = url.openConnection();
            final InputStream is = connection.getInputStream();
            navigate(url, is);
            is.close();
        } catch (final IOException e) {
            EncogLogging.log(EncogLogging.LEVEL_ERROR, e);
            throw new BrowseError(e);
        }
    }
public static String calculatesMD5(String plainText) throws NoSuchAlgorithmException {
        MessageDigest mdAlgorithm = MessageDigest.getInstance("MD5");
        mdAlgorithm.update(plainText.getBytes());
        byte[] digest = mdAlgorithm.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < digest.length; i++) {
            plainText = Integer.toHexString(0xFF & digest[i]);
            if (plainText.length() < 2) {
                plainText = "0" + plainText;
            }
            hexString.append(plainText);
        }
        return hexString.toString();
    }
public String[] getLine(String prefecture) {
        HttpClient httpclient = null;
        String[] lines = null;
        try {
            httpclient = new DefaultHttpClient();
            List<NameValuePair> qparams = new ArrayList<NameValuePair>();
            qparams.add(new BasicNameValuePair("method", "getLines"));
            qparams.add(new BasicNameValuePair("prefecture", prefecture));
            URI uri = URIUtils.createURI("http", "express.heartrails.com", -1, "/api/xml", URLEncodedUtils.format(qparams, "UTF-8"), null);
            HttpGet httpget = new HttpGet(uri);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            InputStream instream = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8"));
            StringBuffer buf = new StringBuffer();
            String str;
            while ((str = reader.readLine()) != null) {
                buf.append(str);
                buf.append("\n");
            }
            reader.close();
            LineResponse res = new LineResponse(buf.toString());
            lines = res.getLineAsString();
        } catch (URISyntaxException ex) {
            ex.printStackTrace();
        } catch (ClientProtocolException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (SAXException ex) {
            ex.printStackTrace();
        } catch (ParserConfigurationException ex) {
            ex.printStackTrace();
        } finally {
            httpclient.getConnectionManager().shutdown();
        }
        return lines;
    }
public void getStation(String prefecture, String line) {
        HttpClient httpclient = null;
        try {
            httpclient = new DefaultHttpClient();
            List<NameValuePair> qparams = new ArrayList<NameValuePair>();
            qparams.add(new BasicNameValuePair("method", "getStations"));
            qparams.add(new BasicNameValuePair("prefecture", prefecture));
            qparams.add(new BasicNameValuePair("line", line));
            URI uri = URIUtils.createURI("http", "express.heartrails.com", -1, "/api/xml", URLEncodedUtils.format(qparams, "UTF-8"), null);
            HttpGet httpget = new HttpGet(uri);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            InputStream instream = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8"));
            StringBuffer buf = new StringBuffer();
            String str;
            while ((str = reader.readLine()) != null) {
                buf.append(str);
                buf.append("\n");
            }
            reader.close();
            stationRes = new StationResponse(buf.toString());
        } catch (URISyntaxException ex) {
            ex.printStackTrace();
        } catch (ClientProtocolException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (SAXException ex) {
            ex.printStackTrace();
        } catch (ParserConfigurationException ex) {
            ex.printStackTrace();
        } finally {
            mSearchStation.setEnabled(true);
        }
    }
public AsciiParser(String systemID) throws GridBagException {
        String id = systemID;
        if (id.endsWith(".xml")) {
            id = StringUtils.replace(id, ".xml", ".gbc");
        }
        ClassLoader loader = this.getClass().getClassLoader();
        URL url = loader.getResource(id);
        if (url == null) {
            throw new GridBagException("Cannot located resource : \"" + systemID + "\".");
        }
        try {
            InputStream inStream = url.openStream();
            constraints = getLines(inStream);
            inStream.close();
        } catch (IOException ie1) {
            throw new GridBagException("Cannot read from resource " + id);
        }
    }
void sort(int a[]) throws Exception {
        for (int i = a.length; --i >= 0; ) {
            boolean flipped = false;
            for (int j = 0; j < i; j++) {
                if (stopRequested) {
                    return;
                }
                if (a[j] > a[j + 1]) {
                    int T = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = T;
                    flipped = true;
                }
                pause(i, j);
            }
            if (!flipped) {
                return;
            }
        }
    }
private void invokeTest(String queryfile, String target) {
        try {
            String query = IOUtils.toString(XPathMarkBenchmarkTest.class.getResourceAsStream(queryfile)).trim();
            String args = EXEC_CMD + " \"" + query + "\" \"" + target + '"';
            System.out.println("Invoke command: \n " + args);
            Process proc = Runtime.getRuntime().exec(args, null, benchmarkDir);
            InputStream is = proc.getInputStream();
            File outFile = new File(outDir, queryfile + ".result");
            IOUtils.copy(is, new FileOutputStream(outFile));
            is.close();
            int ret = proc.waitFor();
            if (ret != 0) {
                System.out.println("process exited with value : " + ret);
            }
        } catch (IOException ioe) {
            throw new IllegalStateException(ioe);
        } catch (InterruptedException irre) {
            throw new IllegalStateException(irre);
        }
    }
@Override
    public Object init() throws Exception {
        if (url != null) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            ClassLoader parent = getClass().getClassLoader();
            GroovyClassLoader loader = new GroovyClassLoader(parent);
            Class groovyClass = loader.parseClass(new File(url.getFile()));
            groovyObject = (GroovyObject) groovyClass.newInstance();
            reader.close();
            initDeclaredMethods();
            return groovyObject;
        } else return null;
    }
@Override
    public void render(Output output) throws IOException {
        output.setStatus(statusCode, statusMessage);
        if (headersMap != null) {
            Iterator<Entry<String, String>> iterator = headersMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, String> header = iterator.next();
                output.addHeader(header.getKey(), header.getValue());
            }
        }
        if (file != null) {
            InputStream inputStream = new FileInputStream(file);
            try {
                output.open();
                OutputStream out = output.getOutputStream();
                IOUtils.copy(inputStream, out);
            } finally {
                inputStream.close();
                output.close();
            }
        }
    }
public static void init(Locale lng) {
        try {
            Locale toLoad = lng != null ? lng : DEFAULT_LOCALE;
            URL url = ClassLoader.getSystemResource("locales/" + toLoad.getISO3Language() + ".properties");
            if (url == null) {
                url = ClassLoader.getSystemResource("locales/" + DEFAULT_LOCALE.getISO3Language() + ".properties");
            }
            PROPS.clear();
            PROPS.load(url.openStream());
        } catch (IOException ioe) {
            try {
                URL url = ClassLoader.getSystemResource("locales/" + DEFAULT_LOCALE.getISO3Language() + ".properties");
                PROPS.clear();
                PROPS.load(url.openStream());
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(99);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(99);
        }
    }
private static List<CountryEntry> retrieveCountries() throws IOException {
        URL url = new URL("http://" + ISO_3166_HOST + ISO_3166_TXT_FILE_PATH);
        BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
        List<CountryEntry> countries = new LinkedList<CountryEntry>();
        boolean parsing = false;
        int trCount = 0;
        int tdCount = 0;
        CountryEntry current = new CountryEntry();
        String nextLine = input.readLine();
        while (nextLine != null) {
            if (nextLine.startsWith("<table")) {
                parsing = true;
            }
            if (nextLine.startsWith("</table>")) {
                break;
            }
            if (parsing) {
                if (nextLine.startsWith("<tr")) {
                    trCount++;
                } else {
                    if ((trCount > 1 && nextLine.startsWith("<td"))) {
                        tdCount++;
                        String data = pullData(nextLine);
                        switch(tdCount) {
                            case 1:
                                current.setName(getCountryName(data));
                                break;
                            case 2:
                                current.setNumber(data);
                                break;
                            case 3:
                                current.setAlpha3(data);
                                break;
                            case 4:
                                current.setAlpha2(data);
                                break;
                            case 5:
                                countries.add(current);
                                current = new CountryEntry();
                                tdCount = 0;
                                break;
                            default:
                                String msg = "Parsing error.  Unexpected column: [" + data + "]";
                                throw new IllegalStateException(msg);
                        }
                    }
                }
            }
            nextLine = input.readLine();
        }
        input.close();
        return countries;
    }
public void actionPerformed(ActionEvent evt) {
            try {
                File tempFile = new File("/tmp/controler.xml");
                File f = new File("/tmp/controler-temp.xml");
                BufferedInputStream copySource = new BufferedInputStream(new FileInputStream(tempFile));
                BufferedOutputStream copyDestination = new BufferedOutputStream(new FileOutputStream(f));
                int read = 0;
                while (read != -1) {
                    read = copySource.read(buffer, 0, BUFFER_SIZE);
                    if (read != -1) {
                        copyDestination.write(buffer, 0, read);
                    }
                }
                copyDestination.write(new String("</log>\n").getBytes());
                copySource.close();
                copyDestination.close();
                XMLParser parser = new XMLParser("Controler");
                parser.parse(f);
                f.delete();
            } catch (IOException ex) {
                System.out.println("An error occured during the file copy!");
            }
        }
public static void main(String[] args) throws Exception {
        File inputFile = new File(args[0]);
        BufferedReader reader = new BufferedReader(new FileReader(inputFile));
        StringBuffer stringBuffer = new StringBuffer();
        String readed;
        while ((readed = reader.readLine()) != null) stringBuffer.append(readed + "\r\n");
        readed = stringBuffer.toString();
        reader.close();
        File outputFile = new File(args[0] + ".output");
        BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
        readed = readed.replaceAll("\\t+", "#");
        readed = readed.replaceAll("\\s*#\\s*", "#");
        readed = readed.replaceAll("Latitude,.*", "");
        readed = readed.replaceAll("Flag of", "");
        readed = readed.replaceAll("^\\s+$", "");
        writer.write(readed);
        writer.close();
    }
private void getRandomGUID(boolean secure) {
        MessageDigest md5;
        StringBuilder sbValueBeforeHash = new StringBuilder();
        try {
            md5 = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            throw new ApplicationIllegalArgumentException(e);
        }
        long time = System.nanoTime();
        long rand = 0;
        if (secure) {
            rand = MySecureRand.nextLong();
        } else {
            rand = MyRand.nextLong();
        }
        sbValueBeforeHash.append(SId);
        sbValueBeforeHash.append(":");
        sbValueBeforeHash.append(Long.toString(time));
        sbValueBeforeHash.append(":");
        sbValueBeforeHash.append(Long.toString(rand));
        valueBeforeHash = sbValueBeforeHash.toString();
        md5.update(valueBeforeHash.getBytes());
        byte[] array = md5.digest();
        StringBuffer sb = new StringBuffer();
        for (int j = 0; j < array.length; ++j) {
            int b = array[j] & 0xFF;
            if (b < 0x10) {
                sb.append('0');
            }
            sb.append(Integer.toHexString(b));
        }
        valueAfterHash = sb.toString();
    }
private Vector _sort(Pair[] ps, String id, int num) {
        Vector ret = new Vector();
        boolean swapped = true;
        int j = 0;
        Pair tmp;
        while (swapped) {
            swapped = false;
            j++;
            for (int i = 0; i < ps.length - j; i++) {
                if (ps[i].c > ps[i + 1].c) {
                    tmp = ps[i];
                    ps[i] = ps[i + 1];
                    ps[i + 1] = tmp;
                    swapped = true;
                }
            }
        }
        int m = Math.min(num, ps.length);
        for (int i = m - 1; i >= 0; i--) {
            if (id == null) ret.addElement(ps[i].n); else if (ps[i].n.startsWith(id) && !ps[i].n.equals(id)) ret.addElement(ps[i].n);
        }
        return ret;
    }
private void readVersion() {
        URL url = ClassLoader.getSystemResource("version");
        if (url == null) {
            return;
        }
        BufferedReader reader = null;
        String line = null;
        try {
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((line = reader.readLine()) != null) {
                if (line.startsWith("Version=")) {
                    version = (line.split("="))[1];
                }
                if (line.startsWith("Revision=")) {
                    revision = (line.split("="))[1];
                }
                if (line.startsWith("Date=")) {
                    String sSec = (line.split("="))[1];
                    Long lSec = Long.valueOf(sSec);
                    compileDate = new Date(lSec);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return;
    }
public void testGetResource_FileOutsideOfClasspath() throws Exception {
        File temp = File.createTempFile("dozerfiletest", ".txt");
        temp.deleteOnExit();
        String resourceName = "file:" + temp.getAbsolutePath();
        URL url = loader.getResource(resourceName);
        assertNotNull("URL should not be null", url);
        InputStream is = url.openStream();
        assertNotNull("input stream should not be null", is);
    }
public static final synchronized String hash(String data) {
        if (digest == null) {
            try {
                digest = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException nsae) {
                log.error("Failed to load the MD5 MessageDigest. " + "Jive will be unable to function normally.", nsae);
            }
        }
        try {
            digest.update(data.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            log.error(e);
        }
        return encodeHex(digest.digest());
    }
@Override
                protected URLConnection openConnection(URL url) throws IOException {
                    return new URLConnection(url) {

                        @Override
                        public void connect() throws IOException {
                        }

                        @Override
                        public InputStream getInputStream() throws IOException {
                            ThemeResource f = getFacelet(getURL().getFile());
                            return new ByteArrayInputStream(f.getText().getBytes());
                        }
                    };
                }
public static void loadPoFile(URL url) {
        states state = states.IDLE;
        String msgCtxt = "";
        String msgId = "";
        String msgStr = "";
        try {
            if (url == null) return;
            InputStream in = url.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF8"));
            String strLine;
            while ((strLine = br.readLine()) != null) {
                if (strLine.startsWith("msgctxt")) {
                    if (state != states.MSGCTXT) msgCtxt = "";
                    state = states.MSGCTXT;
                    strLine = strLine.substring(7).trim();
                }
                if (strLine.startsWith("msgid")) {
                    if (state != states.MSGID) msgId = "";
                    state = states.MSGID;
                    strLine = strLine.substring(5).trim();
                }
                if (strLine.startsWith("msgstr")) {
                    if (state != states.MSGSTR) msgStr = "";
                    state = states.MSGSTR;
                    strLine = strLine.substring(6).trim();
                }
                if (!strLine.startsWith("\"")) {
                    state = states.IDLE;
                    msgCtxt = "";
                    msgId = "";
                    msgStr = "";
                } else {
                    if (state == states.MSGCTXT) {
                        msgCtxt += format(strLine);
                    }
                    if (state == states.MSGID) {
                        if (msgId.isEmpty()) {
                            if (!msgCtxt.isEmpty()) {
                                msgId = msgCtxt + "|";
                                msgCtxt = "";
                            }
                        }
                        msgId += format(strLine);
                    }
                    if (state == states.MSGSTR) {
                        msgCtxt = "";
                        msgStr += format(strLine);
                        if (!msgId.isEmpty()) messages.setProperty(msgId, msgStr);
                    }
                }
            }
            in.close();
        } catch (IOException e) {
            Logger.logError(e, "Error loading message.po.");
        }
    }