semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public SearchHandler(String criteria, int langId) {
        try {
            URL url = new URL("http://eiffel.itba.edu.ar/hci/service/Catalog.groovy?method=GetProductListByName&criteria=" + criteria + "&language_id=" + langId);
            URLConnection urlc = url.openConnection();
            urlc.setDoOutput(false);
            urlc.setAllowUserInteraction(false);
            BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
            String str;
            StringBuffer sb = new StringBuffer();
            while ((str = br.readLine()) != null) {
                sb.append(str);
                sb.append("\n");
            }
            br.close();
            String response = sb.toString();
            if (response == null) {
                return;
            }
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(response));
            Document dom = db.parse(is);
            NodeList nl = dom.getElementsByTagName("product");
            for (int i = 0; i < nl.getLength(); i++) {
                Element nodes = (Element) nl.item(i);
                String id = nodes.getAttribute("id").toString();
                NodeList name = nodes.getElementsByTagName("name");
                NodeList rank2 = nodes.getElementsByTagName("sales_rank");
                NodeList price = nodes.getElementsByTagName("price");
                NodeList url2 = nodes.getElementsByTagName("image_url");
                String nameS = getCharacterDataFromElement((Element) name.item(0));
                String rank2S = getCharacterDataFromElement((Element) rank2.item(0));
                String priceS = getCharacterDataFromElement((Element) price.item(0));
                String url2S = getCharacterDataFromElement((Element) url2.item(0));
                list.add(new ProductShort(id, nameS, rank2S, priceS, url2S));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public void testReaderWriterUC2() throws Exception {
        String inFile = "test_data/mri.png";
        String outFile = "test_output/mri__smooth_testReaderWriter.png";
        itkImageFileReaderUC2_Pointer reader = itkImageFileReaderUC2.itkImageFileReaderUC2_New();
        itkImageFileWriterUC2_Pointer writer = itkImageFileWriterUC2.itkImageFileWriterUC2_New();
        reader.SetFileName(inFile);
        writer.SetFileName(outFile);
        writer.SetInput(reader.GetOutput());
        writer.Update();
    }
public void testReaderWriterF2() throws Exception {
        String inFile = "test_data/mri.png";
        String outFile = "test_output/mri__smooth_testReaderWriter.mhd";
        itkImageFileReaderF2_Pointer reader = itkImageFileReaderF2.itkImageFileReaderF2_New();
        itkImageFileWriterF2_Pointer writer = itkImageFileWriterF2.itkImageFileWriterF2_New();
        reader.SetFileName(inFile);
        writer.SetFileName(outFile);
        writer.SetInput(reader.GetOutput());
        writer.Update();
    }
public void test_openStream() throws Exception {
        URL BASE = URLTest.class.getClassLoader().getResource(URLTest.class.getPackage().getName().replace('.', File.separatorChar) + "/lf.jar");
        URL url = new URL("jar:" + BASE + "!/foo.jar!/Bugs/HelloWorld.class");
        try {
            url.openStream();
            fail("should throw FNFE.");
        } catch (java.io.FileNotFoundException e) {
        }
        File resources = Support_Resources.createTempFolder();
        Support_Resources.copyFile(resources, null, "hyts_htmltest.html");
        u = new URL("file", "", resources.getAbsolutePath() + "/hyts_htmltest.html");
        InputStream is1 = u.openStream();
        assertTrue("Unable to read from stream", is1.read() != 0);
        is1.close();
        boolean exception = false;
        try {
            u = new URL("file:///nonexistenttestdir/tstfile");
            u.openStream();
        } catch (IOException e) {
            exception = true;
        }
        assertTrue("openStream succeeded for non existent resource", exception);
        int port = Support_Jetty.startHttpServerWithDocRoot("resources/org/apache/harmony/luni/tests/java/net/");
        URL u = new URL("jar:" + "http://localhost:" + port + "/lf.jar!/plus.bmp");
        InputStream in = u.openStream();
        byte[] buf = new byte[3];
        int result = in.read(buf);
        assertTrue("Incompete read: " + result, result == 3);
        in.close();
        assertTrue("Returned incorrect data", buf[0] == 0x42 && buf[1] == 0x4d && buf[2] == (byte) 0xbe);
        File test = new File("hytest.$$$");
        FileOutputStream out = new FileOutputStream(test);
        out.write(new byte[] { 0x55, (byte) 0xaa, 0x14 });
        out.close();
        u = new URL("file:" + test.getName());
        in = u.openStream();
        buf = new byte[3];
        result = in.read(buf);
        in.close();
        test.delete();
        assertEquals("Incompete read 3", 3, result);
        assertTrue("Returned incorrect data 3", buf[0] == 0x55 && buf[1] == (byte) 0xaa && buf[2] == 0x14);
    }
private void copyIntoFile(String resource, File output) throws IOException {
        FileOutputStream out = null;
        InputStream in = null;
        try {
            out = FileUtils.openOutputStream(output);
            in = GroovyInstanceTest.class.getResourceAsStream(resource);
            IOUtils.copy(in, out);
        } finally {
            IOUtils.closeQuietly(out);
            IOUtils.closeQuietly(in);
        }
    }
protected void checkWeavingJar() throws IOException {
        OutputStream out = null;
        try {
            final File weaving = new File(getWeavingPath());
            if (!weaving.exists()) {
                new File(getWeavingFolder()).mkdir();
                weaving.createNewFile();
                final Path src = new Path("weaving/openfrwk-weaving.jar");
                final InputStream in = FileLocator.openStream(getBundle(), src, false);
                out = new FileOutputStream(getWeavingPath(), true);
                IOUtils.copy(in, out);
                Logger.log(Logger.INFO, "Put weaving jar at location " + weaving);
            } else {
                Logger.getLog().info("File openfrwk-weaving.jar already exists at " + weaving);
            }
        } catch (final SecurityException e) {
            Logger.log(Logger.ERROR, "[SECURITY EXCEPTION] Not enough privilegies to create " + "folder and copy NexOpen weaving jar at location " + getWeavingFolder());
            Logger.logException(e);
        } finally {
            if (out != null) {
                out.flush();
                out.close();
            }
        }
    }
public void run() {
            ArrayList<Thread> ftpThreadList = new ArrayList<Thread>();
            class ftpLinkElem extends Thread {

                TreeNode node;

                FTPClient ftp;

                protected ftpLinkElem(TreeNode node, FTPClient ftpC) {
                    super();
                    this.node = node;
                    this.ftp = ftpC;
                }

                public void run() {
                    try {
                        String fileLoc = getFileLocation(node.getURL());
                        FTPFile[] fTest = ftp.listFiles(fileLoc);
                        if (fTest[0].isFile()) {
                            int rsp = ftp.getReplyCode();
                            String msg = ftp.getReplyString();
                            if (!FTPReply.isPositiveCompletion(rsp)) {
                                ftp.disconnect();
                                System.out.print("[FAILED] " + msg);
                                failedList.add(node);
                                failCnt++;
                            }
                            System.out.println("FTP Response: " + msg);
                        } else {
                            System.out.print("[FAILED]");
                            failedList.add(node);
                            failCnt++;
                        }
                    } catch (IOException ie) {
                        ie.printStackTrace();
                    }
                }
            }
            updateCurStatus("Checking ftp links", "");
            for (TreeNode testFtp : ftpURLs) {
                try {
                    FTPClient ftp = new FTPClient();
                    ftp.connect(FTPSERVER);
                    ftp.login(FTPUSER, FTPPW);
                    updateCurStatus(testFtp.getURL(), "");
                    ftpLinkElem fe = new ftpLinkElem(testFtp, ftp);
                    fe.start();
                    ftpThreadList.add(fe);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            for (Thread t : ftpThreadList) {
                try {
                    if (t.isAlive()) {
                        t.join();
                    }
                } catch (InterruptedException ie) {
                    ie.printStackTrace();
                }
            }
        }
public static InputSource getInputSource(URL url) throws IOException {
        String proto = url.getProtocol().toLowerCase();
        if (!("http".equals(proto) || "https".equals(proto))) throw new IllegalArgumentException("OAI-PMH only allows HTTP(S) as network protocol!");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        StringBuilder ua = new StringBuilder("Java/");
        ua.append(System.getProperty("java.version"));
        ua.append(" (");
        ua.append(OAIHarvester.class.getName());
        ua.append(')');
        conn.setRequestProperty("User-Agent", ua.toString());
        conn.setRequestProperty("Accept-Encoding", "gzip, deflate, identity;q=0.3, *;q=0");
        conn.setRequestProperty("Accept-Charset", "utf-8, *;q=0.1");
        conn.setRequestProperty("Accept", "text/xml, application/xml, *;q=0.1");
        conn.setUseCaches(false);
        conn.setFollowRedirects(true);
        log.debug("Opening connection...");
        InputStream in = null;
        try {
            conn.connect();
            in = conn.getInputStream();
        } catch (IOException ioe) {
            int after, code;
            try {
                after = conn.getHeaderFieldInt("Retry-After", -1);
                code = conn.getResponseCode();
            } catch (IOException ioe2) {
                after = -1;
                code = -1;
            }
            if (code == HttpURLConnection.HTTP_UNAVAILABLE && after > 0) throw new RetryAfterIOException(after, ioe);
            throw ioe;
        }
        String encoding = conn.getContentEncoding();
        if (encoding == null) encoding = "identity";
        encoding = encoding.toLowerCase();
        log.debug("HTTP server uses " + encoding + " content encoding.");
        if ("gzip".equals(encoding)) in = new GZIPInputStream(in); else if ("deflate".equals(encoding)) in = new InflaterInputStream(in); else if (!"identity".equals(encoding)) throw new IOException("Server uses an invalid content encoding: " + encoding);
        String contentType = conn.getContentType();
        String charset = null;
        if (contentType != null) {
            contentType = contentType.toLowerCase();
            int charsetStart = contentType.indexOf("charset=");
            if (charsetStart >= 0) {
                int charsetEnd = contentType.indexOf(";", charsetStart);
                if (charsetEnd == -1) charsetEnd = contentType.length();
                charsetStart += "charset=".length();
                charset = contentType.substring(charsetStart, charsetEnd).trim();
            }
        }
        log.debug("Charset from Content-Type: '" + charset + "'");
        InputSource src = new InputSource(in);
        src.setSystemId(url.toString());
        src.setEncoding(charset);
        return src;
    }
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws WsException {
        String callback = para(req, JsonWriter.CALLBACK, null);
        String input = para(req, INPUT, null);
        String type = para(req, TYPE, "url");
        String format = para(req, FORMAT, null);
        PrintWriter out = null;
        Reader contentReader = null;
        try {
            out = resp.getWriter();
            if (StringUtils.trimToNull(input) == null) {
                resp.setContentType("text/html");
                printHelp(out);
            } else {
                if (type.equalsIgnoreCase("url")) {
                    HttpGet httpget = new HttpGet(input);
                    try {
                        HttpResponse response = client.execute(httpget);
                        HttpEntity entity = response.getEntity();
                        if (entity != null) {
                            String charset = "UTF-8";
                            contentReader = new InputStreamReader(entity.getContent(), charset);
                            if (false) {
                                contentReader = new FilterXmlReader(contentReader);
                            } else {
                                contentReader = new BufferedReader(contentReader);
                            }
                        }
                    } catch (RuntimeException ex) {
                        httpget.abort();
                        throw ex;
                    }
                } else {
                    contentReader = new StringReader(input);
                }
                long time = System.currentTimeMillis();
                TokenStream stream = nameTokenStream(contentReader);
                SciNameIterator iter = new SciNameIterator(stream);
                if (format != null && format.equalsIgnoreCase("json")) {
                    resp.setContentType("application/json");
                    streamAsJSON(iter, out, callback);
                } else if (format != null && format.equalsIgnoreCase("xml")) {
                    resp.setContentType("text/xml");
                    streamAsXML(iter, out);
                } else {
                    resp.setContentType("text/plain");
                    streamAsText(iter, out);
                }
                log.info("Indexing finished in " + (System.currentTimeMillis() - time) + " msecs");
            }
        } catch (IOException e1) {
            log.error("IOException", e1);
            e1.printStackTrace();
        } finally {
            if (contentReader != null) {
                try {
                    contentReader.close();
                } catch (IOException e) {
                    log.error("IOException", e);
                }
            }
            out.flush();
            out.close();
        }
    }
public final String latestVersion() {
        String latestVersion = "";
        try {
            URL url = new URL(Constants.officialSite + ":80/LatestVersion");
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                latestVersion = str;
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        return latestVersion;
    }
public static void main(String[] args) throws Exception {
        for (int n = 0; n < 8; n++) {
            new Thread() {

                public void run() {
                    try {
                        URL url = new URL("http://localhost:8080/WebGISTileServer/index.jsp?token_timeout=true");
                        URLConnection uc = url.openConnection();
                        uc.addRequestProperty("Referer", "http://localhost:8080/index.jsp");
                        BufferedReader rd = new BufferedReader(new InputStreamReader(uc.getInputStream()));
                        String line;
                        while ((line = rd.readLine()) != null) System.out.println(line);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }
public void run() {
                    try {
                        URL url = new URL("http://localhost:8080/WebGISTileServer/index.jsp?token_timeout=true");
                        URLConnection uc = url.openConnection();
                        uc.addRequestProperty("Referer", "http://localhost:8080/index.jsp");
                        BufferedReader rd = new BufferedReader(new InputStreamReader(uc.getInputStream()));
                        String line;
                        while ((line = rd.readLine()) != null) System.out.println(line);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
private static void readAndWriteFile(File source, File target) {
        try {
            FileInputStream in = new FileInputStream(source);
            FileOutputStream out = new FileOutputStream(target);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (Exception e) {
        }
    }
public synchronized String encryptPassword(String passwordString) throws Exception {
        MessageDigest digest = null;
        digest = MessageDigest.getInstance("SHA");
        digest.update(passwordString.getBytes("UTF-8"));
        byte raw[] = digest.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
private String encode(String plaintext) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(plaintext.getBytes("UTF-8"));
            byte raw[] = md.digest();
            return (new BASE64Encoder()).encode(raw);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("Error encoding: " + e);
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("Error encoding: " + e);
        }
    }
public void readConfig(String urlString) throws Exception {
        try {
            URL url = new URL(urlString);
            InputStream in = url.openStream();
            XmlDoc xml = new Parser().parse(new InputSource(in), true, true);
            Verifier v = new Verifier(InputOutput.create(SCHEMA), null);
            v.verify(xml.getDocument());
            this.config = xml.getDocument();
        } catch (Exception e) {
            log("Can't read " + urlString + ": " + e.toString());
            throw e;
        }
        initParms();
        log("Got parameters: \n" + paramsInfo());
        initMessages();
        log("Got messages: \n" + messagesInfo());
        checkMessageId();
    }
private static void userAuth(String challenge) throws IOException {
        try {
            MessageDigest md = MessageDigest.getInstance("BrokenMD4");
            String passwd = null;
            if (System.getProperty("jarsync.password.gui") != null) {
                JPasswordField pass = new JPasswordField();
                JPanel panel = new JPanel(new GridLayout(2, 1));
                panel.add(new JLabel("Password:"));
                panel.add(pass);
                JOptionPane.showMessageDialog(null, panel, remoteUser + '@' + remoteHost + "'s Password", JOptionPane.QUESTION_MESSAGE);
                passwd = new String(pass.getPassword());
            } else {
                System.out.print(remoteUser + '@' + remoteHost + "'s password: ");
                passwd = Util.readLine(System.in);
                System.out.println();
            }
            md.update(new byte[4]);
            md.update(passwd.getBytes("US-ASCII"));
            md.update(challenge.getBytes("US-ASCII"));
            byte[] response = md.digest();
            Util.writeASCII(out, remoteUser + " " + Util.base64(response) + '\n');
            out.flush();
        } catch (NoSuchAlgorithmException nsae) {
            throw new IOException("could not create message digest.");
        }
    }
public void deleteMessageBuffer(String messageBufferName) throws AppFabricException {
        MessageBufferUtil msgBufferUtilObj = new MessageBufferUtil(solutionName, TokenConstants.getSimpleAuthAuthenticationType());
        String requestUri = msgBufferUtilObj.getRequestUri();
        String messageBufferUri = msgBufferUtilObj.getCreateMessageBufferUri(messageBufferName);
        String authorizationToken = "";
        try {
            ACSTokenProvider tp = new ACSTokenProvider(httpWebProxyServer_, httpWebProxyPort_, this.credentials);
            authorizationToken = tp.getACSToken(requestUri, messageBufferUri);
        } catch (Exception e) {
            throw new AppFabricException(e.getMessage());
        }
        try {
            messageBufferUri = messageBufferUri.replaceAll("http", "https");
            URL urlConn = new URL(messageBufferUri);
            HttpURLConnection connection;
            if (httpWebProxy_ != null) connection = (HttpURLConnection) urlConn.openConnection(httpWebProxy_); else connection = (HttpURLConnection) urlConn.openConnection();
            connection.setRequestMethod("DELETE");
            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-type", MessageBufferConstants.getCONTENT_TYPE_PROPERTY_FOR_ATOM_XML());
            String authStr = TokenConstants.getWrapAuthenticationType() + " " + TokenConstants.getWrapAuthorizationHeaderKey() + "=\"" + authorizationToken + "\"";
            connection.setRequestProperty("Authorization", authStr);
            if (LoggerUtil.getIsLoggingOn()) SDKLoggerHelper.logRequest(connection, SDKLoggerHelper.RecordType.DeleteMessageBuffer_REQUEST);
            String responseCode = "<responseCode>" + connection.getResponseCode() + "</responseCode>";
            if ((connection.getResponseCode() == MessageBufferConstants.HTTP_STATUS_CODE_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();
            } else {
                throw new AppFabricException("MessageBuffer could not be deleted.Error...Response code:  " + connection.getResponseCode());
            }
            if (LoggerUtil.getIsLoggingOn()) SDKLoggerHelper.logMessage(URLEncoder.encode(responseCode, "UTF-8"), SDKLoggerHelper.RecordType.DeleteMessageBuffer_RESPONSE);
        } catch (Exception e) {
            throw new AppFabricException(e.getMessage());
        }
    }