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

                            @Override
                            public void run() {
                                if (JOptionPane.showConfirmDialog(null, "New version of G15Lastfm is available to download!", "New Update for G15Lastfm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                                    LOGGER.debug("User choose to update, opening browser.");
                                    Desktop desktop = Desktop.getDesktop();
                                    try {
                                        desktop.browse(new URI("http://code.google.com/p/g15lastfm/"));
                                    } catch (IOException e) {
                                        LOGGER.debug(e);
                                    } catch (URISyntaxException e) {
                                        LOGGER.debug(e);
                                    }
                                } else {
                                    LOGGER.debug("User choose to not update.");
                                }
                            }
                        });
                    }
                } catch (Exception e) {
                    LOGGER.debug(e);
                }
            }
public InputSource resolveEntity(String pPublicId, String pSystemId) throws SAXException, IOException {
        getCisUtils().debug("Resolving entity publicId=" + pPublicId + ", systemId=" + pSystemId);
        final String res;
        if ("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN".equals(pPublicId)) {
            res = "resources/web-app_2_3.dtd";
        } else {
            return null;
        }
        URL url = getClass().getResource(res);
        if (url == null) {
            throw new SAXException("Failed to locate resource: " + res);
        }
        InputSource isource = new InputSource(url.openStream());
        isource.setSystemId(url.toExternalForm());
        return isource;
    }
public static Document validateXml(File messageFile, URL inputUrl, String[] catalogs) throws IOException, ParserConfigurationException, Exception, SAXException, FileNotFoundException {
        InputSource source = new InputSource(inputUrl.openStream());
        Document logDoc = DomUtil.getNewDom();
        XMLReader reader = SaxUtil.getXMLFormatLoggingXMLReader(log, logDoc, true, catalogs);
        reader.parse(source);
        InputStream logStream = DomUtil.serializeToInputStream(logDoc, "utf-8");
        System.out.println("Creating message file \"" + messageFile.getAbsolutePath() + "\"...");
        OutputStream fos = new FileOutputStream(messageFile);
        IOUtils.copy(logStream, fos);
        return logDoc;
    }
public static void saveZipComponents(ZipComponents zipComponents, File zipFile) throws FileNotFoundException, IOException, Exception {
        ZipOutputStream zipOutStream = new ZipOutputStream(new FileOutputStream(zipFile));
        for (ZipComponent comp : zipComponents.getComponents()) {
            ZipEntry newEntry = new ZipEntry(comp.getName());
            zipOutStream.putNextEntry(newEntry);
            if (comp.isDirectory()) {
            } else {
                if (comp.getName().endsWith("document.xml") || comp.getName().endsWith("document.xml.rels")) {
                }
                InputStream inputStream = comp.getInputStream();
                IOUtils.copy(inputStream, zipOutStream);
                inputStream.close();
            }
        }
        zipOutStream.close();
    }
private static URL downloadFile(URL url, File destFile) throws Exception {
        try {
            URLConnection urlConnection = url.openConnection();
            File tmpFile = null;
            try {
                tmpFile = File.createTempFile("remoteLib_", null);
                InputStream in = null;
                FileOutputStream out = null;
                try {
                    in = urlConnection.getInputStream();
                    out = new FileOutputStream(tmpFile);
                    IOUtils.copy(in, out);
                } finally {
                    if (out != null) {
                        out.close();
                    }
                    if (in != null) {
                        in.close();
                    }
                }
                FileUtils.copyFile(tmpFile, destFile);
            } finally {
                if (tmpFile != null) {
                    tmpFile.delete();
                }
            }
            URL localURL = destFile.toURI().toURL();
            return localURL;
        } catch (Exception ex) {
            throw new RuntimeException("Could not download URL: " + url, ex);
        }
    }
private static URL downLoadZippedFile(URL url, File destDir) throws Exception {
        URLConnection urlConnection = url.openConnection();
        File tmpFile = null;
        try {
            tmpFile = File.createTempFile("remoteLib_", null);
            InputStream in = null;
            FileOutputStream out = null;
            try {
                in = urlConnection.getInputStream();
                out = new FileOutputStream(tmpFile);
                IOUtils.copy(in, out);
            } finally {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            }
            unzip(tmpFile, destDir);
        } finally {
            if (tmpFile != null) {
                tmpFile.delete();
            }
        }
        URL localURL = destDir.toURI().toURL();
        return localURL;
    }
@Deprecated
    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
        XUIResponseWriter w = getResponseWriter();
        XUIViewRoot viewRoot = (XUIViewRoot) component;
        XUIResponseWriter headerW = getResponseWriter().getHeaderWriter();
        headerW.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE foo [\n");
        InputStream is1 = Thread.currentThread().getContextClassLoader().getResourceAsStream("xhtml-lat1.ent");
        headerW.write(new String(IOUtils.copyByte(is1)));
        headerW.write("\n");
        is1.close();
        InputStream is2 = Thread.currentThread().getContextClassLoader().getResourceAsStream("xhtml-special.ent");
        headerW.write(new String(IOUtils.copyByte(is2)));
        headerW.write("\n");
        is2.close();
        InputStream is3 = Thread.currentThread().getContextClassLoader().getResourceAsStream("xhtml-symbol.ent");
        headerW.write(new String(IOUtils.copyByte(is3)));
        headerW.write("\n]>\n");
        is3.close();
        headerW.startElement("html", component);
        XUITheme t = getTheme();
        if (t != null) {
            headerW.writeAttribute("style", getTheme().getHtmlStyle(), "style");
        }
        headerW.startElement("head", component);
        headerW.startElement("base", component);
        HttpServletRequest req = (HttpServletRequest) getRequestContext().getRequest();
        String link = (req.isSecure() ? "https" : "http") + "://" + req.getServerName() + (req.getServerPort() == 80 ? "" : ":" + req.getServerPort()) + getRequestContext().getResourceUrl("");
        headerW.writeAttribute("href", link, "href");
        headerW.endElement("base");
        w.startElement("body", component);
        if (t != null && t.getBodyStyle() != null) {
            w.writeAttribute("style", getTheme().getBodyStyle() + ";height:100%;width:100%", "style");
        }
        headerW.writeText('\n');
        w.startElement("div", component);
        w.writeAttribute("id", ((XUIViewRoot) component).getClientId(), "id");
        if (viewRoot.findComponent(Window.class) != null) {
            w.writeAttribute(HTMLAttr.CLASS, "x-panel", "");
        }
        w.writeAttribute("style", "width:100%;height:100%", null);
        if (t != null) {
            t.addScripts(w.getScriptContext());
            t.addStyle(w.getStyleContext());
        }
    }
public InputPort getInputPort(String file) throws IOException {
        if (file.equals("/dev/null")) {
            return new StreamInputPort(new NullInputStream(), file);
        }
        URL url = Util.tryURL(file);
        if (url != null) {
            return new StreamInputPort(url.openStream(), url.toExternalForm());
        } else return new FileInputPort(getFile(file));
    }
public void shouldBeAbleToDownloadAndUpload() throws IOException {
        OutputStream outputStream = fileSystem.createOutputStream(_("hello"), OutputMode.OVERWRITE);
        outputStream.write(new byte[] { 1, 2, 3 });
        outputStream.close();
        InputStream inputStream = fileSystem.createInputStream(_("hello"));
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        IOUtils.copy(inputStream, buffer);
        inputStream.close();
        assertThat().array(buffer.toByteArray()).isEqualTo(new byte[] { 1, 2, 3 });
    }
public void shouldAllowClosingInputStreamTwice() throws IOException {
        OutputStream outputStream = fileSystem.createOutputStream(_("hello"), OutputMode.OVERWRITE);
        outputStream.write(new byte[] { 1, 2, 3 });
        outputStream.close();
        InputStream inputStream = fileSystem.createInputStream(_("hello"));
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        IOUtils.copy(inputStream, buffer);
        inputStream.close();
        inputStream.close();
    }
public String parseInOneLine() throws Exception {
        BufferedReader br = null;
        InputStream httpStream = null;
        if (url.startsWith("http")) {
            URL fileURL = new URL(url);
            URLConnection urlConnection = fileURL.openConnection();
            httpStream = urlConnection.getInputStream();
            br = new BufferedReader(new InputStreamReader(httpStream, "ISO-8859-1"));
        } else {
            br = new BufferedReader(new FileReader(url));
        }
        StringBuffer sb = new StringBuffer();
        StringBuffer sbAllDoc = new StringBuffer();
        String ligne = null;
        boolean get = false;
        while ((ligne = br.readLine()) != null) {
            log.debug(ligne);
            sbAllDoc.append(ligne + " ");
            if (ligne.indexOf("<table") != -1) {
                get = true;
            }
            if (get) {
                sb.append(ligne + " ");
            }
            if (ligne.indexOf("</table") != -1 || ligne.indexOf("</tr></font><center><a href='affichaire.php") != -1 || ligne.indexOf("</font><center><a href='afficheregion.php") != -1) {
                get = false;
                break;
            }
        }
        oneLine = sb.toString();
        allDocInOneLine = sbAllDoc.toString();
        if (oneLine.indexOf("</table") != -1) {
            tableTab = new TableTag(oneLine.substring(oneLine.indexOf(">") + 1, oneLine.indexOf("</table")));
        } else if (oneLine.indexOf("</font><center><a href='affichaire") != -1) {
            tableTab = new TableTag(oneLine.substring(oneLine.indexOf(">") + 1, oneLine.indexOf("</font><center><a href='affichaire")));
        } else if (oneLine.indexOf("</font><center><a href='afficheregion.php") != -1) {
            tableTab = new TableTag(oneLine.substring(oneLine.indexOf(">") + 1, oneLine.indexOf("</font><center><a href='afficheregion.php")));
        } else {
            log.error("La fin du fichier HTML n'a pas ete trouvee, ca va merder...");
        }
        br.close();
        if (httpStream != null) {
            httpStream.close();
        }
        return allDocInOneLine;
    }
static void copyFile(File in, File out) throws IOException {
        FileChannel source = new FileInputStream(in).getChannel();
        FileChannel destination = new FileOutputStream(out).getChannel();
        source.transferTo(0, source.size(), destination);
        source.close();
        destination.close();
    }
private static InputStream openFileOrURL(String url) throws IOException {
        if (url.startsWith("resource:")) {
            return DcmRcv.class.getClassLoader().getResourceAsStream(url.substring(9));
        }
        try {
            return new URL(url).openStream();
        } catch (MalformedURLException e) {
            return new FileInputStream(url);
        }
    }
private int addPollToDB(DataSource database) {
        int pollid = -2;
        Connection con = null;
        try {
            con = database.getConnection();
            con.setAutoCommit(false);
            String add = "insert into polls" + " values( ?, ?, ?, ?)";
            PreparedStatement prepStatement = con.prepareStatement(add);
            prepStatement.setString(1, selectedCourse.getAdmin());
            prepStatement.setString(2, selectedCourse.getCourseId());
            prepStatement.setString(3, getTitle());
            prepStatement.setInt(4, 0);
            prepStatement.executeUpdate();
            String findNewID = "select max(pollid) from polls";
            prepStatement = con.prepareStatement(findNewID);
            ResultSet newID = prepStatement.executeQuery();
            pollid = -2;
            while (newID.next()) {
                pollid = newID.getInt(1);
            }
            if (pollid == -2) {
                this.sqlError = true;
                throw new Exception();
            }
            String[] options = getAllOptions();
            for (int i = 0; i < 4; i++) {
                String insertOption = "insert into polloptions values ( ?, ?, ? )";
                prepStatement = con.prepareStatement(insertOption);
                prepStatement.setString(1, options[i]);
                prepStatement.setInt(2, 0);
                prepStatement.setInt(3, pollid);
                prepStatement.executeUpdate();
            }
            prepStatement.close();
            con.commit();
        } catch (Exception e) {
            sqlError = true;
            e.printStackTrace();
            if (con != null) try {
                con.rollback();
            } catch (Exception logOrIgnore) {
            }
            try {
                throw e;
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        } finally {
            if (con != null) try {
                con.close();
            } catch (Exception logOrIgnore) {
            }
        }
        return pollid;
    }
public void login() {
        loginsuccessful = false;
        try {
            cookies = new StringBuilder();
            HttpParams params = new BasicHttpParams();
            params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
            DefaultHttpClient httpclient = new DefaultHttpClient(params);
            NULogger.getLogger().info("Trying to log in to crocko.com");
            HttpPost httppost = new HttpPost("https://www.crocko.com/accounts/login");
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            formparams.add(new BasicNameValuePair("login", getUsername()));
            formparams.add(new BasicNameValuePair("password", getPassword()));
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
            httppost.setEntity(entity);
            HttpResponse httpresponse = httpclient.execute(httppost);
            NULogger.getLogger().info("Getting cookies........");
            NULogger.getLogger().info(EntityUtils.toString(httpresponse.getEntity()));
            Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
            Cookie escookie = null;
            while (it.hasNext()) {
                escookie = it.next();
                cookies.append(escookie.getName()).append("=").append(escookie.getValue()).append(";");
                if (escookie.getName().equals("PHPSESSID")) {
                    sessionid = escookie.getValue();
                    NULogger.getLogger().info(sessionid);
                }
            }
            if (cookies.toString().contains("logacc")) {
                NULogger.getLogger().info(cookies.toString());
                loginsuccessful = true;
                username = getUsername();
                password = getPassword();
                NULogger.getLogger().info("Crocko login successful :)");
            }
            if (!loginsuccessful) {
                NULogger.getLogger().info("Crocko.com Login failed :(");
                loginsuccessful = false;
                username = "";
                password = "";
                JOptionPane.showMessageDialog(NeembuuUploader.getInstance(), "<html><b>" + HOSTNAME + "</b> " + TranslationProvider.get("neembuuuploader.accounts.loginerror") + "</html>", HOSTNAME, JOptionPane.WARNING_MESSAGE);
                AccountsManager.getInstance().setVisible(true);
            }
            httpclient.getConnectionManager().shutdown();
        } catch (Exception e) {
            NULogger.getLogger().log(Level.SEVERE, "{0}: {1}", new Object[] { getClass().getName(), e.toString() });
            System.err.println(e);
        }
    }
public static void copy(File src, File dst) {
        try {
            InputStream is = null;
            OutputStream os = null;
            try {
                is = new BufferedInputStream(new FileInputStream(src), BUFFER_SIZE);
                os = new BufferedOutputStream(new FileOutputStream(dst), BUFFER_SIZE);
                byte[] buffer = new byte[BUFFER_SIZE];
                int len = 0;
                while ((len = is.read(buffer)) > 0) os.write(buffer, 0, len);
            } finally {
                if (null != is) is.close();
                if (null != os) os.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static boolean cpy(File a, File b) {
        try {
            FileInputStream astream = null;
            FileOutputStream bstream = null;
            try {
                astream = new FileInputStream(a);
                bstream = new FileOutputStream(b);
                long flength = a.length();
                int bufsize = (int) Math.min(flength, 1024);
                byte buf[] = new byte[bufsize];
                long n = 0;
                while (n < flength) {
                    int naread = astream.read(buf);
                    bstream.write(buf, 0, naread);
                    n += naread;
                }
            } finally {
                if (astream != null) astream.close();
                if (bstream != null) bstream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
private void parseExternalCss(Document d) throws XPathExpressionException, IOException {
        InputStream is = null;
        try {
            XPath xp = xpf.newXPath();
            XPathExpression xpe = xp.compile("//link[@type='text/css']/@href");
            NodeList nl = (NodeList) xpe.evaluate(d, XPathConstants.NODESET);
            for (int i = 0; i < nl.getLength(); i++) {
                Attr a = (Attr) nl.item(i);
                String url = a.getValue();
                URL u = new URL(url);
                is = new BufferedInputStream(u.openStream());
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(is, baos);
                parser.add(new String(baos.toByteArray(), "UTF-8"));
                Element linkNode = a.getOwnerElement();
                Element parent = (Element) linkNode.getParentNode();
                parent.removeChild(linkNode);
                IOUtils.closeQuietly(is);
                is = null;
            }
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
public void test() throws Exception {
        StorageString s = new StorageString("UTF-8");
        s.addText("Test");
        try {
            s.getOutputStream();
            fail("Should throw IOException as method not supported.");
        } catch (IOException e) {
        }
        try {
            s.getWriter();
            fail("Should throw IOException as method not supported.");
        } catch (IOException e) {
        }
        s.addText("ing is important");
        s.close(ResponseStateOk.getInstance());
        assertEquals("Testing is important", s.getText());
        InputStream input = s.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(input, writer, "UTF-8");
        assertEquals("Testing is important", writer.toString());
    }
public List<PathObject> fetchPath(BoardObject board) throws NetworkException {
        if (boardPathMap.containsKey(board.getId())) {
            return boardPathMap.get(board.getId()).getChildren();
        }
        HttpClient client = HttpConfig.newInstance();
        HttpGet get = new HttpGet(HttpConfig.bbsURL() + HttpConfig.BBS_0AN_BOARD + board.getId());
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            Document doc = XmlOperator.readDocument(entity.getContent());
            PathObject parent = new PathObject();
            BBSBodyParseHelper.parsePathList(doc, parent);
            parent = searchAndCreatePathFromRoot(parent);
            boardPathMap.put(board.getId(), parent);
            return parent.getChildren();
        } catch (Exception e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public List<PathObject> fetchPath(PathObject parent) throws NetworkException {
        if (parent.isFetched()) {
            return parent.getChildren();
        } else if (!"d".equals(parent.getType())) {
            return null;
        }
        HttpClient client = HttpConfig.newInstance();
        HttpGet get = new HttpGet(HttpConfig.bbsURL() + HttpConfig.BBS_0AN + parent.getPath());
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            Document doc = XmlOperator.readDocument(entity.getContent());
            BBSBodyParseHelper.parsePathList(doc, parent);
            return parent.getChildren();
        } catch (Exception e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }