semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void readShaderSource(ClassLoader context, String path, URL url, StringBuffer result) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (line.startsWith("#include ")) {
                    String includeFile = line.substring(9).trim();
                    String next = Locator.getRelativeOf(path, includeFile);
                    URL nextURL = Locator.getResource(next, context);
                    if (nextURL == null) {
                        next = includeFile;
                        nextURL = Locator.getResource(next, context);
                    }
                    if (nextURL == null) {
                        throw new FileNotFoundException("Can't find include file " + includeFile);
                    }
                    readShaderSource(context, next, nextURL, result);
                } else {
                    result.append(line + "\n");
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
public static ByteBuffer readShaderBinary(Class context, String path) {
        try {
            URL url = Locator.getResource(context, path);
            if (url == null) {
                return null;
            }
            return StreamUtil.readAll2Buffer(new BufferedInputStream(url.openStream()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
public synchronized void connect() throws FTPException, IOException {
        if (eventAggregator != null) {
            eventAggregator.setConnId(ftpClient.getId());
            ftpClient.setMessageListener(eventAggregator);
            ftpClient.setProgressMonitor(eventAggregator);
            ftpClient.setProgressMonitorEx(eventAggregator);
        }
        statistics.clear();
        configureClient();
        log.debug("Configured client");
        ftpClient.connect();
        log.debug("Client connected");
        if (masterContext.isAutoLogin()) {
            log.debug("Logging in");
            ftpClient.login(masterContext.getUserName(), masterContext.getPassword());
            log.debug("Logged in");
            configureTransferType(masterContext.getContentType());
        } else {
            log.debug("Manual login enabled");
        }
    }
public static void main(String[] args) throws IOException {
        FileChannel fc = new FileOutputStream("src/com/aaron/nio/data.txt").getChannel();
        fc.write(ByteBuffer.wrap("dfsdf ".getBytes()));
        fc.close();
        fc = new RandomAccessFile("src/com/aaron/nio/data.txt", "rw").getChannel();
        fc.position(fc.size());
        fc.write(ByteBuffer.wrap("中文的 ".getBytes()));
        fc.close();
        fc = new FileInputStream("src/com/aaron/nio/data.txt").getChannel();
        ByteBuffer buff = ByteBuffer.allocate(1024);
        fc.read(buff);
        buff.flip();
        while (buff.hasRemaining()) {
            System.out.print(buff.getChar());
        }
        fc.close();
    }
@Override
    public void exec() {
        BufferedReader in = null;
        try {
            URL url = new URL(getUrl());
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer result = new StringBuffer();
            String str;
            while ((str = in.readLine()) != null) {
                result.append(str);
            }
            logger.info("received message: " + result);
        } catch (Exception e) {
            logger.error("HttpGetEvent could not execute", e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    logger.error("BufferedReader could not be closed", e);
                }
            }
        }
    }
public Model read(String uri, String base, String lang) {
        try {
            URL url = new URL(uri);
            return read(url.openStream(), base, lang);
        } catch (IOException e) {
            throw new OntologyException("I/O error while reading from uri " + uri);
        }
    }
public static String hash(String password) {
        try {
            MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
            digest.update(password.getBytes(charset));
            byte[] rawHash = digest.digest();
            return new String(Hex.encodeHex(rawHash));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
@Override
    public final boolean exists() {
        try {
            final URLConnection uc = this.url.openConnection();
            uc.connect();
            uc.getInputStream().close();
            return true;
        } catch (final IOException e) {
            return false;
        }
    }
@Override
    public long getLastModifiedOn() {
        try {
            final URLConnection uc = this.url.openConnection();
            uc.connect();
            final long res = uc.getLastModified();
            try {
                uc.getInputStream().close();
            } catch (final Exception ignore) {
            }
            return res;
        } catch (final IOException e) {
            return 0;
        }
    }
public TemplateLibrary loadTemplateLibrary(GadgetContext context, Uri uri) throws GadgetException {
        HttpRequest request = new HttpRequest(uri);
        request.setCacheTtl(300);
        HttpResponse response = pipeline.execute(request);
        if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
            throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "Unable to retrieve template library xml. HTTP error " + response.getHttpStatusCode());
        }
        String content = response.getResponseAsString();
        try {
            String key = null;
            Element element = null;
            if (!context.getIgnoreCache()) {
                key = HashUtil.rawChecksum(content.getBytes());
                element = parsedXmlCache.getElement(key);
            }
            if (element == null) {
                element = XmlUtil.parse(content);
                if (key != null) {
                    parsedXmlCache.addElement(key, element);
                }
            }
            return new XmlTemplateLibrary(uri, element, content);
        } catch (XmlException e) {
            throw new GadgetException(GadgetException.Code.MALFORMED_XML_DOCUMENT, e);
        }
    }
private void loadRDFURL(URL url) throws RDFParseException, RepositoryException {
        URI urlContext = valueFactory.createURI(url.toString());
        try {
            URLConnection urlConn = url.openConnection();
            urlConn.setRequestProperty("Accept", "application/rdf+xml");
            InputStream is = urlConn.getInputStream();
            repoConn.add(is, url.toString(), RDFFormat.RDFXML, urlContext);
            is.close();
            repoConn.commit();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public void init(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(password.getBytes("UTF-8"), 0, password.length());
            byte[] rawKey = md.digest();
            skeySpec = new SecretKeySpec(rawKey, "AES");
            ivSpec = new IvParameterSpec(rawKey);
            cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(AES.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchPaddingException ex) {
            Logger.getLogger(AES.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(AES.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
public void copyImage(String from, String to) {
        File inputFile = new File(from);
        File outputFile = new File(to);
        try {
            if (inputFile.canRead()) {
                FileInputStream in = new FileInputStream(inputFile);
                FileOutputStream out = new FileOutputStream(outputFile);
                byte[] buf = new byte[65536];
                int c;
                while ((c = in.read(buf)) > 0) out.write(buf, 0, c);
                in.close();
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public XmlDocument parseLocation(String locationUrl) {
        URL url = null;
        try {
            url = new URL(locationUrl);
        } catch (MalformedURLException e) {
            throw new XmlBuilderException("could not parse URL " + locationUrl, e);
        }
        try {
            return parseInputStream(url.openStream());
        } catch (IOException e) {
            throw new XmlBuilderException("could not open connection to URL " + locationUrl, e);
        }
    }
static Object executeMethod(HttpMethod method, int timeout, boolean array) throws HttpRequestFailureException, HttpException, IOException, HttpRequestTimeoutException {
        try {
            method.getParams().setSoTimeout(timeout * 1000);
            int status = -1;
            Object result = null;
            System.out.println("Execute method: " + method.getPath() + " " + method.getQueryString());
            TwitterclipseConfig config = TwitterclipsePlugin.getDefault().getTwitterclipseConfiguration();
            HttpClient httpClient = HttpClientUtils.createHttpClient(TWITTER_BASE_URL, config.getUserId(), config.getPassword());
            status = httpClient.executeMethod(method);
            System.out.println("Received response. status = " + status);
            if (status == HttpStatus.SC_OK) {
                InputStream inputStream = method.getResponseBodyAsStream();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(inputStream, baos);
                String response = new String(baos.toByteArray(), "UTF-8");
                System.out.println(response);
                if (array) result = JSONArray.fromString(response); else result = JSONObject.fromString(response);
            } else {
                throw new HttpRequestFailureException(status);
            }
            return result;
        } catch (SocketTimeoutException e) {
            throw new HttpRequestTimeoutException(e);
        } finally {
            method.releaseConnection();
        }
    }
public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Usage: java JMEImpl inputfile");
            System.exit(0);
        }
        JME jme = null;
        try {
            URL url = new URL(Util.makeAbsoluteURL(args[0]));
            BufferedReader bReader = new BufferedReader(new InputStreamReader(url.openStream()));
            int idx = args[0].indexOf(".");
            String id = (idx == -1) ? args[0] : args[0].substring(0, idx);
            idx = id.lastIndexOf("\\");
            if (idx != -1) id = id.substring(idx + 1);
            jme = new JMEImpl(bReader, id);
            CMLMolecule mol = jme.getMolecule();
            StringWriter sw = new StringWriter();
            mol.debug(sw);
            System.out.println(sw.toString());
            SpanningTree sTree = new SpanningTreeImpl(mol);
            System.out.println(sTree.toSMILES());
            Writer w = new OutputStreamWriter(new FileOutputStream(id + ".xml"));
            PMRDelegate.outputEventStream(mol, w, PMRNode.PRETTY, 0);
            w.close();
            w = new OutputStreamWriter(new FileOutputStream(id + "-new.mol"));
            jme.setOutputCMLMolecule(mol);
            jme.output(w);
            w.close();
        } catch (Exception e) {
            System.out.println("JME failed: " + e);
            e.printStackTrace();
            System.exit(0);
        }
    }
public static void concatenateToDestFile(File sourceFile, File destFile) throws IOException {
        if (!destFile.exists()) {
            if (!destFile.createNewFile()) {
                throw new IllegalArgumentException("Could not create destination file:" + destFile.getName());
            }
        }
        BufferedOutputStream bufferedOutputStream = null;
        BufferedInputStream bufferedInputStream = null;
        byte[] buffer = new byte[1024];
        try {
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(destFile, true));
            bufferedInputStream = new BufferedInputStream(new FileInputStream(sourceFile));
            while (true) {
                int readByte = bufferedInputStream.read(buffer, 0, buffer.length);
                if (readByte == -1) {
                    break;
                }
                bufferedOutputStream.write(buffer, 0, readByte);
            }
        } finally {
            if (bufferedOutputStream != null) {
                bufferedOutputStream.close();
            }
            if (bufferedInputStream != null) {
                bufferedInputStream.close();
            }
        }
    }
protected void handleHttp(String path, IProgressMonitor monitor, SchemaGeneratorContext ctx) throws CoreException, DuplicateFileException {
        InputStream is = null;
        try {
            URL url = new URL(path);
            is = url.openStream();
            IFolder folder = getXsdFolder();
            String _path = url.getPath();
            String[] contents = StringUtils.tokenizeToStringArray(_path, "/");
            String file = contents[contents.length - 1];
            if (file.indexOf(".") > -1) {
                IFile f = folder.getFile(file);
                if (!f.exists()) {
                    f.create(is, false, monitor);
                    String schemaFile = f.getLocation().toFile().getAbsolutePath();
                    ctx.setSchemaFiles(schemaFile);
                    return;
                }
                throw new DuplicateFileException("File " + file + " already exists");
            }
            IStatus status = new Status(IStatus.ERROR, JeeServiceComponentUIPlugin.PLUGIN_ID, IStatus.OK, "I/O Exception", new FileNotFoundException("No file associated to " + url));
            throw new CoreException(status);
        } catch (MalformedURLException e) {
            IStatus status = new Status(IStatus.ERROR, JeeServiceComponentUIPlugin.PLUGIN_ID, IStatus.OK, "Malformed URL Exception", e);
            throw new CoreException(status);
        } catch (IOException e) {
            IStatus status = new Status(IStatus.ERROR, JeeServiceComponentUIPlugin.PLUGIN_ID, IStatus.OK, "I/O Exception", e);
            throw new CoreException(status);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }
    }
@Override
        public String entryToObject(TupleInput input) {
            boolean zipped = input.readBoolean();
            if (!zipped) {
                return input.readString();
            }
            int len = input.readInt();
            try {
                byte array[] = new byte[len];
                input.read(array);
                GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(array));
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                IOUtils.copyTo(in, out);
                in.close();
                out.close();
                return new String(out.toByteArray());
            } catch (IOException err) {
                throw new RuntimeException(err);
            }
        }
@Override
        public void objectToEntry(String object, TupleOutput output) {
            byte array[] = object.getBytes();
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                GZIPOutputStream out = new GZIPOutputStream(baos);
                ByteArrayInputStream in = new ByteArrayInputStream(array);
                IOUtils.copyTo(in, out);
                in.close();
                out.close();
                byte array2[] = baos.toByteArray();
                if (array2.length + 4 < array.length) {
                    output.writeBoolean(true);
                    output.writeInt(array2.length);
                    output.write(array2);
                } else {
                    output.writeBoolean(false);
                    output.writeString(object);
                }
            } catch (IOException err) {
                throw new RuntimeException(err);
            }
        }
protected Scanner createScanner(InputSource source) {
        documentURI = source.getURI();
        if (documentURI == null) {
            documentURI = "";
        }
        Reader r = source.getCharacterStream();
        if (r != null) {
            return new Scanner(r);
        }
        InputStream is = source.getByteStream();
        if (is != null) {
            return new Scanner(is, source.getEncoding());
        }
        String uri = source.getURI();
        if (uri == null) {
            throw new CSSException(formatMessage("empty.source", null));
        }
        try {
            ParsedURL purl = new ParsedURL(uri);
            is = purl.openStreamRaw(CSSConstants.CSS_MIME_TYPE);
            return new Scanner(is, source.getEncoding());
        } catch (IOException e) {
            throw new CSSException(e);
        }
    }
public static String getEncodedPassword(String buff) {
        if (buff == null) return null;
        String t = new String();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(buff.getBytes());
            byte[] r = md.digest();
            for (int i = 0; i < r.length; i++) {
                t += toHexString(r[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return t;
    }
public void transport(File file) throws TransportException {
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] files = file.listFiles();
                for (int i = 0; i < files.length; i++) {
                    transport(file);
                }
            } else if (file.isFile()) {
                try {
                    FileChannel inChannel = new FileInputStream(file).getChannel();
                    FileChannel outChannel = new FileOutputStream(getOption("destination")).getChannel();
                    inChannel.transferTo(0, inChannel.size(), outChannel);
                } catch (IOException e) {
                    log.error("File transfer failed", e);
                }
            }
        }
    }
public Resource parse(URL url, IRDFContainer target) throws RDFException, IOException {
        parseURL = url;
        URLConnection connection = url.openConnection();
        if (charset == null) {
            charset = Charset.forName("UTF-8");
        }
        Reader reader = new InputStreamReader(connection.getInputStream(), charset);
        return internalParse(reader, target);
    }
public static void main(final String[] args) throws RecognitionException, TokenStreamException, IOException, IllegalOptionValueException, UnknownOptionException {
        try {
            CmdLineParser cmdLineParser = new CmdLineParser();
            Option formatOption = cmdLineParser.addStringOption('f', "format");
            Option outputEncodingOption = cmdLineParser.addStringOption('c', "outcharset");
            Option inputEncodingOption = cmdLineParser.addStringOption('i', "incharset");
            cmdLineParser.parse(args);
            String format = (String) cmdLineParser.getOptionValue(formatOption);
            String outputEncoding = (String) cmdLineParser.getOptionValue(outputEncodingOption);
            if (outputEncoding == null || outputEncoding.trim().equals("")) {
                outputEncoding = "utf-8";
                System.out.println("Defaulting to output charset utf-8 as argument -c is missing or not valid.");
            }
            String inputEncoding = (String) cmdLineParser.getOptionValue(inputEncodingOption);
            if (inputEncoding == null || outputEncoding.trim().equals("")) {
                inputEncoding = "utf-8";
                System.out.println("Defaulting to input charset utf-8 as argument -i is missing or not valid.");
            }
            String[] remainingArgs = cmdLineParser.getRemainingArgs();
            if (remainingArgs.length != 2) {
                printUsage("Input and output file are not specified correctly. ");
            }
            File inputFile = new File(remainingArgs[0]);
            if (!inputFile.exists()) {
                printUsage("Input file " + remainingArgs[0] + " does not exist. ");
            }
            if (format == null || format.trim().equals("")) {
                format = (String) FileUtil.cutExtension(inputFile.getName()).getValue();
            }
            File outputFile = new File(remainingArgs[1]);
            if (!outputFile.exists()) {
                outputFile.createNewFile();
            }
            System.out.println("format detected: " + format);
            if ("html".equals(format)) {
                Reader reader = new HtmlEntityDecoderReader(new InputStreamReader(new FileInputStream(inputFile), inputEncoding));
                OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outputFile), outputEncoding);
                char[] buffer = new char[1024];
                int read;
                do {
                    read = reader.read(buffer);
                    if (read > 0) {
                        out.write(buffer, 0, read);
                    }
                } while (read != -1);
                out.flush();
                out.close();
            } else {
                printUsage("Format not specified via argument -f. Also guessing for the extension of input file " + inputFile.getName() + " failed");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            printUsage(ex.getMessage());
        }
    }
public static void parseRDFXML(String url, StatementHandler handler) throws IOException {
        ARP parser = new ARP();
        parser.getHandlers().setStatementHandler(handler);
        URLConnection conn = new URL(url).openConnection();
        String encoding = conn.getContentEncoding();
        InputStream in = null;
        try {
            in = conn.getInputStream();
            if (encoding == null) parser.load(in, url); else parser.load(new InputStreamReader(in, encoding), url);
            in.close();
        } catch (org.xml.sax.SAXException e) {
            throw new OntopiaRuntimeException(e);
        } finally {
            if (in != null) in.close();
        }
    }
public static InputStream getData(DataTransferDescriptor desc, GlobusCredential creds) throws Exception {
        URL url = new URL(desc.getUrl());
        if (url.getProtocol().equals("http")) {
            URLConnection conn = url.openConnection();
            conn.connect();
            return conn.getInputStream();
        } else if (url.getProtocol().equals("https")) {
            if (creds != null) {
                GlobusGSSCredentialImpl cred = new GlobusGSSCredentialImpl(creds, GSSCredential.INITIATE_AND_ACCEPT);
                GSIHttpURLConnection connection = new GSIHttpURLConnection(url);
                connection.setGSSMode(GSIConstants.MODE_SSL);
                connection.setCredentials(cred);
                return connection.getInputStream();
            } else {
                throw new Exception("To use the https protocol to retrieve data from the Transfer Service you must have credentials");
            }
        }
        throw new Exception("Protocol " + url.getProtocol() + " not supported.");
    }