semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public synchronized void readModels(Project p, URL url) throws IOException {
        _proj = p;
        Argo.log.info("=======================================");
        Argo.log.info("== READING MODEL " + url);
        try {
            XMIReader reader = new XMIReader();
            InputSource source = new InputSource(url.openStream());
            source.setSystemId(url.toString());
            _curModel = reader.parse(source);
            if (reader.getErrors()) {
                throw new IOException("XMI file " + url.toString() + " could not be parsed.");
            }
            _UUIDRefs = new HashMap(reader.getXMIUUIDToObjectMap());
        } catch (SAXException saxEx) {
            Exception ex = saxEx.getException();
            if (ex == null) {
                saxEx.printStackTrace();
            } else {
                ex.printStackTrace();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        Argo.log.info("=======================================");
        try {
            _proj.addModel((ru.novosoft.uml.foundation.core.MNamespace) _curModel);
        } catch (PropertyVetoException ex) {
            System.err.println("An error occurred adding the model to the project!");
            ex.printStackTrace();
        }
        Collection ownedElements = _curModel.getOwnedElements();
        Iterator oeIterator = ownedElements.iterator();
        while (oeIterator.hasNext()) {
            MModelElement me = (MModelElement) oeIterator.next();
            if (me instanceof MClass) {
                _proj.defineType((MClass) me);
            } else if (me instanceof MDataType) {
                _proj.defineType((MDataType) me);
            }
        }
    }
public static String getMD5Hash(String in) {
        StringBuffer result = new StringBuffer(32);
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(in.getBytes());
            Formatter f = new Formatter(result);
            for (byte b : md5.digest()) {
                f.format("%02x", b);
            }
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return result.toString();
    }
private boolean load(URL url) {
        try {
            URLConnection connection = url.openConnection();
            parser = new PDFParser(connection.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
private void forcedCopy(File sourceFile, File destFile) throws IOException {
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }
public static void copyFile(File source, File destination) throws IOException {
        FileInputStream fis = new FileInputStream(source);
        FileOutputStream fos = new FileOutputStream(destination);
        FileChannel inCh = fis.getChannel();
        FileChannel outCh = fos.getChannel();
        inCh.transferTo(0, inCh.size(), outCh);
        inCh.close();
        fis.close();
        outCh.close();
        fos.flush();
        fos.close();
    }
private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
        if (destFile.exists() && destFile.isDirectory()) {
            throw new IOException("Destination '" + destFile + "' exists but is a directory");
        }
        FileInputStream input = new FileInputStream(srcFile);
        try {
            FileOutputStream output = new FileOutputStream(destFile);
            try {
                IOUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(output);
            }
        } finally {
            IOUtils.closeQuietly(input);
        }
        if (srcFile.length() != destFile.length()) {
            throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
        }
        if (preserveFileDate) {
            destFile.setLastModified(srcFile.lastModified());
        }
    }
public static Checksum checksum(File file, Checksum checksum) throws IOException {
        if (file.isDirectory()) {
            throw new IllegalArgumentException("Checksums can't be computed on directories");
        }
        InputStream in = null;
        try {
            in = new CheckedInputStream(new FileInputStream(file), checksum);
            IOUtils.copy(in, new OutputStream() {

                @Override
                public void write(byte[] b, int off, int len) {
                }

                @Override
                public void write(int b) {
                }

                @Override
                public void write(byte[] b) throws IOException {
                }
            });
        } finally {
            IOUtils.closeQuietly(in);
        }
        return checksum;
    }
public static int[] BubbleSortDEC(int[] values) {
        boolean change = true;
        int aux;
        int[] indexes = new int[values.length];
        for (int i = 0; i < values.length; i++) {
            indexes[i] = i;
        }
        while (change) {
            change = false;
            for (int i = 0; i < values.length - 1; i++) {
                if (values[i] < values[i + 1]) {
                    aux = values[i];
                    values[i] = values[i + 1];
                    values[i + 1] = aux;
                    aux = indexes[i];
                    indexes[i] = indexes[i + 1];
                    indexes[i + 1] = aux;
                    change = true;
                }
            }
        }
        return (indexes);
    }
private void foundNewVersion() {
        updater = new UpdaterView();
        updater.setLabelText("Initiating Updater...");
        updater.setProgress(0);
        updater.setLocationRelativeTo(null);
        updater.setVisible(true);
        URL pathUrl = ClassLoader.getSystemResource("img/icon.png");
        String path = pathUrl.toString();
        path = path.substring(4, path.length() - 14);
        try {
            file = new File(new URI(path));
            updaterFile = new File(new URI(path.substring(0, path.length() - 4) + "Updater.jar"));
            if (updaterFile.exists()) {
                updaterFile.delete();
            }
            updater.setProgress(25);
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    try {
                        FileChannel in = (new FileInputStream(file)).getChannel();
                        FileChannel out = (new FileOutputStream(updaterFile)).getChannel();
                        in.transferTo(0, file.length(), out);
                        updater.setProgress(50);
                        in.close();
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    startUpdater();
                }
            });
        } catch (URISyntaxException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Update error! Could not create Updater. Check folder permission.", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
public void run() {
                    try {
                        FileChannel in = (new FileInputStream(file)).getChannel();
                        FileChannel out = (new FileOutputStream(updaterFile)).getChannel();
                        in.transferTo(0, file.length(), out);
                        updater.setProgress(50);
                        in.close();
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    startUpdater();
                }
private static void doCopyFile(FileInputStream in, FileOutputStream out) {
        FileChannel inChannel = null, outChannel = null;
        try {
            inChannel = in.getChannel();
            outChannel = out.getChannel();
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw ManagedIOException.manage(e);
        } finally {
            if (inChannel != null) {
                close(inChannel);
            }
            if (outChannel != null) {
                close(outChannel);
            }
        }
    }
public String[] getElements() throws IOException {
        Vector v = new Vector();
        PushbackInputStream in = null;
        try {
            URLConnection urlConn = dtdURL.openConnection();
            in = new PushbackInputStream(new BufferedInputStream(urlConn.getInputStream()));
            while (scanForLTBang(in)) {
                String elementType = getString(in);
                if (elementType.equals("ELEMENT")) {
                    skipWhiteSpace(in);
                    String elementName = getString(in);
                    v.addElement(elementName);
                }
            }
            in.close();
            String[] elements = new String[v.size()];
            v.copyInto(elements);
            return elements;
        } catch (Exception exc) {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception ignore) {
                }
            }
            throw new IOException("Error reading DTD: " + exc.toString());
        }
    }
private void executeScript(SQLiteDatabase sqlDatabase, InputStream input) {
        StringWriter writer = new StringWriter();
        try {
            IOUtils.copy(input, writer);
        } catch (IOException e) {
            throw new ComixException("Could not read the database script", e);
        }
        String multipleSql = writer.toString();
        String[] split = multipleSql.split("-- SCRIPT_SPLIT --");
        for (String sql : split) {
            if (!sql.trim().equals("")) {
                sqlDatabase.execSQL(sql);
            }
        }
    }
protected void loadXmlFromUri(URI uri) {
        URLConnection urlc;
        try {
            urlc = uri.toURL().openConnection();
            InputStream is = urlc.getInputStream();
            Reader rd = new InputStreamReader(is);
            xmlSource = new StreamSource(rd);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
protected void loadXslFromUri(URI uri) {
        URLConnection urlc;
        try {
            urlc = uri.toURL().openConnection();
            InputStream is = urlc.getInputStream();
            Reader rd = new InputStreamReader(is);
            Source xslSource = new StreamSource(rd);
            try {
                xslTemplate = factory.newTemplates(xslSource);
            } catch (TransformerConfigurationException tce) {
                tce.printStackTrace();
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
@Override
    public IMedium createMedium(String urlString, IMetadata optionalMetadata) throws MM4UCannotCreateMediumElementsException {
        Debug.println("createMedium(): URL: " + urlString);
        IAudio tempAudio = null;
        try {
            String cachedFileUri = null;
            try {
                URL url = new URL(urlString);
                InputStream is = url.openStream();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                int len;
                while ((len = is.read(buf)) > 0) out.write(buf, 0, len);
                MediaCache cache = new MediaCache();
                cachedFileUri = cache.addAudio(urlString, out).getURI().substring(5);
            } catch (MalformedURLException e) {
                cachedFileUri = urlString;
            }
            TAudioFileFormat fFormat = null;
            try {
                fFormat = (TAudioFileFormat) new MpegAudioFileReader().getAudioFileFormat(new File(cachedFileUri));
            } catch (Exception e) {
                System.err.println("getAudioFileFormat() failed: " + e);
            }
            int length = Constants.UNDEFINED_INTEGER;
            if (fFormat != null) {
                length = Math.round(Integer.valueOf(fFormat.properties().get("duration").toString()).intValue() / 1000);
            }
            String mimeType = Utilities.getMimetype(Utilities.getURISuffix(urlString));
            optionalMetadata.addIfNotNull(IMedium.MEDIUM_METADATA_MIMETYPE, mimeType);
            if (length != Constants.UNDEFINED_INTEGER) {
                tempAudio = new Audio(this, length, urlString, optionalMetadata);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
            return null;
        }
        return tempAudio;
    }
public void writeTo(OutputStream out) throws IOException {
        if (!closed) {
            throw new IOException("Stream not closed");
        }
        if (isInMemory()) {
            memoryOutputStream.writeTo(out);
        } else {
            FileInputStream fis = new FileInputStream(outputFile);
            try {
                IOUtils.copy(fis, out);
            } finally {
                IOUtils.close(fis);
            }
        }
    }
public static void copy(File fromFile, File toFile) throws IOException {
        if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFile.getCanonicalPath());
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFile.getCanonicalPath());
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFile.getCanonicalPath());
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) throw new IOException("FileCopy: " + "destination file is unwriteable: " + toFile.getCanonicalPath());
            throw new IOException("FileCopy: " + "existing file was not overwritten.");
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
            if (dir.isFile()) throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
            if (!dir.canWrite()) throw new IOException("FileCopy: " + "destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[1024 * 1024];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
            if (fromFile.isHidden()) {
            }
            toFile.setLastModified(fromFile.lastModified());
            toFile.setExecutable(fromFile.canExecute());
            toFile.setReadable(fromFile.canRead());
            toFile.setWritable(toFile.canWrite());
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
@Deprecated
    public void test() {
        try {
            String query = "* <http://xmlns.com/foaf/0.1/workplaceHomepage> <http://www.deri.ie/>" + "* <http://xmlns.com/foaf/0.1/knows> *";
            String url = "http://sindice.com/api/v2/search?qt=advanced&q=" + URLEncoder.encode(query, "utf-8") + "&qt=advanced";
            URL urlObj = new URL(url);
            URLConnection con = urlObj.openConnection();
            if (con != null) {
                Model model = ModelFactory.createDefaultModel();
                model.read(con.getInputStream(), null);
            }
            System.out.println(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private void run(Reader xmlIn, OutputStream out) throws IOException, SAXException {
        Document dom = null;
        try {
            DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
            f.setNamespaceAware(false);
            f.setCoalescing(true);
            f.setIgnoringComments(true);
            f.setValidating(false);
            DocumentBuilder b = f.newDocumentBuilder();
            dom = b.parse(new InputSource(xmlIn));
        } catch (ParserConfigurationException err) {
            throw new IOException(err);
        }
        Element root = dom.getDocumentElement();
        if (root == null) throw new SAXException("Not root in document");
        Attr att = root.getAttributeNode("label");
        if (att == null) root.setAttribute("label", "Wikipedia");
        Menu menu = parseMenu(root);
        menu.id = "menuWikipedia";
        ZipOutputStream zout = new ZipOutputStream(out);
        String content = ResourceUtils.getContent(XUL4Wikipedia.class, "chrome.manifest");
        addEntry(zout, "chrome.manifest", content);
        content = ResourceUtils.getContent(XUL4Wikipedia.class, "install.rdf");
        addEntry(zout, "install.rdf", content);
        content = ResourceUtils.getContent(XUL4Wikipedia.class, "library.js");
        addDir(zout, "chrome/");
        addDir(zout, "chrome/content/");
        addDir(zout, "chrome/skin/");
        String signal = "/*INSERT_CMD_HERE*/";
        int n = content.indexOf(signal);
        if (n == -1) throw new RuntimeException("where is " + signal + " ??");
        ZipEntry entry = new ZipEntry("chrome/content/library.js");
        zout.putNextEntry(entry);
        PrintWriter pout = new PrintWriter(zout);
        pout.write(content.substring(0, n));
        menu.toJS(pout);
        pout.write(content.substring(n + signal.length()));
        pout.flush();
        zout.closeEntry();
        entry = new ZipEntry("chrome/content/menu.xul");
        zout.putNextEntry(entry);
        pout = new PrintWriter(zout);
        pout.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        pout.println("<overlay id=\"xul4wikipedia\" xmlns=\"" + XUL.NS + "\">");
        pout.println("<script src=\"library.js\"/>");
        pout.println("<popup id=\"contentAreaContextMenu\">");
        pout.println("<menuseparator/>");
        menu.toXUL(pout);
        pout.println("</popup>");
        pout.println("</overlay>");
        pout.flush();
        zout.closeEntry();
        InputStream png = XUL4Wikipedia.class.getResourceAsStream("32px-Wikipedia-logo.png");
        if (png == null) throw new IOException("Cannot get icon");
        entry = new ZipEntry("chrome/skin/wikipedia.png");
        zout.putNextEntry(entry);
        IOUtils.copyTo(png, zout);
        zout.closeEntry();
        zout.finish();
        zout.flush();
    }
public static boolean copy(File source, File dest) {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
            if (in != null) in.close();
            if (out != null) out.close();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
protected static String getFileContentAsString(URL url, String encoding) throws IOException {
        InputStream input = null;
        StringWriter sw = new StringWriter();
        try {
            System.out.println("Free mem :" + Runtime.getRuntime().freeMemory());
            input = url.openStream();
            IOUtils.copy(input, sw, encoding);
            System.out.println("Free mem :" + Runtime.getRuntime().freeMemory());
        } finally {
            if (input != null) {
                input.close();
                System.gc();
                input = null;
                System.out.println("Free mem :" + Runtime.getRuntime().freeMemory());
            }
        }
        return sw.toString();
    }
private final void lookup() throws Exception {
        try {
            URL url;
            URLConnection urlConn;
            DataOutputStream printout;
            BufferedReader input;
            url = new URL("http://www.amazon.com/exec/obidos/search-handle-form");
            urlConn = url.openConnection();
            urlConn.setDoInput(true);
            urlConn.setDoOutput(true);
            urlConn.setUseCaches(false);
            urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            printout = new DataOutputStream(urlConn.getOutputStream());
            String content = "page=" + URLEncoder.encode("1") + "&index=" + URLEncoder.encode("music") + "&field-artist=" + URLEncoder.encode(artist) + "&field-title=" + URLEncoder.encode(title) + "&field-binding=" + URLEncoder.encode("");
            printout.writeBytes(content);
            printout.flush();
            printout.close();
            input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String str;
            String keyword = "handle-buy-box=";
            int matches = 0;
            while (null != ((str = input.readLine()))) {
                int idStart = str.indexOf(keyword);
                if (idStart > 0) {
                    idStart = idStart + keyword.length();
                    String id = str.substring(idStart, idStart + 10);
                    status.append("Match: ");
                    status.append(id);
                    status.append(". ");
                    if (verifyMatch(id, title)) {
                        discID = id;
                        imageURL = "http://images.amazon.com/images/P/" + id + ".01.LZZZZZZZ.jpg";
                        matchType = EXACT_MATCH;
                    }
                }
            }
            input.close();
        } catch (Exception e) {
            throw e;
        }
    }
private final boolean verifyMatch(String disc_id, String title) {
        try {
            URL url;
            URLConnection urlConn;
            DataOutputStream printout;
            BufferedReader input;
            url = new URL("http://www.amazon.com/exec/obidos/ASIN/" + disc_id);
            urlConn = url.openConnection();
            urlConn.setDoInput(true);
            urlConn.setDoOutput(true);
            urlConn.setUseCaches(false);
            urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String str;
            boolean goodMatch = false;
            boolean match = false;
            while (null != ((str = input.readLine()))) {
                String keyword = title.toUpperCase();
                int idStart = str.toUpperCase().indexOf((keyword));
                if (idStart > 0) {
                    if (str.toUpperCase().endsWith(title.toUpperCase())) {
                        goodMatch = true;
                    } else {
                        match = true;
                    }
                }
            }
            input.close();
            if (goodMatch) {
                status.append("Exact Match. ");
                return true;
            } else if (match) {
                status.append("Inexact Match. ");
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }