semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public Collection<IAuthor> doImport() throws Exception {
        progress.initialize(2, "Ściągam autorów amerykańskich");
        String url = "http://pl.wikipedia.org/wiki/Kategoria:Ameryka%C5%84scy_autorzy_fantastyki";
        UrlResource resource = new UrlResource(url);
        InputStream urlInputStream = resource.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(urlInputStream, writer);
        progress.advance("Parsuję autorów amerykańskich");
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        String httpDoc = writer.toString();
        httpDoc = httpDoc.replaceFirst("(?s)<!DOCTYPE.+?>\\n", "");
        httpDoc = httpDoc.replaceAll("(?s)<script.+?</script>", "");
        httpDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n" + httpDoc;
        ByteArrayInputStream byteInputStream = new ByteArrayInputStream(httpDoc.getBytes("UTF-8"));
        Document doc = builder.parse(byteInputStream);
        ArrayList<String> authorNames = new ArrayList<String>();
        ArrayList<IAuthor> authors = new ArrayList<IAuthor>();
        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();
        NodeList list = (NodeList) xpath.evaluate("//ul/li/div/div/a", doc, XPathConstants.NODESET);
        for (int i = 0; i < list.getLength(); i++) {
            String name = list.item(i).getTextContent();
            if (StringUtils.isNotBlank(name)) {
                authorNames.add(name);
            }
        }
        list = (NodeList) xpath.evaluate("//td/ul/li/a", doc, XPathConstants.NODESET);
        for (int i = 0; i < list.getLength(); i++) {
            String name = list.item(i).getTextContent();
            if (StringUtils.isNotBlank(name)) {
                authorNames.add(name);
            }
        }
        for (String name : authorNames) {
            int idx = name.lastIndexOf(' ');
            String fname = name.substring(0, idx).trim();
            String lname = name.substring(idx + 1).trim();
            authors.add(new Author(fname, lname));
        }
        progress.advance("Wykonano");
        return authors;
    }
static void copy(String src, String dest) throws IOException {
        File ifp = new File(src);
        File ofp = new File(dest);
        if (ifp.exists() == false) {
            throw new IOException("file '" + src + "' does not exist");
        }
        FileInputStream fis = new FileInputStream(ifp);
        FileOutputStream fos = new FileOutputStream(ofp);
        byte[] b = new byte[1024];
        int readBytes;
        while ((readBytes = fis.read(b)) > 0) fos.write(b, 0, readBytes);
        fis.close();
        fos.close();
    }
@Override
    public void run() {
        try {
            status = UploadStatus.INITIALISING;
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet("http://www.filedropper.com");
            httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2 GTBDFff GTB7.0");
            HttpResponse httpresponse = httpclient.execute(httpget);
            httpresponse.getEntity().consumeContent();
            httppost = new HttpPost("http://www.filedropper.com/index.php?xml=true");
            httppost.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2 GTBDFff GTB7.0");
            MultipartEntity requestEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            requestEntity.addPart("file", new MonitoredFileBody(file, uploadProgress));
            requestEntity.addPart("Upload", new StringBody("Submit Query"));
            httppost.setEntity(requestEntity);
            status = UploadStatus.UPLOADING;
            httpresponse = httpclient.execute(httppost);
            String strResponse = EntityUtils.toString(httpresponse.getEntity());
            status = UploadStatus.GETTINGLINK;
            downURL = "http://www.filedropper.com/" + strResponse.substring(strResponse.lastIndexOf("=") + 1);
            NULogger.getLogger().info(downURL);
            uploadFinished();
        } catch (Exception ex) {
            ex.printStackTrace();
            NULogger.getLogger().severe(ex.toString());
            uploadFailed();
        }
    }
public static Image loadImage(String path) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream in = mainFrame.getClass().getResourceAsStream(path);
        if (in == null) throw new RuntimeException("Ressource " + path + " not found");
        try {
            IOUtils.copy(in, out);
            in.close();
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
            new RuntimeException("Error reading ressource " + path, e);
        }
        return Toolkit.getDefaultToolkit().createImage(out.toByteArray());
    }
public static void redirect(String strRequest, PrintWriter sortie) throws Exception {
        String level = "info.";
        if (ConnectorServlet.debug) level = "debug.";
        Log log = LogFactory.getLog(level + "fr.brgm.exows.gml2gsml.GFI");
        URL url2Request = new URL(strRequest);
        URLConnection conn = url2Request.openConnection();
        DataInputStream buffin = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
        String strLine = null;
        while ((strLine = buffin.readLine()) != null) {
            sortie.println(strLine);
        }
        buffin.close();
    }
public static void main(String[] args) {
        String u = "http://portal.acm.org/results.cfm?query=%28Author%3A%22" + "Boehm%2C+Barry" + "%22%29&srt=score%20dsc&short=0&source_disp=&since_month=&since_year=&before_month=&before_year=&coll=ACM&dl=ACM&termshow=matchboolean&range_query=&CFID=22704101&CFTOKEN=37827144&start=1";
        URL url = null;
        AcmSearchresultPageParser_2010May cb = new AcmSearchresultPageParser_2010May();
        try {
            url = new URL(u);
            HttpURLConnection uc = (HttpURLConnection) url.openConnection();
            uc.setUseCaches(false);
            InputStream is = uc.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            ParserDelegator pd = new ParserDelegator();
            pd.parse(br, cb, true);
            br.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("all doc num= " + cb.getAllDocNum());
        for (int i = 0; i < cb.getEachResultStartPositions().size(); i++) {
            HashMap<String, Integer> m = cb.getEachResultStartPositions().get(i);
            System.out.println(i + "pos= " + m);
        }
    }
private void createNodes() {
        try {
            URL url = this.getClass().getResource(this.nodeFileName);
            InputStreamReader inReader = new InputStreamReader(url.openStream());
            BufferedReader inNodes = new BufferedReader(inReader);

            // BufferedReader inNodes = new BufferedReader(new
            // FileReader("NodesFile.txt"));
            String s;
            while ((s = inNodes.readLine()) != null) {
                String label = inNodes.readLine();
                String fullText = inNodes.readLine();
                String type = inNodes.readLine();
                Node n = new Node(s, type);
                n.label = label;
                n.fullText = fullText;
                node.add(n);
            }
            inNodes.close();

            url = this.getClass().getResource(this.edgeFileName);
            inReader = new InputStreamReader(url.openStream());
            BufferedReader inEdges = new BufferedReader(inReader);
            // BufferedReader inEdges = new BufferedReader(new
            // FileReader("EdgesFile.txt"));
            while ((s = inEdges.readLine()) != null)
                edge.add(new Edge(s, inEdges.readLine(), inEdges.readLine(),
                        inEdges.readLine()));
            inEdges.close();
        } catch (FileNotFoundException e) {
            // TODO �Զ���� catch ��
            e.printStackTrace();
        } catch (IOException e) {
            // TODO �Զ���� catch ��
            e.printStackTrace();
        }
        /*
         * for(Myparser.Nd x:FreeConnectTest.pNd){ Node n = new Node(x.id,
         * x.type); n.label = x.label; node.add(n); } for(Myparser.Ed
         * x:FreeConnectTest.pEd) edge.add(new Edge(x.id, x.source.id,
         * x.target.id));
         */
    }
protected void innerProcess(CrawlURI curi) throws InterruptedException {
        if (!curi.isHttpTransaction()) {
            return;
        }
        if (!TextUtils.matches("^text.*$", curi.getContentType())) {
            return;
        }
        long maxsize = DEFAULT_MAX_SIZE_BYTES.longValue();
        try {
            maxsize = ((Long) getAttribute(curi, ATTR_MAX_SIZE_BYTES)).longValue();
        } catch (AttributeNotFoundException e) {
            logger.severe("Missing max-size-bytes attribute when processing " + curi.toString());
        }
        if (maxsize < curi.getContentSize() && maxsize > -1) {
            return;
        }
        String regexpr = "";
        try {
            regexpr = (String) getAttribute(curi, ATTR_STRIP_REG_EXPR);
        } catch (AttributeNotFoundException e2) {
            logger.severe("Missing strip-reg-exp when processing " + curi.toString());
            return;
        }
        ReplayCharSequence cs = null;
        try {
            cs = curi.getHttpRecorder().getReplayCharSequence();
        } catch (Exception e) {
            curi.addLocalizedError(this.getName(), e, "Failed get of replay char sequence " + curi.toString() + " " + e.getMessage());
            logger.warning("Failed get of replay char sequence " + curi.toString() + " " + e.getMessage() + " " + Thread.currentThread().getName());
            return;
        }
        MessageDigest digest = null;
        try {
            try {
                digest = MessageDigest.getInstance(SHA1);
            } catch (NoSuchAlgorithmException e1) {
                e1.printStackTrace();
                return;
            }
            digest.reset();
            String s = null;
            if (regexpr.length() == 0) {
                s = cs.toString();
            } else {
                Matcher m = TextUtils.getMatcher(regexpr, cs);
                s = m.replaceAll(" ");
                TextUtils.recycleMatcher(m);
            }
            digest.update(s.getBytes());
            byte[] newDigestValue = digest.digest();
            if (logger.isLoggable(Level.FINEST)) {
                logger.finest("Recalculated content digest for " + curi.toString() + " old: " + Base32.encode((byte[]) curi.getContentDigest()) + ", new: " + Base32.encode(newDigestValue));
            }
            curi.setContentDigest(SHA1, newDigestValue);
        } finally {
            if (cs != null) {
                try {
                    cs.close();
                } catch (IOException ioe) {
                    logger.warning(TextUtils.exceptionToString("Failed close of ReplayCharSequence.", ioe));
                }
            }
        }
    }
private static String tinyUrl(String url)
	{
		HttpURLConnection httpURLConnection = null;
		OutputStream httpOutputStream = null;
		String responseStr = null;
		try
		{
			URLConnection con = new URL("http://is.gd/api.php?longurl=" + url).openConnection();
			if(con != null)
			{
				httpURLConnection = (HttpURLConnection)con;
			}
			else
			{
				return url;
			}
			httpURLConnection.setRequestMethod("get");
			httpURLConnection.setDoOutput(true);
			httpOutputStream = httpURLConnection.getOutputStream();
	
			BufferedReader httpBufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));   
			responseStr = HttpHelp.readBufferedContent(httpBufferedReader);
	
			if (responseStr != null && responseStr.length() > 0 && responseStr.indexOf("http") != -1)
			{
				return responseStr;
			}
		}
		catch(Exception e)
		{
		}
		finally
		{
			try
			{
				httpOutputStream.close();
				httpURLConnection.disconnect();
			}
			catch(Exception e)
			{
			}
		}
		return url;
	}
static void test() throws SQLException {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        Savepoint sp = null;
        try {
            conn = JdbcUtils.getConnection();
            conn.setAutoCommit(false);
            st = conn.createStatement();
            String sql = "update user set money=money-10 where id=1";
            st.executeUpdate(sql);
            sp = conn.setSavepoint();
            sql = "update user set money=money-10 where id=3";
            st.executeUpdate(sql);
            sql = "select money from user where id=2";
            rs = st.executeQuery(sql);
            float money = 0.0f;
            if (rs.next()) {
                money = rs.getFloat("money");
            }
            if (money > 300) throw new RuntimeException("�Ѿ��������ֵ��");
            sql = "update user set money=money+10 where id=2";
            st.executeUpdate(sql);
            conn.commit();
        } catch (RuntimeException e) {
            if (conn != null && sp != null) {
                conn.rollback(sp);
                conn.commit();
            }
            throw e;
        } catch (SQLException e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            JdbcUtils.free(rs, st, conn);
        }
    }
private StringBuffer encoder(String arg) {
        if (arg == null) {
            arg = "";
        }
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(arg.getBytes(SysConstant.charset));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toHex(md5.digest());
    }
public void run() {
        if (name == null) {
            System.err.println("Must set file name for retrieval");
            return;
        }
        if (handle == null) {
            System.err.println("Must set CCNHandle");
            return;
        }
        if (htmlPane == null) {
            System.err.println("Must set JEditorPane");
            return;
        }
        JFrame frame = new JFrame();
        JFileChooser chooser = new JFileChooser();
        File f = null;
        chooser.setCurrentDirectory(null);
        int returnVal = chooser.showSaveDialog(frame);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            f = chooser.getSelectedFile();
        } else {
            htmlPane.setText("Save File cancelled");
            return;
        }
        boolean overwrite = false;
        try {
            if (f.exists()) {
                htmlPane.setText("Overwriting contents of " + f.getPath());
                overwrite = true;
            } else {
                f.createNewFile();
            }
            if (f.canWrite()) {
            } else {
                htmlPane.setText("The ContentExplorer is unable to write the content to the specified file.");
                return;
            }
        } catch (IOException e) {
            System.err.println("could not create " + f.getPath() + " for saving content to filesystem");
            htmlPane.setText("could not create " + f.getPath() + " for saving content to filesystem");
        }
        try {
            if (!overwrite) htmlPane.setText("saving " + name + " to " + f.getCanonicalPath()); else htmlPane.setText("overwriting contents of " + f.getCanonicalPath() + " to save " + name);
            CCNFileInputStream fis = new CCNFileInputStream(name, handle);
            FileOutputStream output = new FileOutputStream(f);
            byte[] buffer = new byte[readsize];
            int readcount = 0;
            int readtotal = 0;
            while ((readcount = fis.read(buffer)) != -1) {
                readtotal += readcount;
                output.write(buffer, 0, readcount);
                output.flush();
            }
            htmlPane.setText("Saved " + name + " to " + f.getCanonicalPath());
        } catch (Exception e) {
            htmlPane.setText("Could not save " + name + " to " + f.getPath() + " This may be a prefix for an object or just may not be available at this time.");
            System.err.println("Could not retrieve file: " + name);
        }
    }
public HttpResponseMessage execute(HttpMessage request, Map<String, Object> parameters) throws IOException {
        final String method = request.method;
        final String url = request.url.toExternalForm();
        final InputStream body = request.getBody();
        final boolean isDelete = DELETE.equalsIgnoreCase(method);
        final boolean isPost = POST.equalsIgnoreCase(method);
        final boolean isPut = PUT.equalsIgnoreCase(method);
        byte[] excerpt = null;
        HttpMethod httpMethod;
        if (isPost || isPut) {
            EntityEnclosingMethod entityEnclosingMethod = isPost ? new PostMethod(url) : new PutMethod(url);
            if (body != null) {
                ExcerptInputStream e = new ExcerptInputStream(body);
                String length = request.removeHeaders(HttpMessage.CONTENT_LENGTH);
                entityEnclosingMethod.setRequestEntity((length == null) ? new InputStreamRequestEntity(e) : new InputStreamRequestEntity(e, Long.parseLong(length)));
                excerpt = e.getExcerpt();
            }
            httpMethod = entityEnclosingMethod;
        } else if (isDelete) {
            httpMethod = new DeleteMethod(url);
        } else {
            httpMethod = new GetMethod(url);
        }
        for (Map.Entry<String, Object> p : parameters.entrySet()) {
            String name = p.getKey();
            String value = p.getValue().toString();
            if (FOLLOW_REDIRECTS.equals(name)) {
                httpMethod.setFollowRedirects(Boolean.parseBoolean(value));
            } else if (READ_TIMEOUT.equals(name)) {
                httpMethod.getParams().setIntParameter(HttpMethodParams.SO_TIMEOUT, Integer.parseInt(value));
            }
        }
        for (Map.Entry<String, String> header : request.headers) {
            httpMethod.addRequestHeader(header.getKey(), header.getValue());
        }
        HttpClient client = clientPool.getHttpClient(new URL(httpMethod.getURI().toString()));
        client.executeMethod(httpMethod);
        return new HttpMethodResponse(httpMethod, excerpt, request.getContentCharset());
    }
private String transferWSDL(String wsdlURL, String userPassword) throws WiseConnectionException {
        String filePath = null;
        try {
            URL endpoint = new URL(wsdlURL);
            HttpURLConnection conn = (HttpURLConnection) endpoint.openConnection();
            conn.setDoOutput(false);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
            conn.setRequestProperty("Connection", "close");
            if (userPassword != null) {
                conn.setRequestProperty("Authorization", "Basic " + (new BASE64Encoder()).encode(userPassword.getBytes()));
            }
            InputStream is = null;
            if (conn.getResponseCode() == 200) {
                is = conn.getInputStream();
            } else {
                is = conn.getErrorStream();
                InputStreamReader isr = new InputStreamReader(is);
                StringWriter sw = new StringWriter();
                char[] buf = new char[200];
                int read = 0;
                while (read != -1) {
                    read = isr.read(buf);
                    sw.write(buf);
                }
                throw new WiseConnectionException("Remote server's response is an error: " + sw.toString());
            }
            File outputDir = new File(wiseProperties.getProperty("wise.tmpDir"));
            if (!outputDir.exists()) {
                outputDir.mkdir();
                wiseProperties.setProperty("wise.forceImportObject", "true");
            }
            File file = new File(wiseProperties.getProperty("wise.tmpDir"), new StringBuffer("Wise").append(IDGenerator.nextVal()).append(".xml").toString());
            OutputStream fos = new BufferedOutputStream(new FileOutputStream(file));
            IOUtils.copyStream(fos, is);
            fos.close();
            is.close();
            filePath = file.getPath();
        } catch (WiseConnectionException wce) {
            throw wce;
        } catch (Exception e) {
            throw new WiseConnectionException("Wsdl download failed!", e);
        }
        return filePath;
    }
@Override
    protected String determineDataType() {
        final String spec = getSpec();
        if (spec.endsWith("=jpeg")) {
            return "jpeg";
        } else if (mimeType != UNSET) {
            return mimeType;
        } else if (spec != SPEC_UNSET && spec.startsWith("http") && spec.contains("fedora")) {
            if (spec.endsWith("bdef:AssetDef/getFullView/")) {
                return "html";
            } else {
                String type = getProperty(CONTENT_TYPE);
                if (type == null || type.length() < 1) {
                    try {
                        final URL url = (mURL != null ? mURL : new URL(getSpec()));
                        if (DEBUG.Enabled) out("polling actual HTTP server for content-type: " + url);
                        if (!VUE.isApplet()) type = url.openConnection().getHeaderField("Content-type"); else type = null;
                        if (DEBUG.Enabled) {
                            out("got contentType " + url + " [" + type + "]");
                        }
                        if (type != null && type.length() > 0) setProperty(CONTENT_TYPE, type);
                    } catch (Throwable t) {
                        Log.error("content-type-fetch: " + this, t);
                    }
                }
                if (type != null && type.contains("/")) {
                    mimeType = type.split("/")[1];
                    if (mimeType.indexOf(';') > 0) {
                        mimeType = mimeType.substring(0, mimeType.indexOf(';'));
                    }
                    return mimeType;
                }
            }
        }
        return super.determineDataType();
    }
public List tree(String cat, int branch) {
        Pattern p = Pattern.compile("<a href=\"javascript:checkBranch\\(([0-9]+), 'true'\\)\">([^<]*)</a>");
        Matcher m;
        List res = new ArrayList();
        URL url;
        HttpURLConnection conn;
        System.out.println();
        try {
            url = new URL("http://cri-srv-ade.insa-toulouse.fr:8080/ade/standard/gui/tree.jsp?category=trainee&expand=false&forceLoad=false&reload=false&scroll=0");
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setRequestProperty("Cookie", sessionId);
            BufferedReader i = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = i.readLine()) != null) {
                m = p.matcher(line);
                if (m.find()) {
                    trainee.add(new Node(Integer.parseInt(m.group(1)), m.group(2)));
                    System.out.println(m.group(1) + " - " + m.group(2));
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        return res;
    }