semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void compressFile(File f) throws IOException {
        File target = new File(f.toString() + ".gz");
        System.out.print("Compressing: " + f.getName() + ".. ");
        long initialSize = f.length();
        FileInputStream fis = new FileInputStream(f);
        GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(target));
        byte[] buf = new byte[1024];
        int read;
        while ((read = fis.read(buf)) != -1) {
            out.write(buf, 0, read);
        }
        System.out.println("Done.");
        fis.close();
        out.close();
        long endSize = target.length();
        System.out.println("Initial size: " + initialSize + "; Compressed size: " + endSize);
    }
public static void decompressFile(File f) throws IOException {
        File target = new File(f.toString().substring(0, f.toString().length() - 3));
        System.out.print("Decompressing: " + f.getName() + ".. ");
        long initialSize = f.length();
        GZIPInputStream in = new GZIPInputStream(new FileInputStream(f));
        FileOutputStream fos = new FileOutputStream(target);
        byte[] buf = new byte[1024];
        int read;
        while ((read = in.read(buf)) != -1) {
            fos.write(buf, 0, read);
        }
        System.out.println("Done.");
        fos.close();
        in.close();
        long endSize = target.length();
        System.out.println("Initial size: " + initialSize + "; Decompressed size: " + endSize);
    }
public IUserProfile getUserProfile(String profileID) throws MM4UUserProfileNotFoundException {
        SimpleUserProfile tempProfile = null;
        String tempProfileString = this.profileURI + profileID + FILE_SUFFIX;
        try {
            URL url = new URL(tempProfileString);
            Debug.println("Retrieve profile with ID: " + url);
            tempProfile = new SimpleUserProfile();
            BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
            String tempLine = null;
            tempProfile.add("id", profileID);
            while ((tempLine = input.readLine()) != null) {
                Property tempProperty = PropertyList.splitStringIntoKeyAndValue(tempLine);
                if (tempProperty != null) {
                    tempProfile.addIfNotNull(tempProperty.getKey(), tempProperty.getValue());
                }
            }
            input.close();
        } catch (MalformedURLException exception) {
            throw new MM4UUserProfileNotFoundException(this, "getProfile", "Profile '" + tempProfileString + "' not found.");
        } catch (IOException exception) {
            throw new MM4UUserProfileNotFoundException(this, "getProfile", "Profile '" + tempProfileString + "' not found.");
        }
        return tempProfile;
    }
private void setProfile(String loginName, SimpleUserProfile profile) throws MM4UCannotStoreUserProfileException {
        try {
            OutputStream outStream = null;
            URL url = new URL(this.profileURI + profile.getID() + FILE_SUFFIX);
            if (url.getProtocol().equals("file")) {
                File file = new File(url.getFile());
                outStream = new FileOutputStream(file);
            } else {
                URLConnection connection = url.openConnection();
                connection.setDoOutput(true);
                outStream = connection.getOutputStream();
            }
            OutputStreamWriter writer = new OutputStreamWriter(outStream);
            Enumeration myEnum = profile.keys();
            while (myEnum.hasMoreElements()) {
                String key = myEnum.nextElement().toString();
                if (key != "id") writer.write(key + "=" + profile.getStringValue(key) + System.getProperty("line.separator"));
            }
            writer.flush();
            writer.close();
        } catch (Exception e) {
            throw new MM4UCannotStoreUserProfileException(this, "setProfile", e.toString());
        }
    }
public FileChooserTestFrame() throws HeadlessException, MalformedURLException {
        super();
        addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent aEvent) {
                System.exit(0);
            }
        });
        Dimension dim = getToolkit().getScreenSize();
        Rectangle abounds = getBounds();
        setLocation((dim.width - abounds.width) / 2, (dim.height - abounds.height) / 2);
        setVisible(true);
        URL url = new URL("ftp://cendantstp/");
        char[] password = "spnr".toCharArray();
        PasswordAuthentication passwordAuthentication = new PasswordAuthentication("spnr", password);
        FTPRemoteFileSystemView remoteFileSystemView = new FTPRemoteFileSystemView(url, passwordAuthentication);
        JFileChooser fileChooser = new InsightRemoteFileChooser(remoteFileSystemView);
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setMultiSelectionEnabled(true);
        File[] selectedFiles = null;
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            selectedFiles = fileChooser.getSelectedFiles();
            for (int i = 0; i < selectedFiles.length; i++) {
                if (selectedFiles[i] instanceof FTPFileFile) {
                    FTPFileFile ftpFile = (FTPFileFile) selectedFiles[i];
                    logger.fine(ftpFile.getName());
                    logger.fine(ftpFile.getPath());
                } else {
                    logger.fine(selectedFiles[i].toString());
                    logger.fine(selectedFiles[i].getAbsolutePath());
                }
            }
        }
        remoteFileSystemView.disconnect();
        try {
            if (null != selectedFiles) {
                FTPClient ftpClient = new FTPClient();
                InetAddress inetAddress = InetAddress.getByName(url.getHost());
                ftpClient.connect(inetAddress);
                if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                    throw new FTPBrowseException(ftpClient.getReplyString());
                }
                if (null != passwordAuthentication) {
                    ftpClient.login(passwordAuthentication.getUserName(), new StringBuffer().append(passwordAuthentication.getPassword()).toString());
                }
                for (int i = 0; i < selectedFiles.length; i++) {
                    FTPFileFile file = (FTPFileFile) selectedFiles[i];
                    logger.fine(file.getPath());
                    FileOutputStream fos = new FileOutputStream(new File("d:/junk/ftp/test.txt"));
                    logger.fine("" + ftpClient.retrieveFile(file.getPath().replaceAll("\\\\", "/"), fos));
                    fos.close();
                }
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.exit(0);
    }
public byte[] read(IFile input) {
        InputStream contents = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            contents = input.getContents();
            IOUtils.copy(contents, baos);
            return baos.toByteArray();
        } catch (IOException e) {
            Activator.logUnexpected(null, e);
        } catch (CoreException e) {
            Activator.logUnexpected(null, e);
        } finally {
            IOUtils.closeQuietly(contents);
        }
        return null;
    }
public static NodeId generateTopicId(String topicName) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            System.err.println("No SHA support!");
        }
        md.update(topicName.getBytes());
        byte[] digest = md.digest();
        NodeId newId = new NodeId(digest);
        return newId;
    }
private void buildCache() {
        cache = new HashMap<String, byte[]>();
        JarInputStream jis = null;
        BufferedInputStream bis = null;
        URL[] urls = getURLs();
        for (URL url : urls) {
            try {
                if (url.getPath().endsWith(".jar")) {
                    jis = new JarInputStream(url.openStream());
                    bis = new BufferedInputStream(jis);
                    JarEntry jarEntry = null;
                    while ((jarEntry = jis.getNextJarEntry()) != null) {
                        String name = jarEntry.getName();
                        if (!jarEntry.isDirectory() && name.toLowerCase().endsWith(".class")) {
                            String className = name.replaceAll("/", ".").substring(0, name.length() - 6);
                            if (isClassLoaderConditonVerified(className)) {
                                ByteArrayOutputStream baos = null;
                                BufferedOutputStream bos = null;
                                try {
                                    baos = new ByteArrayOutputStream();
                                    bos = new BufferedOutputStream(baos);
                                    int i = -1;
                                    while ((i = bis.read()) != -1) {
                                        bos.write(i);
                                    }
                                    bos.flush();
                                    cache.put(className, baos.toByteArray());
                                } finally {
                                    if (baos != null) {
                                        try {
                                            baos.close();
                                        } catch (IOException ignore) {
                                        }
                                    }
                                    if (bos != null) {
                                        try {
                                            bos.close();
                                        } catch (IOException ex) {
                                        }
                                    }
                                }
                                jis.closeEntry();
                            }
                        }
                    }
                    try {
                        jis.close();
                    } catch (IOException ignore) {
                    }
                } else {
                    File file = new File(url.getFile());
                    buildCacheFromFile(file, null);
                }
            } catch (IOException ex) {
                continue;
            }
        }
    }
public static boolean copyFile(File from, File tu) {
        final int BUFFER_SIZE = 4096;
        byte[] buffer = new byte[BUFFER_SIZE];
        try {
            FileInputStream in = new FileInputStream(from);
            FileOutputStream out = new FileOutputStream(tu);
            int read;
            while ((read = in.read(buffer)) != -1) {
                out.write(buffer, 0, read);
            }
            in.close();
            out.close();
        } catch (IOException e) {
            return false;
        }
        return true;
    }
public void execute(HttpResponse response) throws HttpException, IOException {
        Collection<Data> allData = internalDataBank.getAll();
        StringBuffer content = new StringBuffer();
        for (Data data : allData) {
            content.append("keyHash:").append(data.getKeyHash()).append(", ");
            content.append("version:").append(data.getVersion()).append(", ");
            content.append("size:").append(data.getContent().length);
            content.append(SystemUtils.LINE_SEPARATOR);
        }
        StringEntity body = new StringEntity(content.toString());
        body.setContentType(PLAIN_TEXT_RESPONSE_CONTENT_TYPE);
        response.setEntity(body);
    }
public boolean reject(String surl, ProgressMonitor mon) throws IllegalArgumentException {
        DocumentBuilder builder = null;
        try {
            builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            URISplit split = URISplit.parse(surl);
            URL url = new URL(split.file);
            InputStream in = url.openStream();
            InputSource source = new InputSource(in);
            Document document = builder.parse(source);
            in.close();
            Node n = document.getDocumentElement();
            String localName = n.getNodeName();
            int i = localName.indexOf(":");
            if (i > -1) {
                localName = localName.substring(i + 1);
            }
            if (localName.equals("Spase")) {
                return false;
            } else if (localName.equals("Eventlist")) {
                return false;
            } else if (localName.equals("VOTABLE")) {
                return false;
            } else {
                return true;
            }
        } catch (Exception ex) {
            Logger.getLogger(SpaseRecordDataSourceFactory.class.getName()).log(Level.SEVERE, null, ex);
            return true;
        }
    }
public boolean download(String url) {
        HttpGet httpGet = new HttpGet(url);
        String filename = FileUtils.replaceNonAlphanumericCharacters(url);
        String completePath = directory + File.separatorChar + filename;
        int retriesLeft = MAX_RETRIES;
        while (retriesLeft > 0) {
            try {
                HttpResponse response = httpClient.execute(httpGet);
                HttpEntity resEntity = response.getEntity();
                if (resEntity != null) {
                    logger.info("Downloading file from " + url + " -> " + completePath);
                    IOUtils.copy(resEntity.getContent(), new FileOutputStream(completePath));
                    logger.info("File " + filename + " was downloaded successfully.");
                    setFileSize(new File(completePath).length());
                    setFilename(filename);
                    return true;
                } else {
                    logger.warn("Trouble downloading file from " + url + ". Status was: " + response.getStatusLine());
                }
            } catch (ClientProtocolException e) {
                logger.error("Protocol error. This is probably serious, and there's no need " + "to continue trying to download this file.", e);
                return false;
            } catch (IOException e) {
                logger.warn("IO trouble: " + e.getMessage() + ". Retries left: " + retriesLeft);
            }
            retriesLeft--;
        }
        return false;
    }
public static void copyFile(File src, File dest) throws IOException, IllegalArgumentException {
        if (src.isDirectory()) throw new IllegalArgumentException("Source file is a directory");
        if (dest.isDirectory()) throw new IllegalArgumentException("Destination file is a directory");
        int bufferSize = 4 * 1024;
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dest);
        byte[] buffer = new byte[bufferSize];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) >= 0) out.write(buffer, 0, bytesRead);
        out.close();
        in.close();
    }
public static File gzipLog() throws IOException {
        RunnerClass.nfh.flush();
        File log = new File(RunnerClass.homedir + "pj.log");
        GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(new File(log.getCanonicalPath() + ".pjl")));
        FileInputStream in = new FileInputStream(log);
        int bufferSize = 4 * 1024;
        byte[] buffer = new byte[bufferSize];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) >= 0) out.write(buffer, 0, bytesRead);
        out.close();
        in.close();
        return new File(log.getCanonicalPath() + ".pjl");
    }
public static File copy(String inFileName, String outFileName) throws IOException {
        File inputFile = new File(inFileName);
        File outputFile = new File(outFileName);
        FileReader in = new FileReader(inputFile);
        FileWriter out = new FileWriter(outputFile);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
        return outputFile;
    }
public static TikaInputStream get(URL url, Metadata metadata) throws IOException {
        if ("file".equalsIgnoreCase(url.getProtocol())) {
            try {
                File file = new File(url.toURI());
                if (file.isFile()) {
                    return get(file, metadata);
                }
            } catch (URISyntaxException e) {
            }
        }
        URLConnection connection = url.openConnection();
        String path = url.getPath();
        int slash = path.lastIndexOf('/');
        if (slash + 1 < path.length()) {
            metadata.set(Metadata.RESOURCE_NAME_KEY, path.substring(slash + 1));
        }
        String type = connection.getContentType();
        if (type != null) {
            metadata.set(Metadata.CONTENT_TYPE, type);
        }
        String encoding = connection.getContentEncoding();
        if (encoding != null) {
            metadata.set(Metadata.CONTENT_ENCODING, encoding);
        }
        int length = connection.getContentLength();
        if (length >= 0) {
            metadata.set(Metadata.CONTENT_LENGTH, Integer.toString(length));
        }
        return new TikaInputStream(new BufferedInputStream(connection.getInputStream()), new TemporaryResources(), length);
    }
public File getFile() throws IOException {
        if (file == null) {
            if (position > 0) {
                throw new IOException("Stream is already being read");
            } else {
                file = tmp.createTemporaryFile();
                OutputStream out = new FileOutputStream(file);
                try {
                    IOUtils.copy(in, out);
                } finally {
                    out.close();
                }
                FileInputStream newStream = new FileInputStream(file);
                tmp.addResource(newStream);
                final InputStream oldStream = in;
                in = new BufferedInputStream(newStream) {

                    @Override
                    public void close() throws IOException {
                        oldStream.close();
                    }
                };
                length = file.length();
            }
        }
        return file;
    }
public Location getLocation(String ip) throws Exception {
        URL url = new URL("http://api.hostip.info/?ip=" + ip);
        SAXReader reader = new SAXReader();
        Document doc = reader.read(url.openStream());
        System.out.println(doc.asXML());
        Location location = new Location(doc);
        return location;
    }
@Override
    public void view(HttpServletRequest request, HttpServletResponse response) throws Exception {
        boolean found = false;
        String name = getArgument(request.getPathInfo());
        if (StringUtils.contains(name, '/')) {
            File file = new File(config.getProperty(Config.MULTIMEDIA_PATH) + Config.FILE_SEPARATOR + name);
            if (file.exists() && file.isFile()) {
                found = true;
                MagicMatch match = Magic.getMagicMatch(file, true);
                response.setContentType(match.getMimeType());
                FileInputStream in = new FileInputStream(file);
                IOUtils.copyLarge(in, response.getOutputStream());
                in.close();
            }
        } else if (!StringUtils.isBlank(name)) {
            int articleId = NumberUtils.toInt(name);
            if (articleId > 0) {
                Article article = articleDao.load(articleId);
                if (article != null) {
                    found = true;
                    sendArticle(request, response, article);
                }
            }
        } else {
            int page = NumberUtils.toInt(request.getParameter("page"), 0);
            Date fromDate = null;
            String from = request.getParameter("from");
            if (StringUtils.isNotBlank(from)) {
                try {
                    fromDate = dayMonthYearEn.parse(from);
                } catch (ParseException e) {
                }
            }
            Date untilDate = null;
            String until = request.getParameter("until");
            if (StringUtils.isNotBlank(until)) {
                try {
                    untilDate = dayMonthYearEn.parse(until);
                } catch (ParseException e) {
                }
            }
            sendArticleList(request, response, articleDao.list(request.getParameter("query"), request.getParameter("author"), request.getParameter("tags"), request.getParameterValues("types"), fromDate, untilDate, page, HITS_PER_PAGE, null));
            found = true;
        }
        if (found != true) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }
    }
public void writeTo(OutputStream out) throws IOException, MessagingException {
        InputStream in = getInputStream();
        Base64OutputStream base64Out = new Base64OutputStream(out);
        IOUtils.copy(in, base64Out);
        base64Out.close();
        mFile.delete();
    }
public String fetch(final String address) throws EncoderException {
        final String escapedAddress = new URLCodec().encode(address);
        final String requestUrl = GeoCodeFetch.urlXmlPath + "&" + "address=" + escapedAddress;
        this.log.debug("requestUrl: {}", requestUrl);
        try {
            final StringBuffer sb = new StringBuffer();
            final URL url = new URL(requestUrl);
            final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                this.log.debug("line: {}", line);
                sb.append(line);
            }
            reader.close();
            return (sb.toString());
        } catch (final MalformedURLException ex) {
            this.log.error(ExceptionUtils.getStackTrace(ex));
        } catch (final IOException ex) {
            this.log.error(ExceptionUtils.getStackTrace(ex));
        }
        return ("");
    }
private List<String> getContainedFilePaths(URL url) throws Exception {
        JarInputStream jis = new JarInputStream(url.openStream());
        ZipEntry zentry = null;
        ArrayList<String> fullNames = new ArrayList<String>();
        while ((zentry = jis.getNextEntry()) != null) {
            String name = zentry.getName();
            if (!zentry.isDirectory()) {
                fullNames.add(name);
            }
        }
        jis.close();
        return (fullNames);
    }
private String getFullClassName(URL url, String className) throws Exception {
        JarInputStream jis = new JarInputStream(url.openStream());
        ZipEntry zentry = null;
        while ((zentry = jis.getNextEntry()) != null) {
            String name = zentry.getName();
            int lastPos = name.lastIndexOf(".class");
            if (lastPos < 0) {
                continue;
            }
            name = name.replace('/', '.');
            int pos = -1;
            if (className != null) {
                pos = name.indexOf(className);
                if (pos >= 0 && name.length() == pos + className.length() + 6) {
                    jis.close();
                    return (name.substring(0, lastPos));
                }
            }
        }
        jis.close();
        return (null);
    }