semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public File extractID3v2TagDataIntoFile(File outputFile) throws TagNotFoundException, IOException {
        int startByte = (int) ((MP3AudioHeader) audioHeader).getMp3StartByte();
        if (startByte >= 0) {
            FileInputStream fis = new FileInputStream(file);
            FileChannel fc = fis.getChannel();
            ByteBuffer bb = ByteBuffer.allocate(startByte);
            fc.read(bb);
            FileOutputStream out = new FileOutputStream(outputFile);
            out.write(bb.array());
            out.close();
            fc.close();
            fis.close();
            return outputFile;
        }
        throw new TagNotFoundException("There is no ID3v2Tag data in this file");
    }
public static EXISchema getEXISchema(String fileName, Class<?> cls, EXISchemaFactoryErrorHandler compilerErrorHandler) throws IOException, ClassNotFoundException, EXISchemaFactoryException {
        EXISchemaFactory schemaCompiler = new EXISchemaFactory();
        schemaCompiler.setCompilerErrorHandler(compilerErrorHandler);
        InputSource inputSource = null;
        if (fileName != null) {
            URL url;
            if ((url = cls.getResource(fileName)) != null) {
                inputSource = new InputSource(url.openStream());
                inputSource.setSystemId(url.toString());
            } else throw new RuntimeException("File '" + fileName + "' not found.");
        }
        EXISchema compiled = schemaCompiler.compile(inputSource);
        InputStream serialized = serializeSchema(compiled);
        return loadSchema(serialized);
    }
public static String checkPublicIP() {
        String ipAddress = null;
        try {
            URL url;
            url = new URL("http://checkip.dyndns.org/");
            InputStreamReader in = new InputStreamReader(url.openStream());
            BufferedReader buffer = new BufferedReader(in);
            String line;
            Pattern p = Pattern.compile("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b");
            while ((line = buffer.readLine()) != null) {
                if (line.indexOf("IP Address:") != -1) {
                    Matcher m = p.matcher(line);
                    if (m.find()) {
                        ipAddress = m.group();
                        break;
                    }
                }
            }
            buffer.close();
            in.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ipAddress;
    }
protected Reader getText() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
        String readLine;
        do {
            readLine = br.readLine();
        } while (readLine != null && readLine.indexOf("</table><br clear=all>") < 0);
        return br;
    }
private int streamConf() throws IOException {
        int avail = 0;
        switch(mode) {
            case FILE:
                if (!Helper.findInString(filename, ".jar")) {
                    is = new FileInputStream(filename);
                    bisr = new BufferedReader(new InputStreamReader(is, INPUT_CHARSET));
                } else {
                    is = Helper.getZipInput(filename.substring(0, filename.indexOf(".jar") + 4), filename.substring(filename.indexOf(".jar") + 5, filename.length()));
                    bisr = new BufferedReader(new InputStreamReader(is, INPUT_CHARSET));
                }
                break;
            case STREAM:
                bisr = new BufferedReader(new InputStreamReader(is, INPUT_CHARSET));
                break;
            case NET:
                is = url.openStream();
                bisr = new BufferedReader(new InputStreamReader(is, INPUT_CHARSET));
                break;
        }
        switch(mode) {
            case FILE:
            case STREAM:
                avail = is.available();
                break;
            case NET:
                while (is.read() != -1) avail++;
                bisr.close();
                is.close();
                is = url.openStream();
                bisr = new BufferedReader(new InputStreamReader(is, INPUT_CHARSET));
                break;
            case STRING:
                avail = fileStr.length();
                break;
        }
        return avail;
    }
@Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String dataSetURL = request.getParameter("datasetURL");
        String contentType = request.getParameter("contentType");
        String studyUID = request.getParameter("studyUID");
        String seriesUID = request.getParameter("seriesUID");
        String objectUID = request.getParameter("objectUID");
        dataSetURL += "&contentType=" + contentType + "&studyUID=" + studyUID + "&seriesUID=" + seriesUID + "&objectUID=" + objectUID;
        dataSetURL = dataSetURL.replace("+", "%2B");
        InputStream resultInStream = null;
        OutputStream resultOutStream = response.getOutputStream();
        try {
            URL url = new URL(dataSetURL);
            resultInStream = url.openStream();
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = resultInStream.read(buffer)) != -1) {
                resultOutStream.write(buffer, 0, bytes_read);
            }
            resultOutStream.flush();
            resultOutStream.close();
            resultInStream.close();
        } catch (Exception e) {
            log.error("Unable to read and send the DICOM dataset page", e);
        }
    }
public static String getEncryptedPassword(String password) throws PasswordException {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
            md.update(password.getBytes("UTF-8"));
        } catch (Exception e) {
            throw new PasswordException(e);
        }
        return convertToString(md.digest());
    }
public static void copy(File srcFile, File destFile) throws IOException {
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream(srcFile);
            out = new FileOutputStream(destFile);
            final byte[] buf = new byte[4096];
            int read;
            while ((read = in.read(buf)) >= 0) {
                out.write(buf, 0, read);
            }
        } finally {
            try {
                if (in != null) in.close();
            } catch (IOException ioe) {
            }
            try {
                if (out != null) out.close();
            } catch (IOException ioe) {
            }
        }
    }
private void displayDiffResults() throws IOException {
        File outFile = File.createTempFile("diff", ".htm");
        outFile.deleteOnExit();
        FileOutputStream outStream = new FileOutputStream(outFile);
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream));
        out.write("<html><head><title>LOC Differences</title>\n" + SCRIPT + "</head>\n" + "<body bgcolor='#ffffff'>\n" + "<div onMouseOver=\"window.defaultStatus='Metrics'\">\n");
        if (addedTable.length() > 0) {
            out.write("<table border><tr><th>Files Added:</th>" + "<th>Add</th><th>Type</th></tr>");
            out.write(addedTable.toString());
            out.write("</table><br><br>");
        }
        if (modifiedTable.length() > 0) {
            out.write("<table border><tr><th>Files Modified:</th>" + "<th>Base</th><th>Del</th><th>Mod</th><th>Add</th>" + "<th>Total</th><th>Type</th></tr>");
            out.write(modifiedTable.toString());
            out.write("</table><br><br>");
        }
        if (deletedTable.length() > 0) {
            out.write("<table border><tr><th>Files Deleted:</th>" + "<th>Del</th><th>Type</th></tr>");
            out.write(deletedTable.toString());
            out.write("</table><br><br>");
        }
        out.write("<table name=METRICS BORDER>\n");
        if (modifiedTable.length() > 0 || deletedTable.length() > 0) {
            out.write("<tr><td>Base:&nbsp;</td><td>");
            out.write(Long.toString(base));
            out.write("</td></tr>\n<tr><td>Deleted:&nbsp;</td><td>");
            out.write(Long.toString(deleted));
            out.write("</td></tr>\n<tr><td>Modified:&nbsp;</td><td>");
            out.write(Long.toString(modified));
            out.write("</td></tr>\n<tr><td>Added:&nbsp;</td><td>");
            out.write(Long.toString(added));
            out.write("</td></tr>\n<tr><td>New & Changed:&nbsp;</td><td>");
            out.write(Long.toString(added + modified));
            out.write("</td></tr>\n");
        }
        out.write("<tr><td>Total:&nbsp;</td><td>");
        out.write(Long.toString(total));
        out.write("</td></tr>\n</table></div>");
        redlinesOut.close();
        out.flush();
        InputStream redlines = new FileInputStream(redlinesTempFile);
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = redlines.read(buffer)) != -1) outStream.write(buffer, 0, bytesRead);
        outStream.write("</BODY></HTML>".getBytes());
        outStream.close();
        Browser.launch(outFile.toURL().toString());
    }
public boolean open() {
        try {
            URL url = new URL(resource);
            conn = url.openConnection();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        } catch (MalformedURLException e) {
            System.out.println("Uable to connect URL:" + resource);
            return false;
        } catch (IOException e) {
            System.out.println("IOExeption when connecting to URL" + resource);
            return false;
        }
        return true;
    }
private Bitmap fetchImage(String urlstr) throws Exception {
        URL url;
        url = new URL(urlstr);
        HttpURLConnection c = (HttpURLConnection) url.openConnection();
        c.setDoInput(true);
        c.setRequestProperty("User-Agent", "Agent");
        c.connect();
        InputStream is = c.getInputStream();
        Bitmap img;
        img = BitmapFactory.decodeStream(is);
        return img;
    }
String processURLInput(String inputURL) throws SoaplabException {
        try {
            File tmpFile = File.createTempFile("gowlab.", null);
            tmpFile.deleteOnExit();
            Object data = inputs.get(inputURL);
            URL url = new URL(data.toString());
            if (url.getProtocol().equals("file")) logAndThrow("Trying to get local file '" + url.toString() + "' is not allowed.");
            URLConnection uc = url.openConnection();
            uc.connect();
            InputStream in = uc.getInputStream();
            byte[] buffer = new byte[256];
            DataOutputStream fileout = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(tmpFile)));
            int bytesRead;
            while ((bytesRead = in.read(buffer)) != -1) {
                fileout.write(buffer, 0, bytesRead);
            }
            fileout.close();
            return tmpFile.getAbsolutePath();
        } catch (IOException e) {
            logAndThrow("In processURLData: " + e.toString());
        }
        return null;
    }
public static String md5(String value) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(value.getBytes());
            return bytesToString(messageDigest.digest());
        } catch (Exception ex) {
            Tools.logException(Tools.class, ex, value);
        }
        return value;
    }
public static void copy(File src, File dst) {
        try {
            FileChannel srcChannel = new FileInputStream(src).getChannel();
            FileChannel dstChannel = new FileOutputStream(dst).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            srcChannel = null;
            dstChannel.close();
            dstChannel = null;
        } catch (IOException ex) {
            Tools.logException(Tools.class, ex, dst.getAbsolutePath());
        }
    }
private File extractResource(String resourceName, File destDir) {
        File file = new File(destDir, resourceName);
        InputStream in = getClass().getResourceAsStream(resourceName);
        try {
            FileOutputStream out = FileUtils.openOutputStream(file);
            try {
                IOUtils.copy(in, out);
            } finally {
                if (out != null) {
                    out.close();
                }
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
        return file;
    }
@Before
    public void setUp() throws Exception {
        final URL url = getClass().getClassLoader().getResource("insecureSSL.keystore");
        final KeyStore keystore = KeyStore.getInstance("jks");
        final char[] pwd = "nopassword".toCharArray();
        keystore.load(url.openStream(), pwd);
        final TrustManagerFactory trustManagerFactory = createTrustManagerFactory();
        trustManagerFactory.init(keystore);
        final TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
        final KeyManagerFactory keyManagerFactory = createKeyManagerFactory();
        keyManagerFactory.init(keystore, pwd);
        final KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
        final SSLContext serverSSLContext = SSLContext.getInstance("TLS");
        serverSSLContext.init(keyManagers, trustManagers, null);
        localServer_ = new LocalTestServer(serverSSLContext);
        localServer_.registerDefaultHandlers();
        localServer_.start();
    }
public void sendRequest(String method) {
        try {
            url = new URL(urlStr);
            httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setRequestMethod(method);
            httpURLConnection.setDoOutput(true);
            httpURLConnection.getOutputStream().flush();
            httpURLConnection.getOutputStream().close();
            System.out.println(httpURLConnection.getResponseMessage());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (httpURLConnection != null) {
                httpURLConnection.disconnect();
            }
        }
    }
public static void readConfigFromResource(String resname) throws Exception {
        URL url = ConfigXMLReader.class.getClassLoader().getResource(resname);
        if (url == null) throw new FileNotFoundException("Couldn't find the config resource:" + resname);
        System.out.println("Reading config from resource: " + url.toString());
        readConfig(url.openStream());
    }
private InputStream open(String url) throws IOException {
        debug(url);
        if (!useCache) {
            return new URL(url).openStream();
        }
        File f = new File(System.getProperty("java.io.tmpdir", "."), Digest.SHA1.encrypt(url) + ".xml");
        debug("Cache : " + f);
        if (f.exists()) {
            return new FileInputStream(f);
        }
        InputStream in = new URL(url).openStream();
        OutputStream out = new FileOutputStream(f);
        IOUtils.copyTo(in, out);
        out.flush();
        out.close();
        in.close();
        return new FileInputStream(f);
    }
public static void copy(FileInputStream source, FileOutputStream target) throws IOException {
        FileChannel sourceChannel = source.getChannel();
        FileChannel targetChannel = target.getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
        sourceChannel.close();
        targetChannel.close();
    }
public final InputStream getStreamFromUrl(final URL url) {
        try {
            if (listener != null) {
                listener.openedStream(url);
            }
            return url.openStream();
        } catch (IOException e) {
            listener.exceptionThrown(e);
            return null;
        }
    }
public static void copyFile(File fromFile, File toFile) throws OWFileCopyException {
        try {
            FileChannel src = new FileInputStream(fromFile).getChannel();
            FileChannel dest = new FileOutputStream(toFile).getChannel();
            dest.transferFrom(src, 0, src.size());
            src.close();
            dest.close();
        } catch (IOException e) {
            throw (new OWFileCopyException("An error occurred while copying a file", e));
        }
    }
private void addMaintainerScripts(TarOutputStream tar, PackageInfo info) throws IOException, ScriptDataTooLargeException {
        for (final MaintainerScript script : info.getMaintainerScripts().values()) {
            if (script.getSize() > Integer.MAX_VALUE) {
                throw new ScriptDataTooLargeException("The script data is too large for the tar file. script=[" + script.getType().getFilename() + "].");
            }
            final TarEntry entry = standardEntry(script.getType().getFilename(), UnixStandardPermissions.EXECUTABLE_FILE_MODE, (int) script.getSize());
            tar.putNextEntry(entry);
            IOUtils.copy(script.getStream(), tar);
            tar.closeEntry();
        }
    }
public boolean config(URL url, boolean throwsException) throws IllegalArgumentException {
        try {
            final MetaRoot conf = UjoManagerXML.getInstance().parseXML(new BufferedInputStream(url.openStream()), MetaRoot.class, this);
            config(conf);
            return true;
        } catch (Exception e) {
            if (throwsException) {
                throw new IllegalArgumentException("Configuration file is not valid ", e);
            } else {
                return false;
            }
        }
    }
private void getPage(final String path, final String dataToSend, final GetPageCallback callback) {
        runner.add(new Runnable() {

            @Override
            public void run() {
                String url = "http://" + resources.getString(R.string.host) + path;
                HttpUriRequest req;
                if (dataToSend == null) {
                    req = new HttpGet(url);
                } else {
                    req = new HttpPost(url);
                    try {
                        ((HttpPost) req).setEntity(new StringEntity(dataToSend));
                    } catch (UnsupportedEncodingException e) {
                        Logger.getLogger(JSBridge.class.getName()).log(Level.SEVERE, "Unsupported encoding.", e);
                    }
                }
                req.addHeader("Cookie", getAuthCookie(false));
                try {
                    HttpResponse response = httpclient.execute(req);
                    Logger.getLogger(JSBridge.class.getName()).log(Level.INFO, "Response status is '" + response.getStatusLine() + "'.");
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        InputStream instream = entity.getContent();
                        try {
                            BufferedReader in = new BufferedReader(new InputStreamReader(instream));
                            StringBuilder b = new StringBuilder();
                            String line;
                            boolean first = true;
                            while ((line = in.readLine()) != null) {
                                b.append(line);
                                if (first) {
                                    first = false;
                                } else {
                                    b.append("\r\n");
                                }
                            }
                            in.close();
                            callback.success(b.toString());
                            return;
                        } catch (RuntimeException ex) {
                            throw ex;
                        } finally {
                            instream.close();
                        }
                    }
                } catch (ClientProtocolException e) {
                    Logger.getLogger(JSBridge.class.getName()).log(Level.SEVERE, "HTTP protocol violated.", e);
                } catch (IOException e) {
                    Logger.getLogger(JSBridge.class.getName()).log(Level.WARNING, "Could not load '" + path + "'.", e);
                }
                Logger.getLogger(JSBridge.class.getName()).log(Level.INFO, "Calling error from JSBridge.getPage because of previous errors.");
                callback.error();
            }
        });
    }
@Override
            public void run() {
                String url = "http://" + resources.getString(R.string.host) + path;
                HttpUriRequest req;
                if (dataToSend == null) {
                    req = new HttpGet(url);
                } else {
                    req = new HttpPost(url);
                    try {
                        ((HttpPost) req).setEntity(new StringEntity(dataToSend));
                    } catch (UnsupportedEncodingException e) {
                        Logger.getLogger(JSBridge.class.getName()).log(Level.SEVERE, "Unsupported encoding.", e);
                    }
                }
                req.addHeader("Cookie", getAuthCookie(false));
                try {
                    HttpResponse response = httpclient.execute(req);
                    Logger.getLogger(JSBridge.class.getName()).log(Level.INFO, "Response status is '" + response.getStatusLine() + "'.");
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        InputStream instream = entity.getContent();
                        try {
                            BufferedReader in = new BufferedReader(new InputStreamReader(instream));
                            StringBuilder b = new StringBuilder();
                            String line;
                            boolean first = true;
                            while ((line = in.readLine()) != null) {
                                b.append(line);
                                if (first) {
                                    first = false;
                                } else {
                                    b.append("\r\n");
                                }
                            }
                            in.close();
                            callback.success(b.toString());
                            return;
                        } catch (RuntimeException ex) {
                            throw ex;
                        } finally {
                            instream.close();
                        }
                    }
                } catch (ClientProtocolException e) {
                    Logger.getLogger(JSBridge.class.getName()).log(Level.SEVERE, "HTTP protocol violated.", e);
                } catch (IOException e) {
                    Logger.getLogger(JSBridge.class.getName()).log(Level.WARNING, "Could not load '" + path + "'.", e);
                }
                Logger.getLogger(JSBridge.class.getName()).log(Level.INFO, "Calling error from JSBridge.getPage because of previous errors.");
                callback.error();
            }