semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private boolean hasPackageInfo(URL url) {
        if (url == null) return false;
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = br.readLine()) != null) {
                if (line.startsWith("Specification-Title: ") || line.startsWith("Specification-Version: ") || line.startsWith("Specification-Vendor: ") || line.startsWith("Implementation-Title: ") || line.startsWith("Implementation-Version: ") || line.startsWith("Implementation-Vendor: ")) return true;
            }
        } catch (IOException ioe) {
        } finally {
            if (br != null) try {
                br.close();
            } catch (IOException e) {
            }
        }
        return false;
    }
public void getFile(OutputStream output, Fragment fragment) throws Exception {
        Assert.Arg.notNull(output, "output");
        Assert.Arg.notNull(fragment, "fragment");
        Assert.Arg.notNull(fragment.getId(), "fragment.getId()");
        if (this.delegate != null) {
            this.delegate.getFile(output, fragment);
            return;
        }
        ensureBaseDirectoryCreated();
        File filePath = getFragmentFilePath(fragment);
        InputStream input = FileUtils.openInputStream(filePath);
        try {
            IOUtils.copyLarge(input, output);
        } finally {
            IOUtils.closeQuietly(input);
        }
    }
public static void copy(String source, String destination) {
        FileReader in = null;
        FileWriter out = null;
        try {
            File inputFile = new File(source);
            File outputFile = new File(destination);
            in = new FileReader(inputFile);
            out = new FileWriter(outputFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null) try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (out != null) try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
public static void extractFile(String jarArchive, String fileToExtract, String destination) {
        FileWriter writer = null;
        ZipInputStream zipStream = null;
        try {
            FileInputStream inputStream = new FileInputStream(jarArchive);
            BufferedInputStream bufferedStream = new BufferedInputStream(inputStream);
            zipStream = new ZipInputStream(bufferedStream);
            writer = new FileWriter(new File(destination));
            ZipEntry zipEntry = null;
            while ((zipEntry = zipStream.getNextEntry()) != null) {
                if (zipEntry.getName().equals(fileToExtract)) {
                    int size = (int) zipEntry.getSize();
                    for (int i = 0; i < size; i++) {
                        writer.write(zipStream.read());
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (zipStream != null) try {
                zipStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (writer != null) try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
protected List<Datastream> getDatastreams(final DepositCollection pDeposit) throws IOException, SWORDException {
        List<Datastream> tDatastreams = super.getDatastreams(pDeposit);
        FileInputStream tInput = null;
        String tFileName = ((LocalDatastream) tDatastreams.get(0)).getPath();
        String tTempFileName = this.getTempDir() + "uploaded-file.tmp";
        IOUtils.copy(tInput = new FileInputStream(tFileName), new FileOutputStream(tTempFileName + ".thum"));
        tInput.close();
        Datastream tThum = new LocalDatastream("THUMBRES_IMG", this.getContentType(), tTempFileName + ".thum");
        tDatastreams.add(tThum);
        IOUtils.copy(tInput = new FileInputStream(tFileName), new FileOutputStream(tTempFileName + ".mid"));
        tInput.close();
        Datastream tMid = new LocalDatastream("MEDRES_IMG", this.getContentType(), tTempFileName + ".mid");
        tDatastreams.add(tMid);
        IOUtils.copy(tInput = new FileInputStream(tFileName), new FileOutputStream(tTempFileName + ".high"));
        tInput.close();
        Datastream tLarge = new LocalDatastream("HIGHRES_IMG", this.getContentType(), tTempFileName + ".high");
        tDatastreams.add(tLarge);
        IOUtils.copy(tInput = new FileInputStream(tFileName), new FileOutputStream(tTempFileName + ".vhigh"));
        tInput.close();
        Datastream tVLarge = new LocalDatastream("VERYHIGHRES_IMG", this.getContentType(), tTempFileName + ".vhigh");
        tDatastreams.add(tVLarge);
        return tDatastreams;
    }
@Override
    public void parse() throws IOException {
        URL url = new URL((new DataUrlResolver()).getDataUrl(DomainName.CROATIA));
        URLConnection con = url.openConnection();
        BufferedReader bStream = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String str;
        bStream.readLine();
        while ((str = bStream.readLine()) != null) {
            String[] tokens = str.split("(\\s+)");
            String charCode = tokens[0].replaceAll("([0-9+])", "");
            Float value = Float.parseFloat(tokens[2].trim().replace(",", "."));
            CurrencyUnit unit = new CurrencyUnit(charCode, value, DEFAULT_MULTIPLIER);
            this.set.add(unit);
        }
    }
private String copy(PluginVersionDetail usePluginVersion, File runtimeRepository) {
        try {
            File tmpFile = null;
            try {
                tmpFile = File.createTempFile("tmpPlugin_", ".zip");
                tmpFile.deleteOnExit();
                URL url = new URL(usePluginVersion.getUri());
                String destFilename = new File(url.getFile()).getName();
                File destFile = new File(runtimeRepository, destFilename);
                InputStream in = null;
                FileOutputStream out = null;
                int bytesDownload = 0;
                long startTime = 0;
                long endTime = 0;
                try {
                    URLConnection urlConnection = url.openConnection();
                    bytesDownload = urlConnection.getContentLength();
                    in = urlConnection.getInputStream();
                    out = new FileOutputStream(tmpFile);
                    startTime = System.currentTimeMillis();
                    IOUtils.copy(in, out);
                    endTime = System.currentTimeMillis();
                } finally {
                    if (out != null) {
                        out.close();
                    }
                    if (in != null) {
                        in.close();
                    }
                }
                String downloadSpeedInfo = null;
                long downloadSpeed = 0;
                if ((endTime - startTime) > 0) {
                    downloadSpeed = 1000L * bytesDownload / (endTime - startTime);
                }
                if (downloadSpeed == 0) {
                    downloadSpeedInfo = "? B/s";
                } else if (downloadSpeed < 1000) {
                    downloadSpeedInfo = downloadSpeed + " B/s";
                } else if (downloadSpeed < 1000000) {
                    downloadSpeedInfo = downloadSpeed / 1000 + " KB/s";
                } else if (downloadSpeed < 1000000000) {
                    downloadSpeedInfo = downloadSpeed / 1000000 + " MB/s";
                } else {
                    downloadSpeedInfo = downloadSpeed / 1000000000 + " GB/s";
                }
                String tmpFileMessageDigest = getMessageDigest(tmpFile.toURI().toURL()).getValue();
                if (!tmpFileMessageDigest.equals(usePluginVersion.getMessageDigest().getValue())) {
                    throw new RuntimeException("Downloaded file: " + usePluginVersion.getUri() + " does not have required message digest: " + usePluginVersion.getMessageDigest().getValue());
                }
                if (!isNoop()) {
                    FileUtils.copyFile(tmpFile, destFile);
                }
                return bytesDownload + " Bytes " + downloadSpeedInfo;
            } finally {
                if (tmpFile != null) {
                    tmpFile.delete();
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException("Could not download " + usePluginVersion.getUri() + " to " + runtimeRepository, ex);
        }
    }
public static void buildPerMovieDiffBinary(String completePath, String slopeOneDataFolderName, String slopeOneDataFileName) {
        try {
            File inFile = new File(completePath + fSep + "SmartGRAPE" + fSep + slopeOneDataFolderName + fSep + slopeOneDataFileName);
            FileChannel inC = new FileInputStream(inFile).getChannel();
            for (int i = 1; i <= 17770; i++) {
                File outFile = new File(completePath + fSep + "SmartGRAPE" + fSep + slopeOneDataFolderName + fSep + "Movie-" + i + "-SlopeOneData.txt");
                FileChannel outC = new FileOutputStream(outFile).getChannel();
                ByteBuffer buf = ByteBuffer.allocate(17770 * 10);
                for (int j = 1; j < i; j++) {
                    ByteBuffer bbuf = ByteBuffer.allocate(12);
                    inC.position((17769 * 17770 * 6) - ((17769 - (j - 1)) * (17770 - (j - 1)) * 6) + (i - j - 1) * 12);
                    inC.read(bbuf);
                    bbuf.flip();
                    buf.putShort(bbuf.getShort());
                    bbuf.getShort();
                    buf.putInt(bbuf.getInt());
                    buf.putFloat(-bbuf.getFloat());
                }
                buf.putShort(new Integer(i).shortValue());
                buf.putInt(0);
                buf.putFloat(0.0f);
                ByteBuffer remainingBuf = inC.map(FileChannel.MapMode.READ_ONLY, (17769 * 17770 * 6) - ((17769 - (i - 1)) * (17770 - (i - 1)) * 6), (17770 - i) * 12);
                while (remainingBuf.hasRemaining()) {
                    remainingBuf.getShort();
                    buf.putShort(remainingBuf.getShort());
                    buf.putInt(remainingBuf.getInt());
                    buf.putFloat(remainingBuf.getFloat());
                }
                buf.flip();
                outC.write(buf);
                buf.clear();
                outC.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private void importUrl(String str) throws Exception {
        URL url = new URL(str);
        InputStream xmlStream = url.openStream();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        MessageHolder messages = MessageHolder.getInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(xmlStream);
        Element rootElement = document.getDocumentElement();
        EntrySetParser entrySetParser = new EntrySetParser();
        EntrySetTag entrySet = entrySetParser.process(rootElement);
        UpdateProteinsI proteinFactory = new UpdateProteins();
        BioSourceFactory bioSourceFactory = new BioSourceFactory();
        ControlledVocabularyRepository.check();
        EntrySetChecker.check(entrySet, proteinFactory, bioSourceFactory);
        if (messages.checkerMessageExists()) {
            MessageHolder.getInstance().printCheckerReport(System.err);
        } else {
            EntrySetPersister.persist(entrySet);
            if (messages.checkerMessageExists()) {
                MessageHolder.getInstance().printPersisterReport(System.err);
            } else {
                System.out.println("The data have been successfully saved in your Intact node.");
            }
        }
    }
public static void copyFile(File from, File to) throws Exception {
        if (!from.exists()) return;
        FileInputStream in = new FileInputStream(from);
        FileOutputStream out = new FileOutputStream(to);
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytes_read;
        while (true) {
            bytes_read = in.read(buffer);
            if (bytes_read == -1) break;
            out.write(buffer, 0, bytes_read);
        }
        out.flush();
        out.close();
        in.close();
    }
@Test
    public void testSpeedyShareUpload() throws Exception {
        request.setUrl("http://www.speedyshare.com/upload.php");
        request.setFile("fileup0", file);
        HttpResponse response = httpClient.execute(request);
        assertTrue(response.is2xxSuccess());
        assertTrue(response.getResponseHeaders().size() > 0);
        String body = IOUtils.toString(response.getResponseBody());
        assertTrue(body.contains("Download link"));
        assertTrue(body.contains("Delete password"));
        response.close();
    }
@Test
    public void testImageshackUpload() throws Exception {
        request.setUrl("http://www.imageshack.us/index.php");
        request.addParameter("xml", "yes");
        request.setFile("fileupload", file);
        HttpResponse response = httpClient.execute(request);
        assertTrue(response.is2xxSuccess());
        assertTrue(response.getResponseHeaders().size() > 0);
        String body = IOUtils.toString(response.getResponseBody());
        assertTrue(body.contains("<image_link>"));
        assertTrue(body.contains("<thumb_link>"));
        assertTrue(body.contains("<image_location>"));
        assertTrue(body.contains("<image_name>"));
        response.close();
    }
public static void writeToPetrify(TransitionSystem ts, Writer bw) throws IOException {
        File temp = new File("_temp");
        BufferedWriter tw = new BufferedWriter(new FileWriter(temp));
        BufferedReader tr = new BufferedReader(new FileReader(temp));
        HashSet<ModelGraphVertex> sources = new HashSet<ModelGraphVertex>();
        HashSet<ModelGraphVertex> dests = new HashSet<ModelGraphVertex>();
        ArrayList transitions = ts.getEdges();
        HashSet<String> events = new HashSet<String>();
        for (int i = 0; i < transitions.size(); i++) {
            TransitionSystemEdge transition = (TransitionSystemEdge) transitions.get(i);
            events.add(replaceBadSymbols(transition.getIdentifier()));
            sources.add(transition.getSource());
            dests.add(transition.getDest());
            if (ts.getStateNameFlag() == TransitionSystem.ID) {
                tw.write("s" + transition.getSource().getId() + " ");
                tw.write(replaceBadSymbols(transition.getIdentifier()) + " ");
                tw.write("s" + transition.getDest().getId() + "\n");
            } else {
                tw.write(replaceBadSymbols(transition.getSource().getIdentifier()) + " ");
                tw.write(replaceBadSymbols(transition.getIdentifier()) + " ");
                tw.write(replaceBadSymbols(transition.getDest().getIdentifier()) + "\n");
            }
        }
        tw.close();
        bw.write(".model " + ts.getName().replaceAll(" ", "_") + "\n");
        bw.write(".dummy ");
        Iterator it = events.iterator();
        while (it.hasNext()) bw.write(it.next() + " ");
        bw.write("\n");
        bw.write(".state graph" + "\n");
        int c;
        while ((c = tr.read()) != -1) bw.write(c);
        tr.close();
        temp.delete();
        for (ModelGraphVertex dest : dests) {
            if (sources.contains(dest)) {
                sources.remove(dest);
            }
        }
        ModelGraphVertex source = sources.isEmpty() ? null : sources.iterator().next();
        if (ts.getStateNameFlag() == TransitionSystem.ID) {
            if (!ts.hasExplicitEnd()) bw.write(".marking {s0}" + "\n"); else bw.write(".marking {s" + source.getId() + "}\n");
        } else if (source != null) {
            bw.write(".marking {" + replaceBadSymbols(source.getIdentifier()) + "}\n");
        }
        bw.write(".end");
    }
public HttpURLHandler(URL url, String requestMethod, Map<String, String> parameters, String outputEncoding) throws IOException {
        logger.debug("Creating http url handler for: " + url + "; using method: " + requestMethod + "; with parameters: " + parameters);
        if (url == null) throw new IllegalArgumentException("Null pointer in url");
        if (!"http".equals(url.getProtocol()) && !"https".equals(url.getProtocol())) throw new IllegalArgumentException("Illegal url protocol: \"" + url.getProtocol() + "\"; must be \"http\" or \"https\"");
        if (requestMethod == null) throw new IllegalArgumentException("Null pointer in requestMethod");
        if (!"GET".equals(requestMethod) && !"POST".equals(requestMethod)) throw new IllegalArgumentException("Illegal request method: " + requestMethod + "; must be \"GET\" or \"POST\"");
        if (parameters == null) throw new IllegalArgumentException("Null pointer in parameters");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
        connection.setRequestMethod(requestMethod);
        connection.setUseCaches(false);
        if (EMPTY_MAP.equals(parameters)) {
            connection.setDoOutput(false);
        } else {
            connection.setDoOutput(true);
            OutputStream out = connection.getOutputStream();
            writeParameters(out, parameters, outputEncoding);
            out.close();
        }
        inputStream = connection.getInputStream();
    }
public static List<String> getServers() throws Exception {
        List<String> servers = new ArrayList<String>();
        URL url = new URL("http://tfast.org/en/servers.php");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String line = null;
        while ((line = in.readLine()) != null) {
            if (line.contains("serv=")) {
                int i = line.indexOf("serv=");
                servers.add(line.substring(i + 5, line.indexOf("\"", i)));
            }
        }
        in.close();
        return servers;
    }
private void process(String zipFileName, String directory, String db) throws SQLException {
        InputStream in = null;
        try {
            if (!FileUtils.exists(zipFileName)) {
                throw new IOException("File not found: " + zipFileName);
            }
            String originalDbName = null;
            int originalDbLen = 0;
            if (db != null) {
                originalDbName = getOriginalDbName(zipFileName, db);
                if (originalDbName == null) {
                    throw new IOException("No database named " + db + " found");
                }
                if (originalDbName.startsWith(File.separator)) {
                    originalDbName = originalDbName.substring(1);
                }
                originalDbLen = originalDbName.length();
            }
            in = FileUtils.openFileInputStream(zipFileName);
            ZipInputStream zipIn = new ZipInputStream(in);
            while (true) {
                ZipEntry entry = zipIn.getNextEntry();
                if (entry == null) {
                    break;
                }
                String fileName = entry.getName();
                fileName = fileName.replace('\\', File.separatorChar);
                fileName = fileName.replace('/', File.separatorChar);
                if (fileName.startsWith(File.separator)) {
                    fileName = fileName.substring(1);
                }
                boolean copy = false;
                if (db == null) {
                    copy = true;
                } else if (fileName.startsWith(originalDbName + ".")) {
                    fileName = db + fileName.substring(originalDbLen);
                    copy = true;
                }
                if (copy) {
                    OutputStream out = null;
                    try {
                        out = FileUtils.openFileOutputStream(directory + File.separator + fileName, false);
                        IOUtils.copy(zipIn, out);
                        out.close();
                    } finally {
                        IOUtils.closeSilently(out);
                    }
                }
                zipIn.closeEntry();
            }
            zipIn.closeEntry();
            zipIn.close();
        } catch (IOException e) {
            throw Message.convertIOException(e, zipFileName);
        } finally {
            IOUtils.closeSilently(in);
        }
    }
public void echo(HttpRequest request, HttpResponse response) throws IOException {
        InputStream in = request.getInputStream();
        if ("gzip".equals(request.getField("Content-Encoding"))) {
            in = new GZIPInputStream(in);
        }
        IOUtils.copy(in, response.getOutputStream());
    }
public synchronized String encrypt(final String pPassword) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        final MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(pPassword.getBytes("UTF-8"));
        final byte raw[] = md.digest();
        return BASE64Encoder.encodeBuffer(raw);
    }
protected void initializeGraphicalViewer() {
        getGraphicalViewer().setContents(loadModel());
        getGraphicalViewer().addDropTargetListener(createTransferDropTargetListener());
        getGraphicalViewer().addSelectionChangedListener(new ISelectionChangedListener() {

            public void selectionChanged(SelectionChangedEvent event) {
                if (event.getSelection().isEmpty()) {
                    return;
                }
                loadProperties(((StructuredSelection) event.getSelection()).getFirstElement());
            }
        });
    }
public void run() {
        String s, s2;
        s = "";
        s2 = "";
        try {
            URL url = new URL("http://www.m-w.com/dictionary/" + Word);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while (((str = in.readLine()) != null) && (!stopped)) {
                s = s + str;
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        Pattern pattern = Pattern.compile("popWin\\('/cgi-bin/(.+?)'", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher matcher = pattern.matcher(s);
        if ((!stopped) && (matcher.find())) {
            String newurl = "http://m-w.com/cgi-bin/" + matcher.group(1);
            try {
                URL url2 = new URL(newurl);
                BufferedReader in2 = new BufferedReader(new InputStreamReader(url2.openStream()));
                String str;
                while (((str = in2.readLine()) != null) && (!stopped)) {
                    s2 = s2 + str;
                }
                in2.close();
            } catch (MalformedURLException e) {
            } catch (IOException e) {
            }
            Pattern pattern2 = Pattern.compile("<A HREF=\"http://(.+?)\">Click here to listen with your default audio player", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
            Matcher matcher2 = pattern2.matcher(s2);
            if ((!stopped) && (matcher2.find())) {
                if (getWave("http://" + matcher2.group(1))) label.setEnabled(true);
            }
        }
        button.setEnabled(true);
    }