semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private boolean parse(Type type, URL url, boolean checkDict) throws Exception {
        boolean ok = true;
        Exception ee = null;
        Element rootElement = null;
        try {
            InputStream in = url.openStream();
            if (type.equals(Type.XOM)) {
                new Builder().build(in);
            } else if (type.equals(Type.CML)) {
                rootElement = new CMLBuilder().build(in).getRootElement();
            }
            in.close();
        } catch (Exception e) {
            ee = e;
        }
        if (ee != null) {
            logger.severe("failed to cmlParse: " + url + "\n..... because: [" + ee + "] [" + ee.getMessage() + "] in [" + url + "]");
            ok = false;
        }
        if (ok && checkDict) {
            ok = checkDict(rootElement);
        }
        return ok;
    }
public void testReadNormal() throws Exception {
        archiveFileManager.executeWith(new TemporaryFileExecutor() {

            public void execute(File temporaryFile) throws Exception {
                ZipArchive archive = new ZipArchive(temporaryFile.getPath());
                InputStream input = archive.getInputFrom(ARCHIVE_FILE_1);
                if (input != null) {
                    ByteArrayOutputStream output = new ByteArrayOutputStream();
                    IOUtils.copyAndClose(input, output);
                    assertEquals(ARCHIVE_FILE_1 + " contents not correct", ARCHIVE_FILE_1_CONTENT, output.toString());
                } else {
                    fail("cannot open " + ARCHIVE_FILE_1);
                }
            }
        });
    }
public void execute(File temporaryFile) throws Exception {
                ZipArchive archive = new ZipArchive(temporaryFile.getPath());
                InputStream input = archive.getInputFrom(ARCHIVE_FILE_1);
                if (input != null) {
                    ByteArrayOutputStream output = new ByteArrayOutputStream();
                    IOUtils.copyAndClose(input, output);
                    assertEquals(ARCHIVE_FILE_1 + " contents not correct", ARCHIVE_FILE_1_CONTENT, output.toString());
                } else {
                    fail("cannot open " + ARCHIVE_FILE_1);
                }
            }
private String extractFileFromZip(ZipFile zip, String fileName) throws IOException {
        String contents = null;
        ZipEntry entry = zip.getEntry(fileName);
        if (entry != null) {
            InputStream input = zip.getInputStream(entry);
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            IOUtils.copyAndClose(input, buffer);
            contents = buffer.toString();
        }
        return contents;
    }
public boolean urlToSpeech(String urlPath) {
        boolean ok = false;
        try {
            URL url = new URL(urlPath);
            InputStream is = url.openStream();
            ok = streamToSpeech(is);
        } catch (IOException ioe) {
            System.err.println("Can't read data from " + urlPath);
        }
        return ok;
    }
public void readBooklist(String filename) {
        Reader input = null;
        try {
            if (filename.startsWith("http:")) {
                URL url = new URL(filename);
                URLConnection conn = url.openConnection();
                input = new InputStreamReader(conn.getInputStream());
            } else {
                String fileNameAll = filename;
                try {
                    fileNameAll = new File(filename).getCanonicalPath();
                } catch (IOException e) {
                    fileNameAll = new File(filename).getAbsolutePath();
                }
                input = new FileReader(new File(fileNameAll));
            }
            BufferedReader reader = new BufferedReader(input);
            String line;
            Date today = new Date();
            while ((line = reader.readLine()) != null) {
                if (shuttingDown) break;
                String fields[] = line.split("\\|");
                Map<String, String> valuesToAdd = new LinkedHashMap<String, String>();
                valuesToAdd.put("fund_code_facet", fields[11]);
                valuesToAdd.put("date_received_facet", fields[0]);
                DateFormat format = new SimpleDateFormat("yyyyMMdd");
                Date dateReceived = format.parse(fields[0], new ParsePosition(0));
                if (dateReceived.after(today)) continue;
                String docID = "u" + fields[9];
                try {
                    Map<String, Object> docMap = getDocumentMap(docID);
                    if (docMap != null) {
                        addNewDataToRecord(docMap, valuesToAdd);
                        documentCache.put(docID, docMap);
                        if (doUpdate && docMap != null && docMap.size() != 0) {
                            update(docMap);
                        }
                    }
                } catch (SolrMarcIndexerException e) {
                    if (e.getLevel() == SolrMarcIndexerException.IGNORE) {
                        logger.error("Indexing routine says record " + docID + " should be ignored");
                    } else if (e.getLevel() == SolrMarcIndexerException.DELETE) {
                        logger.error("Indexing routine says record " + docID + " should be deleted");
                    }
                    if (e.getLevel() == SolrMarcIndexerException.EXIT) {
                        logger.error("Indexing routine says processing should be terminated by record " + docID);
                        break;
                    }
                }
            }
        } catch (FileNotFoundException e) {
            logger.info(e.getMessage());
            logger.error(e.getCause());
        } catch (IOException e) {
            logger.info(e.getMessage());
            logger.error(e.getCause());
        }
    }
private FTPClient connectFtps() throws NoSuchAlgorithmException, IOException {
        FTPClient apacheClient;
        if (isSecure) {
            apacheClient = new FTPSClient(true);
        } else {
            apacheClient = new FTPClient();
        }
        apacheClient.addProtocolCommandListener(new LogFtpListener(LOG));
        if (isSecure) {
            apacheClient.connect(host, 990);
        } else {
            apacheClient.connect(host);
        }
        if (!apacheClient.login(user, pass)) {
            throw new IllegalArgumentException("Unrecognized Username/Password");
        }
        apacheClient.setFileType(FTPClient.BINARY_FILE_TYPE);
        apacheClient.getStatus();
        apacheClient.help();
        apacheClient.enterLocalPassiveMode();
        return apacheClient;
    }
public ImportFromFile() {
        JFrame jf = new JFrame();
        JFileChooser fc = new JFileChooser(KTH.data._path);
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int returnVal = fc.showOpenDialog(jf);
        File file = null;
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = fc.getSelectedFile();
            KTH.data._path = file.getParent();
            System.out.println(file.getAbsolutePath() + "\n");
        } else {
        }
        if (file != null) {
            File f = new File(KTH.data.getHomeDir() + File.separator + KTH.data.katalogName);
            System.out.println(f + (f.exists() ? " is found " : " is missing "));
            if (f.exists() && !IOUtils.isNewerContent(file, f)) {
            } else {
                try {
                    IOUtils.copyFile(file, f, true);
                } catch (Exception e) {
                    KTH.out.err(e);
                }
            }
            KTH.dc2.removeDc("Import");
        } else {
        }
    }
public static boolean download(String url, File file) {
        HttpURLConnection conn = null;
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {
            conn = (HttpURLConnection) new URL(url).openConnection();
            conn.connect();
            if (conn.getResponseCode() == 200) {
                System.out.println("length:" + conn.getContentLength());
                in = new BufferedInputStream(conn.getInputStream());
                out = new BufferedOutputStream(new FileOutputStream(file));
                byte[] b = new byte[1024 << 10];
                int i = 0;
                while ((i = in.read(b)) > -1) {
                    if (i > 0) out.write(b, 0, i);
                }
                return true;
            } else {
                System.out.println(conn.getResponseCode() + ":" + url);
            }
        } catch (Exception 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();
            }
            if (conn != null) conn.disconnect();
        }
        return false;
    }
public synchronized void readProject(URL url, boolean addMembers) throws IOException {
        _url = url;
        try {
            readProject(url.openStream(), addMembers);
        } catch (IOException e) {
            Argo.log.info("Couldn't open InputStream in ArgoParser.load(" + url + ") " + e);
            e.printStackTrace();
            lastLoadMessage = e.toString();
            throw e;
        }
    }
public static void copy(File src, File dest) throws FileNotFoundException, IOException {
        FileInputStream in = new FileInputStream(src);
        FileOutputStream out = new FileOutputStream(dest);
        try {
            byte[] buf = new byte[1024];
            int c = -1;
            while ((c = in.read(buf)) > 0) out.write(buf, 0, c);
        } finally {
            in.close();
            out.close();
        }
    }
public static IFigure render(IDiagram diagram) {
        Diagram realDiagram;
        try {
            realDiagram = ((Diagram.IDiagramImpl) diagram).getDiagram();
        } catch (ClassCastException x) {
            throw new IllegalArgumentException("invalid diagram parameter");
        }
        ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.createControl(RMBenchPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
        viewer.setRootEditPart(new ScalableFreeformRootEditPart());
        viewer.setEditPartFactory(new CustomEditPartFactory());
        viewer.setContents(realDiagram);
        AbstractGraphicalEditPart aep = (AbstractGraphicalEditPart) viewer.getRootEditPart();
        refresh(aep);
        IFigure root = ((AbstractGraphicalEditPart) viewer.getRootEditPart()).getFigure();
        setPreferedSize(root);
        return root;
    }
public File convert(URI uri) throws DjatokaException {
        processing.add(uri.toString());
        File urlLocal = null;
        try {
            logger.info("processingRemoteURI: " + uri.toURL());
            boolean isJp2 = false;
            InputStream src = IOUtils.getInputStream(uri.toURL());
            String ext = uri.toURL().toString().substring(uri.toURL().toString().lastIndexOf(".") + 1).toLowerCase();
            if (ext.equals(FORMAT_ID_TIF) || ext.equals(FORMAT_ID_TIFF)) {
                urlLocal = File.createTempFile("convert" + uri.hashCode(), "." + FORMAT_ID_TIF);
            } else if (formatMap.containsKey(ext) && (formatMap.get(ext).equals(FORMAT_MIMEYPE_JP2) || formatMap.get(ext).equals(FORMAT_MIMEYPE_JPX))) {
                urlLocal = File.createTempFile("cache" + uri.hashCode(), "." + ext);
                isJp2 = true;
            } else {
                if (src.markSupported()) src.mark(15);
                if (ImageProcessingUtils.checkIfJp2(src)) urlLocal = File.createTempFile("cache" + uri.hashCode(), "." + FORMAT_ID_JP2);
                if (src.markSupported()) src.reset(); else {
                    src.close();
                    src = IOUtils.getInputStream(uri.toURL());
                }
            }
            if (urlLocal == null) {
                urlLocal = File.createTempFile("convert" + uri.hashCode(), ".img");
            }
            urlLocal.deleteOnExit();
            FileOutputStream dest = new FileOutputStream(urlLocal);
            IOUtils.copyStream(src, dest);
            if (!isJp2) urlLocal = processImage(urlLocal, uri);
            src.close();
            dest.close();
            return urlLocal;
        } catch (Exception e) {
            urlLocal.delete();
            throw new DjatokaException(e);
        } finally {
            if (processing.contains(uri.toString())) processing.remove(uri.toString());
        }
    }
public void test1() throws Exception {
        String senha = "minhaSenha";
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        digest.update(senha.getBytes());
        byte[] bytes = digest.digest();
        BASE64Encoder encoder = new BASE64Encoder();
        String senhaCodificada = encoder.encode(bytes);
        System.out.println("Senha     : " + senha);
        System.out.println("Senha SHA1: " + senhaCodificada);
    }
public static byte[] loadFile(File file) throws IOException {
        BufferedInputStream in = null;
        ByteArrayOutputStream sink = null;
        try {
            in = new BufferedInputStream(new FileInputStream(file));
            sink = new ByteArrayOutputStream();
            IOUtils.copy(in, sink);
            return sink.toByteArray();
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(sink);
        }
    }
public InputStream loadResource(String location) throws GenericConfigException {
        URL url = getURL(location);
        try {
            return url.openStream();
        } catch (java.io.IOException e) {
            throw new GenericConfigException("Error opening URL resource at location [" + url.toExternalForm() + "]", e);
        }
    }
void sort(int a[]) throws Exception {
        int j;
        int limit = a.length;
        int st = -1;
        while (st < limit) {
            boolean flipped = false;
            st++;
            limit--;
            for (j = st; j < limit; j++) {
                if (stopRequested) {
                    return;
                }
                if (a[j] > a[j + 1]) {
                    int T = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = T;
                    flipped = true;
                    pause(st, limit);
                }
            }
            if (!flipped) {
                return;
            }
            for (j = limit; --j >= st; ) {
                if (stopRequested) {
                    return;
                }
                if (a[j] > a[j + 1]) {
                    int T = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = T;
                    flipped = true;
                    pause(st, limit);
                }
            }
            if (!flipped) {
                return;
            }
        }
        pause(st, limit);
    }
@DeclarePerfMonTimer("SortingTest.bubbleSort")
    private void bubbleSort(int values[]) {
        int len = values.length - 1;
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len - i; j++) {
                if (values[j] > values[j + 1]) {
                    int tmp = values[j];
                    values[j] = values[j + 1];
                    values[j + 1] = tmp;
                }
            }
        }
    }
private void downloadThread() {
        int c;
        status = false;
        try {
            URLConnection urlc = resource.url.openConnection();
            File f = resource.createFile();
            boolean resume = false;
            resource.resetBytesDown();
            if (f.exists()) {
                if (f.lastModified() > resource.date.getTime()) {
                    if ((resource.getFileSize() == f.length())) {
                        status = true;
                        return;
                    } else {
                        urlc.setRequestProperty("Range", "bytes=" + f.length() + "-");
                        resume = true;
                        resource.incrementBytesDown(f.length());
                        System.out.println("Resume download");
                        System.out.println("file length: " + f.length());
                    }
                }
            }
            urlc.connect();
            bin = new BufferedInputStream(urlc.getInputStream());
            file_out = new FileOutputStream(f.getPath(), resume);
            while (life) {
                if (bin.available() > 0) {
                    c = bin.read();
                    if (c == -1) {
                        break;
                    }
                    file_out.write(c);
                    if (resource.incrementBytesDown()) {
                        break;
                    } else {
                        continue;
                    }
                }
                sleep(WAIT_FOR_A_BYTE_TIME);
            }
            file_out.flush();
            status = true;
        } catch (IOException e) {
            System.out.println("excepcion cpoy file");
        } catch (InterruptedException e) {
            System.out.println("InterruptException download");
            System.out.println(e);
        }
    }
private void headinfoThread() {
        try {
            URLConnection urlc = resource.url.openConnection();
            resource.setFileSize(urlc.getContentLength());
            resource.setDate(urlc.getLastModified());
        } catch (IOException e) {
            System.out.println("Error ResourceConnection, downloading headinfo");
            System.out.println(e);
        }
    }
private void copyFromStdin(Path dst, FileSystem dstFs) throws IOException {
        if (dstFs.isDirectory(dst)) {
            throw new IOException("When source is stdin, destination must be a file.");
        }
        if (dstFs.exists(dst)) {
            throw new IOException("Target " + dst.toString() + " already exists.");
        }
        FSDataOutputStream out = dstFs.create(dst);
        try {
            IOUtils.copyBytes(System.in, out, getConf(), false);
        } finally {
            out.close();
        }
    }
private void tail(String[] cmd, int pos) throws IOException {
        CommandFormat c = new CommandFormat("tail", 1, 1, "f");
        String src = null;
        Path path = null;
        try {
            List<String> parameters = c.parse(cmd, pos);
            src = parameters.get(0);
        } catch (IllegalArgumentException iae) {
            System.err.println("Usage: java FsShell " + TAIL_USAGE);
            throw iae;
        }
        boolean foption = c.getOpt("f") ? true : false;
        path = new Path(src);
        FileSystem srcFs = path.getFileSystem(getConf());
        if (srcFs.isDirectory(path)) {
            throw new IOException("Source must be a file.");
        }
        long fileSize = srcFs.getFileStatus(path).getLen();
        long offset = (fileSize > 1024) ? fileSize - 1024 : 0;
        while (true) {
            FSDataInputStream in = srcFs.open(path);
            in.seek(offset);
            IOUtils.copyBytes(in, System.out, 1024, false);
            offset = in.getPos();
            in.close();
            if (!foption) {
                break;
            }
            fileSize = srcFs.getFileStatus(path).getLen();
            offset = (fileSize > offset) ? offset : fileSize;
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
public static void readDefault() {
        ClassLoader l = Skeleton.class.getClassLoader();
        URL url = l.getResource("weka/core/parser/JFlex/skeleton.default");
        if (url == null) {
            Out.error(ErrorMessages.SKEL_IO_ERROR_DEFAULT);
            throw new GeneratorException();
        }
        try {
            InputStreamReader reader = new InputStreamReader(url.openStream());
            readSkel(new BufferedReader(reader));
        } catch (IOException e) {
            Out.error(ErrorMessages.SKEL_IO_ERROR_DEFAULT);
            throw new GeneratorException();
        }
    }
public static void bubbleSort(Auto[] xs) {
        boolean unsorted = true;
        while (unsorted) {
            unsorted = false;
            for (int i = 0; i < xs.length - 1; i++) {
                if (!(xs[i].getPreis() >= xs[i + 1].getPreis())) {
                    Auto dummy = xs[i];
                    xs[i] = xs[i + 1];
                    xs[i + 1] = dummy;
                    unsorted = true;
                }
            }
        }
    }
public static void copy(File from_file, File to_file) throws IOException {
        if (!from_file.exists()) abort("FileCopy: no such source file: " + from_file.getName());
        if (!from_file.isFile()) abort("FileCopy: can't copy directory: " + from_file.getName());
        if (!from_file.canRead()) abort("FileCopy: source file is unreadable: " + from_file.getName());
        if (to_file.isDirectory()) to_file = new File(to_file, from_file.getName());
        if (to_file.exists()) {
            if (!to_file.canWrite()) abort("FileCopy: destination file is unwriteable: " + to_file.getName());
        } else {
            String parent = to_file.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) abort("FileCopy: destination directory doesn't exist: " + parent);
            if (dir.isFile()) abort("FileCopy: destination is not a directory: " + parent);
            if (!dir.canWrite()) abort("FileCopy: destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(from_file);
            to = new FileOutputStream(to_file);
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) {
                to.write(buffer, 0, bytes_read);
            }
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
            }
        }
    }
public static void copyFile(File src, File dest, boolean force) throws IOException {
        if (dest.exists()) {
            if (force) {
                dest.delete();
            } else {
                throw new IOException("Cannot overwrite existing file: " + dest);
            }
        }
        byte[] buffer = new byte[1];
        int read = 0;
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(src);
            out = new FileOutputStream(dest);
            while (true) {
                read = in.read(buffer);
                if (read == -1) {
                    break;
                }
                out.write(buffer, 0, read);
            }
        } finally {
            if (in != null) {
                try {
                    in.close();
                } finally {
                    if (out != null) {
                        out.close();
                    }
                }
            }
        }
    }