semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static XMLConfigurator loadFromSystemProperty(String propertyName) throws IOException {
        String urlStr = System.getProperty(propertyName);
        if (urlStr == null || urlStr.length() == 0) {
            return null;
        }
        InputStream in = null;
        DOMRetriever xmlDoc = null;
        try {
            URL url = new URL(urlStr);
            xmlDoc = new DOMRetriever(in = url.openStream());
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        } finally {
            if (in != null) in.close();
        }
        return newInstance(xmlDoc);
    }
public void doFilter(final ServletRequest arg0, final ServletResponse arg1, final FilterChain arg2) throws IOException, ServletException {
        if (!this.init) {
            final HttpServletResponse response = Dynamic._.Cast(arg1);
            response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Mainfilter not initialized.");
            return;
        }
        if (this.mainFilter != null) {
            try {
                URL url = this.context.getResource("/WEB-INF/classes/log4j.properties");
                URLConnection uc = url.openConnection();
                if (uc.getLastModified() != lastLoadLog4j) {
                    lastLoadLog4j = uc.getLastModified();
                    try {
                        uc.getInputStream().close();
                    } catch (Exception ignore) {
                    }
                    PropertyConfigurator.configure(url);
                } else {
                    try {
                        uc.getInputStream().close();
                    } catch (Exception ignore) {
                    }
                }
            } catch (final Exception e) {
            }
            this.mainFilter.doFilter(arg0, arg1);
        } else {
            final HttpServletResponse response = Dynamic._.Cast(arg1);
            response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Mainfilter bad setup.");
        }
    }
public void testGetContentInputStream() {
        try {
            URL url = new URL("http://www.designerfashion.de/Seiten/r2-Felljacke.html");
            InputStream in = url.openStream();
            Content c = provider.getContent(in);
            assertNotNull(c);
            assertEquals("Web Page", c.getType());
            assertEquals("net.sf.iqser.plugin.web.html", c.getProvider());
            assertEquals(8, c.getAttributes().size());
            assertEquals("Name", c.getAttributes().iterator().next().getName());
        } catch (MalformedURLException e) {
            fail("Malformed URL - " + e.getMessage());
        } catch (IOException e) {
            fail("Couldn't read source - " + e.getMessage());
        }
    }
@Override
    public List<ProvaSolution[]> run(ProvaService prova, String agent, String key, String src) throws IOException {
        File file = new File(src);
        BufferedReader in;
        InputStream is = null;
        try {
            if (!file.exists() || !file.canRead()) {
                try {
                    is = Thread.currentThread().getContextClassLoader().getResourceAsStream(src);
                    in = new BufferedReader(new InputStreamReader(is));
                } catch (Exception ex1) {
                    try {
                        is = RuleReaderImpl.class.getResourceAsStream(src);
                        in = new BufferedReader(new InputStreamReader(is));
                    } catch (Exception ex2) {
                        try {
                            URL url = new URL(src);
                            in = new BufferedReader(new InputStreamReader(url.openStream()));
                        } catch (Exception ex3) {
                            throw new IOException("Cannot read from " + src);
                        }
                    }
                }
            } else {
                FileReader fr = new FileReader(file);
                in = new BufferedReader(fr);
            }
            List<ProvaSolution[]> results = prova.consult(agent, in, key);
            return results;
        } finally {
            if (is != null) is.close();
        }
    }
public static Document loadXML(URL url) {
        Document doc = null;
        try {
            DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            doc = docBuilder.parse(url.openStream());
        } catch (ParserConfigurationException pce) {
        } catch (SAXException saxe) {
        } catch (IOException ioe) {
        }
        return doc;
    }
public String upload(String urlString, ByteArrayOutputStream dataStream) {
        HttpURLConnection conn = null;
        DataOutputStream dos = null;
        String exsistingFileName = "blah.png";
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary = "*****";
        try {
            URL url = new URL(urlString);
            conn = (HttpURLConnection) url.openConnection();
            conn.setInstanceFollowRedirects(false);
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
            dos = new DataOutputStream(conn.getOutputStream());
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"aFile\";" + " filename=\"" + exsistingFileName + "\"" + lineEnd);
            dos.writeBytes(lineEnd);
            dos.write(dataStream.toByteArray());
            dos.writeBytes(lineEnd);
            dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
            dos.flush();
            dos.close();
            return conn.getHeaderField("location");
        } catch (MalformedURLException ex) {
            log.log(Level.INFO, "From ServletCom CLIENT REQUEST:" + ex);
        } catch (IOException ioe) {
            log.log(Level.INFO, "From ServletCom CLIENT REQUEST:" + ioe);
        }
        return null;
    }
private static String downloadMedia(String mediadir, URL remoteFile) throws Exception, InterruptedException {
        File tmpDir = new File(System.getProperty("java.io.tmpdir") + "org.ogre4j.examples/" + mediadir);
        if (!tmpDir.exists()) {
            tmpDir.mkdirs();
        }
        URLConnection urlConnection = remoteFile.openConnection();
        if (urlConnection.getConnectTimeout() != 0) {
            urlConnection.setConnectTimeout(0);
        }
        InputStream content = remoteFile.openStream();
        BufferedInputStream bin = new BufferedInputStream(content);
        String downloaded = tmpDir.getCanonicalPath() + File.separatorChar + new File(remoteFile.getFile()).getName();
        File file = new File(downloaded);
        BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(file));
        System.out.println("downloading file " + remoteFile + " ...");
        for (long i = 0; i < urlConnection.getContentLength(); i++) {
            bout.write(bin.read());
        }
        bout.close();
        bout = null;
        bin.close();
        return downloaded;
    }
@NotNull
    public Set<Class<?>> in(Package pack) {
        String packageName = pack.getName();
        String packageOnly = pack.getName();
        final boolean recursive = true;
        Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
        String packageDirName = packageOnly.replace('.', '/');
        Enumeration<URL> dirs;
        try {
            dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
        } catch (IOException e) {
            throw new PackageScanFailedException("Could not read from package directory: " + packageDirName, e);
        }
        while (dirs.hasMoreElements()) {
            URL url = dirs.nextElement();
            String protocol = url.getProtocol();
            if ("file".equals(protocol)) {
                try {
                    findClassesInDirPackage(packageOnly, URLDecoder.decode(url.getFile(), "UTF-8"), recursive, classes);
                } catch (UnsupportedEncodingException e) {
                    throw new PackageScanFailedException("Could not read from file: " + url, e);
                }
            } else if ("jar".equals(protocol)) {
                JarFile jar;
                try {
                    jar = ((JarURLConnection) url.openConnection()).getJarFile();
                } catch (IOException e) {
                    throw new PackageScanFailedException("Could not read from jar url: " + url, e);
                }
                Enumeration<JarEntry> entries = jar.entries();
                while (entries.hasMoreElements()) {
                    JarEntry entry = entries.nextElement();
                    String name = entry.getName();
                    if (name.charAt(0) == '/') {
                        name = name.substring(1);
                    }
                    if (name.startsWith(packageDirName)) {
                        int idx = name.lastIndexOf('/');
                        if (idx != -1) {
                            packageName = name.substring(0, idx).replace('/', '.');
                        }
                        if ((idx != -1) || recursive) {
                            if (name.endsWith(".class") && !entry.isDirectory()) {
                                String className = name.substring(packageName.length() + 1, name.length() - 6);
                                add(packageName, classes, className);
                            }
                        }
                    }
                }
            }
        }
        return classes;
    }
public void xtestURL1() throws Exception {
        URL url = new URL(IOTest.URL);
        InputStream inputStream = url.openStream();
        OutputStream outputStream = new FileOutputStream("C:/Temp/testURL1.mp4");
        IOUtils.copy(inputStream, outputStream);
        inputStream.close();
        outputStream.close();
    }
public void xtestURL2() throws Exception {
        URL url = new URL(IOTest.URL);
        InputStream inputStream = url.openStream();
        OutputStream outputStream = new FileOutputStream("C:/Temp/testURL2.mp4");
        IOUtils.copy(inputStream, outputStream);
        inputStream.close();
        outputStream.close();
    }
public void xtestFile1() throws Exception {
        InputStream inputStream = new FileInputStream(IOTest.FILE);
        OutputStream outputStream = new FileOutputStream("C:/Temp/testFile1.mp4");
        IOUtils.copy(inputStream, outputStream);
        inputStream.close();
        outputStream.close();
    }
public void xtestFile2() throws Exception {
        InputStream inputStream = new FileInputStream(IOTest.FILE);
        OutputStream outputStream = new FileOutputStream("C:/Temp/testFile2.mp4");
        IOUtils.copy(inputStream, outputStream);
        inputStream.close();
        outputStream.close();
    }
public Collection<Regula> citesteReguli() throws IOException {
        URL url = new URL(urlulSpreLocatiaCurenta, fisier);
        BufferedReader reader = new BufferedReader(new InputStreamReader((url.openStream())));
        Collection<Regula> rezultat = new ArrayList<Regula>();
        String line = "";
        while (!"".equals(line = reader.readLine())) {
            Regula r = parseazaRegula(line);
            if (r != null) rezultat.add(r);
        }
        return rezultat;
    }
public boolean getAuth(String content) throws IOException {
        String resp_remote;
        try {
            URL url = new URL(remoteurl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setRequestMethod("POST");
            OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
            writer.write("md5sum=" + content);
            writer.close();
            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream is = connection.getInputStream();
                BufferedReader rd = new BufferedReader(new InputStreamReader(is));
                String line;
                StringBuffer response = new StringBuffer();
                while ((line = rd.readLine()) != null) {
                    response.append(line);
                    response.append('\r');
                }
                rd.close();
                resp_remote = response.toString();
                wd.del();
                wd.setKey(resp_remote);
                return true;
            } else {
                return false;
            }
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        return false;
    }
public static String getMd5Hash(String plaintext) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(plaintext.getBytes());
            byte[] digest = md5.digest();
            BigInteger bigInt = new BigInteger(1, digest);
            String hashtext = bigInt.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        } catch (final NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
private void scanURL(String packagePath, Collection<String> componentClassNames, URL url) throws IOException {
        URLConnection connection = url.openConnection();
        JarFile jarFile;
        if (connection instanceof JarURLConnection) {
            jarFile = ((JarURLConnection) connection).getJarFile();
        } else {
            jarFile = getAlternativeJarFile(url);
        }
        if (jarFile != null) {
            scanJarFile(packagePath, componentClassNames, jarFile);
        } else if (supportsDirStream(url)) {
            Stack<Queued> queue = new Stack<Queued>();
            queue.push(new Queued(url, packagePath));
            while (!queue.isEmpty()) {
                Queued queued = queue.pop();
                scanDirStream(queued.packagePath, queued.packageURL, componentClassNames, queue);
            }
        } else {
            String packageName = packagePath.replace("/", ".");
            if (packageName.endsWith(".")) {
                packageName = packageName.substring(0, packageName.length() - 1);
            }
            scanDir(packageName, new File(url.getFile()), componentClassNames);
        }
    }
private void weightAndPlaceClasses() {
        int rows = getRows();
        for (int curRow = _maxPackageRank; curRow < rows; curRow++) {
            xPos = getHGap() / 2;
            BOTLRuleDiagramNode[] rowObject = getObjectsInRow(curRow);
            for (int i = 0; i < rowObject.length; i++) {
                if (curRow == _maxPackageRank) {
                    int nDownlinks = rowObject[i].getDownlinks().size();
                    rowObject[i].setWeight((nDownlinks > 0) ? (1 / nDownlinks) : 2);
                } else {
                    Vector uplinks = rowObject[i].getUplinks();
                    int nUplinks = uplinks.size();
                    if (nUplinks > 0) {
                        float average_col = 0;
                        for (int j = 0; j < uplinks.size(); j++) {
                            average_col += ((BOTLRuleDiagramNode) (uplinks.elementAt(j))).getColumn();
                        }
                        average_col /= nUplinks;
                        rowObject[i].setWeight(average_col);
                    } else {
                        rowObject[i].setWeight(1000);
                    }
                }
            }
            int[] pos = new int[rowObject.length];
            for (int i = 0; i < pos.length; i++) {
                pos[i] = i;
            }
            boolean swapped = true;
            while (swapped) {
                swapped = false;
                for (int i = 0; i < pos.length - 1; i++) {
                    if (rowObject[pos[i]].getWeight() > rowObject[pos[i + 1]].getWeight()) {
                        int temp = pos[i];
                        pos[i] = pos[i + 1];
                        pos[i + 1] = temp;
                        swapped = true;
                    }
                }
            }
            for (int i = 0; i < pos.length; i++) {
                rowObject[pos[i]].setColumn(i);
                if ((i > _vMax) && (rowObject[pos[i]].getUplinks().size() == 0) && (rowObject[pos[i]].getDownlinks().size() == 0)) {
                    if (getColumns(rows - 1) > _vMax) {
                        rows++;
                    }
                    rowObject[pos[i]].setRank(rows - 1);
                } else {
                    rowObject[pos[i]].setLocation(new Point(xPos, yPos));
                    xPos += rowObject[pos[i]].getSize().getWidth() + getHGap();
                }
            }
            yPos += getRowHeight(curRow) + getVGap();
        }
    }
public boolean check(int timeout) {
            StringBuilder result = null;
            java.net.URL url;
            java.io.InputStream in = null;
            try {
                url = new java.net.URL(location + "/prisms?method=test");
                java.net.URLConnection conn = url.openConnection();
                conn.setConnectTimeout(timeout);
                in = conn.getInputStream();
                java.io.Reader reader = new java.io.InputStreamReader(in);
                result = new StringBuilder();
                int read = reader.read();
                while (read >= 0) {
                    result.append((char) read);
                    read = reader.read();
                }
            } catch (java.io.IOException e) {
                log.error("Instance check failed", e);
                if (in != null) try {
                    in.close();
                } catch (java.io.IOException e2) {
                }
            }
            return result != null && result.toString().startsWith("success");
        }
private static void dumpUrl(URL url) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String s = reader.readLine();
        while (s != null) {
            System.out.println(s);
            s = reader.readLine();
        }
        reader.close();
    }
public static void main(String[] args) {
        final String filePath1 = "e:\\mysite\\data\\up\\itsite";
        final String filePath2 = "d:\\works\\itsite\\itsite";
        IOUtils.listAllFilesNoRs(new File(filePath2), new FileFilter() {

            @Override
            public boolean accept(File file) {
                if (file.getName().equals(".svn")) {
                    return false;
                }
                final long modify = file.lastModified();
                final long time = DateUtils.toDate("2012-03-21 17:43", "yyyy-MM-dd HH:mm").getTime();
                if (modify >= time) {
                    if (file.isFile()) {
                        File f = new File(StringsUtils.replace(file.getAbsolutePath(), filePath2, filePath1));
                        f.getParentFile().mkdirs();
                        try {
                            IOUtils.copyFile(file, f);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        System.out.println(f.getName());
                    }
                }
                return true;
            }
        });
    }
@Override
            public boolean accept(File file) {
                if (file.getName().equals(".svn")) {
                    return false;
                }
                final long modify = file.lastModified();
                final long time = DateUtils.toDate("2012-03-21 17:43", "yyyy-MM-dd HH:mm").getTime();
                if (modify >= time) {
                    if (file.isFile()) {
                        File f = new File(StringsUtils.replace(file.getAbsolutePath(), filePath2, filePath1));
                        f.getParentFile().mkdirs();
                        try {
                            IOUtils.copyFile(file, f);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        System.out.println(f.getName());
                    }
                }
                return true;
            }
private InputStream loadFromUrl(URL url, String contentType) throws IOException {
        Proxy proxy = null;
        if (isUseProxy) {
            Authenticator.setDefault(new Authenticator() {

                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(proxyUser, proxyPassword.toCharArray());
                }
            });
            proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
        } else {
            proxy = Proxy.NO_PROXY;
        }
        URLConnection connection = url.openConnection(proxy);
        connection.setRequestProperty("Accept-Charset", DEFAULT_CHARSET);
        connection.setRequestProperty("Content-Type", contentType);
        connection.setRequestProperty("User-Agent", USER_AGENT);
        InputStream response = connection.getInputStream();
        return response;
    }
public boolean backupLastAuditSchema(File lastAuditSchema) {
        boolean isBkupFileOK = false;
        String writeTimestamp = DateFormatUtils.format(new java.util.Date(), configFile.getTimestampPattern());
        File target = new File(configFile.getAuditSchemaFileDir() + File.separator + configFile.getAuditSchemaFileName() + ".bkup_" + writeTimestamp);
        FileChannel sourceChannel = null;
        FileChannel targetChannel = null;
        try {
            sourceChannel = new FileInputStream(lastAuditSchema).getChannel();
            targetChannel = new FileOutputStream(target).getChannel();
            targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        } catch (IOException e) {
            logger.log(Level.SEVERE, "IO exception occurred while copying file", e);
        } finally {
            if ((target != null) && (target.exists()) && (target.length() > 0)) {
                isBkupFileOK = true;
            }
            try {
                if (sourceChannel != null) {
                    sourceChannel.close();
                }
                if (targetChannel != null) {
                    targetChannel.close();
                }
            } catch (IOException e) {
                logger.warning("closing channels failed");
            }
        }
        return isBkupFileOK;
    }
public static void decompressGZIP(File gzip, File to, long skip) throws IOException {
        GZIPInputStream gis = null;
        BufferedOutputStream bos = null;
        try {
            bos = new BufferedOutputStream(new FileOutputStream(to));
            FileInputStream fis = new FileInputStream(gzip);
            fis.skip(skip);
            gis = new GZIPInputStream(fis);
            final byte[] buffer = new byte[IO_BUFFER];
            int read = -1;
            while ((read = gis.read(buffer)) != -1) {
                bos.write(buffer, 0, read);
            }
        } finally {
            try {
                gis.close();
            } catch (Exception nope) {
            }
            try {
                bos.flush();
            } catch (Exception nope) {
            }
            try {
                bos.close();
            } catch (Exception nope) {
            }
        }
    }