semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public String fetchContent(PathObject file) throws NetworkException {
        if (file.isFetched()) {
            return file.getContent();
        }
        if (!"f".equals(file.getType())) {
            return null;
        }
        HttpClient client = HttpConfig.newInstance();
        HttpGet get = new HttpGet(HttpConfig.bbsURL() + HttpConfig.BBS_ANC + file.getPath());
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            Document doc = XmlOperator.readDocument(entity.getContent());
            return BBSBodyParseHelper.parsePathContent(doc, file);
        } catch (Exception e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
protected FTPClient ftpConnect() throws SocketException, IOException, NoSuchAlgorithmException {
        FilePathItem fpi = getFilePathItem();
        FTPClient f = new FTPClient();
        f.connect(fpi.getHost());
        f.login(fpi.getUsername(), fpi.getPassword());
        return f;
    }
public static void copyFile(File sourceFile, File destFile) throws IOException {
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }
static void createCompleteXML(File file) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(errorFile);
            fos = new FileOutputStream(file);
            byte[] data = new byte[Integer.parseInt(BlueXStatics.prop.getProperty("allocationUnit"))];
            int offset;
            while ((offset = fis.read(data)) != -1) fos.write(data, 0, offset);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fis.close();
            } catch (Exception e) {
            }
            try {
                fos.close();
            } catch (Exception e) {
            }
        }
        FileWriter fw = null;
        try {
            fw = new FileWriter(file, true);
            fw.append("</detail>");
            fw.append("\n</exception>");
            fw.append("\n</log>");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fw.close();
            } catch (Exception e) {
            }
        }
    }
private Collection<URL> doSearch(final URL url) throws IOException {
        final Collection<URL> result = new ArrayList<URL>();
        final InputStream is = url.openStream();
        final ReadHTML parse = new ReadHTML(is);
        final StringBuilder buffer = new StringBuilder();
        boolean capture = false;
        int ch;
        while ((ch = parse.read()) != -1) {
            if (ch == 0) {
                final Tag tag = parse.getTag();
                if (tag.getName().equalsIgnoreCase("url")) {
                    buffer.setLength(0);
                    capture = true;
                } else if (tag.getName().equalsIgnoreCase("/url")) {
                    result.add(new URL(buffer.toString()));
                    buffer.setLength(0);
                    capture = false;
                }
            } else {
                if (capture) {
                    buffer.append((char) ch);
                }
            }
        }
        return result;
    }
@Before
    public void setUp() throws Exception {
        configureSslSocketConnector();
        SecurityHandler securityHandler = createBasicAuthenticationSecurityHandler();
        HandlerList handlerList = new HandlerList();
        handlerList.addHandler(securityHandler);
        handlerList.addHandler(new AbstractHandler() {

            @Override
            public void handle(String s, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, int i) throws IOException, ServletException {
                expected = new StringBuilder();
                System.out.println("uri: " + httpServletRequest.getRequestURI());
                System.out.println("queryString: " + (queryString = httpServletRequest.getQueryString()));
                System.out.println("method: " + httpServletRequest.getMethod());
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(httpServletRequest.getInputStream(), baos);
                System.out.println("body: " + (body = baos.toString()));
                PrintWriter writer = httpServletResponse.getWriter();
                writer.append("testsvar");
                expected.append("testsvar");
                Random r = new Random();
                for (int j = 0; j < 10; j++) {
                    int value = r.nextInt(Integer.MAX_VALUE);
                    writer.append(value + "");
                    expected.append(value);
                }
                System.out.println();
                writer.close();
                httpServletResponse.setStatus(HttpServletResponse.SC_OK);
            }
        });
        server.addHandler(handlerList);
        server.start();
    }
@Override
            public void handle(String s, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, int i) throws IOException, ServletException {
                expected = new StringBuilder();
                System.out.println("uri: " + httpServletRequest.getRequestURI());
                System.out.println("queryString: " + (queryString = httpServletRequest.getQueryString()));
                System.out.println("method: " + httpServletRequest.getMethod());
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(httpServletRequest.getInputStream(), baos);
                System.out.println("body: " + (body = baos.toString()));
                PrintWriter writer = httpServletResponse.getWriter();
                writer.append("testsvar");
                expected.append("testsvar");
                Random r = new Random();
                for (int j = 0; j < 10; j++) {
                    int value = r.nextInt(Integer.MAX_VALUE);
                    writer.append(value + "");
                    expected.append(value);
                }
                System.out.println();
                writer.close();
                httpServletResponse.setStatus(HttpServletResponse.SC_OK);
            }
private static URLConnection connectToNCBIValidator() throws IOException {
        final URL url = new URL(NCBI_URL);
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestProperty("Content-Type", CONTENT_TYPE);
        return connection;
    }
public static void copy(File src, File dest) throws IOException {
        FileChannel srcChannel = new FileInputStream(src).getChannel();
        FileChannel destChannel = new FileOutputStream(dest).getChannel();
        destChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        destChannel.close();
    }
public boolean add(String url) {
        try {
            HttpURLConnection request = (HttpURLConnection) new URL(url).openConnection();
            request.setRequestMethod("POST");
            request.setRequestProperty(GameRecord.GAME_IP_HEADER, String.valueOf(ip));
            request.setRequestProperty(GameRecord.GAME_PORT_HEADER, String.valueOf(port));
            request.setRequestProperty(GameRecord.GAME_MESSAGE_HEADER, message);
            request.setRequestProperty(GameRecord.GAME_LATITUDE_HEADER, df.format(lat));
            request.setRequestProperty(GameRecord.GAME_LONGITUDE_HEADER, df.format(lon));
            request.setRequestProperty("Content-Length", "0");
            request.connect();
            if (request.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new IOException("Unexpected response: " + request.getResponseCode() + " " + request.getResponseMessage());
            }
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
public static boolean delete(String url, int ip, int port) {
        try {
            HttpURLConnection request = (HttpURLConnection) new URL(url).openConnection();
            request.setRequestMethod("DELETE");
            request.setRequestProperty(GameRecord.GAME_IP_HEADER, String.valueOf(ip));
            request.setRequestProperty(GameRecord.GAME_PORT_HEADER, String.valueOf(port));
            request.connect();
            return request.getResponseCode() == HttpURLConnection.HTTP_OK;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
public static GameRecord[] get(String url, float lat, float lon, int count) {
        try {
            HttpURLConnection req = (HttpURLConnection) new URL(url).openConnection();
            req.setRequestMethod("GET");
            req.setRequestProperty(GameRecord.GAME_LATITUDE_HEADER, df.format(lat));
            req.setRequestProperty(GameRecord.GAME_LONGITUDE_HEADER, df.format(lon));
            req.setRequestProperty("X-GameQueryCount", String.valueOf(count));
            req.connect();
            if (req.getResponseCode() == HttpURLConnection.HTTP_OK) {
                List<GameRecord> gl = new ArrayList<GameRecord>();
                BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    if (!line.startsWith("#")) {
                        gl.add(GameRecord.decode(line));
                    }
                }
                return gl.toArray(new GameRecord[gl.size()]);
            } else {
                System.out.println(req.getResponseMessage());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
private static String loadUrlToString(String a_url) throws IOException {
        URL l_url1 = new URL(a_url);
        BufferedReader br = new BufferedReader(new InputStreamReader(l_url1.openStream()));
        String l_content = "";
        String l_ligne = null;
        l_content = br.readLine();
        while ((l_ligne = br.readLine()) != null) {
            l_content += AA.SL + l_ligne;
        }
        return l_content;
    }
public void loadJarFile(String jarFileNameParam) throws KExceptionClass {
        jarFileName = jarFileNameParam;
        {
            String message = "Loading resource file [";
            message += jarFileName;
            message += "]...";
            log.log(this, message);
        }
        try {
            URL url = new URL(jarFileName);
            JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
            jarConnection.setUseCaches(false);
            JarFile jarFile = jarConnection.getJarFile();
            Enumeration jarEntries = jarFile.entries();
            while (jarEntries.hasMoreElements()) {
                ZipEntry zipEntrie = (ZipEntry) jarEntries.nextElement();
                {
                    String message = "Scanning [";
                    message += jarFileName;
                    message += "] found [";
                    message += describeEntry(zipEntrie);
                    message += "]";
                    log.log(this, message);
                }
                htSizes.put(zipEntrie.getName(), new Integer((int) zipEntrie.getSize()));
            }
            ;
            jarFile.close();
            BufferedInputStream inputBuffer = new BufferedInputStream(jarConnection.getJarFileURL().openStream());
            ZipInputStream input = new ZipInputStream(inputBuffer);
            ZipEntry zipEntrie = null;
            while ((zipEntrie = input.getNextEntry()) != null) {
                if (zipEntrie.isDirectory()) continue;
                {
                    String message = "Scanning [";
                    message += jarFileName;
                    message += "] loading [";
                    message += zipEntrie.getName();
                    message += "] for [";
                    message += zipEntrie.getSize();
                    message += "] bytes.";
                    log.log(this, message);
                }
                int size = (int) zipEntrie.getSize();
                if (size == -1) {
                    size = ((Integer) htSizes.get(zipEntrie.getName())).intValue();
                }
                ;
                byte[] entrieData = new byte[(int) size];
                int offset = 0;
                int dataRead = 0;
                while (((int) size - offset) > 0) {
                    dataRead = input.read(entrieData, offset, (int) size - offset);
                    if (dataRead == -1) break;
                    offset += dataRead;
                }
                htJarContents.put(zipEntrie.getName(), entrieData);
                if (debugOn) {
                    System.out.println(zipEntrie.getName() + "  offset=" + offset + ",size=" + size + ",csize=" + zipEntrie.getCompressedSize());
                }
                ;
            }
            ;
        } catch (Exception error) {
            String message = "Error loading data from JAR file [";
            message += error.toString();
            message += "]";
            throw new KExceptionClass(message, new KExceptionClass(error.toString(), null));
        }
        ;
    }
private static final void addFile(ZipArchiveOutputStream os, File file, String prefix) throws IOException {
        ArchiveEntry entry = os.createArchiveEntry(file, file.getAbsolutePath().substring(prefix.length() + 1));
        os.putArchiveEntry(entry);
        FileInputStream fis = new FileInputStream(file);
        IOUtils.copy(fis, os);
        fis.close();
        os.closeArchiveEntry();
    }
private void dumpFile(File repository, File copy) {
        try {
            if (copy.exists() && !copy.delete()) {
                throw new RuntimeException("can't delete copy: " + copy);
            }
            printFile("Real Archive File", repository);
            new ZipArchive(repository.getPath());
            IOUtils.copyFiles(repository, copy);
            printFile("Copy Archive File", copy);
            new ZipArchive(copy.getPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public Stopper(String stopWordsFile) {
        try {
            BufferedReader br = null;
            FileReader fr = null;
            if (stopWordsFile.startsWith("http")) {
                URL url = new URL(stopWordsFile);
                br = new BufferedReader(new InputStreamReader(url.openStream()));
            } else {
                fr = new FileReader(new File(stopWordsFile));
                br = new BufferedReader(fr);
            }
            String line = null;
            while ((line = br.readLine()) != null) {
                line = line.trim();
                stopWords.put(line, "");
            }
            fr.close();
        } catch (Exception e) {
            System.out.println("Stopwords not Found");
            return;
        }
    }
public InputStream open() {
        try {
            if ("file".equals(url.getProtocol())) {
                if (new File(url.toURI()).exists()) {
                    inputStream = url.openStream();
                }
            } else {
                con = url.openConnection();
                if (con instanceof JarURLConnection) {
                    JarURLConnection jarCon = (JarURLConnection) con;
                    jarCon.setUseCaches(false);
                    jarFile = jarCon.getJarFile();
                }
                inputStream = con.getInputStream();
            }
        } catch (Exception e) {
        }
        return inputStream;
    }
protected void copyAndDelete(final URL _src, final long _temp) throws IOException {
        final File storage = getStorageFile(_src, _temp);
        final File dest = new File(_src.getFile());
        FileChannel in = null;
        FileChannel out = null;
        if (storage.equals(dest)) {
            return;
        }
        try {
            readWriteLock_.lockWrite();
            if (dest.exists()) {
                dest.delete();
            }
            if (storage.exists() && !storage.renameTo(dest)) {
                in = new FileInputStream(storage).getChannel();
                out = new FileOutputStream(dest).getChannel();
                final long len = in.size();
                final long copied = out.transferFrom(in, 0, in.size());
                if (len != copied) {
                    throw new IOException("unable to complete write");
                }
            }
        } finally {
            readWriteLock_.unlockWrite();
            try {
                if (in != null) {
                    in.close();
                }
            } catch (final IOException _evt) {
                FuLog.error(_evt);
            }
            try {
                if (out != null) {
                    out.close();
                }
            } catch (final IOException _evt) {
                FuLog.error(_evt);
            }
            storage.delete();
        }
    }
public static Boolean decompress(File source, File destination) {
        FileOutputStream outputStream;
        ZipInputStream inputStream;
        try {
            outputStream = null;
            inputStream = new ZipInputStream(new FileInputStream(source));
            int read;
            byte buffer[] = new byte[BUFFER_SIZE];
            ZipEntry zipEntry;
            while ((zipEntry = inputStream.getNextEntry()) != null) {
                if (zipEntry.isDirectory()) new File(destination, zipEntry.getName()).mkdirs(); else {
                    File fileEntry = new File(destination, zipEntry.getName());
                    fileEntry.getParentFile().mkdirs();
                    outputStream = new FileOutputStream(fileEntry);
                    while ((read = inputStream.read(buffer, 0, BUFFER_SIZE)) != -1) {
                        outputStream.write(buffer, 0, read);
                    }
                    outputStream.flush();
                    outputStream.close();
                }
            }
            inputStream.close();
        } catch (Exception oException) {
            return false;
        }
        return true;
    }
public ClassifiedCandidate postToClassifiedCandidate(ClassifiedCandidate cand, RawCandidateMatched basic) throws BookKeeprCommunicationException {
        try {
            synchronized (httpClient) {
                HttpPost req = new HttpPost(remoteHost.getUrl() + "/cand/" + Long.toHexString(cand.getId()));
                req.setHeader("Accept-Encoding", "gzip");
                ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
                XMLWriter.write(out, basic);
                ByteArrayInputStream in2 = new ByteArrayInputStream(out.toByteArray());
                req.setEntity(new InputStreamEntity(in2, -1));
                HttpResponse resp = httpClient.execute(req);
                if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    try {
                        InputStream in = resp.getEntity().getContent();
                        Header hdr = resp.getFirstHeader("Content-Encoding");
                        String enc = "";
                        if (hdr != null) {
                            enc = resp.getFirstHeader("Content-Encoding").getValue();
                        }
                        if (enc.equals("gzip")) {
                            in = new GZIPInputStream(in);
                        }
                        XMLAble xmlable = XMLReader.read(in);
                        in.close();
                        if (xmlable instanceof ClassifiedCandidate) {
                            ClassifiedCandidate p = (ClassifiedCandidate) xmlable;
                            return p;
                        } else {
                            resp.getEntity().consumeContent();
                            throw new BookKeeprCommunicationException("BookKeepr returned the wrong thing for ClassifiedCandidate");
                        }
                    } catch (SAXException ex) {
                        Logger.getLogger(BookKeeprConnection.class.getName()).log(Level.WARNING, "Got a malformed message from the bookkeepr", ex);
                        throw new BookKeeprCommunicationException(ex);
                    }
                } else {
                    throw new BookKeeprCommunicationException("Got a " + resp.getStatusLine().getStatusCode() + " from the BookKeepr");
                }
            }
        } catch (HttpException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (IOException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (URISyntaxException ex) {
            throw new BookKeeprCommunicationException(ex);
        }
    }
public ViewedCandidatesIndex getAllViewedCandidates() throws BookKeeprCommunicationException {
        try {
            synchronized (httpClient) {
                HttpGet req = new HttpGet(remoteHost.getUrl() + "/cand/viewed");
                req.setHeader("Accept-Encoding", "gzip");
                HttpResponse resp = httpClient.execute(req);
                if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    try {
                        InputStream in = resp.getEntity().getContent();
                        Header hdr = resp.getFirstHeader("Content-Encoding");
                        String enc = "";
                        if (hdr != null) {
                            enc = resp.getFirstHeader("Content-Encoding").getValue();
                        }
                        if (enc.equals("gzip")) {
                            in = new GZIPInputStream(in);
                        }
                        XMLAble xmlable = XMLReader.read(in);
                        in.close();
                        if (xmlable instanceof ViewedCandidatesIndex) {
                            ViewedCandidatesIndex p = (ViewedCandidatesIndex) xmlable;
                            return p;
                        } else {
                            resp.getEntity().consumeContent();
                            throw new BookKeeprCommunicationException("BookKeepr returned the wrong thing for ViewedCandidatesIndex");
                        }
                    } catch (SAXException ex) {
                        Logger.getLogger(BookKeeprConnection.class.getName()).log(Level.WARNING, "Got a malformed message from the bookkeepr", ex);
                        throw new BookKeeprCommunicationException(ex);
                    }
                } else {
                    throw new BookKeeprCommunicationException("Got a " + resp.getStatusLine().getStatusCode() + " from the BookKeepr");
                }
            }
        } catch (HttpException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (IOException ex) {
            throw new BookKeeprCommunicationException(ex);
        } catch (URISyntaxException ex) {
            throw new BookKeeprCommunicationException(ex);
        }
    }