semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static boolean filecopy(final File source, final File target) {
        boolean out = false;
        if (source.isDirectory() || !source.exists() || target.isDirectory() || source.equals(target)) return false;
        try {
            target.getParentFile().mkdirs();
            target.createNewFile();
            FileChannel sourceChannel = new FileInputStream(source).getChannel();
            try {
                FileChannel targetChannel = new FileOutputStream(target).getChannel();
                try {
                    targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
                    out = true;
                } finally {
                    targetChannel.close();
                }
            } finally {
                sourceChannel.close();
            }
        } catch (IOException e) {
            out = false;
        }
        return out;
    }
static void copyFile(File file, File file1) throws IOException {
        byte abyte0[] = new byte[512];
        FileInputStream fileinputstream = new FileInputStream(file);
        FileOutputStream fileoutputstream = new FileOutputStream(file1);
        int i;
        while ((i = fileinputstream.read(abyte0)) > 0) fileoutputstream.write(abyte0, 0, i);
        fileinputstream.close();
        fileoutputstream.close();
    }
private static String readGeoJSON(String feature) {
        StringBuffer content = new StringBuffer();
        try {
            URL url = new URL(feature);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                content.append(line);
            }
            conn.disconnect();
        } catch (Exception e) {
        }
        return content.toString();
    }
public void run() {
        for (int i = 0; i < iClNumberOfCycles; i++) {
            try {
                long lStartTime = System.currentTimeMillis();
                InputStream in = urlClDestinationURL.openStream();
                byte buf[] = new byte[1024];
                int num;
                while ((num = in.read(buf)) > 0) ;
                in.close();
                long lStopTime = System.currentTimeMillis();
                Node.getLogger().write((lStopTime - lStartTime) + " ms");
                avgCalls.update(lStopTime - lStartTime);
                System.out.print("*");
                System.out.flush();
                calls.update();
            } catch (Exception e) {
                cntErrors.update();
                System.out.print("X");
                System.out.flush();
            }
        }
    }
protected HttpResponse executeRequest(AbstractHttpRequest request) throws ConnectionException, RequestCancelledException {
        try {
            HttpResponse response = getHttpClient().execute(request);
            if (!response.is2xxSuccess()) {
                throw new ConnectionException();
            }
            return response;
        } catch (IOException ex) {
            throw new ConnectionException();
        } catch (TimeoutException ex) {
            throw new ConnectionException();
        }
    }
public DocumentSummary parseDocument(URL url) throws IOException, DocumentHandlerException {
        try {
            DocumentSummary documentSummary = new DocumentSummary();
            SaxTextContentParser saxParser = new SaxTextContentParser();
            InputSource inputSource = new InputSource(url.openStream());
            documentSummary.contentReader = new StringReader(saxParser.parse(inputSource));
            return documentSummary;
        } catch (SAXException e) {
            throw new DocumentHandlerException(GuiMessages.getString("XmlDocumentHandler.xmlParsingErrorMessage.header") + e.getMessage(), e);
        } catch (ParserConfigurationException e) {
            throw new DocumentHandlerException(GuiMessages.getString("XmlDocumentHandler.xmlParsingErrorMessage.header") + e.getMessage(), e);
        }
    }
@Override
    public void copy(File source, File dest) throws IOException {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = (new FileInputStream(source)).getChannel();
            out = (new FileOutputStream(dest)).getChannel();
            in.transferTo(0, source.length(), out);
        } catch (FileNotFoundException e) {
            throw new IOException("Wrong source or destination path for backup operation!");
        } finally {
            if (out != null) {
                out.close();
            }
            if (in != null) {
                in.close();
            }
        }
    }
public static boolean downloadFile(String urlString, String outputFile, int protocol) {
        InputStream is = null;
        File file = new File(outputFile);
        FileOutputStream fos = null;
        if (protocol == HTTP_PROTOCOL) {
            try {
                URL url = new URL(urlString);
                URLConnection ucnn = null;
                if (BlueXStatics.proxy == null || url.getProtocol().equals("file")) ucnn = url.openConnection(); else ucnn = url.openConnection(BlueXStatics.proxy);
                is = ucnn.getInputStream();
                fos = new FileOutputStream(file);
                byte[] data = new byte[4096];
                int offset;
                while ((offset = is.read(data)) != -1) {
                    fos.write(data, 0, offset);
                }
                return true;
            } catch (Exception ex) {
            } finally {
                try {
                    is.close();
                } catch (Exception e) {
                }
                try {
                    fos.close();
                } catch (Exception e) {
                }
            }
        } else throw new ProtocolNotSupportedException("The protocol selected is not supported by this version of downloadFile() method.");
        return false;
    }
private void send(java.awt.event.ActionEvent evt) {
        String url = this.getURL();
        if (url != null) {
            String tinyurl = "";
            try {
                URLConnection conn = new URL("http://tinyurl.com/api-create.php?url=" + url).openConnection();
                conn.setDoInput(true);
                conn.connect();
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                tinyurl = br.readLine();
            } catch (SocketTimeoutException ste) {
                ste.printStackTrace();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            String addresses = (String) this._model.getElementAt(0);
            for (int i = 1; i < this._model.getSize(); i++) addresses += "," + (String) this._model.getElementAt(i);
            SendDialog dialog = new SendDialog("Web Image Browser view", "To view, click the URL below\n\n" + url + "\n\n" + ((tinyurl != null) ? ("or\n\n" + tinyurl) : ""), addresses);
            dialog.setVisible(true);
        } else JOptionPane.showMessageDialog(this, "<html><center>" + "Sorry, but the file in<br>" + "\"" + this.path.getText() + "\"<br>" + "doesn't seem to be a valid " + "WIBShare-able file." + "</center></html>", "WIBShare Error", JOptionPane.ERROR_MESSAGE);
    }
protected static void writeFileToStream(FileWrapper file, String filename, ZipOutputStream zipStream) throws CausedIOException, IOException {
        InputStream in;
        try {
            in = file.getInputStream();
        } catch (Exception e) {
            throw new CausedIOException("Could not obtain InputStream for " + filename, e);
        }
        try {
            IOUtils.copy(in, zipStream);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
public static void readAsFile(String fileName, String url) {
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        URLConnection conn = null;
        try {
            conn = new URL(url).openConnection();
            conn.setDoInput(true);
            in = new BufferedInputStream(conn.getInputStream());
            out = new BufferedOutputStream(new FileOutputStream(fileName));
            int b;
            while ((b = in.read()) != -1) {
                out.write(b);
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        } finally {
            if (null != in) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (null != out) {
                try {
                    out.flush();
                    out.close();
                } catch (IOException e) {
                }
            }
        }
    }
public static byte[] findHead(String url) {
        byte[] result = new byte[0];
        InputStream in = null;
        try {
            in = new URL(appendSlash(url)).openStream();
            byte[] buffer = new byte[1024];
            int len = -1;
            while ((len = in.read(buffer)) != -1) {
                byte[] temp = new byte[result.length + len];
                System.arraycopy(result, 0, temp, 0, result.length);
                System.arraycopy(buffer, 0, temp, result.length, len);
                result = temp;
                if (DEBUG) {
                    log.debug(String.format("len=%d, result.length=%d", len, result.length));
                }
                if (result.length > 4096) {
                    break;
                }
                if (result.length > 1024) {
                    String s = new String(result).replaceAll("\\s+", " ");
                    Matcher m = P_HEAD.matcher(s);
                    if (m.find()) {
                        break;
                    }
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            try {
                if (null != in) in.close();
            } catch (IOException e) {
            }
        }
        return result;
    }
public static void copyFile(File dest, File src) throws IOException {
        FileChannel srcChannel = new FileInputStream(src).getChannel();
        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
public String getShortToken(String md5Str) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(md5Str.getBytes(JspRunConfig.charset));
        } catch (Exception e) {
            e.printStackTrace();
        }
        StringBuffer token = toHex(md5.digest());
        return token.substring(8, 24);
    }
public String getLongToken(String md5Str) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(md5Str.getBytes(JspRunConfig.charset));
        } catch (Exception e) {
            e.printStackTrace();
        }
        StringBuffer token = toHex(md5.digest());
        return token.toString();
    }
protected void yesAction() {
        try {
            String result = getSurveyURL() + "&buildtime=" + Version.getBuildTimeString();
            LOG.log(result);
            if (!maySubmitSurvey()) {
                return;
            }
            BufferedReader br = null;
            try {
                URL url = new URL(result);
                InputStream urls = url.openStream();
                InputStreamReader is = new InputStreamReader(urls);
                br = new BufferedReader(is);
                String line;
                StringBuilder sb = new StringBuilder();
                while ((line = br.readLine()) != null) {
                    sb.append(line);
                    sb.append(System.getProperty("line.separator"));
                }
                LOG.log(sb.toString());
            } catch (IOException e) {
                LOG.log("Could not open URL using Java", e);
                try {
                    PlatformFactory.ONLY.openURL(new URL(result));
                    DrJava.getConfig().setSetting(OptionConstants.LAST_DRJAVA_SURVEY_RESULT, result);
                } catch (IOException e2) {
                    LOG.log("Could not open URL using web browser", e2);
                }
            } finally {
                try {
                    if (br != null) br.close();
                } catch (IOException e) {
                }
            }
        } finally {
            noAction();
        }
    }
public static byte[] openHttpResult(String urlPath, boolean retry) throws IOException {
        AQUtility.debug("net", urlPath);
        URL url = new URL(urlPath);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setUseCaches(false);
        connection.setInstanceFollowRedirects(true);
        connection.setConnectTimeout(NET_TIMEOUT);
        int code = connection.getResponseCode();
        if (code == 307 && retry) {
            String redirect = connection.getHeaderField("Location");
            return openHttpResult(redirect, false);
        }
        if (code == -1 && retry) {
            return openHttpResult(urlPath, false);
        }
        AQUtility.debug("response", code);
        if (code == -1 || code < 200 || code >= 300) {
            throw new IOException();
        }
        byte[] result = AQUtility.toBytes(connection.getInputStream());
        return result;
    }
protected void copyFile(String from, String to, String workingDirectory) throws Exception {
        URL monitorCallShellScriptUrl = Thread.currentThread().getContextClassLoader().getResource(from);
        File f = new File(monitorCallShellScriptUrl.getFile());
        String directoryPath = f.getAbsolutePath();
        String fileName = from;
        InputStream in = null;
        if (directoryPath.indexOf(".jar!") > -1) {
            URL urlJar = new URL(directoryPath.substring(directoryPath.indexOf("file:"), directoryPath.indexOf('!')));
            JarFile jf = new JarFile(urlJar.getFile());
            JarEntry je = jf.getJarEntry(from);
            fileName = je.getName();
            in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        } else {
            in = new FileInputStream(f);
        }
        File outScriptFile = new File(to);
        FileOutputStream fos = new FileOutputStream(outScriptFile);
        int nextChar;
        while ((nextChar = in.read()) != -1) fos.write(nextChar);
        fos.flush();
        fos.close();
        try {
            LinuxCommandExecutor cmdExecutor = new LinuxCommandExecutor();
            cmdExecutor.setWorkingDirectory(workingDirectory);
            cmdExecutor.runCommand("chmod 777 " + to);
        } catch (Exception e) {
            throw e;
        }
    }
protected File EncodeReturn() throws EncodeFailedException, IOException {
        CryptoClient c = getNode().getCryptoClientByID(PiggybackCrypto);
        File tmpf = getNode().getTempFM().createNewFile("encodereturn", "download");
        ChannelWriter cw = new ChannelWriter(tmpf);
        cw.putLongFile(DownloadData);
        cw.close();
        File encdata = c.RawEncode(tmpf, RawKey);
        File pigdata = PigData.EncodeData(encdata);
        File pigroute = ReturnPigRoute.EncodeData(ReturnRouteFile);
        FileOutputStream fos = new FileOutputStream(pigroute, true);
        FileChannel foc = fos.getChannel();
        FileInputStream fis = new FileInputStream(pigdata);
        FileChannel fic = fis.getChannel();
        fic.transferTo(0, fic.size(), foc);
        foc.close();
        fic.close();
        pigdata.delete();
        ReturnRouteFile.delete();
        encdata.delete();
        return pigroute;
    }
public static String readFromURL(String url_) {
        StringBuffer buffer = new StringBuffer();
        try {
            URL url = new URL(url_);
            System.setProperty("http.agent", "");
            URLConnection connection = url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
            connection.setDoInput(true);
            InputStream inStream = connection.getInputStream();
            BufferedReader input = new BufferedReader(new InputStreamReader(inStream, "utf8"));
            String line = "";
            while ((line = input.readLine()) != null) {
                buffer.append(line + "\n");
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        return buffer.toString();
    }
public static void writeURLToFile(String url, String path) throws MalformedURLException, IOException {
        java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(url).openStream());
        java.io.FileOutputStream fos = new java.io.FileOutputStream(path);
        java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
        byte data[] = new byte[1024];
        int count;
        while ((count = in.read(data, 0, 1024)) != -1) {
            ;
            bout.write(data, 0, count);
        }
        bout.close();
        in.close();
    }
public static String submitURLRequest(String url) throws HttpException, IOException, URISyntaxException {
        HttpClient httpclient = new DefaultHttpClient();
        InputStream stream = null;
        user_agents = new LinkedList<String>();
        user_agents.add("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
        String response_text = "";
        URI uri = new URI(url);
        HttpGet post = new HttpGet(uri);
        int MAX = user_agents.size() - 1;
        int index = (int) Math.round(((double) Math.random() * (MAX)));
        String agent = user_agents.get(index);
        httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, agent);
        httpclient.getParams().setParameter("User-Agent", agent);
        httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.ACCEPT_NONE);
        HttpResponse response = httpclient.execute(post);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            stream = entity.getContent();
            response_text = convertStreamToString(stream);
        }
        httpclient.getConnectionManager().shutdown();
        if (stream != null) {
            stream.close();
        }
        return response_text;
    }
private String File2String(String directory, String filename) {
        String line;
        InputStream in = null;
        try {
            File f = new File(filename);
            System.out.println("File On:>>>>>>>>>> " + f.getCanonicalPath());
            in = new FileInputStream(f);
        } catch (FileNotFoundException ex) {
            in = null;
        } catch (IOException ex) {
            in = null;
        }
        try {
            if (in == null) {
                filename = directory + "/" + filename;
                java.net.URL urlFile = ClassLoader.getSystemResource(filename);
                if (urlFile == null) {
                    System.out.println("Integrated Chips list file not found: " + filename);
                    System.exit(-1);
                }
                in = urlFile.openStream();
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            StringBuffer xmlText = new StringBuffer();
            while ((line = reader.readLine()) != null) {
                xmlText.append(line);
            }
            reader.close();
            return xmlText.toString();
        } catch (FileNotFoundException ex) {
            System.out.println("Integrated Chips list file not found");
            System.exit(-1);
        } catch (IOException ex) {
            ex.printStackTrace();
            System.exit(-1);
        }
        return null;
    }
private synchronized File zipTempFile(File tempFile) throws BlogunityException {
        try {
            File zippedFile = new File(BlogunityManager.getSystemConfiguration().getTempDir(), tempFile.getName() + ".zip");
            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zippedFile));
            byte[] readBuffer = new byte[2156];
            int bytesIn = 0;
            FileInputStream fis = new FileInputStream(tempFile);
            ZipEntry anEntry = new ZipEntry(tempFile.getName());
            zos.putNextEntry(anEntry);
            while ((bytesIn = fis.read(readBuffer)) != -1) {
                zos.write(readBuffer, 0, bytesIn);
            }
            fis.close();
            zos.close();
            return zippedFile;
        } catch (Exception e) {
            throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.FEED_ZIP_FAILED, e));
        }
    }
private synchronized File gzipTempFile(File tempFile) throws BlogunityException {
        try {
            File gzippedFile = new File(BlogunityManager.getSystemConfiguration().getTempDir(), tempFile.getName() + ".gz");
            GZIPOutputStream zos = new GZIPOutputStream(new FileOutputStream(gzippedFile));
            byte[] readBuffer = new byte[2156];
            int bytesIn = 0;
            FileInputStream fis = new FileInputStream(tempFile);
            while ((bytesIn = fis.read(readBuffer)) != -1) {
                zos.write(readBuffer, 0, bytesIn);
            }
            fis.close();
            zos.close();
            return gzippedFile;
        } catch (Exception e) {
            throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.FEED_GZIP_FAILED, e));
        }
    }
private void logoutUser(String session) {
        try {
            String data = URLEncoder.encode("SESSION", "UTF-8") + "=" + URLEncoder.encode("" + session, "UTF-8");
            if (_log != null) _log.error("Voice: logoutUser = " + m_strUrl + "LogoutUserServlet&" + data);
            URL url = new URL(m_strUrl + "LogoutUserServlet");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            wr.close();
            rd.close();
        } catch (Exception e) {
            if (_log != null) _log.error("Voice error : " + e);
        }
    }
@Override
    public String resolveItem(String oldJpgFsPath) throws DatabaseException {
        if (oldJpgFsPath == null || "".equals(oldJpgFsPath)) throw new NullPointerException("oldJpgFsPath");
        try {
            getConnection().setAutoCommit(false);
        } catch (SQLException e) {
            LOGGER.warn("Unable to set autocommit off", e);
        }
        PreparedStatement statement = null;
        String ret = null;
        try {
            statement = getConnection().prepareStatement(SELECT_ITEM_STATEMENT);
            statement.setString(1, oldJpgFsPath);
            ResultSet rs = statement.executeQuery();
            int i = 0;
            int id = -1;
            int rowsAffected = 0;
            while (rs.next()) {
                id = rs.getInt("id");
                ret = rs.getString("imageFile");
                i++;
            }
            if (id != -1 && new File(ret).exists()) {
                statement = getConnection().prepareStatement(UPDATE_ITEM_STATEMENT);
                statement.setInt(1, id);
                rowsAffected = statement.executeUpdate();
            } else {
                return null;
            }
            if (rowsAffected == 1) {
                getConnection().commit();
                LOGGER.debug("DB has been updated.");
            } else {
                getConnection().rollback();
                LOGGER.error("DB has not been updated -> rollback!");
            }
        } catch (SQLException e) {
            LOGGER.error(e);
        } finally {
            closeConnection();
        }
        return ret;
    }