semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static long copy(InputStream source, OutputStream sink) {
        try {
            return IOUtils.copyLarge(source, sink);
        } catch (IOException e) {
            logger.error(e.toString(), e);
            throw new FaultException("System error copying stream", e);
        } finally {
            IOUtils.closeQuietly(source);
            IOUtils.closeQuietly(sink);
        }
    }
private void playAudio(String mediaUrl) {
        try {
            URLConnection cn = new URL(mediaUrl).openConnection();
            InputStream is = cn.getInputStream();
            mediaFile = new File(this.getCacheDir(), "mediafile");
            FileOutputStream fos = new FileOutputStream(mediaFile);
            byte buf[] = new byte[16 * 1024];
            Log.i("FileOutputStream", "Download");
            do {
                int numread = is.read(buf);
                if (numread <= 0) break;
                fos.write(buf, 0, numread);
            } while (true);
            fos.flush();
            fos.close();
            Log.i("FileOutputStream", "Saved");
            MediaPlayer.OnCompletionListener listener = new MediaPlayer.OnCompletionListener() {

                public void onCompletion(MediaPlayer mp) {
                    mp.release();
                    Log.i("MediaPlayer.OnCompletionListener", "MediaPlayer Released");
                }
            };
            mixPlayer.setOnCompletionListener(listener);
            FileInputStream fis = new FileInputStream(mediaFile);
            mixPlayer.setDataSource(fis.getFD());
            mixPlayer.prepare();
            Log.i("MediaPlayer", "Start Player");
            loading = false;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static void copyFileTo(String destFileName, String resourceFileName) {
        if (destFileName == null || resourceFileName == null) throw new IllegalArgumentException("Argument cannot be null.");
        try {
            FileInputStream in = null;
            FileOutputStream out = null;
            File resourceFile = new File(resourceFileName);
            if (!resourceFile.isFile()) {
                System.out.println(resourceFileName + " cannot be opened.");
                return;
            }
            in = new FileInputStream(resourceFile);
            out = new FileOutputStream(new File(destFileName));
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
public static void copyResourceFileTo(String destFileName, String resourceFileName) {
        if (destFileName == null || resourceFileName == null) throw new IllegalArgumentException("Argument cannot be null.");
        try {
            FileInputStream in = null;
            FileOutputStream out = null;
            URL url = HelperMethods.class.getResource(resourceFileName);
            if (url == null) {
                System.out.println("URL " + resourceFileName + " cannot be created.");
                return;
            }
            String fileName = url.getFile();
            fileName = fileName.replaceAll("%20", " ");
            File resourceFile = new File(fileName);
            if (!resourceFile.isFile()) {
                System.out.println(fileName + " cannot be opened.");
                return;
            }
            in = new FileInputStream(resourceFile);
            out = new FileOutputStream(new File(destFileName));
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            String act = request.getParameter("act");
            if (null == act) {
            } else if ("down".equalsIgnoreCase(act)) {
                String vest = request.getParameter("vest");
                String id = request.getParameter("id");
                if (null == vest) {
                    t_attach_Form attach = null;
                    t_attach_QueryMap query = new t_attach_QueryMap();
                    attach = query.getByID(id);
                    if (null != attach) {
                        String filename = attach.getAttach_name();
                        String fullname = attach.getAttach_fullname();
                        response.addHeader("Content-Disposition", "attachment;filename=" + filename + "");
                        File file = new File(fullname);
                        if (file.exists()) {
                            java.io.FileInputStream in = new FileInputStream(file);
                            org.apache.commons.io.IOUtils.copy(in, response.getOutputStream());
                        }
                    }
                } else if ("review".equalsIgnoreCase(vest)) {
                    t_infor_review_QueryMap reviewQuery = new t_infor_review_QueryMap();
                    t_infor_review_Form review = reviewQuery.getByID(id);
                    String seq = request.getParameter("seq");
                    String name = null, fullname = null;
                    if ("1".equals(seq)) {
                        name = review.getAttachname1();
                        fullname = review.getAttachfullname1();
                    } else if ("2".equals(seq)) {
                        name = review.getAttachname2();
                        fullname = review.getAttachfullname2();
                    } else if ("3".equals(seq)) {
                        name = review.getAttachname3();
                        fullname = review.getAttachfullname3();
                    }
                    String downTypeStr = DownType.getInst().getDownTypeByFileName(name);
                    logger.debug("filename=" + name + " downtype=" + downTypeStr);
                    response.setContentType(downTypeStr);
                    response.addHeader("Content-Disposition", "attachment;filename=" + name + "");
                    File file = new File(fullname);
                    if (file.exists()) {
                        java.io.FileInputStream in = new FileInputStream(file);
                        org.apache.commons.io.IOUtils.copy(in, response.getOutputStream());
                        in.close();
                    }
                }
            } else if ("upload".equalsIgnoreCase(act)) {
                String infoId = request.getParameter("inforId");
                logger.debug("infoId=" + infoId);
            }
        } catch (Exception e) {
        }
    }
@SuppressWarnings({ "ProhibitedExceptionDeclared" })
    public int run(@NotNull final List<String> args) throws Exception {
        int returnCode = 0;
        if (args.size() == 0) {
            log(Level.SEVERE, "noarguments");
            returnCode++;
        }
        final byte[] buf = new byte[BUF_SIZE];
        for (final String arg : args) {
            try {
                final URL url = new URL(arg);
                final URLConnection con = url.openConnection();
                final InputStream in = con.getInputStream();
                try {
                    final String location = con.getHeaderField("Content-Location");
                    final String outputFilename = new File((location != null ? new URL(url, location) : url).getFile()).getName();
                    log(Level.INFO, "writing", arg, outputFilename);
                    final OutputStream out = new FileOutputStream(outputFilename);
                    try {
                        for (int bytesRead; (bytesRead = in.read(buf)) != -1; ) {
                            out.write(buf, 0, bytesRead);
                        }
                    } finally {
                        out.close();
                    }
                } finally {
                    in.close();
                }
            } catch (final IOException e) {
                log(Level.WARNING, "cannotopen", arg, e);
                returnCode++;
            }
        }
        return returnCode;
    }
public static String getServiceContent(String serviceURL) throws IOException {
        URL url = new URL(serviceURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();
        int code = connection.getResponseCode();
        if (code == HttpURLConnection.HTTP_OK) {
            InputStream is = connection.getInputStream();
            byte[] buffer = null;
            String stringBuffer = "";
            buffer = new byte[4096];
            int totBytes, bytes, sumBytes = 0;
            totBytes = connection.getContentLength();
            while (true) {
                bytes = is.read(buffer);
                if (bytes <= 0) break;
                stringBuffer = stringBuffer + new String(buffer);
            }
            return stringBuffer;
        }
        return null;
    }
public static String postServiceContent(String serviceURL, String text) throws IOException {
        URL url = new URL(serviceURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.connect();
        int code = connection.getResponseCode();
        if (code == HttpURLConnection.HTTP_OK) {
            InputStream is = connection.getInputStream();
            byte[] buffer = null;
            String stringBuffer = "";
            buffer = new byte[4096];
            int totBytes, bytes, sumBytes = 0;
            totBytes = connection.getContentLength();
            while (true) {
                bytes = is.read(buffer);
                if (bytes <= 0) break;
                stringBuffer = stringBuffer + new String(buffer);
            }
            return stringBuffer;
        }
        return null;
    }
public static void sendPostRequest() {
        String data = "text=Eschirichia coli";
        try {
            URL url = new URL("http://taxonfinder.ubio.org/analyze?");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
            writer.write(data);
            writer.flush();
            StringBuffer answer = new StringBuffer();
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                answer.append(line);
            }
            writer.close();
            reader.close();
            System.out.println(answer.toString());
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
public static void copyFile(File from, File to) throws IOException {
        ensureFile(to);
        FileChannel srcChannel = new FileInputStream(from).getChannel();
        FileChannel dstChannel = new FileOutputStream(to).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
public void testReleaseConnectionOnAbort() throws Exception {
        HttpParams mgrpar = defaultParams.copy();
        ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
        ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, null);
        final HttpHost target = getServerHttp();
        final HttpRoute route = new HttpRoute(target, null, false);
        final int rsplen = 8;
        final String uri = "/random/" + rsplen;
        HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
        ManagedClientConnection conn = getConnection(mgr, route);
        conn.open(route, httpContext, defaultParams);
        HttpResponse response = Helper.execute(request, conn, target, httpExecutor, httpProcessor, defaultParams, httpContext);
        assertEquals("wrong status in first response", HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        try {
            getConnection(mgr, route, 100L, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (ConnectionPoolTimeoutException e) {
        }
        assertTrue(conn instanceof AbstractClientConnAdapter);
        ((AbstractClientConnAdapter) conn).abortConnection();
        conn = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
        assertFalse("connection should have been closed", conn.isOpen());
        mgr.releaseConnection(conn, -1, null);
        mgr.shutdown();
    }
public void testConnectionManagerGC() throws Exception {
        ThreadSafeClientConnManager mgr = createTSCCM(null, null);
        final HttpHost target = getServerHttp();
        final HttpRoute route = new HttpRoute(target, null, false);
        final int rsplen = 8;
        final String uri = "/random/" + rsplen;
        HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
        ManagedClientConnection conn = getConnection(mgr, route);
        conn.open(route, httpContext, defaultParams);
        HttpResponse response = Helper.execute(request, conn, target, httpExecutor, httpProcessor, defaultParams, httpContext);
        EntityUtils.toByteArray(response.getEntity());
        conn.markReusable();
        mgr.releaseConnection(conn, -1, null);
        WeakReference<ThreadSafeClientConnManager> wref = new WeakReference<ThreadSafeClientConnManager>(mgr);
        mgr = null;
        System.gc();
        Thread.sleep(1000);
        assertNull("TSCCM not garbage collected", wref.get());
    }
public String download(String urlString) {
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = null;
        try {
            URL url = new URL(urlString);
            HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
            reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } catch (MalformedURLException e) {
            Log.e("exception", e.getMessage());
        } catch (IOException e) {
            Log.e("exception", e.getMessage());
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                Log.e("exception", e.getMessage());
            }
        }
        return builder.toString();
    }
private String hashmd5(String suppliedPassword) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(suppliedPassword.getBytes());
        String encriptedPassword = null;
        try {
            encriptedPassword = new String(Base64.encode(md.digest()), "ASCII");
        } catch (UnsupportedEncodingException e) {
        }
        return encriptedPassword;
    }
@Primitive
    public static Value caml_md5_string(final CodeRunner ctxt, final Value str, final Value ofs, final Value len) throws Fail.Exception {
        try {
            final MessageDigest md5 = MessageDigest.getInstance(Md5.ALGO);
            md5.update(str.asBlock().getBytes(), ofs.asLong(), len.asLong());
            return Value.createFromBlock(Block.createString(md5.digest()));
        } catch (final NoSuchAlgorithmException nsae) {
            Fail.invalidArgument("Digest.substring");
            return Value.UNIT;
        }
    }
private void createPolicy(String policyName) throws SPLException {
        URL url = getClass().getResource(policyName + ".spl");
        StringBuffer contents = new StringBuffer();
        try {
            BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = null;
            while ((line = input.readLine()) != null) {
                contents.append(line);
                contents.append(System.getProperty("line.separator"));
            }
            input.close();
            System.out.println(policyName);
            System.out.println(contents.toString());
            boolean createReturn = jspl.createPolicy(policyName, contents.toString());
            System.out.println("Policy Created : " + policyName + " - " + createReturn);
            System.out.println("");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
public boolean copyDirectoryTree(File srcPath, File dstPath) {
        try {
            if (srcPath.isDirectory()) {
                if (!dstPath.exists()) dstPath.mkdir();
                String files[] = srcPath.list();
                for (int i = 0; i < files.length; i++) copyDirectoryTree(new File(srcPath, files[i]), new File(dstPath, files[i]));
            } else {
                if (!srcPath.exists()) {
                    errMsgLog += "copyDirectoryTree I/O error from '" + srcPath + "' does not exist.\n";
                    lastErrMsgLog = errMsgLog;
                    return (false);
                } else {
                    InputStream in = new FileInputStream(srcPath);
                    OutputStream out = new FileOutputStream(dstPath);
                    byte[] buf = new byte[10240];
                    int len;
                    while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
                    in.close();
                    out.close();
                }
            }
            return (true);
        } catch (Exception e) {
            errMsgLog += "copyDirectoryTree I/O error from '" + srcPath.getName() + "' to '" + dstPath.getName() + "\n  " + e + "\n";
            lastErrMsgLog = errMsgLog;
            return (false);
        }
    }
private boolean cacheUrlFile(String filePath, String realUrl, boolean isOnline) {
        try {
            URL url = new URL(realUrl);
            String encoding = "gbk";
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), encoding));
            StringBuilder sb = new StringBuilder();
            sb.append(configCenter.getWebRoot()).append(getCacheString(isOnline)).append(filePath);
            fileEditor.createDirectory(sb.toString());
            return fileEditor.saveFile(sb.toString(), in);
        } catch (IOException e) {
        }
        return false;
    }
private boolean readUrlFile(String fullUrl, PrintWriter out) {
        try {
            URL url = new URL(fullUrl);
            String encoding = "gbk";
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), encoding));
            return fileEditor.pushStream(out, in, fullUrl, false);
        } catch (Exception e) {
        }
        return false;
    }
public static void exportGestureSet(List<GestureSet> sets, File file) {
        try {
            FileOutputStream outputStream = new FileOutputStream(file);
            IOUtils.copy(exportGestureSetsAsStream(sets), outputStream);
            outputStream.close();
        } catch (FileNotFoundException e) {
            LOGGER.log(Level.SEVERE, "Could not export Gesture Sets. Export File not found.", e);
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "Could not export Gesture Sets.", e);
        }
    }
public static String sendSoapMsg(String SOAPUrl, byte[] b, String SOAPAction) throws IOException {
        log.finest("HTTP REQUEST SIZE " + b.length);
        if (SOAPAction.startsWith("\"") == false) SOAPAction = "\"" + SOAPAction + "\"";
        URL url = new URL(SOAPUrl);
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        httpConn.setRequestProperty("SOAPAction", SOAPAction);
        httpConn.setRequestProperty("Content-Type", "text/xml; charset=\"utf-8\"");
        httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
        httpConn.setRequestProperty("Cache-Control", "no-cache");
        httpConn.setRequestProperty("Pragma", "no-cache");
        httpConn.setRequestMethod("POST");
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);
        OutputStream out = httpConn.getOutputStream();
        out.write(b);
        out.close();
        InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
        BufferedReader in = new BufferedReader(isr);
        StringBuffer response = new StringBuffer(1024);
        String inputLine;
        while ((inputLine = in.readLine()) != null) response.append(inputLine);
        in.close();
        log.finest("HTTP RESPONSE SIZE: " + response.length());
        return response.toString();
    }
private HttpURLConnection getConnection(String url) throws IOException {
        HttpURLConnection con = null;
        if (proxyHost != null && !proxyHost.equals("")) {
            if (proxyAuthUser != null && !proxyAuthUser.equals("")) {
                log("Proxy AuthUser: " + proxyAuthUser);
                log("Proxy AuthPassword: " + proxyAuthPassword);
                Authenticator.setDefault(new Authenticator() {

                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        if (getRequestorType().equals(RequestorType.PROXY)) {
                            return new PasswordAuthentication(proxyAuthUser, proxyAuthPassword.toCharArray());
                        } else {
                            return null;
                        }
                    }
                });
            }
            final Proxy proxy = new Proxy(Type.HTTP, InetSocketAddress.createUnresolved(proxyHost, proxyPort));
            if (DEBUG) {
                log("Opening proxied connection(" + proxyHost + ":" + proxyPort + ")");
            }
            con = (HttpURLConnection) new URL(url).openConnection(proxy);
        } else {
            con = (HttpURLConnection) new URL(url).openConnection();
        }
        if (connectionTimeout > 0 && !isJDK14orEarlier) {
            con.setConnectTimeout(connectionTimeout);
        }
        if (readTimeout > 0 && !isJDK14orEarlier) {
            con.setReadTimeout(readTimeout);
        }
        return con;
    }
public static final String md5(final String s) {
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(s.getBytes());
            byte messageDigest[] = digest.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                String h = Integer.toHexString(0xFF & messageDigest[i]);
                while (h.length() < 2) {
                    h = "0" + h;
                }
                hexString.append(h);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }