semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void copyFiles(String strPath, String dstPath) throws IOException {
        File src = new File(strPath);
        File dest = new File(dstPath);
        if (src.isDirectory()) {
            dest.mkdirs();
            String list[] = src.list();
            for (int i = 0; i < list.length; i++) {
                if (list[i].lastIndexOf(SVN) != -1) {
                    if (!SVN.equalsIgnoreCase(list[i].substring(list[i].length() - 4, list[i].length()))) {
                        String dest1 = dest.getAbsolutePath() + "\\" + list[i];
                        String src1 = src.getAbsolutePath() + "\\" + list[i];
                        copyFiles(src1, dest1);
                    }
                } else {
                    String dest1 = dest.getAbsolutePath() + "\\" + list[i];
                    String src1 = src.getAbsolutePath() + "\\" + list[i];
                    copyFiles(src1, dest1);
                }
            }
        } else {
            FileInputStream fin = new FileInputStream(src);
            FileOutputStream fout = new FileOutputStream(dest);
            int c;
            while ((c = fin.read()) >= 0) fout.write(c);
            fin.close();
            fout.close();
        }
    }
public static int getUrl(final String s) {
        try {
            final URL url = new URL(s);
            final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            int count = 0;
            String data = null;
            while ((data = reader.readLine()) != null) {
                System.out.printf("Results(%3d) of data: %s\n", count, data);
                ++count;
            }
            return count;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
private static boolean loadResources(String ext) {
        InputStream in;
        try {
            URL url = Thread.currentThread().getContextClassLoader().getResource("bg/plambis/dict/local/i18n" + ext + ".xml");
            if (url == null) return false;
            in = url.openStream();
        } catch (IOException e1) {
            e1.printStackTrace();
            return false;
        }
        try {
            Serializer serializer = new Persister();
            resources = serializer.read(TextResource.class, in);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public static String hashURL(String url) {
        if (url == null) {
            throw new IllegalArgumentException("URL may not be null. ");
        }
        String result = null;
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            if (md != null) {
                md.reset();
                md.update(url.getBytes());
                BigInteger hash = new BigInteger(1, md.digest());
                result = hash.toString(16);
            }
            md = null;
        } catch (NoSuchAlgorithmException ex) {
            result = null;
        }
        return result;
    }
protected Ontology loadOntology(String ontologyIri) throws IOException, ParserException, InvalidModelException {
        assert ontologyIri != null;
        URL url = null;
        Ontology ontology = null;
        url = new URL(ontologyIri);
        InputStream is = url.openStream();
        TopEntity[] identifiable = parser.parse(new InputStreamReader(is));
        if (identifiable.length > 0 && identifiable[0] instanceof Ontology) {
            ontology = ((Ontology) identifiable[0]);
        }
        return ontology;
    }
private MimeTypes() {
        try {
            final URL url = RES.getURL("types");
            final InputStream is = url.openStream();
            final BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line = br.readLine();
            while (line != null) {
                line = line.trim();
                final int p = line.indexOf('#');
                if (p >= 0) {
                    line = line.substring(0, p).trim();
                }
                if (line.length() > 0) {
                    final StringTokenizer st = new StringTokenizer(line, " \t");
                    if (st.countTokens() > 1) {
                        final String mime = st.nextToken();
                        while (st.hasMoreTokens()) {
                            extnMap.put(st.nextToken(), mime);
                        }
                    }
                }
                line = br.readLine();
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        canParse.add(TEXT_HTML);
        canParse.add(TEXT_CSS);
    }
protected void load() throws IOException {
        for (ClassLoader classLoader : classLoaders) {
            Enumeration<URL> en = classLoader.getResources("META-INF/services/" + serviceClass.getName());
            while (en.hasMoreElements()) {
                URL url = en.nextElement();
                InputStream in = url.openStream();
                try {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                    try {
                        String line = null;
                        while ((line = reader.readLine()) != null) {
                            if (!line.startsWith("#")) {
                                line = line.trim();
                                if (line.length() > 0) contributions.add(resolveClass(url, line));
                            }
                        }
                    } finally {
                        reader.close();
                    }
                } finally {
                    in.close();
                }
            }
        }
    }
static void cleanFile(File file) {
        final Counter cnt = new Counter();
        final File out = new File(FileUtils.appendToFileName(file.getAbsolutePath(), ".cleaned"));
        final SAMFileReader reader = new SAMFileReader(file);
        final SAMRecordIterator it = reader.iterator();
        final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), true, out);
        if (!it.hasNext()) return;
        log.info("Cleaning file " + file + " to " + out.getName());
        SAMRecord last = it.next();
        writer.addAlignment(last);
        while (it.hasNext()) {
            final SAMRecord now = it.next();
            final int start1 = last.getAlignmentStart();
            final int start2 = now.getAlignmentStart();
            final int end1 = last.getAlignmentEnd();
            final int end2 = now.getAlignmentEnd();
            if (start1 == start2 && end1 == end2) {
                log.debug("Discarding record " + now.toString());
                cnt.count();
                continue;
            }
            writer.addAlignment(now);
            last = now;
        }
        writer.close();
        reader.close();
        log.info(file + " done, discarded " + cnt.getCount() + " reads");
        exe.shutdown();
    }
public Savable loadResource(String name, PrimitiveLoader loader) {
        Savable objeto = null;
        URL url = ResourceLocator.locateFile(loader.getBaseFolder(), name, loader.getCompiledExtension());
        if (url == null) {
            url = ResourceLocator.locateFile(loader.getBaseFolder(), name, loader.getPrimitiveExtension());
            if (url != null) {
                try {
                    objeto = loader.loadResource(name, url.openStream());
                    File file = ResourceLocator.replaceExtension(url, loader.getCompiledExtension());
                    BinaryExporter.getInstance().save(objeto, file);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
            }
        } else {
            try {
                objeto = BinaryImporter.getInstance().load(url.openStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return objeto;
    }
private String addEqError(EquivalencyException e, int namespaceId) throws SQLException {
        List l = Arrays.asList(e.getListOfEqErrors());
        int size = l.size();
        String sql = getClassifyDAO().getStatement(TABLE_KEY, "ADD_CLASSIFY_EQ_ERROR");
        PreparedStatement ps = null;
        conn.setAutoCommit(false);
        try {
            deleteCycleError(namespaceId);
            deleteEqError(namespaceId);
            long conceptGID1 = -1;
            long conceptGID2 = -1;
            ps = conn.prepareStatement(sql);
            for (int i = 0; i < l.size(); i++) {
                EqError error = (EqError) l.get(i);
                ConceptRef ref1 = error.getConcept1();
                ConceptRef ref2 = error.getConcept2();
                conceptGID1 = getConceptGID(ref1, namespaceId);
                conceptGID2 = getConceptGID(ref2, namespaceId);
                ps.setLong(1, conceptGID1);
                ps.setLong(2, conceptGID2);
                ps.setInt(3, namespaceId);
                int result = ps.executeUpdate();
                if (result == 0) {
                    throw new SQLException("unable to add eq error: " + sql);
                }
            }
            conn.commit();
            return "EquivalencyException: Concept: " + conceptGID1 + " namespaceId: " + namespaceId + " conceptGID2: " + conceptGID2 + ((size > 1) ? "...... more" : "");
        } catch (SQLException sqle) {
            conn.rollback();
            throw sqle;
        } catch (Exception ex) {
            conn.rollback();
            throw toSQLException(ex, "cannot add eq errors");
        } finally {
            conn.setAutoCommit(true);
            if (ps != null) {
                ps.close();
            }
        }
    }
public String getSHA1Hex(String original) {
        MessageDigest digest;
        String result = "";
        try {
            digest = MessageDigest.getInstance("sha1");
            digest.reset();
            digest.update(original.getBytes());
            byte[] dig = digest.digest();
            String hexStr = "";
            for (int i = 0; i < dig.length; i++) {
                hexStr += Integer.toString((dig[i] & 0xff) + 0x100, 16).substring(1);
            }
            result = hexStr;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return result;
    }
public DicomReader(URL url) throws java.io.IOException {
        final URLConnection u = url.openConnection();
        final int size = u.getContentLength();
        final byte[] array = new byte[size];
        int bytes_read = 0;
        final DataInputStream in = new DataInputStream(u.getInputStream());
        while (bytes_read < size) {
            bytes_read += in.read(array, bytes_read, size - bytes_read);
        }
        in.close();
        this.dHR = new DicomHeaderReader(array);
        h = dHR.getRows();
        w = dHR.getColumns();
        highBit = dHR.getHighBit();
        bitsStored = dHR.getBitStored();
        bitsAllocated = dHR.getBitAllocated();
        n = (bitsAllocated / 8);
        signed = (dHR.getPixelRepresentation() == 1);
        this.pixData = dHR.getPixels();
        ignoreNegValues = true;
        samplesPerPixel = dHR.getSamplesPerPixel();
        numberOfFrames = dHR.getNumberOfFrames();
        dbg("Number of Frames " + numberOfFrames);
    }
public boolean isValidPage(BookPage page) {
        boolean isValid = false;
        try {
            if (page.getType() == BookPage.TYPE_RESOURCE) {
                BookPagePreviewPanel panel = new BookPagePreviewPanel(dControl, true);
                panel.setCurrentBookPage(page);
                isValid = !page.getUri().equals("") && panel.isValid();
            } else if (page.getType() == BookPage.TYPE_URL) {
                URL url = new URL(page.getUri());
                url.openStream().close();
                isValid = true;
            } else if (page.getType() == BookPage.TYPE_IMAGE) {
                if (page.getUri().length() > 0) isValid = true;
            }
        } catch (Exception e) {
            isValid = false;
        }
        return isValid;
    }
public static String encrypt(String value) {
        MessageDigest messageDigest;
        byte[] raw = null;
        try {
            messageDigest = MessageDigest.getInstance("SHA");
            messageDigest.update(((String) value).getBytes("UTF-8"));
            raw = messageDigest.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return (new BASE64Encoder()).encode(raw);
    }
private static Set<? extends Class<?>> findEntitiesFromUrl(URL url) {
        try {
            JarEntry entry;
            JarInputStream jarStream = new JarInputStream(url.openStream());
            Set<Class<?>> classes = new HashSet<Class<?>>();
            while ((entry = jarStream.getNextJarEntry()) != null) {
                String name = entry.getName();
                if (!entry.isDirectory() && name.endsWith(".class")) {
                    addIfEntity(classes, name);
                }
            }
            return classes;
        } catch (IOException ioe) {
            log.error("Could not search URL '", url, "' for entities due to an IOException: ", ioe.getMessage());
        }
        return new HashSet<Class<?>>();
    }
public final void conectar() throws IOException, FTPException {
        ftp = null;
        ftp = new FTPClient();
        ftp.setRemoteHost(cfg.getFTPHost());
        ftp.connect();
        ftp.login(cfg.getFTPUser(), cfg.getFTPPass());
        ftp.setProgressMonitor(pMonitor);
        ftp.setConnectMode(FTPConnectMode.PASV);
        ftp.setType(FTPTransferType.BINARY);
    }
public String storeUploadedZip(byte[] zip, String name) {
        List filesToStore = new ArrayList();
        int i = 0;
        ZipInputStream zipIs = new ZipInputStream(new ByteArrayInputStream(zip));
        ZipEntry zipEntry = zipIs.getNextEntry();
        while (zipEntry != null) {
            if (zipEntry.isDirectory() == false) {
                i++;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(zipIs, baos);
                baos.close();
            }
            zipIs.closeEntry();
            zipEntry = zipIs.getNextEntry();
        }
    }
private static void copyFile(File src, File dst) throws IOException {
        FileChannel in = new FileInputStream(src).getChannel();
        FileChannel out = new FileOutputStream(dst).getChannel();
        in.transferTo(0, in.size(), out);
        in.close();
        out.close();
    }
public synchronized int executeCommand(Vector<String> pvStatement) throws Exception {
        int ret = 0, i = 0;
        Statement stmt = null;
        String temp = "";
        try {
            oConexion.setAutoCommit(false);
            stmt = oConexion.createStatement();
            for (i = 0; i < pvStatement.size(); i++) {
                temp = (String) pvStatement.elementAt(i);
                ret += stmt.executeUpdate(temp);
            }
            oConexion.commit();
        } catch (SQLException e) {
            oConexion.rollback();
            throw e;
        } finally {
            stmt.close();
            stmt = null;
        }
        return ret;
    }
@Override
        public void actionPerformed(ActionEvent e) {
            if (copiedFiles_ != null) {
                File[] tmpFiles = new File[copiedFiles_.length];
                File tmpDir = new File(Settings.getPropertyString(ConstantKeys.project_dir), "tmp/");
                tmpDir.mkdirs();
                for (int i = copiedFiles_.length - 1; i >= 0; i--) {
                    Frame f = FrameManager.getInstance().getFrameAtIndex(i);
                    try {
                        File in = f.getFile();
                        File out = new File(tmpDir, f.getFile().getName());
                        FileChannel inChannel = new FileInputStream(in).getChannel();
                        FileChannel outChannel = new FileOutputStream(out).getChannel();
                        inChannel.transferTo(0, inChannel.size(), outChannel);
                        if (inChannel != null) inChannel.close();
                        if (outChannel != null) outChannel.close();
                        tmpFiles[i] = out;
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
                try {
                    FrameManager.getInstance().insertFrames(getTable().getSelectedRow(), FrameManager.INSERT_TYPE.MOVE, tmpFiles);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
public void download(RequestContext ctx) throws IOException {
        if (ctx.isRobot()) {
            ctx.forbidden();
            return;
        }
        long id = ctx.id();
        File bean = File.INSTANCE.Get(id);
        if (bean == null) {
            ctx.not_found();
            return;
        }
        String f_ident = ctx.param("fn", "");
        if (id >= 100 && !StringUtils.equals(f_ident, bean.getIdent())) {
            ctx.not_found();
            return;
        }
        if (bean.IsLoginRequired() && ctx.user() == null) {
            StringBuilder login = new StringBuilder(LinkTool.home("home/login?goto_page="));
            ctx.redirect(login.toString());
            return;
        }
        FileInputStream fis = null;
        try {
            java.io.File file = StorageService.FILES.readFile(bean.getPath());
            fis = new FileInputStream(file);
            ctx.response().setContentLength((int) file.length());
            String ext = FilenameUtils.getExtension(bean.getPath());
            String mine_type = Multimedia.mime_types.get(ext);
            if (mine_type != null) ctx.response().setContentType(mine_type);
            String ua = ctx.header("user-agent");
            if (ua != null && ua.indexOf("Firefox") >= 0) ctx.header("Content-Disposition", "attachment; filename*=\"utf8''" + LinkTool.encode_url(bean.getName()) + "." + ext + "\""); else ctx.header("Content-Disposition", "attachment; filename=" + LinkTool.encode_url(bean.getName() + "." + ext));
            IOUtils.copy(fis, ctx.response().getOutputStream());
            bean.IncDownloadCount(1);
        } finally {
            IOUtils.closeQuietly(fis);
        }
    }
@Nullable
        @Override
        public InputSource resolveEntity(final String publicId, final String systemId) throws IOException {
            if (systemId.endsWith(".xml")) {
                return null;
            }
            InputSource inputSource = null;
            final URL url = IOUtils.getResource(new File("system/dtd"), PATTERN_DIRECTORY_PART.matcher(systemId).replaceAll(""));
            final InputStream inputStream = url.openStream();
            try {
                final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
                try {
                    inputSource = new InputSource(bufferedInputStream);
                } finally {
                    if (inputSource == null) {
                        bufferedInputStream.close();
                    }
                }
            } finally {
                if (inputSource == null) {
                    inputStream.close();
                }
            }
            return inputSource;
        }
public void callUpdate() {
        LOGGER.debug("Checking for Updates");
        new Thread() {

            @Override
            public void run() {
                String lastVersion = null;
                try {
                    URL projectSite = new URL("http://code.google.com/p/g15lastfm/");
                    URLConnection urlC = projectSite.openConnection();
                    BufferedReader in = new BufferedReader(new InputStreamReader(urlC.getInputStream()));
                    String inputLine;
                    while ((inputLine = in.readLine()) != null) {
                        if (inputLine.contains("<strong>Current version:")) {
                            lastVersion = inputLine;
                            break;
                        }
                    }
                    in.close();
                    if (lastVersion != null && lastVersion.length() > 0) {
                        lastVersion = lastVersion.substring(lastVersion.indexOf("Current version:") + 16);
                        lastVersion = lastVersion.substring(0, lastVersion.indexOf("</strong>")).trim();
                        LOGGER.debug("last Version=" + lastVersion);
                    }
                    if (!lastVersion.equals(G15LastfmPlayer.getVersion())) LOGGER.debug("Not necessary to update"); else {
                        LOGGER.debug("New update found!");
                        SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                if (JOptionPane.showConfirmDialog(null, "New version of G15Lastfm is available to download!", "New Update for G15Lastfm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                                    LOGGER.debug("User choose to update, opening browser.");
                                    Desktop desktop = Desktop.getDesktop();
                                    try {
                                        desktop.browse(new URI("http://code.google.com/p/g15lastfm/"));
                                    } catch (IOException e) {
                                        LOGGER.debug(e);
                                    } catch (URISyntaxException e) {
                                        LOGGER.debug(e);
                                    }
                                } else {
                                    LOGGER.debug("User choose to not update.");
                                }
                            }
                        });
                    }
                } catch (Exception e) {
                    LOGGER.debug(e);
                }
            }
        }.start();
    }