semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void parse(Project project, Object source, RootHandler handler) {
        AntXMLContext context = (AntXMLContext) Reflect.getField(handler, "context");
        File buildFile = null;
        URL url = null;
        String buildFileName = null;
        if (source instanceof File) {
            buildFile = (File) source;
            buildFile = fu.normalize(buildFile.getAbsolutePath());
            context.setBuildFile(buildFile);
            buildFileName = buildFile.toString();
        } else if (source instanceof URL) {
            url = (URL) source;
            buildFileName = url.toString();
        } else {
            throw new BuildException("Source " + source.getClass().getName() + " not supported by this plugin");
        }
        InputStream inputStream = null;
        InputSource inputSource = null;
        try {
            XMLReader parser = JAXPUtils.getNamespaceXMLReader();
            String uri = null;
            if (buildFile != null) {
                uri = fu.toURI(buildFile.getAbsolutePath());
                inputStream = new FileInputStream(buildFile);
            } else {
                inputStream = url.openStream();
                uri = url.toString();
            }
            inputSource = new InputSource(inputStream);
            if (uri != null) {
                inputSource.setSystemId(uri);
            }
            project.log("parsing buildfile " + buildFileName + " with URI = " + uri, Project.MSG_VERBOSE);
            DefaultHandler hb = handler;
            parser.setContentHandler(hb);
            parser.setEntityResolver(hb);
            parser.setErrorHandler(hb);
            parser.setDTDHandler(hb);
            parser.parse(inputSource);
        } catch (SAXParseException exc) {
            Location location = new Location(exc.getSystemId(), exc.getLineNumber(), exc.getColumnNumber());
            Throwable t = exc.getException();
            if (t instanceof BuildException) {
                BuildException be = (BuildException) t;
                if (be.getLocation() == Location.UNKNOWN_LOCATION) {
                    be.setLocation(location);
                }
                throw be;
            }
            throw new BuildException(exc.getMessage(), t, location);
        } catch (SAXException exc) {
            Throwable t = exc.getException();
            if (t instanceof BuildException) {
                throw (BuildException) t;
            }
            throw new BuildException(exc.getMessage(), t);
        } catch (FileNotFoundException exc) {
            throw new BuildException(exc);
        } catch (UnsupportedEncodingException exc) {
            throw new BuildException("Encoding of project file " + buildFileName + " is invalid.", exc);
        } catch (IOException exc) {
            throw new BuildException("Error reading project file " + buildFileName + ": " + exc.getMessage(), exc);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException ioe) {
                }
            }
        }
    }
public static String ReadURL(URL url, boolean textonly) {
        try {
            URLConnection uconn = url.openConnection();
            Object ucont = uconn.getContent();
            if (ucont instanceof InputStream) return ReadInputStream((java.io.InputStream) ucont, textonly); else return "" + ucont;
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
        return null;
    }
private void storeConfigurationPropertiesFile(java.net.URL url, String comp) {
        java.util.Properties p;
        try {
            p = new java.util.Properties();
            p.load(url.openStream());
        } catch (java.io.IOException ie) {
            System.err.println("error opening: " + url.getPath() + ": " + ie.getMessage());
            return;
        }
        storeConfiguration(p, comp);
        return;
    }
public List<String> loadList(String name) {
        List<String> ret = new ArrayList<String>();
        try {
            URL url = getClass().getClassLoader().getResource("lists/" + name + ".utf-8");
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
            String line;
            while ((line = reader.readLine()) != null) {
                ret.add(line);
            }
            reader.close();
        } catch (IOException e) {
            showError("No se puede cargar la lista de valores: " + name, e);
        }
        return ret;
    }
@Override
    public VocabularyLocation next() {
        try {
            if (!urls.isEmpty()) {
                final URL url = urls.poll();
                return new VocabularyLocation(url.toExternalForm(), VocabularyFormat.RDFXML, 0, url.openStream());
            }
            if (!files.isEmpty()) {
                File file = files.poll();
                return new VocabularyLocation(file.getCanonicalPath(), file.getName().endsWith(".ntriples") ? VocabularyFormat.NTRIPLES : VocabularyFormat.RDFXML, file.lastModified(), new FileInputStream(file));
            }
            if (nextZipEntry != null) {
                String zipEntryAsString = IOUtils.toString(new CloseShieldInputStream(in), "UTF-8");
                VocabularyLocation location = new VocabularyLocation(nextZipEntry.getName(), nextZipEntry.getName().endsWith(".rdf") ? VocabularyFormat.RDFXML : null, nextZipEntry.getTime(), IOUtils.toInputStream(zipEntryAsString, "UTF-8"));
                findNextZipEntry();
                return location;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        throw new NoSuchElementException();
    }
@Override
    protected svm_model loadModel(InputStream inputStream) throws IOException {
        File tmpFile = File.createTempFile("tmp", ".mdl");
        FileOutputStream output = new FileOutputStream(tmpFile);
        try {
            IOUtils.copy(inputStream, output);
            return libsvm.svm.svm_load_model(tmpFile.getPath());
        } finally {
            output.close();
            tmpFile.delete();
        }
    }
public static void writeToFile(final File file, final InputStream in) throws IOException {
        IOUtils.createFile(file);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            IOUtils.copyStream(in, fos);
        } finally {
            IOUtils.closeIO(fos);
        }
    }
public static void copyFile(final File sourceFile, final File destFile) throws IOException {
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        FileInputStream inStream = null;
        FileOutputStream outStream = null;
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = (inStream = new FileInputStream(sourceFile)).getChannel();
            destination = (outStream = new FileOutputStream(destFile)).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            closeIO(source);
            closeIO(inStream);
            closeIO(destination);
            closeIO(outStream);
        }
    }
public static InputStream obterConteudoArquivo(String u) {
        URL url;
        try {
            url = new URL(u);
            URLConnection conn = null;
            if (proxy != null) conn = url.openConnection(proxy.getProxy()); else conn = url.openConnection();
            return new DataInputStream(conn.getInputStream());
        } catch (MalformedURLException e) {
            throw new AlfredException(e);
        } catch (IOException e) {
            throw new AlfredException(e);
        }
    }
public static String obterConteudoSite(String u) {
        URL url;
        try {
            url = new URL(u);
            URLConnection conn = null;
            if (proxy != null) conn = url.openConnection(proxy.getProxy()); else conn = url.openConnection();
            conn.setDoOutput(true);
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charset.forName("UTF-8")));
            String line;
            StringBuilder resultado = new StringBuilder();
            while ((line = rd.readLine()) != null) {
                resultado.append(line);
                resultado.append("\n");
            }
            rd.close();
            return resultado.toString();
        } catch (MalformedURLException e) {
            throw new AlfredException("Não foi possível obter contato com o site " + u, e);
        } catch (IOException e) {
            throw new AlfredException("Não foi possível obter contato com o site " + u, e);
        }
    }
protected byte[] getTSAResponse(byte[] requestBytes) throws Exception {
        URL url = new URL(tsaURL);
        URLConnection tsaConnection;
        tsaConnection = (URLConnection) url.openConnection();
        tsaConnection.setDoInput(true);
        tsaConnection.setDoOutput(true);
        tsaConnection.setUseCaches(false);
        tsaConnection.setRequestProperty("Content-Type", "application/timestamp-query");
        tsaConnection.setRequestProperty("Content-Transfer-Encoding", "binary");
        if ((tsaUsername != null) && !tsaUsername.equals("")) {
            String userPassword = tsaUsername + ":" + tsaPassword;
            tsaConnection.setRequestProperty("Authorization", "Basic " + Base64.encodeBytes(userPassword.getBytes()));
        }
        OutputStream out = tsaConnection.getOutputStream();
        out.write(requestBytes);
        out.close();
        InputStream inp = tsaConnection.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int bytesRead = 0;
        while ((bytesRead = inp.read(buffer, 0, buffer.length)) >= 0) {
            baos.write(buffer, 0, bytesRead);
        }
        byte[] respBytes = baos.toByteArray();
        String encoding = tsaConnection.getContentEncoding();
        if (encoding != null && encoding.equalsIgnoreCase("base64")) {
            respBytes = Base64.decode(new String(respBytes));
        }
        return respBytes;
    }
public void logout(String cookieString) throws NetworkException {
        HttpClient client = HttpConfig.newInstance();
        HttpGet get = new HttpGet(HttpConfig.bbsURL() + HttpConfig.BBS_LOGOUT);
        if (cookieString != null && cookieString.length() != 0) get.setHeader("Cookie", cookieString);
        try {
            HttpResponse response = client.execute(get);
            if (response != null && response.getEntity() != null) {
                HTTPUtil.consume(response.getEntity());
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public List<BoardObject> favBoard() throws NetworkException, ContentException {
        HttpClient client = HttpConfig.newInstance();
        HttpGet get = new HttpGet(HttpConfig.bbsURL() + HttpConfig.BBS_FAV);
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            if (HTTPUtil.isHttp200(response) && HTTPUtil.isXmlContentType(response)) {
                Document doc = XmlOperator.readDocument(entity.getContent());
                return BBSBodyParseHelper.parseFavBoardList(doc);
            } else {
                String msg = BBSBodyParseHelper.parseFailMsg(entity);
                throw new ContentException(msg);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public boolean addFavBoard(BoardObject board) throws NetworkException, ContentException {
        String url = HttpConfig.bbsURL() + HttpConfig.BBS_FAV_ADD + board.getId();
        HttpClient client = HttpConfig.newInstance();
        HttpGet get = new HttpGet(url);
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            if (HTTPUtil.isHttp200(response) && HTTPUtil.isXmlContentType(response)) {
                HTTPUtil.consume(response.getEntity());
                return true;
            } else {
                String msg = BBSBodyParseHelper.parseFailMsg(entity);
                throw new ContentException(msg);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public boolean setFavBoard(List<BoardObject> list) throws NetworkException, ContentException {
        HttpClient client = HttpConfig.newInstance();
        HttpPost post = new HttpPost(HttpConfig.bbsURL() + HttpConfig.BBS_FAV_SETTING);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        for (BoardObject board : list) nvps.add(new BasicNameValuePair(board.getId(), "on"));
        try {
            post.setEntity(new UrlEncodedFormEntity(nvps, BBSBodyParseHelper.BBS_CHARSET));
            HttpResponse response = client.execute(post);
            HttpEntity entity = response.getEntity();
            if (HTTPUtil.isHttp200(response) && HTTPUtil.isXmlContentType(response)) {
                HTTPUtil.consume(response.getEntity());
                return true;
            } else {
                String msg = BBSBodyParseHelper.parseFailMsg(entity);
                throw new ContentException(msg);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public static String digest(String algorithm, String text) {
        MessageDigest mDigest = null;
        try {
            mDigest = MessageDigest.getInstance(algorithm);
            mDigest.update(text.getBytes(ENCODING));
        } catch (NoSuchAlgorithmException nsae) {
            Logger.error(Encryptor.class, nsae.getMessage(), nsae);
        } catch (UnsupportedEncodingException uee) {
            Logger.error(Encryptor.class, uee.getMessage(), uee);
        }
        byte raw[] = mDigest.digest();
        return (new BASE64Encoder()).encode(raw);
    }
public static String getMd5Hash(String text) {
        StringBuffer result = new StringBuffer(32);
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(text.getBytes());
            Formatter f = new Formatter(result);
            byte[] digest = md5.digest();
            for (int i = 0; i < digest.length; i++) {
                f.format("%02x", new Object[] { new Byte(digest[i]) });
            }
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return result.toString();
    }
public static void main(String args[]) throws IOException {
        String inFileName = args[0];
        String outFileName = args[1];
        long position = 0L;
        try {
            position = Long.parseLong(args[2]);
        } catch (NumberFormatException nfex1) {
            try {
                position = Long.parseLong(args[2], 16);
            } catch (NumberFormatException nfex2) {
                System.err.println("Wrong offset");
                System.exit(0);
            }
        }
        if (position < 1L) {
            System.err.println("Wrong offset. Must be more than 0");
            System.exit(0);
        }
        System.out.println("Copying  input: " + inFileName);
        System.out.println("        output: " + outFileName);
        System.out.println("          from: " + position);
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(inFileName));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFileName));
        bis.skip(position);
        for (byte[] b = new byte[1]; bis.read(b) > 0; bos.write(b)) ;
        bis.close();
        bos.close();
    }
public boolean isValid(WizardContext context) {
        if (serviceSelection < 0) {
            return false;
        }
        ServiceReference selection = (ServiceReference) serviceList.getElementAt(serviceSelection);
        if (selection == null) {
            return false;
        }
        String function = (String) context.getAttribute(ServiceWizard.ATTRIBUTE_FUNCTION);
        context.setAttribute(ServiceWizard.ATTRIBUTE_SERVICE_REFERENCE, selection);
        URL url = selection.getResourceURL();
        InputStream inputStream = null;
        try {
            inputStream = url.openStream();
            InputSource inputSource = new InputSource(inputStream);
            JdbcService service = ServiceDigester.parseService(inputSource, IsqlToolkit.getSharedEntityResolver());
            context.setAttribute(ServiceWizard.ATTRIBUTE_SERVICE, service);
            return true;
        } catch (IOException error) {
            if (!ServiceWizard.FUNCTION_DELETE.equals(function)) {
                String loc = url.toExternalForm();
                String message = messages.format("SelectServiceStep.failed_to_load_service_from_url", loc);
                context.showErrorDialog(error, message);
            } else {
                return true;
            }
        } catch (Exception error) {
            String message = messages.format("SelectServiceStep.service_load_error", url.toExternalForm());
            context.showErrorDialog(error, message);
        }
        return false;
    }
private boolean extract(File archive, File dir, IProgressMonitor monitor) {
        monitor.subTask("Extract : " + archive.getName());
        if (!dir.exists()) {
            dir.mkdirs();
        } else {
            File[] files = dir.listFiles();
            for (int j = 0; j < files.length; j++) {
                files[j].delete();
            }
        }
        ZipInputStream zis = null;
        try {
            zis = new ZipInputStream(new FileInputStream(archive));
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                File indexFile = new File(dir, entry.getName());
                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream(indexFile);
                    IOUtils.copy(zis, fos);
                } finally {
                    IOUtils.closeQuietly(fos);
                }
            }
            return true;
        } catch (Exception ex) {
            M4EclipsePlugin.log(new Status(IStatus.ERROR, M4EclipsePlugin.PLUGIN_ID, -1, "For index '" + dir.getName() + "' Unable to initialize indexes", ex));
        } finally {
            IOUtils.closeQuietly(zis);
        }
        return false;
    }
private void download(File archive, File timestamp, URL url, IProgressMonitor monitor) throws IOException {
        monitor.subTask("download " + url.toString());
        InputStream in = null;
        FileOutputStream out = null;
        URLConnection conn = null;
        try {
            conn = url.openConnection();
            Writer writer = null;
            try {
                Date date = new Date(conn.getLastModified());
                writer = new FileWriter(timestamp);
                writer.write(this.FORMAT.format(date));
            } catch (IOException e) {
                timestamp.delete();
            } finally {
                IOUtils.closeQuietly(writer);
            }
            in = conn.getInputStream();
            out = new FileOutputStream(archive);
            IOUtils.copy(in, out);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }
    }
private boolean checkTimestamp(File timestamp, URL url) {
        try {
            if (timestamp.exists()) {
                FileReader reader = null;
                Date dateLocal = null;
                try {
                    reader = new FileReader(timestamp);
                    StringWriter tmp = new StringWriter();
                    IOUtils.copy(reader, tmp);
                    dateLocal = this.FORMAT.parse(tmp.toString());
                } catch (ParseException e) {
                    timestamp.delete();
                } catch (IOException e) {
                } finally {
                    IOUtils.closeQuietly(reader);
                }
                if (dateLocal != null) {
                    try {
                        URLConnection conn = url.openConnection();
                        Date date = this.FORMAT.parse(this.FORMAT.format(new Date(conn.getLastModified())));
                        return (date.compareTo(dateLocal) == 0);
                    } catch (IOException e) {
                    }
                }
            }
        } catch (Throwable t) {
        }
        return false;
    }
static Object loadPersistentRepresentationFromFile(URL url) throws PersistenceException {
        PersistenceManager.persistenceURL.get().addFirst(url);
        ObjectInputStream ois = null;
        HierarchicalStreamReader reader = null;
        XStream xstream = null;
        try {
            Reader inputReader = new java.io.InputStreamReader(url.openStream());
            try {
                XMLInputFactory inputFactory = XMLInputFactory.newInstance();
                XMLStreamReader xsr = inputFactory.createXMLStreamReader(url.toExternalForm(), inputReader);
                reader = new StaxReader(new QNameMap(), xsr);
            } catch (XMLStreamException xse) {
                throw new PersistenceException("Error creating reader", xse);
            }
            xstream = new XStream(new StaxDriver());
            xstream.setClassLoader(Gate.getClassLoader());
            ois = xstream.createObjectInputStream(reader);
            Object res = null;
            Iterator urlIter = ((Collection) PersistenceManager.getTransientRepresentation(ois.readObject())).iterator();
            while (urlIter.hasNext()) {
                URL anUrl = (URL) urlIter.next();
                try {
                    Gate.getCreoleRegister().registerDirectories(anUrl);
                } catch (GateException ge) {
                    Err.prln("Could not reload creole directory " + anUrl.toExternalForm());
                }
            }
            res = ois.readObject();
            ois.close();
            return res;
        } catch (PersistenceException pe) {
            throw pe;
        } catch (Exception e) {
            throw new PersistenceException("Error loading GAPP file", e);
        } finally {
            PersistenceManager.persistenceURL.get().removeFirst();
            if (PersistenceManager.persistenceURL.get().isEmpty()) {
                PersistenceManager.persistenceURL.remove();
            }
        }
    }
public static boolean isImageLinkReachable(WebImage image) {
        if (image.getUrl() == null) return false;
        try {
            URL url = new URL(image.getUrl());
            url.openStream().close();
        } catch (MalformedURLException e) {
            return false;
        } catch (IOException e) {
            return false;
        }
        return true;
    }
private File copyFile(File source, File destiny) {
        try {
            FileInputStream fileinputstream = new FileInputStream(source);
            FileOutputStream fileoutputstream = new FileOutputStream(destiny);
            byte abyte0[] = new byte[4096];
            int i;
            while ((i = fileinputstream.read(abyte0)) != -1) fileoutputstream.write(abyte0, 0, i);
            fileinputstream.close();
            fileoutputstream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage());
        }
        return destiny;
    }