semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public List<RTTicket> getTicketsForQueue(final String queueName, long limit) {
        getSession();
        final List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("query", "Queue='" + queueName + "' AND Status='open'"));
        params.add(new BasicNameValuePair("format", "i"));
        params.add(new BasicNameValuePair("orderby", "-id"));
        final HttpGet get = new HttpGet(m_baseURL + "/REST/1.0/search/ticket?" + URLEncodedUtils.format(params, "UTF-8"));
        final List<RTTicket> tickets = new ArrayList<RTTicket>();
        final List<Long> ticketIds = new ArrayList<Long>();
        try {
            final HttpResponse response = getClient().execute(get);
            int responseCode = response.getStatusLine().getStatusCode();
            if (responseCode != HttpStatus.SC_OK) {
                throw new RequestTrackerException("Received a non-200 response code from the server: " + responseCode);
            } else {
                InputStreamReader isr = null;
                BufferedReader br = null;
                try {
                    if (response.getEntity() == null) return null;
                    isr = new InputStreamReader(response.getEntity().getContent());
                    br = new BufferedReader(isr);
                    String line = null;
                    do {
                        line = br.readLine();
                        if (line != null) {
                            if (line.contains("does not exist.")) {
                                return null;
                            }
                            if (line.startsWith("ticket/")) {
                                ticketIds.add(Long.parseLong(line.replace("ticket/", "")));
                            }
                        }
                    } while (line != null);
                } catch (final Exception e) {
                    throw new RequestTrackerException("Unable to read ticket IDs from query.", e);
                } finally {
                    IOUtils.closeQuietly(br);
                    IOUtils.closeQuietly(isr);
                }
            }
        } catch (final Exception e) {
            LogUtils.errorf(this, e, "An exception occurred while getting tickets for queue " + queueName);
            return null;
        }
        for (final Long id : ticketIds) {
            try {
                tickets.add(getTicket(id, false));
            } catch (final RequestTrackerException e) {
                LogUtils.warnf(this, e, "Unable to retrieve ticket.");
            }
        }
        return tickets;
    }
public static boolean copy(String from, String to) {
        boolean result;
        String newLine;
        FileInputStream input;
        FileOutputStream output;
        File source;
        int fileLength;
        byte byteBuff[];
        result = false;
        input = null;
        output = null;
        source = null;
        try {
            input = new FileInputStream(from);
            output = new FileOutputStream(to);
            source = new File(from);
            fileLength = (int) source.length();
            byteBuff = new byte[fileLength];
            while (input.read(byteBuff, 0, fileLength) != -1) output.write(byteBuff, 0, fileLength);
            result = true;
        } catch (FileNotFoundException e) {
            System.out.println(from + " does not exist!");
        } catch (IOException e) {
            System.out.println("Error reading/writing files!");
        } finally {
            try {
                if (input != null) input.close();
                if (output != null) output.close();
            } catch (IOException e) {
            }
        }
        return result;
    }
public static void main(String[] args) {
        String in = "/Users/laemmel/svn/shared-svn/projects/120multiDestPeds/floor_plan/boundaries.shp";
        String out = "/Users/laemmel/svn/shared-svn/projects/120multiDestPeds/floor_plan/boundaries_closed.shp";
        ShapeFileReader reader = new ShapeFileReader();
        reader.readFileAndInitialize(in);
        QuadTree<Coordinate> quad = new QuadTree<Coordinate>(reader.getBounds().getMinX(), reader.getBounds().getMinY(), reader.getBounds().getMaxX(), reader.getBounds().getMaxY());
        for (Feature ft : reader.getFeatureSet()) {
            MultiLineString ml = (MultiLineString) ft.getDefaultGeometry();
            for (int i = 0; i < ml.getNumGeometries(); i++) {
                LineString ls = (LineString) ml.getGeometryN(i);
                Point start = ls.getStartPoint();
                checkIt(start, quad);
                Point end = ls.getEndPoint();
                checkIt(end, quad);
            }
        }
        ShapeFileWriter.writeGeometries(reader.getFeatureSet(), out);
    }
public void mkdirs(String path) throws IOException {
        GridFTP ftp = new GridFTP();
        ftp.setDefaultPort(port);
        System.out.println(this + ".mkdirs " + path);
        try {
            ftp.connect(host);
            ftp.login(username, password);
            int reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("FTP server refused connection.");
            }
            ftp.mkdirs(path);
            ftp.logout();
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public boolean storeFile(String local, String remote) throws IOException {
        boolean stored = false;
        GridFTP ftp = new GridFTP();
        ftp.setDefaultPort(port);
        System.out.println(this + ".storeFile " + remote);
        try {
            ftp.connect(host);
            ftp.login(username, password);
            int reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
                return false;
            }
            ftp.put(local, remote);
            ftp.logout();
            stored = true;
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return stored;
    }
public boolean getFile(String local, String remote) throws IOException {
        boolean result = false;
        GridFTP ftp = new GridFTP();
        ftp.setDefaultPort(port);
        System.out.println(this + ".getFile " + remote);
        try {
            ftp.connect(host);
            ftp.login(username, password);
            int reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
                return false;
            }
            ftp.get(local, remote);
            ftp.logout();
            result = true;
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println(this + ".getFile return " + result);
        return result;
    }
public String md5(String string) throws GeneralSecurityException {
        MessageDigest algorithm = MessageDigest.getInstance("MD5");
        algorithm.reset();
        algorithm.update(string.getBytes());
        byte messageDigest[] = algorithm.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
        }
        return hexString.toString();
    }
public ByteBuffer[] write(ByteBuffer[] byteBuffers) {
        if (!m_sslInitiated) {
            return m_writer.write(byteBuffers);
        }
        if (m_engine.getHandshakeStatus() != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
            if (!NIOUtils.isEmpty(byteBuffers)) {
                m_initialOutBuffer = NIOUtils.concat(m_initialOutBuffer, m_writer.write(byteBuffers));
                byteBuffers = new ByteBuffer[0];
            }
            ByteBuffer buffer = SSL_BUFFER.get();
            ByteBuffer[] buffers = null;
            try {
                SSLEngineResult result = null;
                while (m_engine.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_WRAP) {
                    buffer.clear();
                    result = m_engine.wrap(byteBuffers, buffer);
                    buffer.flip();
                    buffers = NIOUtils.concat(buffers, NIOUtils.copy(buffer));
                }
                if (result == null) return null;
                if (result.getStatus() != SSLEngineResult.Status.OK) throw new SSLException("Unexpectedly not ok wrapping handshake data, was " + result.getStatus());
                reactToHandshakeStatus(result.getHandshakeStatus());
            } catch (SSLException e) {
                throw new RuntimeException(e);
            }
            return buffers;
        }
        ByteBuffer buffer = SSL_BUFFER.get();
        buffer.clear();
        if (NIOUtils.isEmpty(byteBuffers)) {
            if (m_initialOutBuffer == null) return null;
        } else {
            byteBuffers = m_writer.write(byteBuffers);
        }
        if (m_initialOutBuffer != null) {
            byteBuffers = NIOUtils.concat(m_initialOutBuffer, byteBuffers);
            m_initialOutBuffer = null;
        }
        ByteBuffer[] encrypted = null;
        while (!NIOUtils.isEmpty(byteBuffers)) {
            buffer.clear();
            try {
                m_engine.wrap(byteBuffers, buffer);
            } catch (SSLException e) {
                throw new RuntimeException(e);
            }
            buffer.flip();
            encrypted = NIOUtils.concat(encrypted, NIOUtils.copy(buffer));
        }
        return encrypted;
    }
public static File downloadURL(URL url, File dir, String sfilename) {
        MerlotDebug.msg("Downloading URL: " + url);
        String filename = url.getFile();
        if (filename.indexOf('/') >= 0) {
            filename = filename.substring(filename.lastIndexOf('/') + 1);
        }
        File cache = new File(dir, sfilename);
        try {
            if (!dir.exists()) {
                dir.mkdirs();
            }
            URLConnection connection = url.openConnection();
            if (cache.exists() && cache.canRead()) {
                connection.connect();
                long remoteTimestamp = connection.getLastModified();
                if (remoteTimestamp == 0 || remoteTimestamp > cache.lastModified()) {
                    cache = downloadContent(connection, cache);
                } else {
                    MerlotDebug.msg("Using cached version for URL: " + url);
                }
            } else {
                cache = downloadContent(connection, cache);
            }
        } catch (IOException ex) {
            MerlotDebug.exception(ex);
        }
        if (cache != null && cache.exists()) {
            return cache;
        } else {
            return null;
        }
    }
public static void main(String[] args) {
        String u = "http://portal.acm.org/results.cfm?query=%28Author%3A%22" + "Boehm%2C+Barry" + "%22%29&srt=score%20dsc&short=0&source_disp=&since_month=&since_year=&before_month=&before_year=&coll=ACM&dl=ACM&termshow=matchboolean&range_query=&CFID=22704101&CFTOKEN=37827144&start=1";
        URL url = null;
        AcmSearchresultPageParser_2008Apr cb = new AcmSearchresultPageParser_2008Apr();
        try {
            url = new URL(u);
            HttpURLConnection uc = (HttpURLConnection) url.openConnection();
            uc.setUseCaches(false);
            InputStream is = uc.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            ParserDelegator pd = new ParserDelegator();
            pd.parse(br, cb, true);
            br.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("all doc num= " + cb.getAllDocNum());
        for (int i = 0; i < cb.getEachResultStartposisions().size(); i++) {
            HashMap<String, Integer> m = cb.getEachResultStartposisions().get(i);
            System.out.println(i + "pos= " + m);
        }
    }
private InputStream sendRequest(SequenceI seq) throws UnsupportedEncodingException, IOException {
        StringBuilder putBuf = new StringBuilder();
        processOptions(putBuf);
        putBuf.append("INPUT_SEQUENCE=");
        putBuf.append(URLEncoder.encode(">" + seq.getName() + "\n", ENCODING));
        putBuf.append(URLEncoder.encode(seq.getResidues(), ENCODING));
        URL url = new URL(PRIMER_BLAST_URL);
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(putBuf.toString());
        wr.flush();
        wr.close();
        apollo.util.IOUtil.informationDialog("Primer-BLAST request sent");
        return conn.getInputStream();
    }
public static File[] splitFile(FileValidator validator, File source, long target_length, File todir, String prefix) {
        if (target_length == 0) return null;
        if (todir == null) {
            todir = new File(System.getProperty("java.io.tmpdir"));
        }
        if (prefix == null || prefix.equals("")) {
            prefix = source.getName();
        }
        Vector result = new Vector();
        FileOutputStream fos = null;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(source);
            byte[] bytes = new byte[CACHE_SIZE];
            long current_target_size = 0;
            int current_target_nb = 1;
            int nbread = -1;
            try {
                File f = new File(todir, prefix + i18n.getString("targetname_suffix") + current_target_nb);
                if (!validator.verifyFile(f)) return null;
                result.add(f);
                fos = new FileOutputStream(f);
                while ((nbread = fis.read(bytes)) > -1) {
                    if ((current_target_size + nbread) > target_length) {
                        int limit = (int) (target_length - current_target_size);
                        fos.write(bytes, 0, limit);
                        fos.close();
                        current_target_nb++;
                        current_target_size = 0;
                        f = new File(todir, prefix + "_" + current_target_nb);
                        if (!validator.verifyFile(f)) return null;
                        result.add(f);
                        fos = new FileOutputStream(f);
                        fos.write(bytes, limit, nbread - limit);
                        current_target_size += nbread - limit;
                    } else {
                        fos.write(bytes, 0, nbread);
                        current_target_size += nbread;
                    }
                }
            } catch (IOException ioe) {
                JOptionPane.showMessageDialog(null, ioe, i18n.getString("Failure"), JOptionPane.ERROR_MESSAGE);
            } finally {
                try {
                    if (fos != null) fos.close();
                } catch (IOException e) {
                }
                try {
                    if (fis != null) fis.close();
                } catch (IOException e) {
                }
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e, i18n.getString("Failure"), JOptionPane.ERROR_MESSAGE);
        } finally {
            try {
                if (fos != null) fos.close();
            } catch (IOException e) {
            }
        }
        File[] fresult = null;
        if (result.size() > 0) {
            fresult = new File[result.size()];
            fresult = (File[]) result.toArray(fresult);
        }
        return fresult;
    }
public static void joinFiles(FileValidator validator, File target, File[] sources) {
        FileOutputStream fos = null;
        try {
            if (!validator.verifyFile(target)) return;
            fos = new FileOutputStream(target);
            FileInputStream fis = null;
            byte[] bytes = new byte[512];
            for (int i = 0; i < sources.length; i++) {
                fis = new FileInputStream(sources[i]);
                int nbread = 0;
                try {
                    while ((nbread = fis.read(bytes)) > -1) {
                        fos.write(bytes, 0, nbread);
                    }
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null, ioe, i18n.getString("Failure"), JOptionPane.ERROR_MESSAGE);
                } finally {
                    fis.close();
                }
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e, i18n.getString("Failure"), JOptionPane.ERROR_MESSAGE);
        } finally {
            try {
                if (fos != null) fos.close();
            } catch (IOException e) {
            }
        }
    }
public static void nioJoinFiles(FileLib.FileValidator validator, File target, File[] sources) {
        boolean big_files = false;
        for (int i = 0; i < sources.length; i++) {
            if (sources[i].length() > Integer.MAX_VALUE) {
                big_files = true;
                break;
            }
        }
        if (big_files) {
            joinFiles(validator, target, sources);
        } else {
            System.out.println(i18n.getString("jdk14_comment"));
            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(target);
                FileChannel fco = fos.getChannel();
                FileInputStream fis = null;
                for (int i = 0; i < sources.length; i++) {
                    fis = new FileInputStream(sources[i]);
                    FileChannel fci = fis.getChannel();
                    java.nio.MappedByteBuffer map;
                    try {
                        map = fci.map(FileChannel.MapMode.READ_ONLY, 0, (int) sources[i].length());
                        fco.write(map);
                        fci.close();
                    } catch (IOException ioe) {
                        JOptionPane.showMessageDialog(null, ioe, i18n.getString("Failure"), JOptionPane.ERROR_MESSAGE);
                        try {
                            fis.close();
                            fos.close();
                        } catch (IOException e) {
                        }
                    } finally {
                        fis.close();
                    }
                }
                fco.close();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e, i18n.getString("Failure"), JOptionPane.ERROR_MESSAGE);
            } finally {
                try {
                    if (fos != null) fos.close();
                } catch (IOException e) {
                }
            }
        }
    }
@Test
    public void requestWebapp() throws Exception {
        final HttpClient client = new DefaultHttpClient();
        final String echoValue = "ShrinkWrap>Tomcat Integration";
        final List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("to", PATH_ECHO_SERVLET));
        params.add(new BasicNameValuePair("echo", echoValue));
        final URI uri = URIUtils.createURI("http", BIND_HOST, HTTP_BIND_PORT, NAME_SIPAPP + SEPARATOR + servletClass.getSimpleName(), URLEncodedUtils.format(params, "UTF-8"), null);
        final HttpGet request = new HttpGet(uri);
        log.info("Executing request to: " + request.getURI());
        final HttpResponse response = client.execute(request);
        System.out.println(response.getStatusLine());
        final HttpEntity entity = response.getEntity();
        if (entity == null) {
            Assert.fail("Request returned no entity");
        }
        final BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
        final String line = reader.readLine();
        Assert.assertEquals("Unexpected response from Servlet", echoValue + NAME_SIPAPP, line);
    }
public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            System.out.println("arguments: sourcefile destfile");
            System.exit(1);
        }
        FileChannel in = new FileInputStream(args[0]).getChannel(), out = new FileOutputStream(args[1]).getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(BSIZE);
        while (in.read(buffer) != -1) {
            buffer.flip();
            out.write(buffer);
            buffer.clear();
        }
    }
private byte[] getBytesFromUrl(URL url) {
        ByteArrayOutputStream bais = new ByteArrayOutputStream();
        InputStream is = null;
        try {
            is = url.openStream();
            byte[] byteChunk = new byte[4096];
            int n;
            while ((n = is.read(byteChunk)) > 0) {
                bais.write(byteChunk, 0, n);
            }
        } catch (IOException e) {
            System.err.printf("Failed while reading bytes from %s: %s", url.toExternalForm(), e.getMessage());
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }
        return bais.toByteArray();
    }
private void initJarURL() {
        try {
            URL url = getKwantuJarURLInMavenRepo(artifactId, version);
            File tempJarFile = File.createTempFile(artifactId + "-" + version, ".jar");
            OutputStream out = new FileOutputStream(tempJarFile);
            InputStream in = url.openStream();
            int length = 0;
            byte[] bytes = new byte[2048];
            while ((length = in.read(bytes)) > 0) {
                out.write(bytes, 0, length);
            }
            in.close();
            out.close();
            jarURL = tempJarFile.toURI().toURL();
        } catch (IOException ex) {
            throw new KwantuFaultException(ex);
        }
    }
public static void main(String[] args) throws IOException {
        PrintStream filesTxt = new PrintStream(new BufferedOutputStream(new FileOutputStream("temp/index/files.txt")));
        String[] files = new File(Constants.INDEX_PATH).list();
        for (int i = 0; i < files.length; i++) {
            String f = files[i];
            if (f.equals("deletable") || f.startsWith(".")) continue;
            FileInputStream in = new FileInputStream(new File(Constants.INDEX_PATH, f));
            FileOutputStream out = new FileOutputStream(new File(targetDir, f + ".t"));
            byte[] buf = new byte[16384];
            int n;
            while ((n = in.read(buf)) > 0) out.write(buf, 0, n);
            in.close();
            out.close();
            filesTxt.println(f);
        }
        filesTxt.close();
    }