semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void doGet(HttpServletRequest request, HttpServletResponse response, CollOPort colloport, PrintStream out) throws ServletException, IOException {
        response.addDateHeader("Expires", System.currentTimeMillis() - 86400);
        String id = request.getParameter("id");
        String url_index = request.getParameter("url_index");
        int url_i;
        try {
            url_i = Integer.parseInt(url_index);
        } catch (NumberFormatException nfe) {
            url_i = 0;
        }
        Summary summary = colloport.getSummary(id);
        String filename = request.getPathInfo();
        if (filename != null && filename.length() > 0) {
            filename = filename.substring(1);
        }
        String includeURLAll = summary.getIncludeURL();
        String includeURLs[] = includeURLAll.split(" ");
        String includeURL = includeURLs[url_i];
        if (includeURL != null && includeURL.length() > 0) {
            if (filename.indexOf(":") > 0) {
                includeURL = "";
            } else if (filename.startsWith("/")) {
                includeURL = includeURL.substring(0, includeURL.indexOf("/"));
            } else if (!includeURL.endsWith("/") && includeURL.indexOf(".") > 0) {
                includeURL = includeURL.substring(0, includeURL.lastIndexOf("/") + 1);
            }
            URL url = null;
            try {
                url = new URL(includeURL + response.encodeURL(filename));
            } catch (MalformedURLException mue) {
                System.out.println(mue);
            }
            URLConnection conn = null;
            if (url != null) {
                try {
                    conn = url.openConnection();
                } catch (IOException ioe) {
                    System.out.println(ioe);
                }
            }
            if (conn != null) {
                String contentType = conn.getContentType();
                String contentDisposition;
                if (contentType == null) {
                    contentType = "application/x-java-serialized-object";
                    contentDisposition = "attachment;filename=\"" + filename + "\"";
                } else {
                    contentDisposition = "inline;filename=\"" + filename + "\"";
                }
                response.setHeader("content-disposition", contentDisposition);
                response.setContentType(contentType);
                try {
                    InputStream inputStream = conn.getInputStream();
                    byte[] buffer = new byte[4096];
                    int bytesRead;
                    while ((bytesRead = inputStream.read(buffer)) >= 0) {
                        response.getOutputStream().write(buffer, 0, bytesRead);
                    }
                    inputStream.close();
                } catch (IOException ioe) {
                    response.setContentType("text/plain");
                    ioe.printStackTrace(out);
                }
                if (conn instanceof HttpURLConnection) {
                    ((HttpURLConnection) conn).disconnect();
                }
            }
        }
    }
public static String getUrl(String urlString) {
        int retries = 0;
        String result = "";
        while (true) {
            try {
                URL url = new URL(urlString);
                BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = rdr.readLine();
                while (line != null) {
                    result += line;
                    line = rdr.readLine();
                }
                return result;
            } catch (IOException ex) {
                if (retries == 5) {
                    logger.debug("Problem getting url content exhausted");
                    return result;
                } else {
                    logger.debug("Problem getting url content retrying..." + urlString);
                    try {
                        Thread.sleep((int) Math.pow(2.0, retries) * 1000);
                    } catch (InterruptedException e) {
                    }
                    retries++;
                }
            }
        }
    }
public void start(OutputStream bytes, Target target) throws IOException {
        URLConnection conn = url.openConnection();
        InputStream fis = conn.getInputStream();
        byte[] buf = new byte[4096];
        while (true) {
            int bytesRead = fis.read(buf);
            if (bytesRead < 1) break;
            bytes.write(buf, 0, bytesRead);
        }
        fis.close();
    }
protected ProductionTabsProperties(final PlayerID playerId, final List<Rule> mRules, final String mapDir) {
        m_rules = mRules;
        final ResourceLoader loader = ResourceLoader.getMapResourceLoader(mapDir);
        String propertyFile = PROPERTY_FILE + "." + playerId.getName() + ".properties";
        URL url = loader.getResource(propertyFile);
        if (url == null) {
            propertyFile = PROPERTY_FILE + ".properties";
            url = loader.getResource(propertyFile);
            if (url == null) {
            } else {
                try {
                    m_properties.load(url.openStream());
                } catch (final IOException e) {
                    System.out.println("Error reading " + propertyFile + e);
                }
            }
        }
    }
public void setRemoteConfig(String s) {
        try {
            HashMap<String, String> map = new HashMap<String, String>();
            URL url = new URL(s);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                if (line.startsWith("#")) continue;
                String[] split = line.split("=");
                if (split.length >= 2) {
                    map.put(split[0], split[1]);
                }
            }
            MethodAndFieldSetter.setMethodsAndFields(this, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private void fileCopy(File filename) throws IOException {
        if (this.stdOut) {
            this.fileDump(filename);
            return;
        }
        File source_file = new File(spoolPath + "/" + filename);
        File destination_file = new File(copyPath + "/" + filename);
        FileInputStream source = null;
        FileOutputStream destination = null;
        byte[] buffer;
        int bytes_read;
        try {
            if (!source_file.exists() || !source_file.isFile()) throw new FileCopyException("no such source file: " + source_file);
            if (!source_file.canRead()) throw new FileCopyException("source file is unreadable: " + source_file);
            if (destination_file.exists()) {
                if (destination_file.isFile()) {
                    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                    if (!destination_file.canWrite()) throw new FileCopyException("destination file is unwriteable: " + destination_file);
                    if (!this.overwrite) {
                        System.out.print("File " + destination_file + " already exists. Overwrite? (Y/N): ");
                        System.out.flush();
                        if (!in.readLine().toUpperCase().equals("Y")) throw new FileCopyException("copy cancelled.");
                    }
                } else throw new FileCopyException("destination is not a file: " + destination_file);
            } else {
                File parentdir = parent(destination_file);
                if (!parentdir.exists()) throw new FileCopyException("destination directory doesn't exist: " + destination_file);
                if (!parentdir.canWrite()) throw new FileCopyException("destination directory is unwriteable: " + destination_file);
            }
            source = new FileInputStream(source_file);
            destination = new FileOutputStream(destination_file);
            buffer = new byte[1024];
            while ((bytes_read = source.read(buffer)) != -1) {
                destination.write(buffer, 0, bytes_read);
            }
            System.out.println("File " + filename + " successfull copied to " + destination_file);
            if (this.keep == false && source_file.isFile()) {
                try {
                    source.close();
                } catch (Exception e) {
                }
                if (source_file.delete()) {
                    new File(this.spoolPath + "/info/" + filename + ".desc").delete();
                }
            }
        } finally {
            if (source != null) try {
                source.close();
            } catch (IOException e) {
            }
            if (destination != null) try {
                destination.flush();
            } catch (IOException e) {
            }
            if (destination != null) try {
                destination.close();
            } catch (IOException e) {
            }
        }
    }
private String executePost(String targetURL, String urlParameters) {
        URL url;
        HttpURLConnection connection = null;
        try {
            url = new URL(targetURL);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
            connection.setRequestProperty("Content-Language", "en-US");
            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuffer response = new StringBuffer();
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }
            rd.close();
            return response.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
public String load(URL url) throws LoaderException {
        log.debug("loading content");
        log.trace("opening connection: " + url);
        BufferedReader in = null;
        URLConnection conn = null;
        try {
            conn = url.openConnection();
            in = null;
            if (encodedProxyLogin != null) {
                conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedProxyLogin);
            }
        } catch (IOException ioe) {
            log.warn("Error create connection");
            throw new LoaderException("Error create connection", ioe);
        }
        log.trace("connection opened, reading ... ");
        StringBuilder buffer = new StringBuilder();
        try {
            in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                buffer.append(inputLine);
            }
        } catch (IOException ioe) {
            log.warn("Error loading content");
            throw new LoaderException("Error reading content. ", ioe);
        } finally {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
        log.debug("content loaded");
        return buffer.toString();
    }
public static String md5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("MD5");
        byte[] md5hash;
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        md5hash = md.digest();
        return convertToHex(md5hash);
    }
public JsonValue get(Url url) {
        try {
            URLConnection connection = new URL(url + "").openConnection();
            return createItemFromResponse(url, connection);
        } catch (IOException e) {
            throw ItemscriptError.internalError(this, "get.IOException", e);
        }
    }
protected void entryMatched(EntryMonitor monitor, Entry entry) {
        FTPClient ftpClient = new FTPClient();
        try {
            Resource resource = entry.getResource();
            if (!resource.isFile()) {
                return;
            }
            if (server.length() == 0) {
                return;
            }
            String passwordToUse = monitor.getRepository().getPageHandler().processTemplate(password, false);
            ftpClient.connect(server);
            if (user.length() > 0) {
                ftpClient.login(user, password);
            }
            int reply = ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftpClient.disconnect();
                monitor.handleError("FTP server refused connection:" + server, null);
                return;
            }
            ftpClient.setFileType(FTP.IMAGE_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            if (directory.length() > 0) {
                ftpClient.changeWorkingDirectory(directory);
            }
            String filename = monitor.getRepository().getEntryManager().replaceMacros(entry, fileTemplate);
            InputStream is = new BufferedInputStream(monitor.getRepository().getStorageManager().getFileInputStream(new File(resource.getPath())));
            boolean ok = ftpClient.storeUniqueFile(filename, is);
            is.close();
            if (ok) {
                monitor.logInfo("Wrote file:" + directory + " " + filename);
            } else {
                monitor.handleError("Failed to write file:" + directory + " " + filename, null);
            }
        } catch (Exception exc) {
            monitor.handleError("Error posting to FTP:" + server, exc);
        } finally {
            try {
                ftpClient.logout();
            } catch (Exception exc) {
            }
            try {
                ftpClient.disconnect();
            } catch (Exception exc) {
            }
        }
    }
private void sort() {
        for (int i = 0; i < density.length; i++) {
            for (int j = density.length - 2; j >= i; j--) {
                if (density[j] > density[j + 1]) {
                    KDNode n = nonEmptyNodesArray[j];
                    nonEmptyNodesArray[j] = nonEmptyNodesArray[j + 1];
                    nonEmptyNodesArray[j + 1] = n;
                    double d = density[j];
                    density[j] = density[j + 1];
                    density[j + 1] = d;
                }
            }
        }
    }
public static DigitalObjectContent byReference(final InputStream inputStream) {
        try {
            File tempFile = File.createTempFile("tempContent", "tmp");
            tempFile.deleteOnExit();
            FileOutputStream out = new FileOutputStream(tempFile);
            IOUtils.copyLarge(inputStream, out);
            out.close();
            return new ImmutableContent(tempFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        throw new IllegalStateException("Could not create content for input stream: " + inputStream);
    }
public static void copy(String pstrFileFrom, String pstrFileTo) {
        try {
            FileChannel srcChannel = new FileInputStream(pstrFileFrom).getChannel();
            FileChannel dstChannel = new FileOutputStream(pstrFileTo).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public static void main(String[] args) throws Exception {
        HttpGet get = new HttpGet("https://localhost/docs/index.html");
        DefaultHttpClient client = new DefaultHttpClient();
        ServerConfig config = new ServerConfig(new Properties());
        config.setParam("https.keyStoreFile", "test.keystore");
        config.setParam("https.keyPassword", "nopassword");
        config.setParam("https.keyStoreType", "JKS");
        config.setParam("https.protocol", "SSLv3");
        SSLContextCreator ssl = new SSLContextCreator(config);
        SSLContext ctx = ssl.getSSLContext();
        SSLSocketFactory socketFactory = new SSLSocketFactory(ctx);
        Scheme sch = new Scheme("https", 443, socketFactory);
        client.getConnectionManager().getSchemeRegistry().register(sch);
        HttpResponse response = client.execute(get);
        System.out.println(response.getStatusLine().getStatusCode());
    }
public InputStream sendGetMessage(Properties args) throws IOException {
        String argString = "";
        if (args != null) {
            argString = "?" + toEncodedString(args);
        }
        URL url = new URL(servlet.toExternalForm() + argString);
        URLConnection con = url.openConnection();
        con.setUseCaches(false);
        sendHeaders(con);
        return con.getInputStream();
    }
@Override
    public String compute_hash(String plaintext) {
        MessageDigest d;
        try {
            d = MessageDigest.getInstance(get_algorithm_name());
            d.update(plaintext.getBytes());
            byte[] hash = d.digest();
            StringBuffer sb = new StringBuffer();
            for (byte b : hash) sb.append(String.format("%02x", b));
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
void copyTo(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException {
        if (shouldMock()) {
            return;
        }
        assert httpRequest != null;
        assert httpResponse != null;
        final long start = System.currentTimeMillis();
        try {
            final URLConnection connection = openConnection(url, headers);
            connection.setRequestProperty("Accept-Language", httpRequest.getHeader("Accept-Language"));
            connection.connect();
            try {
                InputStream input = connection.getInputStream();
                if ("gzip".equals(connection.getContentEncoding())) {
                    input = new GZIPInputStream(input);
                }
                httpResponse.setContentType(connection.getContentType());
                TransportFormat.pump(input, httpResponse.getOutputStream());
            } finally {
                close(connection);
            }
        } finally {
            LOGGER.info("http call done in " + (System.currentTimeMillis() - start) + " ms for " + url);
        }
    }
private Vendor createVendor() throws SQLException, IOException {
        Connection conn = null;
        Statement st = null;
        String query = null;
        ResultSet rs = null;
        try {
            conn = dataSource.getConnection();
            st = conn.createStatement();
            query = "insert into " + DB.Tbl.vend + "(" + col.title + "," + col.addDate + "," + col.authorId + ") values('" + title + "',now()," + user.getId() + ")";
            st.executeUpdate(query, new String[] { col.id });
            rs = st.getGeneratedKeys();
            if (!rs.next()) {
                throw new SQLException("Не удается получить generated key 'id' в таблице vendors.");
            }
            int genId = rs.getInt(1);
            rs.close();
            saveDescr(genId);
            conn.commit();
            Vendor v = new Vendor();
            v.setId(genId);
            v.setTitle(title);
            v.setDescr(descr);
            VendorViewer.getInstance().vendorListChanged();
            return v;
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (Exception e1) {
            }
            throw e;
        } finally {
            try {
                rs.close();
            } catch (Exception e) {
            }
            try {
                st.close();
            } catch (Exception e) {
            }
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
public static void main(String[] args) {
        try {
            FileReader reader = new FileReader(args[0]);
            FileWriter writer = new FileWriter(args[1]);
            html2xhtml(reader, writer);
            writer.close();
            reader.close();
        } catch (Exception e) {
            freemind.main.Resources.getInstance().logException(e);
        }
    }
public void extract(CabFolder cabfolder, File outputFolder) throws IOException {
        InputStream in = null;
        OutputStream out = null;
        File file;
        byte[] buffer = new byte[2048];
        int read, remain, maxread = buffer.length;
        in = new CabFileInputStream(cabfolder);
        CabEntry[] cabentries = this.getEntries();
        for (int i = 0; i < cabentries.length; i++) {
            if (cabentries[i].getCabFolder() == cabfolder) {
                file = new File(outputFolder, cabentries[i].getName().replace('\\', '/'));
                FileUtils.createParents(file);
                out = new FileOutputStream(file);
                remain = cabentries[i].getInflatedSize();
                while (remain != 0 && (read = in.read(buffer, 0, maxread)) != -1) {
                    out.write(buffer, 0, read);
                    remain -= read;
                    if (buffer.length > remain) maxread = remain; else maxread = buffer.length;
                }
                in.close();
                out.close();
            }
        }
    }
public void copy(File source, File destination) {
        try {
            FileInputStream fileInputStream = new FileInputStream(source);
            FileOutputStream fileOutputStream = new FileOutputStream(destination);
            FileChannel inputChannel = fileInputStream.getChannel();
            FileChannel outputChannel = fileOutputStream.getChannel();
            transfer(inputChannel, outputChannel, source.length(), false);
            fileInputStream.close();
            fileOutputStream.close();
            destination.setLastModified(source.lastModified());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }