semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static String calculateMD5(String s) {
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.reset();
            m.update(s.getBytes());
            return new BigInteger(1, m.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            throw new UndeclaredThrowableException(e);
        }
    }
public void write(String resource, String destinationPath) throws IOException, CoreException {
        OutputStream output = null;
        InputStream contentStream = null;
        try {
            contentStream = new BufferedInputStream(new FileInputStream(resource));
            output = new BufferedOutputStream(new FileOutputStream(destinationPath));
            int available = contentStream.available();
            available = available <= 0 ? DEFAULT_BUFFER_SIZE : available;
            int chunkSize = Math.min(DEFAULT_BUFFER_SIZE, available);
            byte[] readBuffer = new byte[chunkSize];
            int n = contentStream.read(readBuffer);
            while (n > 0) {
                output.write(readBuffer, 0, n);
                n = contentStream.read(readBuffer);
            }
        } finally {
            if (contentStream != null) {
                try {
                    contentStream.close();
                } catch (IOException e) {
                    IDEWorkbenchPlugin.log("Error closing input stream for file: " + resource, e);
                }
            }
            if (output != null) {
                output.close();
            }
        }
    }
public static File copyFile(File fileToCopy, File copiedFile) {
        BufferedInputStream in = null;
        BufferedOutputStream outWriter = null;
        if (!copiedFile.exists()) {
            try {
                copiedFile.createNewFile();
            } catch (IOException e1) {
                ExceptionHandlingService.INSTANCE.handleException(e1);
                return null;
            }
        }
        try {
            in = new BufferedInputStream(new FileInputStream(fileToCopy), 4096);
            outWriter = new BufferedOutputStream(new FileOutputStream(copiedFile), 4096);
            int c;
            while ((c = in.read()) != -1) outWriter.write(c);
            in.close();
            outWriter.close();
        } catch (FileNotFoundException e) {
            ExceptionHandlingService.INSTANCE.handleException(e);
            return null;
        } catch (IOException e) {
            ExceptionHandlingService.INSTANCE.handleException(e);
            return null;
        }
        return copiedFile;
    }
private List<String> readLines(String filename) {
        List<String> lines = new ArrayList<String>();
        URL url = Util.getResource(filename);
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            while (true) {
                String line = br.readLine();
                if (line == null) {
                    break;
                }
                lines.add(line);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return lines;
    }
public static void copy(final File src, File dst, final boolean overwrite) throws IOException, IllegalArgumentException {
        if (!src.isFile() || !src.exists()) {
            throw new IllegalArgumentException("Source file '" + src.getAbsolutePath() + "' not found!");
        }
        if (dst.exists()) {
            if (dst.isDirectory()) {
                dst = new File(dst, src.getName());
            } else if (dst.isFile()) {
                if (!overwrite) {
                    throw new IllegalArgumentException("Destination file '" + dst.getAbsolutePath() + "' already exists!");
                }
            } else {
                throw new IllegalArgumentException("Invalid destination object '" + dst.getAbsolutePath() + "'!");
            }
        }
        final File dstParent = dst.getParentFile();
        if (!dstParent.exists()) {
            if (!dstParent.mkdirs()) {
                throw new IOException("Failed to create directory " + dstParent.getAbsolutePath());
            }
        }
        long fileSize = src.length();
        if (fileSize > 20971520l) {
            final FileInputStream in = new FileInputStream(src);
            final FileOutputStream out = new FileOutputStream(dst);
            try {
                int doneCnt = -1;
                final int bufSize = 32768;
                final byte buf[] = new byte[bufSize];
                while ((doneCnt = in.read(buf, 0, bufSize)) >= 0) {
                    if (doneCnt == 0) {
                        Thread.yield();
                    } else {
                        out.write(buf, 0, doneCnt);
                    }
                }
                out.flush();
            } finally {
                try {
                    in.close();
                } catch (final IOException e) {
                }
                try {
                    out.close();
                } catch (final IOException e) {
                }
            }
        } else {
            final FileInputStream fis = new FileInputStream(src);
            final FileOutputStream fos = new FileOutputStream(dst);
            final FileChannel in = fis.getChannel(), out = fos.getChannel();
            try {
                long offs = 0, doneCnt = 0;
                final long copyCnt = Math.min(65536, fileSize);
                do {
                    doneCnt = in.transferTo(offs, copyCnt, out);
                    offs += doneCnt;
                    fileSize -= doneCnt;
                } while (fileSize > 0);
            } finally {
                try {
                    in.close();
                } catch (final IOException e) {
                }
                try {
                    out.close();
                } catch (final IOException e) {
                }
                try {
                    fis.close();
                } catch (final IOException e) {
                }
                try {
                    fos.close();
                } catch (final IOException e) {
                }
            }
        }
    }
public static boolean copyFile(File src, File target) throws IOException {
        if (src == null || target == null || !src.exists()) return false;
        if (!target.exists()) if (!createNewFile(target)) return false;
        InputStream ins = new BufferedInputStream(new FileInputStream(src));
        OutputStream ops = new BufferedOutputStream(new FileOutputStream(target));
        int b;
        while (-1 != (b = ins.read())) ops.write(b);
        Streams.safeClose(ins);
        Streams.safeFlush(ops);
        Streams.safeClose(ops);
        return target.setLastModified(src.lastModified());
    }
public void copieFichier(String fileIn, String fileOut) {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(fileIn).getChannel();
            out = new FileOutputStream(fileOut).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }
    }
public File createFileFromClasspathResource(String resourceUrl) throws IOException {
        File fichierTest = File.createTempFile("xmlFieldTestFile", "");
        FileOutputStream fos = new FileOutputStream(fichierTest);
        InputStream is = DefaultXmlFieldSelectorTest.class.getResourceAsStream(resourceUrl);
        IOUtils.copy(is, fos);
        is.close();
        fos.close();
        return fichierTest;
    }
private static HttpURLConnection getConnection(URL url) throws IOException {
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestProperty("Accept", "application/zip;text/html");
        return conn;
    }
public void addUrl(URL url) throws IOException, SAXException {
        InputStream inStream = url.openStream();
        String path = url.getPath();
        int slashInx = path.lastIndexOf('/');
        String name = path.substring(slashInx + 1);
        Document doc = docBuild.parse(inStream);
        Element root = doc.getDocumentElement();
        String rootTag = root.getTagName();
        if (rootTag.equals("graphml")) {
            NodeList graphNodes = root.getElementsByTagName("graph");
            for (int i = 0; i < graphNodes.getLength(); i++) {
                Element elem = (Element) graphNodes.item(i);
                String graphName = elem.getAttribute("id");
                if (graphName == null) {
                    graphName = name;
                }
                addStructure(new GraphSpec(graphName));
                urlRefs.put(graphName, url);
            }
        } else if (rootTag.equals("tree")) {
            addStructure(new TreeSpec(name));
            urlRefs.put(name, url);
        } else {
            throw new IllegalArgumentException("Format of " + url + " not understood.");
        }
        inStream.close();
    }
public void createZip(File zipFileName, Vector<File> selected) {
        try {
            byte[] buffer = new byte[4096];
            ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFileName), 8096));
            out.setLevel(Deflater.BEST_COMPRESSION);
            out.setMethod(ZipOutputStream.DEFLATED);
            for (int i = 0; i < selected.size(); i++) {
                FileInputStream in = new FileInputStream(selected.get(i));
                String file = selected.get(i).getPath();
                if (file.indexOf("\\") != -1) file = file.substring(file.lastIndexOf(Options.fs) + 1, file.length());
                ZipEntry ze = new ZipEntry(file);
                out.putNextEntry(ze);
                int len;
                while ((len = in.read(buffer)) > 0) out.write(buffer, 0, len);
                out.closeEntry();
                in.close();
                selected.get(i).delete();
            }
            out.close();
        } catch (IllegalArgumentException iae) {
            iae.printStackTrace();
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
public static File copyFile(File from, File to) throws IOException {
        FileOutputStream fos = new FileOutputStream(to);
        FileInputStream fis = new FileInputStream(from);
        FileChannel foc = fos.getChannel();
        FileChannel fic = fis.getChannel();
        foc.transferFrom(fic, 0, fic.size());
        foc.close();
        fic.close();
        return to;
    }
public static void setContenu(ContenuFichierElectronique contenuFichier, FichierElectronique fichierElectronique, UtilisateurIFGD utilisateurCourant) throws IOException, DocumentVideException {
        if (contenuFichier != null) {
            SupportDocument support = fichierElectronique.getSupport();
            support.setFichierElectronique(fichierElectronique);
            FicheDocument ficheDocument = support.getFicheDocument();
            String nomFichier = contenuFichier.getNomFichier();
            String extension = FilenameUtils.getExtension(nomFichier);
            if (ficheDocument.getFichierElectronique(nomFichier) != null) {
                FichierElectronique fichierElectroniqueExistant = ficheDocument.getFichierElectronique(nomFichier);
                if (fichierElectroniqueExistant.getId() != null && !fichierElectroniqueExistant.getId().equals(fichierElectronique.getId())) {
                    throw new FichierElectroniqueExistantException(nomFichier, ficheDocument);
                }
            }
            if (fichierElectronique.getId() == null) {
                if (OfficeDocumentPropertiesUtil.canWriteIdIGID(extension)) {
                    Long idIgid = OfficeDocumentPropertiesUtil.getIdIGID(contenuFichier);
                    if (idIgid != null) {
                        throw new FichierElectroniqueExistantException(nomFichier, idIgid, ficheDocument);
                    }
                }
            }
            InputStream inputStream = contenuFichier.getInputStream();
            OutputStream outputStream = fichierElectronique.getOutputStream();
            try {
                IOUtils.copy(inputStream, outputStream);
            } finally {
                try {
                    inputStream.close();
                } finally {
                    outputStream.close();
                }
            }
            String typeMime = contenuFichier.getContentType();
            long tailleFichier = contenuFichier.getTailleFichier();
            Date dateDerniereModification = new Date();
            fichierElectronique.setNom(nomFichier);
            fichierElectronique.setTypeMime(extension);
            creerFormatSiNecessaire(typeMime, extension);
            fichierElectronique.setTaille(tailleFichier);
            fichierElectronique.setDateDerniereModification(dateDerniereModification);
            fichierElectronique.setSoumetteur(utilisateurCourant);
            if (extension.endsWith("msg")) {
                CourrielUtils.peuplerMetadonneesCourriel(fichierElectronique.getNom(), ficheDocument, contenuFichier.getInputStream(), utilisateurCourant);
            } else if (extension.endsWith("eml")) {
                Map<String, Object> properties = new GestionnaireProprietesMimeMessageParser().parseMsg(contenuFichier.getInputStream());
                CourrielUtils.peuplerMetadonneesCourriel(fichierElectronique.getNom(), ficheDocument, properties, utilisateurCourant);
            } else {
                FGDProprietesDocumentUtils.copierMetadonneesProprietes(fichierElectronique, ficheDocument);
            }
        }
    }
public Object downloadFile(File destinationFile, URL[] urls, DownloadListener listener, Object checksum, long length, PRIORITY priority) throws DownloadException {
        URL url = urls[0];
        if (!url.getProtocol().equalsIgnoreCase("http")) {
            throw new DownloadException(" Only HTTP is supported in this version ");
        }
        if (!destinationFile.exists()) {
            try {
                destinationFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
                throw new DownloadException("Unable to download from URL : " + url.toString());
            }
        }
        HeadMethod head = new HeadMethod(url.toString());
        HttpClient httpClient = new HttpClient();
        try {
            httpClient.executeMethod(head);
            Header[] headers = head.getResponseHeaders();
            for (Header header : headers) {
                System.out.println(header);
            }
            Header header = head.getResponseHeader("Content-Length");
            Object contentLength = header.getValue();
            Long fileLength = Long.parseLong(contentLength.toString());
            System.out.println(length + " : " + fileLength);
            GetMethod get = new GetMethod(url.toString());
            httpClient.executeMethod(get);
            InputStream ins = get.getResponseBodyAsStream();
            FileOutputStream fos = new FileOutputStream(destinationFile);
            IOUtils.copy(ins, fos);
            System.out.println(" DOWNLOADED FILE");
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
public void sendTemplate(String filename, TemplateValues values) throws IOException {
        Checker.checkEmpty(filename, "filename");
        Checker.checkNull(values, "values");
        URL url = _getFile(filename);
        boolean writeSpaces = Context.getRootContext().getRunMode() == RUN_MODE.DEV ? true : false;
        Template t = new Template(url.openStream(), writeSpaces);
        try {
            t.write(getWriter(), values);
        } catch (ErrorListException ele) {
            Context.getRootContext().getLogger().error(ele);
        }
    }
public void sendTextFile(String filename) throws IOException {
        Checker.checkEmpty(filename, "filename");
        URL url = _getFile(filename);
        PrintWriter out = getWriter();
        Streams.copy(new InputStreamReader(url.openStream()), out);
        out.close();
    }
public void sendBinaryFile(String filename) throws IOException {
        Checker.checkEmpty(filename, "filename");
        URL url = _getFile(filename);
        OutputStream out = getOutputStream();
        Streams.copy(url.openStream(), out);
        out.close();
    }
private String hashPassword(String password) {
        if (password != null && password.trim().length() > 0) {
            try {
                MessageDigest md5 = MessageDigest.getInstance("MD5");
                md5.update(password.trim().getBytes());
                BigInteger hash = new BigInteger(1, md5.digest());
                return hash.toString(16);
            } catch (NoSuchAlgorithmException nsae) {
            }
        }
        return null;
    }
private String getClassname(Bundle bundle) {
        URL urlEntry = bundle.getEntry("jdbcBundleInfo.xml");
        InputStream in = null;
        try {
            in = urlEntry.openStream();
            try {
                StringBuilder sb = new StringBuilder();
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                String line;
                while ((line = reader.readLine()) != null) {
                    if (!line.startsWith("<!DOCTYPE")) {
                        sb.append(line);
                    }
                }
                SAXBuilder builder = new SAXBuilder(false);
                Document doc = builder.build(new StringReader(sb.toString()));
                Element eRoot = doc.getRootElement();
                if ("jdbcBundleInfo".equals(eRoot.getName())) {
                    Attribute atri = eRoot.getAttribute("className");
                    if (atri != null) {
                        return atri.getValue();
                    }
                }
            } catch (JDOMException e) {
            }
        } catch (IOException e) {
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
        }
        return null;
    }
private void updateViewerContent(ScrollingGraphicalViewer viewer) {
        BioPAXGraph graph = (BioPAXGraph) viewer.getContents().getModel();
        if (!graph.isMechanistic()) return;
        Map<String, Color> highlightMap = new HashMap<String, Color>();
        for (Object o : graph.getNodes()) {
            IBioPAXNode node = (IBioPAXNode) o;
            if (node.isHighlighted()) {
                highlightMap.put(node.getIDHash(), node.getHighlightColor());
            }
        }
        for (Object o : graph.getEdges()) {
            IBioPAXEdge edge = (IBioPAXEdge) o;
            if (edge.isHighlighted()) {
                highlightMap.put(edge.getIDHash(), edge.getHighlightColor());
            }
        }
        HighlightLayer hLayer = (HighlightLayer) ((ChsScalableRootEditPart) viewer.getRootEditPart()).getLayer(HighlightLayer.HIGHLIGHT_LAYER);
        hLayer.removeAll();
        hLayer.highlighted.clear();
        viewer.deselectAll();
        graph.recordLayout();
        PathwayHolder p = graph.getPathway();
        if (withContent != null) {
            p.updateContentWith(withContent);
        }
        BioPAXGraph newGraph = main.getRootGraph().excise(p);
        newGraph.setAsRoot();
        viewer.setContents(newGraph);
        boolean layedout = newGraph.fetchLayout();
        if (!layedout) {
            new CoSELayoutAction(main).run();
        }
        viewer.deselectAll();
        GraphAnimation.run(viewer);
        for (Object o : newGraph.getNodes()) {
            IBioPAXNode node = (IBioPAXNode) o;
            if (highlightMap.containsKey(node.getIDHash())) {
                node.setHighlightColor(highlightMap.get(node.getIDHash()));
                node.setHighlight(true);
            }
        }
        for (Object o : newGraph.getEdges()) {
            IBioPAXEdge edge = (IBioPAXEdge) o;
            if (highlightMap.containsKey(edge.getIDHash())) {
                edge.setHighlightColor(highlightMap.get(edge.getIDHash()));
                edge.setHighlight(true);
            }
        }
    }
TreeMap<Integer, Integer> initProperties(URL propurl) {
        String zoneFileName = null;
        String costFileName = null;
        String homesFileName = null;
        String jobsFileName = null;
        Properties props = new Properties();
        try {
            props.loadFromXML(propurl.openStream());
            zoneFileName = props.getProperty("zoneFileName");
            costFileName = props.getProperty("costFileName");
            homesFileName = props.getProperty("homesFileName");
            jobsFileName = props.getProperty("jobsFileName");
            maxiter = Integer.parseInt(props.getProperty("maxiter"));
            mu = Double.parseDouble(props.getProperty("mu"));
            theta = Double.parseDouble(props.getProperty("theta"));
            threshold1 = Double.parseDouble(props.getProperty("threshold1"));
            threshold2 = Double.parseDouble(props.getProperty("threshold2"));
            verbose = Boolean.parseBoolean(props.getProperty("verbose"));
        } catch (Exception xc) {
            xc.printStackTrace();
            System.exit(-1);
        }
        HashSet<Integer> zoneids = SomeIO.readZoneIDs(zoneFileName);
        numZ = zoneids.size();
        if (verbose) {
            System.out.println("Data:");
            System.out.println(" . #zones:" + numZ);
        }
        int idx = 0;
        TreeMap<Integer, Integer> zonemap = new TreeMap<Integer, Integer>();
        for (Integer id : zoneids) zonemap.put(id, idx++);
        cij = SomeIO.readMatrix(costFileName, numZ, numZ);
        for (int i = 0; i < numZ; i++) {
            double mincij = Double.POSITIVE_INFINITY;
            for (int j = 0; j < numZ; j++) {
                double v = cij.get(i, j);
                if ((v < mincij) && (v > 0.0)) mincij = v;
            }
            if (cij.get(i, i) == 0.0) cij.set(i, i, mincij);
        }
        setupECij();
        double meanCost = 0.0;
        double stdCost = 0.0;
        for (int i = 0; i < numZ; i++) {
            for (int j = 0; j < numZ; j++) {
                double v = cij.get(i, j);
                meanCost += v;
                stdCost += v * v;
            }
        }
        meanCost = meanCost / (numZ * numZ);
        stdCost = stdCost / (numZ * numZ) - meanCost * meanCost;
        if (verbose) System.out.println(" . Travel costs  mean=" + meanCost + " std.dev.= " + Math.sqrt(stdCost));
        P = SomeIO.readZoneAttribute(numZ, homesFileName, zonemap);
        J = SomeIO.readZoneAttribute(numZ, jobsFileName, zonemap);
        double maxpj = 0.0;
        double sp = 0.0;
        double sj = 0.0;
        for (int i = 0; i < numZ; i++) {
            sp += P[i];
            sj += J[i];
            if (P[i] > maxpj) maxpj = P[i];
            if (J[i] > maxpj) maxpj = J[i];
        }
        if (Math.abs(sp - sj) > 1.0) {
            System.err.println("Error: #jobs(" + sj + ")!= #homes(" + sp + ")");
            System.exit(-1);
        }
        N = sp;
        if (verbose) System.out.println(" . Trip tables: #jobs=#homes= " + N);
        return zonemap;
    }