semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void copyFile(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileOutputStream fos = new FileOutputStream(out);
        FileChannel outChannel = fos.getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
            fos.flush();
            fos.close();
        }
    }
private static int computeNativesHash() {
        try {
            String classpath = System.getProperty("java.class.path");
            URL url = Thread.currentThread().getContextClassLoader().getResource("com/jme3/system/Natives.class");
            StringBuilder sb = new StringBuilder(url.toString());
            if (sb.indexOf("jar:") == 0) {
                sb.delete(0, 4);
                sb.delete(sb.indexOf("!"), sb.length());
                sb.delete(sb.lastIndexOf("/") + 1, sb.length());
            }
            try {
                url = new URL(sb.toString());
            } catch (MalformedURLException ex) {
                throw new UnsupportedOperationException(ex);
            }
            URLConnection conn = url.openConnection();
            int hash = classpath.hashCode() ^ (int) conn.getLastModified();
            return hash;
        } catch (IOException ex) {
            throw new UnsupportedOperationException(ex);
        }
    }
public static void extractNativeLib(String sysName, String name, boolean load, boolean warning) throws IOException {
        String fullname = System.mapLibraryName(name);
        String path = "native/" + sysName + "/" + fullname;
        URL url = Thread.currentThread().getContextClassLoader().getResource(path);
        if (url == null) {
            if (!warning) {
                logger.log(Level.WARNING, "Cannot locate native library: {0}/{1}", new String[] { sysName, fullname });
            }
            return;
        }
        URLConnection conn = url.openConnection();
        InputStream in = conn.getInputStream();
        File targetFile = new File(getExtractionDir(), fullname);
        OutputStream out = null;
        try {
            if (targetFile.exists()) {
                long targetLastModified = targetFile.lastModified();
                long sourceLastModified = conn.getLastModified();
                if (targetLastModified + 1000 > sourceLastModified) {
                    logger.log(Level.FINE, "Not copying library {0}. Latest already extracted.", fullname);
                    return;
                }
            }
            out = new FileOutputStream(targetFile);
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            in = null;
            out.close();
            out = null;
            targetFile.setLastModified(conn.getLastModified());
        } catch (FileNotFoundException ex) {
            if (ex.getMessage().contains("used by another process")) {
                return;
            }
            throw ex;
        } finally {
            if (load) {
                System.load(targetFile.getAbsolutePath());
            }
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
        logger.log(Level.FINE, "Copied {0} to {1}", new Object[] { fullname, targetFile });
    }
public List<String> getLinks(String url) {
        List<String> links = new ArrayList<String>();
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
            String s;
            StringBuilder builder = new StringBuilder();
            while ((s = bufferedReader.readLine()) != null) {
                builder.append(s);
            }
            Matcher tagmatch = htmltag.matcher(builder.toString());
            while (tagmatch.find()) {
                Matcher matcher = link.matcher(tagmatch.group());
                matcher.find();
                String link = matcher.group().replaceFirst("href=\"", "").replaceFirst("\">", "");
                if (valid(link)) {
                    links.add(makeAbsolute(url, link));
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return links;
    }
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String contentType = req.getParameter("type");
        String arg = req.getParameter("file");
        if (arg == null) {
            resp.sendError(404, "Missing File Arg");
            return;
        }
        File f = new File(arg);
        if (!f.exists()) {
            resp.sendError(404, "Missing File: " + f);
            return;
        }
        if (contentType != null) {
            resp.setContentType(contentType);
        }
        log.debug("Requested File: " + f + " as type: " + contentType);
        resp.setContentLength((int) f.length());
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            OutputStream os = resp.getOutputStream();
            IOUtils.copyLarge(fis, os);
            os.flush();
            fis.close();
        } catch (Throwable e) {
            log.error("Failed to send file: " + f);
            resp.sendError(500, "Failed to get file " + f);
        } finally {
            IOUtils.closeQuietly(fis);
        }
    }
private void readFromFile1() throws DException {
        URL url1 = null;
        if (url == null) {
            url = getClass().getResource("/com/daffodilwoods/daffodildb/utils/parser/parser.schema");
            try {
                url = new URL(url.getProtocol() + ":" + url.getPath().substring(0, url.getPath().indexOf("/parser.schema")));
            } catch (MalformedURLException ex2) {
                ex2.printStackTrace();
                throw new DException("DSE0", new Object[] { ex2 });
            }
            try {
                url1 = new URL(url.getProtocol() + ":" + url.getPath() + "/parser.schema");
            } catch (MalformedURLException ex) {
                throw new DException("DSE0", new Object[] { ex });
            }
            if (url1 == null) {
                throw new DException("DSE0", new Object[] { "Parser.schema file is missing in classpath." });
            }
        } else {
            try {
                url1 = new URL(url.getProtocol() + ":" + url.getPath() + "/parser.schema");
            } catch (MalformedURLException ex) {
                throw new DException("DSE0", new Object[] { ex });
            }
        }
        ArrayList arr1 = null;
        StringBuffer rule = null;
        try {
            LineNumberReader raf = new LineNumberReader(new BufferedReader(new InputStreamReader(url1.openStream())));
            arr1 = new ArrayList();
            rule = new StringBuffer("");
            while (true) {
                String str1 = raf.readLine();
                if (str1 == null) {
                    break;
                }
                String str = str1.trim();
                if (str.length() == 0) {
                    if (rule.length() > 0) {
                        arr1.add(rule.toString());
                    }
                    rule = new StringBuffer("");
                } else {
                    rule.append(" ").append(str);
                }
            }
            raf.close();
        } catch (IOException ex1) {
            ex1.printStackTrace();
            throw new DException("DSE0", new Object[] { ex1 });
        }
        if (rule.length() > 0) arr1.add(rule.toString());
        for (int i = 0; i < arr1.size(); i++) {
            String str = (String) arr1.get(i);
            int index = str.indexOf("::=");
            if (index == -1) {
                P.pln("Error " + str);
                throw new DException("DSE0", new Object[] { "Rule is missing from parser.schema" });
            }
            String key = str.substring(0, index).trim();
            String value = str.substring(index + 3).trim();
            Object o = fileEntries.put(key, value);
            if (o != null) {
                new Exception("Duplicate Defination for Rule [" + key + "] Value [" + value + "] Is Replaced By  [" + o + "]").printStackTrace();
            }
        }
    }
private CExtractHelper getData(String p_url) {
        CExtractHelper l_extractHelper = new CExtractHelper();
        URL l_url;
        HttpURLConnection l_connection;
        try {
            System.out.println("Getting [" + p_url + "]");
            l_url = new URL(p_url);
            try {
                URLConnection l_uconn = l_url.openConnection();
                l_connection = (HttpURLConnection) l_uconn;
                l_connection.setConnectTimeout(2000);
                l_connection.setReadTimeout(2000);
                l_connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
                l_connection.connect();
                int l_responseCode = l_connection.getResponseCode();
                String response = l_connection.getResponseMessage();
                System.out.println("HTTP/1.x " + l_responseCode + " " + response);
                for (int j = 1; ; j++) {
                    String l_header = l_connection.getHeaderField(j);
                    String l_key = l_connection.getHeaderFieldKey(j);
                    if (l_header == null || l_key == null) {
                        break;
                    }
                }
                InputStream l_inputStream = new BufferedInputStream(l_connection.getInputStream());
                CRemoteXML l_parser = new CRemoteXML();
                try {
                    Document l_document = l_parser.parse(l_inputStream);
                    PrintWriter l_writerOut = new PrintWriter(new OutputStreamWriter(System.out, charsetName), true);
                    OutputFormat l_format = OutputFormat.createPrettyPrint();
                    XMLWriter l_xmlWriter = new XMLWriter(l_writerOut, l_format);
                    l_xmlWriter.write(l_document);
                    l_xmlWriter.flush();
                    l_connection.disconnect();
                    l_extractHelper.m_document = l_document;
                    return l_extractHelper;
                } catch (DocumentException e) {
                    e.printStackTrace();
                    l_connection.disconnect();
                    System.out.println("XML parsing issue");
                    l_extractHelper.m_generalFailure = true;
                }
            } catch (SocketTimeoutException e) {
                l_extractHelper.m_timeoutFailure = true;
                System.out.println("Timed out");
            } catch (IOException e) {
                e.printStackTrace();
                l_extractHelper.m_generalFailure = true;
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
            l_extractHelper.m_generalFailure = true;
        }
        return l_extractHelper;
    }
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mButton1 = (Button) findViewById(R.id.myButton1);
        mButton2 = (Button) findViewById(R.id.myButton2);
        mTextView1 = (TextView) findViewById(R.id.myTextView1);
        mButton1.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {
                String uriAPI = "http://www.sina.com";
                HttpPost httpRequest = new HttpPost(uriAPI);
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("str", "post string"));
                try {
                    httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
                    HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
                    if (httpResponse.getStatusLine().getStatusCode() == 200) {
                        String strResult = EntityUtils.toString(httpResponse.getEntity());
                        mTextView1.setText(strResult);
                    } else {
                        mTextView1.setText("Error Response: " + httpResponse.getStatusLine().toString());
                    }
                } catch (ClientProtocolException e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                } catch (IOException e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                } catch (Exception e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                }
            }
        });
        mButton2.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {
                String uriAPI = "http://www.sina.com";
                HttpGet httpRequest = new HttpGet(uriAPI);
                try {
                    HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
                    if (httpResponse.getStatusLine().getStatusCode() == 200) {
                        String strResult = EntityUtils.toString(httpResponse.getEntity());
                        strResult = eregi_replace("(\r\n|\r|\n|\n\r)", "", strResult);
                        mTextView1.setText(strResult);
                    } else {
                        mTextView1.setText("Error Response: " + httpResponse.getStatusLine().toString());
                    }
                } catch (ClientProtocolException e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                } catch (IOException e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                } catch (Exception e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                }
            }
        });
    }
public void onClick(View v) {
                String uriAPI = "http://www.sina.com";
                HttpPost httpRequest = new HttpPost(uriAPI);
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("str", "post string"));
                try {
                    httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
                    HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
                    if (httpResponse.getStatusLine().getStatusCode() == 200) {
                        String strResult = EntityUtils.toString(httpResponse.getEntity());
                        mTextView1.setText(strResult);
                    } else {
                        mTextView1.setText("Error Response: " + httpResponse.getStatusLine().toString());
                    }
                } catch (ClientProtocolException e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                } catch (IOException e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                } catch (Exception e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                }
            }
public void onClick(View v) {
                String uriAPI = "http://www.sina.com";
                HttpGet httpRequest = new HttpGet(uriAPI);
                try {
                    HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
                    if (httpResponse.getStatusLine().getStatusCode() == 200) {
                        String strResult = EntityUtils.toString(httpResponse.getEntity());
                        strResult = eregi_replace("(\r\n|\r|\n|\n\r)", "", strResult);
                        mTextView1.setText(strResult);
                    } else {
                        mTextView1.setText("Error Response: " + httpResponse.getStatusLine().toString());
                    }
                } catch (ClientProtocolException e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                } catch (IOException e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                } catch (Exception e) {
                    mTextView1.setText(e.getMessage().toString());
                    e.printStackTrace();
                }
            }
public static void main(String[] args) {
        if (args.length != 2) {
            printUsage();
        }
        String url = args[0];
        String path = args[1];
        BufferedReader pbsFileReader = null;
        try {
            pbsFileReader = new BufferedReader(new FileReader(path));
        } catch (FileNotFoundException ex) {
            System.err.println("Pbs file " + path + " not found");
            System.exit(1);
        }
        String line = "";
        HttpURLConnection conn = null;
        BufferedWriter out = null;
        BufferedReader in = null;
        try {
            conn = (HttpURLConnection) new URL(url).openConnection();
            conn.setDoOutput(true);
            out = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
            while (true) {
                line = pbsFileReader.readLine();
                if (line == null) {
                    break;
                }
                out.write(line);
                out.newLine();
                System.err.println(line);
            }
            in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            line = "";
            while (true) {
                line = in.readLine();
                if (line == null) {
                    break;
                }
                System.out.println(line);
            }
            out.close();
            in.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public Manifest(URL url) throws IOException {
        if (!url.getProtocol().equals("jar")) {
            url = new URL("jar:" + url.toExternalForm() + "!/");
        }
        JarURLConnection uc = (JarURLConnection) url.openConnection();
        setManifest(uc.getManifest());
    }
public String digest(String message) throws NoSuchAlgorithmException, EncoderException {
        MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
        messageDigest.update(message.getBytes());
        byte[] raw = messageDigest.digest();
        byte[] chars = new Base64().encode(raw);
        return new String(chars);
    }
@SuppressWarnings("rawtypes")
    public static String[] loadAllPropertiesFromClassLoader(Properties properties, String... resourceNames) throws IOException {
        List successLoadProperties = new ArrayList();
        for (String resourceName : resourceNames) {
            URL url = GeneratorProperties.class.getResource(resourceName);
            if (url != null) {
                successLoadProperties.add(url.getFile());
                InputStream input = null;
                try {
                    URLConnection con = url.openConnection();
                    con.setUseCaches(false);
                    input = con.getInputStream();
                    if (resourceName.endsWith(".xml")) {
                        properties.loadFromXML(input);
                    } else {
                        properties.load(input);
                    }
                } finally {
                    if (input != null) {
                        input.close();
                    }
                }
            }
        }
        return (String[]) successLoadProperties.toArray(new String[0]);
    }
@TestTargetNew(level = TestLevel.COMPLETE, notes = "", method = "getJarFile", args = {  })
    public void test_getJarFile() throws MalformedURLException, IOException {
        URL url = null;
        url = createContent("lf.jar", "missing");
        JarURLConnection connection = null;
        connection = (JarURLConnection) url.openConnection();
        try {
            connection.connect();
            fail("Did not throw exception on connect");
        } catch (IOException e) {
        }
        try {
            connection.getJarFile();
            fail("Did not throw exception after connect");
        } catch (IOException e) {
        }
        URL invURL = createContent("InvalidJar.jar", "Test.class");
        JarURLConnection juConn = (JarURLConnection) invURL.openConnection();
        try {
            juConn.getJarFile();
            fail("IOException was not thrown.");
        } catch (java.io.IOException io) {
        }
        File resources = Support_Resources.createTempFolder();
        Support_Resources.copyFile(resources, null, "hyts_att.jar");
        File file = new File(resources.toString() + "/hyts_att.jar");
        URL fUrl1 = new URL("jar:file:" + file.getPath() + "!/");
        JarURLConnection con1 = (JarURLConnection) fUrl1.openConnection();
        ZipFile jf1 = con1.getJarFile();
        JarURLConnection con2 = (JarURLConnection) fUrl1.openConnection();
        ZipFile jf2 = con2.getJarFile();
        assertTrue("file: JarFiles not the same", jf1 == jf2);
        jf1.close();
        assertTrue("File should exist", file.exists());
        fUrl1 = createContent("lf.jar", "");
        con1 = (JarURLConnection) fUrl1.openConnection();
        jf1 = con1.getJarFile();
        con2 = (JarURLConnection) fUrl1.openConnection();
        jf2 = con2.getJarFile();
        assertTrue("http: JarFiles not the same", jf1 == jf2);
        jf1.close();
    }
@TestTargetNew(level = TestLevel.PARTIAL, notes = "Exceptions checking missed.", method = "setUseCaches", args = { boolean.class })
    public void test_setUseCaches() throws Exception {
        File resources = Support_Resources.createTempFolder();
        Support_Resources.copyFile(resources, null, "hyts_att.jar");
        File file = new File(resources.toString() + "/hyts_att.jar");
        URL url = new URL("jar:file:" + file.getPath() + "!/HasAttributes.txt");
        JarURLConnection connection = (JarURLConnection) url.openConnection();
        connection.setUseCaches(false);
        InputStream in = connection.getInputStream();
        in = connection.getInputStream();
        JarFile jarFile1 = connection.getJarFile();
        JarEntry jarEntry1 = connection.getJarEntry();
        in.read();
        in.close();
        JarFile jarFile2 = connection.getJarFile();
        JarEntry jarEntry2 = connection.getJarEntry();
        assertSame(jarFile1, jarFile2);
        assertSame(jarEntry1, jarEntry2);
        try {
            connection.getInputStream();
            fail("should throw IllegalStateException");
        } catch (IllegalStateException e) {
        }
    }
@TestTargetNew(level = TestLevel.COMPLETE, notes = "", method = "getJarFileURL", args = {  })
    public void test_getJarFileURL() throws Exception {
        URL u = createContent("lf.jar", "plus.bmp");
        URL fileURL = new URL(u.getPath().substring(0, u.getPath().indexOf("!")));
        juc = (JarURLConnection) u.openConnection();
        assertTrue("Returned incorrect file URL", juc.getJarFileURL().equals(fileURL));
        URL url = new URL("jar:file:///bar.jar!/foo.jar!/Bugs/HelloWorld.class");
        assertEquals("file:/bar.jar", ((JarURLConnection) url.openConnection()).getJarFileURL().toString());
    }