semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static Map loadHandlerList(final String resourceName, ClassLoader loader) {
        if (loader == null) loader = ClassLoader.getSystemClassLoader();
        final Map result = new HashMap();
        try {
            final Enumeration resources = loader.getResources(resourceName);
            if (resources != null) {
                while (resources.hasMoreElements()) {
                    final URL url = (URL) resources.nextElement();
                    final Properties mapping;
                    InputStream urlIn = null;
                    try {
                        urlIn = url.openStream();
                        mapping = new Properties();
                        mapping.load(urlIn);
                    } catch (IOException ioe) {
                        continue;
                    } finally {
                        if (urlIn != null) try {
                            urlIn.close();
                        } catch (Exception ignore) {
                        }
                    }
                    for (Enumeration keys = mapping.propertyNames(); keys.hasMoreElements(); ) {
                        final String protocol = (String) keys.nextElement();
                        final String implClassName = mapping.getProperty(protocol);
                        final Object currentImpl = result.get(protocol);
                        if (currentImpl != null) {
                            if (implClassName.equals(currentImpl.getClass().getName())) continue; else throw new IllegalStateException("duplicate " + "protocol handler class [" + implClassName + "] for protocol " + protocol);
                        }
                        result.put(protocol, loadURLStreamHandler(implClassName, loader));
                    }
                }
            }
        } catch (IOException ignore) {
        }
        return result;
    }
public Download(URL url, int segs) {
        this.url = url;
        Mediator.register(this);
        status = "Starting...";
        try {
            totalSize = url.openConnection().getContentLength();
            name = url.getPath().substring(url.getPath().lastIndexOf('/') + 1);
            if (name.isEmpty()) {
                name = "UNKNOWN";
            }
            tempFolder = new File(Configuration.PARTS_FOLDER, getName());
            tempFolder.mkdir();
        } catch (IOException ex) {
            Logger.post(Logger.Level.WARNING, "URL could not be opened: " + url);
        }
        dest = new File(System.getProperty("user.home") + File.separator + name);
        if (segs > totalSize) {
            segs = totalSize;
        }
        Properties props = new Properties();
        props.setProperty("url", getUrl().toString());
        props.setProperty("segments", String.valueOf(segs));
        try {
            props.storeToXML(new FileOutputStream(new File(getTempFolder(), "index.xml")), "Warning: Editing this file may compromise the integrity of the download");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        segments = new Segment[segs];
        for (int i = 0; i < segs; i++) {
            segments[i] = new Segment(this, i);
        }
        Thread thread = new Thread(this);
        thread.setDaemon(true);
        thread.start();
        status = "Downloading...";
        Mediator.post(new DownloadStatusChanged(this));
        Logger.post(Logger.Level.INFO, "Starting download: " + getName());
    }
private static void replaceEntityMappings(File signserverearpath, File entityMappingXML) throws ZipException, IOException {
        ZipInputStream earFile = new ZipInputStream(new FileInputStream(signserverearpath));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ZipOutputStream tempZip = new ZipOutputStream(baos);
        ZipEntry next = earFile.getNextEntry();
        while (next != null) {
            ByteArrayOutputStream content = new ByteArrayOutputStream();
            byte[] data = new byte[30000];
            int numberread;
            while ((numberread = earFile.read(data)) != -1) {
                content.write(data, 0, numberread);
            }
            if (next.getName().equals("signserver-ejb.jar")) {
                content = replaceEntityMappings(content, entityMappingXML);
                next = new ZipEntry("signserver-ejb.jar");
            }
            tempZip.putNextEntry(next);
            tempZip.write(content.toByteArray());
            next = earFile.getNextEntry();
        }
        earFile.close();
        tempZip.close();
        FileOutputStream fos = new FileOutputStream(signserverearpath);
        fos.write(baos.toByteArray());
        fos.close();
    }
public static String MD5_hex(String p) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(p.getBytes());
            BigInteger hash = new BigInteger(1, md.digest());
            String ret = hash.toString(16);
            return ret;
        } catch (NoSuchAlgorithmException e) {
            logger.error("can not create confirmation key", e);
            throw new TechException(e);
        }
    }
private String load(URL url) {
        BufferedReader r = null;
        try {
            r = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer buf = new StringBuffer();
            while (r.ready()) {
                buf.append(r.readLine()).append('\n');
            }
            r.close();
            return buf.toString();
        } catch (IOException e) {
            logger.severe("Could not load shader program: " + e);
            logger.logp(Level.SEVERE, getClass().getName(), "load(URL)", "Exception", e);
            return null;
        }
    }
private static String md5Encode(String pass) {
        String string;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(pass.getBytes());
            byte[] result = md.digest();
            string = bytes2hexStr(result);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("La libreria java.security no implemente MD5");
        }
        return string;
    }
public String getProxy(String userName, String password) throws Exception {
        URL url = new URL(httpURL);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        ObjectOutputStream outputToServlet = new ObjectOutputStream(conn.getOutputStream());
        outputToServlet.writeObject(userName);
        outputToServlet.writeObject(password);
        outputToServlet.flush();
        outputToServlet.close();
        ObjectInputStream inputFromServlet = new ObjectInputStream(conn.getInputStream());
        return inputFromServlet.readObject() + "";
    }
public void init() {
        super.init();
        Runnable doActions = new Runnable() {

            public void run() {
                if (_plot == null) {
                    _plot = newPlot();
                }
                getContentPane().add(plot(), BorderLayout.NORTH);
                int width;
                int height;
                String widthspec = getParameter("width");
                if (widthspec != null) {
                    width = Integer.parseInt(widthspec);
                } else {
                    width = 400;
                }
                String heightspec = getParameter("height");
                if (heightspec != null) {
                    height = Integer.parseInt(heightspec);
                } else {
                    height = 400;
                }
                _setPlotSize(width, height);
                plot().setButtons(true);
                Color background = Color.white;
                String colorspec = getParameter("background");
                if (colorspec != null) {
                    background = PlotBox.getColorByName(colorspec);
                }
                setBackground(background);
                plot().setBackground(background);
                getContentPane().setBackground(background);
                Color foreground = Color.black;
                colorspec = getParameter("foreground");
                if (colorspec != null) {
                    foreground = PlotBox.getColorByName(colorspec);
                }
                setForeground(foreground);
                plot().setForeground(foreground);
                plot().setVisible(true);
                String dataurlspec = getParameter("dataurl");
                if (dataurlspec != null) {
                    try {
                        showStatus("Reading data");
                        URL dataurl = new URL(getDocumentBase(), dataurlspec);
                        InputStream in = dataurl.openStream();
                        _read(in);
                        showStatus("Done");
                    } catch (MalformedURLException e) {
                        System.err.println(e.toString());
                    } catch (FileNotFoundException e) {
                        System.err.println("PlotApplet: file not found: " + e);
                    } catch (IOException e) {
                        System.err.println("PlotApplet: error reading input file: " + e);
                    }
                }
            }
        };
        try {
            SwingUtilities.invokeAndWait(doActions);
        } catch (Exception ex) {
        }
    }
public void run() {
                if (_plot == null) {
                    _plot = newPlot();
                }
                getContentPane().add(plot(), BorderLayout.NORTH);
                int width;
                int height;
                String widthspec = getParameter("width");
                if (widthspec != null) {
                    width = Integer.parseInt(widthspec);
                } else {
                    width = 400;
                }
                String heightspec = getParameter("height");
                if (heightspec != null) {
                    height = Integer.parseInt(heightspec);
                } else {
                    height = 400;
                }
                _setPlotSize(width, height);
                plot().setButtons(true);
                Color background = Color.white;
                String colorspec = getParameter("background");
                if (colorspec != null) {
                    background = PlotBox.getColorByName(colorspec);
                }
                setBackground(background);
                plot().setBackground(background);
                getContentPane().setBackground(background);
                Color foreground = Color.black;
                colorspec = getParameter("foreground");
                if (colorspec != null) {
                    foreground = PlotBox.getColorByName(colorspec);
                }
                setForeground(foreground);
                plot().setForeground(foreground);
                plot().setVisible(true);
                String dataurlspec = getParameter("dataurl");
                if (dataurlspec != null) {
                    try {
                        showStatus("Reading data");
                        URL dataurl = new URL(getDocumentBase(), dataurlspec);
                        InputStream in = dataurl.openStream();
                        _read(in);
                        showStatus("Done");
                    } catch (MalformedURLException e) {
                        System.err.println(e.toString());
                    } catch (FileNotFoundException e) {
                        System.err.println("PlotApplet: file not found: " + e);
                    } catch (IOException e) {
                        System.err.println("PlotApplet: error reading input file: " + e);
                    }
                }
            }
public static Reader getReader(String url) throws MalformedURLException, IOException {
        if (url.startsWith("file:")) return new FileReader(url.substring(5)); else if (url.startsWith("http:")) return new InputStreamReader(new URL(url).openStream());
        throw new MalformedURLException("Invalid URI schema, file: or http: expected.");
    }
private synchronized void configure() {
        final Map res = new HashMap();
        try {
            final Enumeration resources = getConfigResources();
            SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
            while (resources.hasMoreElements()) {
                final URL url = (URL) resources.nextElement();
                DefaultHandler saxHandler = new DefaultHandler() {

                    private Group group;

                    private StringBuffer tagContent = new StringBuffer();

                    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
                        if ("group".equals(qName)) {
                            group = new Group(attributes.getValue("name"));
                            String minimizeJs = attributes.getValue("minimize");
                            String minimizeCss = attributes.getValue("minimizeCss");
                            group.setMinimize(!"false".equals(minimizeJs));
                            group.setMinimizeCss("true".equals(minimizeCss));
                        } else if ("js".equals(qName) || "css".equals(qName) || "group-ref".equals(qName)) tagContent.setLength(0);
                    }

                    public void characters(char ch[], int start, int length) throws SAXException {
                        tagContent.append(ch, start, length);
                    }

                    public void endElement(String uri, String localName, String qName) throws SAXException {
                        if ("group".equals(qName)) res.put(group.getName(), group); else if ("js".equals(qName)) group.getJsNames().add(tagContent.toString()); else if ("css".equals(qName)) group.getCssNames().add(tagContent.toString()); else if ("group-ref".equals(qName)) {
                            String name = tagContent.toString();
                            Group subGroup = (Group) res.get(name);
                            if (subGroup == null) throw new RuntimeException("Error parsing " + url.toString() + " <group-ref>" + name + "</group-ref> unknown");
                            group.getSubgroups().add(subGroup);
                        }
                    }
                };
                try {
                    saxParser.parse(url.openStream(), saxHandler);
                } catch (Throwable e) {
                    log.warn(e.toString(), e);
                    log.warn("Exception " + e.toString() + " ignored, let's move on..");
                }
            }
            configurationFilesMaxModificationTime = findMaxConfigModificationTime();
        } catch (SAXException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e);
        }
        this.groups = res;
    }
private boolean getRemoteFiles() throws Exception {
        boolean resp = false;
        int respCode = 0;
        URL url = new URL(storageUrlString);
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        RequestUtils requestUtils = new RequestUtils();
        requestUtils.preRequestAddParameter("senderObj", "FileGetter");
        requestUtils.preRequestAddParameter("wfiType", "zen");
        requestUtils.preRequestAddParameter("portalID", this.portalID);
        requestUtils.preRequestAddParameter("userID", this.userID);
        addRenameFileParameters(requestUtils);
        requestUtils.createPostRequest();
        httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + requestUtils.getBoundary());
        httpURLConnection.setRequestMethod("POST");
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setDoInput(true);
        try {
            httpURLConnection.connect();
            OutputStream out = httpURLConnection.getOutputStream();
            byte[] preBytes = requestUtils.getPreRequestStringBytes();
            out.write(preBytes);
            out.flush();
            byte[] postBytes = requestUtils.getPostRequestStringBytes();
            out.write(postBytes);
            out.flush();
            out.close();
            respCode = httpURLConnection.getResponseCode();
            if (HttpURLConnection.HTTP_OK == respCode) {
                resp = true;
                InputStream in = httpURLConnection.getInputStream();
                ZipUtils.getInstance().getFilesFromStream(in, getFilesDir);
                in.close();
            }
            if (respCode == 500) {
                resp = false;
            }
            if (respCode == 560) {
                resp = false;
                throw new Exception("Server Side Remote Exeption !!! respCode = (" + respCode + ")");
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("Cannot connect to: " + storageUrlString, e);
        }
        return resp;
    }
public static void copyFile(File inputFile, File outputFile) throws IOException {
        FileChannel srcChannel = new FileInputStream(inputFile).getChannel();
        FileChannel dstChannel = new FileOutputStream(outputFile).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
public void testReadPerMemberAllFour() throws IOException {
        GZIPMembersInputStream gzin = new GZIPMembersInputStream(new ByteArrayInputStream(allfour_gz));
        gzin.setEofEachMember(true);
        int count0 = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong 1k member count", 1024, count0);
        assertEquals("wrong member number", 0, gzin.getMemberNumber());
        assertEquals("wrong member0 start", 0, gzin.getCurrentMemberStart());
        assertEquals("wrong member0 end", noise1k_gz.length, gzin.getCurrentMemberEnd());
        gzin.nextMember();
        int count1 = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong 32k member count", (32 * 1024), count1);
        assertEquals("wrong member number", 1, gzin.getMemberNumber());
        assertEquals("wrong member1 start", noise1k_gz.length, gzin.getCurrentMemberStart());
        assertEquals("wrong member1 end", noise1k_gz.length + noise32k_gz.length, gzin.getCurrentMemberEnd());
        gzin.nextMember();
        int count2 = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong 1-byte member count", 1, count2);
        assertEquals("wrong member number", 2, gzin.getMemberNumber());
        assertEquals("wrong member2 start", noise1k_gz.length + noise32k_gz.length, gzin.getCurrentMemberStart());
        assertEquals("wrong member2 end", noise1k_gz.length + noise32k_gz.length + a_gz.length, gzin.getCurrentMemberEnd());
        gzin.nextMember();
        int count3 = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong 5-byte member count", 5, count3);
        assertEquals("wrong member number", 3, gzin.getMemberNumber());
        assertEquals("wrong member3 start", noise1k_gz.length + noise32k_gz.length + a_gz.length, gzin.getCurrentMemberStart());
        assertEquals("wrong member3 end", noise1k_gz.length + noise32k_gz.length + a_gz.length + hello_gz.length, gzin.getCurrentMemberEnd());
        gzin.nextMember();
        int countEnd = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong eof count", 0, countEnd);
    }
public void testReadPerMemberSixSmall() throws IOException {
        GZIPMembersInputStream gzin = new GZIPMembersInputStream(new ByteArrayInputStream(sixsmall_gz));
        gzin.setEofEachMember(true);
        for (int i = 0; i < 3; i++) {
            int count2 = IOUtils.copy(gzin, new NullOutputStream());
            assertEquals("wrong 1-byte member count", 1, count2);
            gzin.nextMember();
            int count3 = IOUtils.copy(gzin, new NullOutputStream());
            assertEquals("wrong 5-byte member count", 5, count3);
            gzin.nextMember();
        }
        int countEnd = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong eof count", 0, countEnd);
    }
public void testMemberSeek() throws IOException {
        GZIPMembersInputStream gzin = new GZIPMembersInputStream(new ByteArrayInputStream(allfour_gz));
        gzin.setEofEachMember(true);
        gzin.compressedSeek(noise1k_gz.length + noise32k_gz.length);
        int count2 = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong 1-byte member count", 1, count2);
        assertEquals("wrong Member2 start", noise1k_gz.length + noise32k_gz.length, gzin.getCurrentMemberStart());
        assertEquals("wrong Member2 end", noise1k_gz.length + noise32k_gz.length + a_gz.length, gzin.getCurrentMemberEnd());
        gzin.nextMember();
        int count3 = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong 5-byte member count", 5, count3);
        assertEquals("wrong Member3 start", noise1k_gz.length + noise32k_gz.length + a_gz.length, gzin.getCurrentMemberStart());
        assertEquals("wrong Member3 end", noise1k_gz.length + noise32k_gz.length + a_gz.length + hello_gz.length, gzin.getCurrentMemberEnd());
        gzin.nextMember();
        int countEnd = IOUtils.copy(gzin, new NullOutputStream());
        assertEquals("wrong eof count", 0, countEnd);
    }
@SuppressWarnings("deprecation")
    public void testMemberIterator() throws IOException {
        GZIPMembersInputStream gzin = new GZIPMembersInputStream(new ByteArrayInputStream(allfour_gz));
        Iterator<GZIPMembersInputStream> iter = gzin.memberIterator();
        assertTrue(iter.hasNext());
        GZIPMembersInputStream gzMember0 = iter.next();
        int count0 = IOUtils.copy(gzMember0, new NullOutputStream());
        assertEquals("wrong 1k member count", 1024, count0);
        assertEquals("wrong member number", 0, gzin.getMemberNumber());
        assertEquals("wrong member0 start", 0, gzin.getCurrentMemberStart());
        assertEquals("wrong member0 end", noise1k_gz.length, gzin.getCurrentMemberEnd());
        assertTrue(iter.hasNext());
        GZIPMembersInputStream gzMember1 = iter.next();
        int count1 = IOUtils.copy(gzMember1, new NullOutputStream());
        assertEquals("wrong 32k member count", (32 * 1024), count1);
        assertEquals("wrong member number", 1, gzin.getMemberNumber());
        assertEquals("wrong member1 start", noise1k_gz.length, gzin.getCurrentMemberStart());
        assertEquals("wrong member1 end", noise1k_gz.length + noise32k_gz.length, gzin.getCurrentMemberEnd());
        assertTrue(iter.hasNext());
        GZIPMembersInputStream gzMember2 = iter.next();
        int count2 = IOUtils.copy(gzMember2, new NullOutputStream());
        assertEquals("wrong 1-byte member count", 1, count2);
        assertEquals("wrong member number", 2, gzin.getMemberNumber());
        assertEquals("wrong member2 start", noise1k_gz.length + noise32k_gz.length, gzin.getCurrentMemberStart());
        assertEquals("wrong member2 end", noise1k_gz.length + noise32k_gz.length + a_gz.length, gzin.getCurrentMemberEnd());
        assertTrue(iter.hasNext());
        GZIPMembersInputStream gzMember3 = iter.next();
        int count3 = IOUtils.copy(gzMember3, new NullOutputStream());
        assertEquals("wrong 5-byte member count", 5, count3);
        assertEquals("wrong member number", 3, gzin.getMemberNumber());
        assertEquals("wrong member3 start", noise1k_gz.length + noise32k_gz.length + a_gz.length, gzin.getCurrentMemberStart());
        assertEquals("wrong member3 end", noise1k_gz.length + noise32k_gz.length + a_gz.length + hello_gz.length, gzin.getCurrentMemberEnd());
        assertFalse(iter.hasNext());
    }