semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected Resolver queryResolver(String resolver, String command, String arg1, String arg2) {
        InputStream iStream = null;
        String RFC2483 = resolver + "?command=" + command + "&format=tr9401&uri=" + arg1 + "&uri2=" + arg2;
        String line = null;
        try {
            URL url = new URL(RFC2483);
            URLConnection urlCon = url.openConnection();
            urlCon.setUseCaches(false);
            Resolver r = (Resolver) newCatalog();
            String cType = urlCon.getContentType();
            if (cType.indexOf(";") > 0) {
                cType = cType.substring(0, cType.indexOf(";"));
            }
            r.parseCatalog(cType, urlCon.getInputStream());
            return r;
        } catch (CatalogException cex) {
            if (cex.getExceptionType() == CatalogException.UNPARSEABLE) {
                catalogManager.debug.message(1, "Unparseable catalog: " + RFC2483);
            } else if (cex.getExceptionType() == CatalogException.UNKNOWN_FORMAT) {
                catalogManager.debug.message(1, "Unknown catalog format: " + RFC2483);
            }
            return null;
        } catch (MalformedURLException mue) {
            catalogManager.debug.message(1, "Malformed resolver URL: " + RFC2483);
            return null;
        } catch (IOException ie) {
            catalogManager.debug.message(1, "I/O Exception opening resolver: " + RFC2483);
            return null;
        }
    }
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String requestPath = req.getRequestURI();
        String cdecUrl = "http://cdec.water.ca.gov" + requestPath + "?" + req.getQueryString();
        System.out.println("CDEC URL: " + cdecUrl);
        URL url = new URL(cdecUrl);
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        StringBuffer buffer = new StringBuffer();
        String line = null;
        int ncolumnInner = 0;
        while ((line = reader.readLine()) != null) {
            if (line.contains("<div class=\"column_inner\"")) {
                ncolumnInner++;
            }
            if (ncolumnInner == 2) {
                if (line.contains("</div>")) {
                    break;
                }
                if (line.contains("href")) {
                    line = line.replaceAll("href", "  target=\"external_page\" href");
                }
                if (line.contains("http://cdec.water.ca.gov:80")) {
                    line = line.replaceAll("http://cdec.water.ca.gov:80/", "/");
                }
                if (line.contains("href=")) {
                    line = line.replaceAll("(href=\"|href=)", "$1http://cdec.water.ca.gov");
                }
                buffer.append(line);
            } else {
                continue;
            }
        }
        resp.getWriter().write(buffer.toString());
        resp.getWriter().flush();
        reader.close();
    }
public static void reset() throws Exception {
        Session session = DataStaticService.getHibernateSessionFactory().openSession();
        try {
            Connection connection = session.connection();
            try {
                Statement statement = connection.createStatement();
                try {
                    statement.executeUpdate("delete from Bundle");
                    connection.commit();
                } finally {
                    statement.close();
                }
            } catch (HibernateException e) {
                connection.rollback();
                throw new Exception(e);
            } catch (SQLException e) {
                connection.rollback();
                throw new Exception(e);
            }
        } catch (SQLException e) {
            throw new Exception(e);
        } finally {
            session.close();
        }
    }
@Override
    public void run() {
        String key = getKey();
        synchronized (this.lauchedHTTPRequests) {
            if (this.lauchedHTTPRequests.contains(key)) return;
            this.lauchedHTTPRequests.add(key);
        }
        String st = this.dataSource.getTileURL(this.x, this.y, this.z);
        URL url;
        try {
            url = new URL(st);
        } catch (MalformedURLException e1) {
            logger.warning("Error in URL: " + st);
            return;
        }
        String geoJSON = "";
        try {
            InputStream is;
            if ("file".equals(url.getProtocol())) is = new FileInputStream(url.getFile()); else if ("http".equals(url.getProtocol())) is = url.openStream(); else {
                logger.warning("Impossible to load settings from " + url + ". Unsupported protocol " + url.getProtocol());
                return;
            }
            BufferedReader in = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = in.readLine()) != null) geoJSON += line;
            in.close();
        } catch (FileNotFoundException e) {
            return;
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        VectorTile tile = new VectorTile(geoJSON, x, y, z);
        Geometry[] geoms = new Geometry[tile.getPieces().size()];
        int i = 0;
        for (MfGeo geo : tile.getPieces()) {
            if (geo.getGeoType() == GeoType.GEOMETRY) {
                geoms[i++] = ((MfGeometry) geo).getInternalGeometry();
            } else if (geo.getGeoType() == GeoType.FEATURE) {
                MfFeature mf = (MfFeature) geo;
                geoms[i++] = mf.getMfGeometry().getInternalGeometry();
            }
        }
        GeometryCollection gc = new GeometryFactory().createGeometryCollection(geoms);
        this.dataSource.getDataLoader().add(new OpenCartoFeature(this.dataSource.getLayer(), new Rep(gc), this.z));
        this.dataSource.getLayer().getDisplayCacheLoader().coin();
        synchronized (this.lauchedHTTPRequests) {
            this.lauchedHTTPRequests.remove(key);
        }
    }
private void listAndInstantiateServiceProviders() {
        final Enumeration<URL> resources = ClassLoaderHelper.getResources(SERVICES_FILE, ServiceManager.class);
        String name;
        try {
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                InputStream stream = url.openStream();
                try {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(stream), 100);
                    name = reader.readLine();
                    while (name != null) {
                        name = name.trim();
                        if (!name.startsWith("#")) {
                            final ServiceProvider<?> serviceProvider = ClassLoaderHelper.instanceFromName(ServiceProvider.class, name, ServiceManager.class, "service provider");
                            @SuppressWarnings("unchecked") final Class<ServiceProvider<?>> serviceProviderClass = (Class<ServiceProvider<?>>) serviceProvider.getClass();
                            managedProviders.put(serviceProviderClass, new ServiceProviderWrapper(serviceProvider));
                        }
                        name = reader.readLine();
                    }
                } finally {
                    stream.close();
                }
            }
        } catch (IOException e) {
            throw new SearchException("Unable to read " + SERVICES_FILE, e);
        }
    }
private static void copyFile(File source, File destination) throws IOException, SecurityException {
        if (!destination.exists()) destination.createNewFile();
        FileChannel sourceChannel = null;
        FileChannel destinationChannel = null;
        try {
            sourceChannel = new FileInputStream(source).getChannel();
            destinationChannel = new FileOutputStream(destination).getChannel();
            long count = 0;
            long size = sourceChannel.size();
            while ((count += destinationChannel.transferFrom(sourceChannel, 0, size - count)) < size) ;
        } finally {
            if (sourceChannel != null) sourceChannel.close();
            if (destinationChannel != null) destinationChannel.close();
        }
    }
public void run() {
        RandomAccessFile file = null;
        InputStream stream = null;
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("Range", "bytes=" + downloaded + "-");
            connection.connect();
            if (connection.getResponseCode() / 100 != 2) {
                error();
            }
            int contentLength = connection.getContentLength();
            if (contentLength < 1) {
                error();
            }
            if (size == -1) {
                size = contentLength;
                stateChanged();
            }
            file = new RandomAccessFile(destination, "rw");
            file.seek(downloaded);
            stream = connection.getInputStream();
            while (status == DOWNLOADING) {
                byte buffer[];
                if (size - downloaded > MAX_BUFFER_SIZE) {
                    buffer = new byte[MAX_BUFFER_SIZE];
                } else {
                    buffer = new byte[size - downloaded];
                }
                int read = stream.read(buffer);
                if (read == -1) break;
                file.write(buffer, 0, read);
                downloaded += read;
                stateChanged();
            }
            if (status == DOWNLOADING) {
                status = COMPLETE;
                stateChanged();
            }
        } catch (Exception e) {
            error();
        } finally {
            if (file != null) {
                try {
                    file.close();
                } catch (Exception e) {
                }
            }
            if (stream != null) {
                try {
                    stream.close();
                } catch (Exception e) {
                }
            }
        }
    }
public static void main(String[] args) {
        try {
            URL url = new URL("http://www.lineadecodigo.com");
            BufferedReader in = null;
            try {
                in = new BufferedReader(new InputStreamReader(url.openStream()));
            } catch (Throwable t) {
            }
            String inputLine;
            String inputText = "";
            while ((inputLine = in.readLine()) != null) {
                inputText = inputText + inputLine;
            }
            System.out.println("El contenido de la URL es: " + inputText);
            in.close();
        } catch (MalformedURLException me) {
            System.out.println("URL erronea");
        } catch (IOException ioe) {
            System.out.println("Error IO");
        }
    }
public synchronized void readConfiguration() throws IOException, SecurityException {
        String path;
        InputStream inputStream;
        path = System.getProperty("java.util.logging.config.file");
        if ((path == null) || (path.length() == 0)) {
            String url = (System.getProperty("gnu.classpath.home.url") + "/logging.properties");
            inputStream = new URL(url).openStream();
        } else inputStream = new java.io.FileInputStream(path);
        try {
            readConfiguration(inputStream);
        } finally {
            inputStream.close();
        }
    }
private void updateFile(File file) throws FileNotFoundException, IOException {
        File destFile = new File(file.getPath().replace(URL_UNZIPPED_PREFIX + latestVersion, ""));
        FileChannel in = null;
        FileChannel out = null;
        try {
            if (!destFile.exists()) {
                destFile.getParentFile().mkdirs();
                destFile.createNewFile();
            }
            in = new FileInputStream(file).getChannel();
            out = new FileOutputStream(destFile).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (out != null) out.close();
            if (in != null) in.close();
        }
    }
void copyFile(File inputFile, File outputFile) {
        try {
            FileReader in;
            in = new FileReader(inputFile);
            FileWriter out = new FileWriter(outputFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static String hash(final String text) {
        try {
            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 Sha1.convertToHex(sha1hash);
        } catch (final Exception e) {
            return null;
        }
    }
public byte[] authClient(String host, String user, String passwd, String realm, String serverChallenge) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        OutputStream b64os = new BASE64EncoderStream(bos, Integer.MAX_VALUE);
        SecureRandom random;
        try {
            random = new SecureRandom();
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            if (debugout != null) debugout.println("DEBUG DIGEST-MD5: " + ex);
            throw new IOException(ex.toString());
        }
        StringBuffer result = new StringBuffer();
        uri = "smtp/" + host;
        String nc = "00000001";
        String qop = "auth";
        byte[] bytes = new byte[32];
        int resp;
        if (debugout != null) debugout.println("DEBUG DIGEST-MD5: Begin authentication ...");
        Hashtable map = tokenize(serverChallenge);
        if (realm == null) {
            String text = (String) map.get("realm");
            realm = text != null ? new StringTokenizer(text, ",").nextToken() : host;
        }
        String nonce = (String) map.get("nonce");
        random.nextBytes(bytes);
        b64os.write(bytes);
        b64os.flush();
        String cnonce = bos.toString();
        bos.reset();
        md5.update(md5.digest(ASCIIUtility.getBytes(user + ":" + realm + ":" + passwd)));
        md5.update(ASCIIUtility.getBytes(":" + nonce + ":" + cnonce));
        clientResponse = toHex(md5.digest()) + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":";
        md5.update(ASCIIUtility.getBytes("AUTHENTICATE:" + uri));
        md5.update(ASCIIUtility.getBytes(clientResponse + toHex(md5.digest())));
        result.append("username=\"" + user + "\"");
        result.append(",realm=\"" + realm + "\"");
        result.append(",qop=" + qop);
        result.append(",nc=" + nc);
        result.append(",nonce=\"" + nonce + "\"");
        result.append(",cnonce=\"" + cnonce + "\"");
        result.append(",digest-uri=\"" + uri + "\"");
        result.append(",response=" + toHex(md5.digest()));
        if (debugout != null) debugout.println("DEBUG DIGEST-MD5: Response => " + result.toString());
        b64os.write(ASCIIUtility.getBytes(result.toString()));
        b64os.flush();
        return bos.toByteArray();
    }
private void getImage(String filename) throws MalformedURLException, IOException, SAXException, FileNotFoundException {
        String url = Constants.STRATEGICDOMINATION_URL + "/images/gameimages/" + filename;
        WebRequest req = new GetMethodWebRequest(url);
        SiteResponse response = getSiteResponse(req);
        File file = new File("etc/images/" + filename);
        FileOutputStream outputStream = new FileOutputStream(file);
        IOUtils.copy(response.getInputStream(), outputStream);
    }
public static String encrypt(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA1");
            md.update(input.getBytes("UTF-8"));
            return toHexString(md.digest());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
public boolean run() {
        String url;
        try {
            url = getFileName();
        } catch (NoSuchFieldException e) {
            return false;
        }
        if (url == null) {
            logger.error("URL not specified! Cannot continue.");
            return false;
        }
        try {
            URL newURL = new URL(url);
            String extension = url.substring((url.lastIndexOf(".")) + 1, url.length());
            File temp = File.createTempFile("temp", "." + extension);
            System.out.printf("Storing URL contents to a temp file : %s\n", temp);
            temp.deleteOnExit();
            InputStream urlINS = new BufferedInputStream(newURL.openConnection().getInputStream());
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(temp));
            int len = 0;
            for (int singleByte = urlINS.read(); singleByte != -1; singleByte = urlINS.read()) {
                out.write(singleByte);
                len++;
            }
            System.out.printf("Stored %d bytes from URL contents\n", len);
            out.flush();
            out.close();
            System.out.printf("URL/Temp extension : %s\n", extension);
            if (extension.equalsIgnoreCase("gz")) {
                String shorterName = url.substring(0, url.lastIndexOf("."));
                String extension2 = shorterName.substring((shorterName.lastIndexOf(".")) + 1, shorterName.length());
                File temp2 = File.createTempFile("temp", "." + extension2);
                temp2.deleteOnExit();
                System.out.printf("URL/Temp extension after decompressing gzip : %s\n", extension2);
                GZIPInputStream decompressor = new GZIPInputStream(new FileInputStream(temp));
                OutputStream target = new FileOutputStream(temp2);
                byte[] buffer = new byte[1024];
                int length;
                while ((length = decompressor.read(buffer)) > 0) {
                    target.write(buffer, 0, length);
                }
                target.flush();
                target.close();
                temp = temp2;
            }
            String tempName = temp.getName();
            extension = tempName.substring((tempName.lastIndexOf(".")) + 1, tempName.length());
            Preprocessor fileLoader = null;
            BasePreprocessorConfig configObject = null;
            if (MethodCallTable.containsKey(extension) == false) {
                fileLoader = MethodCallTable.get("default");
            } else {
                fileLoader = MethodCallTable.get(extension);
            }
            System.out.printf("Calling filter '%s' for extension: %s\n", fileLoader.getPreprocessingMethodName(), extension);
            configObject = new LoadCSVPreprocessorConfig();
            configObject.setValueByName("FileName", temp.getAbsolutePath());
            fileLoader.setConfigurationClass(configObject);
            return fileLoader.run();
        } catch (Exception e) {
            logger.error(e);
            return false;
        }
    }
private void copy(File source, File target) throws IOException {
        FileChannel in = (new FileInputStream(source)).getChannel();
        FileChannel out = (new FileOutputStream(target)).getChannel();
        in.transferTo(0, source.length(), out);
        in.close();
        out.close();
    }
public File createFileFromClasspathResource(String resourceUrl) throws IOException {
        File fichierTest = File.createTempFile("xmlFieldTestFile", "");
        FileOutputStream fos = new FileOutputStream(fichierTest);
        InputStream is = XmlFieldDomSelectorTest.class.getResourceAsStream(resourceUrl);
        IOUtils.copy(is, fos);
        is.close();
        fos.close();
        return fichierTest;
    }
public static String sha1(String src) {
        MessageDigest md1 = null;
        try {
            md1 = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        try {
            md1.update(src.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return hex(md1.digest());
    }
public String move(Integer param) {
        LOG.debug("move " + param);
        StringBuffer ret = new StringBuffer();
        try {
            URL url = new URL("http://" + host + "/decoder_control.cgi?command=" + param + "&user=" + user + "&pwd=" + password);
            URLConnection con = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                ret.append(inputLine);
            }
            in.close();
        } catch (Exception e) {
            logException(e);
            connect(host, user, password);
        }
        return ret.toString();
    }
public static LinkedList<String> read(URL url) throws IOException {
        LinkedList<String> data = new LinkedList<String>();
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String input = "";
        while (true) {
            input = br.readLine();
            if (input == null) break;
            data.add(input);
        }
        br.close();
        return data;
    }
public static LinkedList<String> read(URL url, String exc) throws IOException {
        LinkedList<String> data = new LinkedList<String>();
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String input = "";
        while (true) {
            input = br.readLine();
            if (input == null) break;
            if (!input.startsWith(exc)) {
                data.add(input);
            }
        }
        br.close();
        return data;
    }
private void connect(URL url) throws IOException {
        String protocol = url.getProtocol();
        if (!protocol.equals("http")) throw new IllegalArgumentException("URL must use 'http:' protocol");
        int port = url.getPort();
        if (port == -1) port = 80;
        fileName = url.getFile();
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        toServer = new OutputStreamWriter(conn.getOutputStream());
        fromServer = conn.getInputStream();
    }