semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String getWebContent(String remoteUrl, String encoding) {
        StringBuffer sb = new StringBuffer();
        try {
            java.net.URL url = new java.net.URL(remoteUrl);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), encoding));
            String line;
            while ((line = in.readLine()) != null) {
                sb.append(line);
            }
            in.close();
        } catch (Exception e) {
            logger.error("获取远程网址内容失败 - " + remoteUrl, e);
        }
        return sb.toString();
    }
public void copy(String sourcePath, String targetPath) throws IOException {
        File sourceFile = new File(sourcePath);
        File targetFile = new File(targetPath);
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream(sourceFile);
            fileOutputStream = new FileOutputStream(targetFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = fileInputStream.read(buffer)) != -1) fileOutputStream.write(buffer, 0, bytesRead);
        } finally {
            if (fileInputStream != null) try {
                fileInputStream.close();
            } catch (IOException exception) {
                JOptionPane.showMessageDialog(null, AcideLanguageManager.getInstance().getLabels().getString("s265") + sourcePath, AcideLanguageManager.getInstance().getLabels().getString("s266"), JOptionPane.ERROR_MESSAGE);
                AcideLog.getLog().error(exception.getMessage());
            }
            if (fileOutputStream != null) try {
                fileOutputStream.close();
            } catch (IOException exception) {
                JOptionPane.showMessageDialog(null, AcideLanguageManager.getInstance().getLabels().getString("s267") + targetPath, AcideLanguageManager.getInstance().getLabels().getString("268"), JOptionPane.ERROR_MESSAGE);
                AcideLog.getLog().error(exception.getMessage());
            }
        }
    }
private DataFileType[] getDataFiles(Collection<ContentToSend> contentsToSend) {
            DataFileType[] files = new DataFileType[contentsToSend.size()];
            int fileIndex = 0;
            for (ContentToSend contentToSend : contentsToSend) {
                DataFileType dataFile = DataFileType.Factory.newInstance();
                dataFile.setFilename(contentToSend.getFileName());
                dataFile.setId("D" + fileIndex);
                dataFile.setMimeType(contentToSend.getMimeType());
                dataFile.setContentType(DataFileType.ContentType.EMBEDDED_BASE_64);
                final StringWriter stringWriter = new StringWriter();
                final OutputStream encodeStream = Base64.newEncoder(stringWriter, 0, null);
                final InputStream is = contentToSend.getInputStream();
                try {
                    long sizeCopied = IOUtils.copyLarge(is, encodeStream);
                    dataFile.setSize(BigDecimal.valueOf(sizeCopied));
                } catch (IOException e) {
                    throw new RuntimeException("Failed to get input to the file to be sent", e);
                } finally {
                    IOUtils.closeQuietly(encodeStream);
                    IOUtils.closeQuietly(is);
                }
                dataFile.setStringValue(stringWriter.toString());
                files[fileIndex++] = dataFile;
            }
            return files;
        }
private static <OS extends OutputStream> OS getUnzipAndDecodeOutputStream(InputStream inputStream, final OS outputStream) {
        final PipedOutputStream pipedOutputStream = new PipedOutputStream();
        final List<Throwable> ungzipThreadThrowableList = new LinkedList<Throwable>();
        Writer decoderWriter = null;
        Thread ungzipThread = null;
        try {
            final PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream);
            ungzipThread = new Thread(new Runnable() {

                public void run() {
                    GZIPInputStream gzipInputStream = null;
                    try {
                        gzipInputStream = new GZIPInputStream(pipedInputStream);
                        IOUtils.copy(gzipInputStream, outputStream);
                    } catch (Throwable t) {
                        ungzipThreadThrowableList.add(t);
                    } finally {
                        IOUtils.closeQuietly(gzipInputStream);
                        IOUtils.closeQuietly(pipedInputStream);
                    }
                }
            });
            decoderWriter = Base64.newDecoder(pipedOutputStream);
            ungzipThread.start();
            IOUtils.copy(inputStream, decoderWriter, DVK_MESSAGE_CHARSET);
            decoderWriter.flush();
            pipedOutputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException("failed to unzip and decode input", e);
        } finally {
            IOUtils.closeQuietly(decoderWriter);
            IOUtils.closeQuietly(pipedOutputStream);
            if (ungzipThread != null) {
                try {
                    ungzipThread.join();
                } catch (InterruptedException ie) {
                    throw new RuntimeException("thread interrupted while for ungzip thread to finish", ie);
                }
            }
        }
        if (!ungzipThreadThrowableList.isEmpty()) {
            throw new RuntimeException("ungzip failed", ungzipThreadThrowableList.get(0));
        }
        return outputStream;
    }
public void run() {
                    GZIPInputStream gzipInputStream = null;
                    try {
                        gzipInputStream = new GZIPInputStream(pipedInputStream);
                        IOUtils.copy(gzipInputStream, outputStream);
                    } catch (Throwable t) {
                        ungzipThreadThrowableList.add(t);
                    } finally {
                        IOUtils.closeQuietly(gzipInputStream);
                        IOUtils.closeQuietly(pipedInputStream);
                    }
                }
private static void main(String mp3Path) throws IOException {
        String convPath = "http://android.adinterest.biz/wav2mp3.php?k=";
        String uri = convPath + mp3Path;
        URL rssurl = new URL(uri);
        InputStream is = rssurl.openStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        String buf = "";
        while ((buf = br.readLine()) != null) {
        }
        is.close();
        br.close();
    }
private static void readAndRewrite(File inFile, File outFile) throws IOException {
        ImageInputStream iis = ImageIO.createImageInputStream(new BufferedInputStream(new FileInputStream(inFile)));
        DcmParser dcmParser = DcmParserFactory.getInstance().newDcmParser(iis);
        Dataset ds = DcmObjectFactory.getInstance().newDataset();
        dcmParser.setDcmHandler(ds.getDcmHandler());
        dcmParser.parseDcmFile(null, Tags.PixelData);
        PixelDataReader pdReader = pdFact.newReader(ds, iis, dcmParser.getDcmDecodeParam().byteOrder, dcmParser.getReadVR());
        System.out.println("reading " + inFile + "...");
        pdReader.readPixelData(false);
        ImageOutputStream out = ImageIO.createImageOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
        DcmEncodeParam dcmEncParam = DcmEncodeParam.IVR_LE;
        ds.writeDataset(out, dcmEncParam);
        ds.writeHeader(out, dcmEncParam, Tags.PixelData, dcmParser.getReadVR(), dcmParser.getReadLength());
        System.out.println("writing " + outFile + "...");
        PixelDataWriter pdWriter = pdFact.newWriter(pdReader.getPixelDataArray(), false, ds, out, dcmParser.getDcmDecodeParam().byteOrder, dcmParser.getReadVR());
        pdWriter.writePixelData();
        out.flush();
        out.close();
        System.out.println("done!");
    }
private void getRandomGUID(boolean secure) {
        MessageDigest md5 = null;
        final StringBuilder sbValueBeforeMD5 = new StringBuilder();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            logger.fatal("", e);
            return;
        }
        try {
            final long time = System.currentTimeMillis();
            long rand = 0;
            if (secure) {
                rand = mySecureRand.nextLong();
            } else {
                rand = myRand.nextLong();
            }
            sbValueBeforeMD5.append(sId);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            final byte[] array = md5.digest();
            final StringBuilder sb = new StringBuilder();
            for (int j = 0; j < array.length; ++j) {
                final int b = array[j] & 0xFF;
                if (b < 0x10) {
                    sb.append('0');
                }
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            logger.fatal("", e);
        }
    }
public static final String getUniqueId() {
        String digest = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            String timeVal = "" + (System.currentTimeMillis() + 1);
            String localHost = "";
            try {
                localHost = InetAddress.getLocalHost().toString();
            } catch (UnknownHostException e) {
                throw new RuntimeException("Error trying to get localhost" + e.getMessage());
            }
            String randVal = "" + new Random().nextInt();
            String val = timeVal + localHost + randVal;
            md.reset();
            md.update(val.getBytes());
            digest = toHexString(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("NoSuchAlgorithmException : " + e.getMessage());
        }
        return digest;
    }
public static void copy(File source, File dest) throws Exception {
        FileInputStream in = new FileInputStream(source);
        FileOutputStream out = new FileOutputStream(dest);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
    }
public void notifyIterationEnds(final IterationEndsEvent event) {
        log.info("moving files...");
        File source = new File("deqsim.log");
        if (source.exists()) {
            File destination = new File(Controler.getIterationFilename("deqsim.log"));
            if (!IOUtils.renameFile(source, destination)) {
                log.info("WARNING: Could not move deqsim.log to its iteration directory.");
            }
        }
        int parallelCnt = 0;
        source = new File("deqsim.log." + parallelCnt);
        while (source.exists()) {
            File destination = new File(Controler.getIterationFilename("deqsim.log." + parallelCnt));
            if (!IOUtils.renameFile(source, destination)) {
                log.info("WARNING: Could not move deqsim.log." + parallelCnt + " to its iteration directory.");
            }
            parallelCnt++;
            source = new File("deqsim.log." + parallelCnt);
        }
        source = new File("loads_out.txt");
        if (source.exists()) {
            File destination = new File(Controler.getIterationFilename("loads_out.txt"));
            try {
                IOUtils.copyFile(source, destination);
            } catch (FileNotFoundException e) {
                log.info("WARNING: Could not copy loads_out.txt to its iteration directory.");
            } catch (IOException e) {
                log.info("WARNING: Could not copy loads_out.txt to its iteration directory.");
            }
            destination = new File("loads_in.txt");
            if (!IOUtils.renameFile(source, destination)) {
                log.info("WARNING: Could not move loads_out.txt to loads_in.txt.");
            }
        }
        source = new File("linkprocs.txt");
        if (source.exists()) {
            File destination = new File(Controler.getIterationFilename("linkprocs.txt"));
            if (!IOUtils.renameFile(source, destination)) {
                log.info("WARNING: Could not move linkprocs.txt to its iteration directory.");
            }
        }
    }
@Override
    public final boolean delete() throws RecordException {
        if (frozen) {
            throw new RecordException("The object is frozen.");
        }
        Connection conn = ConnectionManager.getConnection();
        LoggableStatement pStat = null;
        Class<? extends Record> actualClass = this.getClass();
        StatementBuilder builder = null;
        try {
            builder = new StatementBuilder("delete from " + TableNameResolver.getTableName(actualClass) + " where id = :id");
            Field f = FieldHandler.findField(this.getClass(), "id");
            builder.set("id", FieldHandler.getValue(f, this));
            pStat = builder.getPreparedStatement(conn);
            log.log(pStat.getQueryString());
            int i = pStat.executeUpdate();
            return i == 1;
        } catch (Exception e) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
                throw new RecordException("Error executing rollback");
            }
            throw new RecordException(e);
        } finally {
            try {
                if (pStat != null) {
                    pStat.close();
                }
                conn.commit();
                conn.close();
            } catch (SQLException e) {
                throw new RecordException("Error closing connection");
            }
        }
    }
public static void doVersionCheck(View view) {
        view.showWaitCursor();
        try {
            URL url = new URL(jEdit.getProperty("version-check.url"));
            InputStream in = url.openStream();
            BufferedReader bin = new BufferedReader(new InputStreamReader(in));
            String line;
            String version = null;
            String build = null;
            while ((line = bin.readLine()) != null) {
                if (line.startsWith(".version")) version = line.substring(8).trim(); else if (line.startsWith(".build")) build = line.substring(6).trim();
            }
            bin.close();
            if (version != null && build != null) {
                if (jEdit.getBuild().compareTo(build) < 0) newVersionAvailable(view, version, url); else {
                    GUIUtilities.message(view, "version-check" + ".up-to-date", new String[0]);
                }
            }
        } catch (IOException e) {
            String[] args = { jEdit.getProperty("version-check.url"), e.toString() };
            GUIUtilities.error(view, "read-error", args);
        }
        view.hideWaitCursor();
    }
public static Image getPluginImage(Object plugin, String name) {
        try {
            try {
                URL url = getPluginImageURL(plugin, name);
                if (m_URLImageMap.containsKey(url)) return m_URLImageMap.get(url);
                InputStream is = url.openStream();
                Image image;
                try {
                    image = getImage(is);
                    m_URLImageMap.put(url, image);
                } finally {
                    is.close();
                }
                return image;
            } catch (Throwable e) {
            }
        } catch (Throwable e) {
        }
        return null;
    }
private Document saveFile(Document document, File file) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATEFORMAT_YYYYMMDD);
        List<Preference> preferences = prefService.findAll();
        if (preferences != null && !preferences.isEmpty()) {
            Preference preference = preferences.get(0);
            String repo = preference.getRepository();
            StringBuffer sbRepo = new StringBuffer(repo);
            sbRepo.append(File.separator);
            StringBuffer sbFolder = new StringBuffer(document.getLocation());
            File folder = new File(sbRepo.append(sbFolder).toString());
            log.info("Check in file ID [" + document.getId() + "] to " + folder.getAbsolutePath());
            if (!folder.exists()) {
                folder.mkdirs();
            }
            FileChannel fcSource = null, fcDest = null, fcVersionDest = null;
            try {
                StringBuffer sbFile = new StringBuffer(folder.getAbsolutePath()).append(File.separator).append(document.getId()).append(".").append(document.getExt());
                StringBuffer sbVersionFile = new StringBuffer(folder.getAbsolutePath()).append(File.separator).append(document.getId()).append("_").append(document.getVersion().toString()).append(".").append(document.getExt());
                fcSource = new FileInputStream(file).getChannel();
                fcDest = new FileOutputStream(sbFile.toString()).getChannel();
                fcVersionDest = new FileOutputStream(sbVersionFile.toString()).getChannel();
                fcDest.transferFrom(fcSource, 0, fcSource.size());
                fcSource = new FileInputStream(file).getChannel();
                fcVersionDest.transferFrom(fcSource, 0, fcSource.size());
                document.setLocation(sbFolder.toString());
                documentService.save(document);
            } catch (FileNotFoundException notFoundEx) {
                log.error("saveFile file not found: " + document.getName(), notFoundEx);
            } catch (IOException ioEx) {
                log.error("saveFile IOException: " + document.getName(), ioEx);
            } finally {
                try {
                    if (fcSource != null) {
                        fcSource.close();
                    }
                    if (fcDest != null) {
                        fcDest.close();
                    }
                    if (fcVersionDest != null) {
                        fcVersionDest.close();
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
        return document;
    }
public static void copyFile(File in, File out) throws IOException {
        try {
            FileReader inf = new FileReader(in);
            OutputStreamWriter outf = new OutputStreamWriter(new FileOutputStream(out), "UTF-8");
            int c;
            while ((c = inf.read()) != -1) outf.write(c);
            inf.close();
            outf.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private DefaultMutableTreeNode parseTree() {
        try {
            DefaultMutableTreeNode root;
            URL url = RebusHelp.class.getResource("/org/olga/rebus/gui/help/html/content.xml");
            InputStream is = url.openStream();
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setIgnoringComments(true);
            factory.setValidating(false);
            DocumentBuilder parser = factory.newDocumentBuilder();
            Document document = parser.parse(is);
            NodeList elements = document.getElementsByTagName("help");
            Element element = (Element) elements.item(0);
            root = createTreeContent(element);
            is.close();
            return root;
        } catch (IOException e) {
            System.out.println(e.getMessage());
            return null;
        } catch (ParserConfigurationException e1) {
            System.out.println(e1.getMessage());
            return null;
        } catch (org.xml.sax.SAXException e2) {
            System.out.println(e2.getMessage());
            return null;
        }
    }
private HttpResponse executePutPost(HttpEntityEnclosingRequestBase request, String content) {
        try {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Content: {}", content);
            }
            StringEntity e = new StringEntity(content, "UTF-8");
            e.setContentType("application/json");
            request.setEntity(e);
            return executeRequest(request);
        } catch (Exception e) {
            throw Exceptions.propagate(e);
        }
    }
public void copy(File in, File out) throws Exception {
        FileChannel src = new FileInputStream(in).getChannel();
        FileChannel dest = new FileOutputStream(out).getChannel();
        src.transferTo(0, src.size(), dest);
        src.close();
        dest.close();
    }
private synchronized void awaitResponse() throws BOSHException {
        HttpEntity entity = null;
        try {
            HttpResponse httpResp = client.execute(post, context);
            entity = httpResp.getEntity();
            byte[] data = EntityUtils.toByteArray(entity);
            String encoding = entity.getContentEncoding() != null ? entity.getContentEncoding().getValue() : null;
            if (ZLIBCodec.getID().equalsIgnoreCase(encoding)) {
                data = ZLIBCodec.decode(data);
            } else if (GZIPCodec.getID().equalsIgnoreCase(encoding)) {
                data = GZIPCodec.decode(data);
            }
            body = StaticBody.fromString(new String(data, CHARSET));
            statusCode = httpResp.getStatusLine().getStatusCode();
            sent = true;
        } catch (IOException iox) {
            abort();
            toThrow = new BOSHException("Could not obtain response", iox);
            throw (toThrow);
        } catch (RuntimeException ex) {
            abort();
            throw (ex);
        }
    }
public void deployDir(File srcDir, String destDir) {
        File[] dirFiles = srcDir.listFiles();
        for (int k = 0; dirFiles != null && k < dirFiles.length; k++) {
            if (!dirFiles[k].getName().startsWith(".")) {
                if (dirFiles[k].isFile()) {
                    File deployFile = new File(destDir + File.separator + dirFiles[k].getName());
                    if (dirFiles[k].lastModified() != deployFile.lastModified() || dirFiles[k].length() != deployFile.length()) {
                        IOUtils.copy(dirFiles[k], deployFile);
                    }
                } else if (dirFiles[k].isDirectory()) {
                    String newDestDir = destDir + File.separator + dirFiles[k].getName();
                    deployDir(dirFiles[k], newDestDir);
                }
            }
        }
    }