semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Test
    public void GetBingSearchResult() throws UnsupportedEncodingException {
        String query = "Scanner Java example";
        String request = "http://api.bing.net/xml.aspx?AppId=731DD1E61BE6DE4601A3008DC7A0EB379149EC29" + "&Version=2.2&Market=en-US&Query=" + URLEncoder.encode(query, "UTF-8") + "&Sources=web+spell&Web.Count=50";
        try {
            URL url = new URL(request);
            System.out.println("Host : " + url.getHost());
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            String finalContents = "";
            while ((inputLine = reader.readLine()) != null) {
                finalContents += "\n" + inputLine;
            }
            Document doc = Jsoup.parse(finalContents);
            Elements eles = doc.getElementsByTag("web:Url");
            for (Element ele : eles) {
                System.out.println(ele.text());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public void fetchPublicContent(int id) throws IOException {
        String fileName = FILE_NAME_PREFIX + id + ".xml";
        File file = new File(fileName);
        if (file.exists()) {
            System.out.println("user: " + id + " not fetched because it already exists");
            return;
        }
        OutputStream out = new FileOutputStream(file, false);
        URL url = new URL("http://twitter.com/statuses/followers.xml?id=" + id);
        URLConnection conn = url.openConnection();
        InputStream in = conn.getInputStream();
        int i = 0;
        while ((i = in.read()) != -1) {
            out.write(i);
        }
        in.close();
        out.close();
    }
public String readFile(String filename) throws IOException {
        FTPClient ftpClient = new FTPClient();
        ftpClient.connect(server, port);
        ftpClient.login(USERNAME, PASSWORD);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        boolean success = ftpClient.retrieveFile(filename, outputStream);
        ftpClient.disconnect();
        if (!success) {
            throw new IOException("Retrieve file failed: " + filename);
        }
        return outputStream.toString();
    }
public static void main(String[] args) {
        String logConfiguration = args[2];
        DOMConfigurator.configure(logConfiguration);
        String urlToRun = args[0];
        String outputFile = args[1];
        InputStream conInput = null;
        BufferedReader reader = null;
        BufferedWriter writer = null;
        if (logger.isDebugEnabled()) {
            logger.debug("output file is " + outputFile);
        }
        try {
            URL url = new URL(urlToRun);
            URLConnection urlCon = url.openConnection();
            urlCon.connect();
            conInput = urlCon.getInputStream();
            reader = new BufferedReader(new InputStreamReader(conInput));
            File output = new File(outputFile);
            writer = new BufferedWriter(new FileWriter(output));
            String line = null;
            while ((line = reader.readLine()) != null) {
                logger.debug(line);
                writer.write(line);
            }
            writer.flush();
        } catch (MalformedURLException murle) {
            logger.error(urlToRun + " is not a valid URL", murle);
        } catch (IOException ioe) {
            logger.error("IO Error ocured while opening connection to " + urlToRun, ioe);
        } finally {
            try {
                reader.close();
                conInput.close();
                writer.close();
            } catch (IOException ioe) {
                throw new RuntimeException("Cannot close readers or streams", ioe);
            }
        }
    }
private String convert(InputStream input, String encoding) throws Exception {
        Process p = Runtime.getRuntime().exec("tidy -q -f /dev/null -wrap 0 --output-xml yes --doctype omit --force-output true --new-empty-tags  " + emptyTags + " --quote-nbsp no -utf8");
        Thread t = new CopyThread(input, p.getOutputStream());
        t.start();
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        IOUtils.copy(p.getInputStream(), output);
        p.waitFor();
        t.join();
        return output.toString();
    }
private boolean authenticate(Module module) throws Exception {
        SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
        rand.setSeed(System.currentTimeMillis());
        byte[] challenge = new byte[16];
        rand.nextBytes(challenge);
        String b64 = Util.base64(challenge);
        Util.writeASCII(out, RSYNCD_AUTHREQD + b64 + "\n");
        String reply = Util.readLine(in);
        if (reply.indexOf(" ") < 0) {
            Util.writeASCII(out, AT_ERROR + ": bad response\n");
            if (remoteVersion < 25) Util.writeASCII(out, RSYNCD_EXIT + "\n");
            socket.close();
            throw new IOException("bad response");
        }
        String user = reply.substring(0, reply.indexOf(" "));
        String response = reply.substring(reply.indexOf(" ") + 1);
        if (!module.users.contains(user)) {
            Util.writeASCII(out, AT_ERROR + ": user " + user + " not allowed\n");
            if (remoteVersion < 25) Util.writeASCII(out, RSYNCD_EXIT + "\n");
            socket.close();
            throw new IOException("user " + user + " not allowed");
        }
        LineNumberReader secrets = new LineNumberReader(new FileReader(module.secretsFile));
        MessageDigest md4 = MessageDigest.getInstance("BrokenMD4");
        String line;
        while ((line = secrets.readLine()) != null) {
            if (line.startsWith(user + ":")) {
                String passwd = line.substring(line.lastIndexOf(":") + 1);
                md4.update(new byte[4]);
                md4.update(passwd.getBytes("US-ASCII"));
                md4.update(b64.getBytes("US-ASCII"));
                String hash = Util.base64(md4.digest());
                if (hash.equals(response)) {
                    secrets.close();
                    return true;
                } else {
                    Util.writeASCII(out, AT_ERROR + ": auth failed on module " + module.name + "\n");
                    if (remoteVersion < 25) Util.writeASCII(out, RSYNCD_EXIT + "\n");
                    socket.close();
                    secrets.close();
                    logger.error("auth failed on module " + module.name);
                    return false;
                }
            }
        }
        Util.writeASCII(out, AT_ERROR + ": auth failed on module " + module.name + "\n");
        if (remoteVersion < 25) Util.writeASCII(out, RSYNCD_EXIT + "\n");
        socket.close();
        secrets.close();
        logger.error("auth failed on module " + module.name);
        return false;
    }
public static boolean copyFile(File soureFile, File destFile) {
        boolean copySuccess = false;
        if (soureFile != null && destFile != null && soureFile.exists()) {
            try {
                new File(destFile.getParent()).mkdirs();
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destFile));
                BufferedInputStream in = new BufferedInputStream(new FileInputStream(soureFile));
                for (int currentByte = in.read(); currentByte != -1; currentByte = in.read()) out.write(currentByte);
                in.close();
                out.close();
                copySuccess = true;
            } catch (Exception e) {
                copySuccess = false;
            }
        }
        return copySuccess;
    }
public static void toZip(File zippedFile, File[] filesToZip, String zipComment, boolean savePath, int compressionLevel) throws IOException, FileNotFoundException, ZipException {
        if (zippedFile != null && filesToZip != null) {
            new File(zippedFile.getParent()).mkdirs();
            ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new CheckedOutputStream(new FileOutputStream(zippedFile), new CRC32())));
            if (ZIP_NO_COMPRESSION <= compressionLevel && compressionLevel <= ZIP_MAX_COMPRESSION) out.setLevel(compressionLevel); else out.setLevel(ZIP_MAX_COMPRESSION);
            if (zipComment != null) out.setComment(zipComment);
            for (int i = 0; i < filesToZip.length; i++) {
                BufferedInputStream in;
                if (savePath) {
                    in = new BufferedInputStream(new FileInputStream(filesToZip[i]));
                    out.putNextEntry(new ZipEntry(cleanPath(filesToZip[i].getAbsolutePath())));
                } else {
                    in = new BufferedInputStream(new FileInputStream(filesToZip[i]));
                    out.putNextEntry(new ZipEntry(filesToZip[i].getName()));
                }
                for (int c = in.read(); c != -1; c = in.read()) out.write(c);
                in.close();
            }
            out.close();
        } else throw new ZipException(MAIN_RESOURCE_BUNDLE.getString("default.ZipException.text"));
    }
private static void convertToOnline(final String filePath, final DocuBean docuBean) throws Exception {
        File source = new File(filePath + File.separator + docuBean.getFileName());
        File dir = new File(filePath + File.separator + docuBean.getId());
        if (!dir.exists()) {
            dir.mkdir();
        }
        File in = source;
        boolean isSpace = false;
        if (source.getName().indexOf(" ") != -1) {
            in = new File(StringUtils.replace(source.getName(), " ", ""));
            try {
                IOUtils.copyFile(source, in);
            } catch (IOException e) {
                e.printStackTrace();
            }
            isSpace = true;
        }
        File finalPdf = null;
        try {
            String outPath = dir.getAbsolutePath();
            final File pdf = DocViewerConverter.toPDF(in, outPath);
            convertToSwf(pdf, outPath, docuBean);
            finalPdf = new File(outPath + File.separator + FileUtils.getFilePrefix(StringUtils.replace(source.getName(), " ", "")) + "_decrypted.pdf");
            if (!finalPdf.exists()) {
                finalPdf = pdf;
            }
            pdfByFirstPageToJpeg(finalPdf, outPath, docuBean);
            if (docuBean.getSuccess() == 2 && dir.listFiles().length < 2) {
                docuBean.setSuccess(3);
            }
        } catch (Exception e) {
            throw e;
        } finally {
            if (isSpace) {
                IOUtils.delete(in);
            }
        }
    }
public static String getMD5(String s) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(s.getBytes());
        byte[] result = md5.digest();
        StringBuilder hexString = new StringBuilder();
        for (int i = 0; i < result.length; i++) {
            hexString.append(String.format("%02x", 0xFF & result[i]));
        }
        return hexString.toString();
    }
public String requestGET(String baseUrl, Map<String, String> params) throws Exception {
        String result = "";
        StringBuffer url = new StringBuffer();
        url.append(baseUrl);
        if (params != null && !params.isEmpty()) {
            List<String> keys = new ArrayList<String>(params.keySet());
            for (String key : keys) {
                url.append(key);
                url.append("/");
                url.append(URLEncoder.encode(params.get(key), "UTF-8"));
            }
        }
        HttpGet get = new HttpGet(url.toString());
        HttpResponse res = client.execute(get);
        HttpEntity entity = null;
        if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            entity = res.getEntity();
            BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent()));
            String read = "";
            StringBuffer content = new StringBuffer();
            while ((read = in.readLine()) != null) {
                content.append(read);
            }
            in.close();
            JSONObject rObj = new JSONObject(content.toString());
            result = rObj.getString("msg");
        } else {
            result = "HTTP请求失败";
        }
        if (entity != null) entity.consumeContent();
        client.getConnectionManager().shutdown();
        get = null;
        return result;
    }
public String requestPOST(String baseUrl, Map<String, String> params) throws Exception {
        String result = "";
        HttpPost request = new HttpPost(baseUrl);
        HttpEntity entity = null;
        if (params != null && !params.isEmpty()) {
            List<NameValuePair> postParams = new ArrayList<NameValuePair>();
            List<String> keys = new ArrayList<String>(params.keySet());
            for (String key : keys) {
                postParams.add(new BasicNameValuePair(key, params.get(key)));
            }
            entity = new UrlEncodedFormEntity(postParams, "utf-8");
            request.setEntity(entity);
        }
        HttpResponse res = client.execute(request);
        if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            entity = res.getEntity();
            BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent()));
            StringBuffer content = new StringBuffer();
            String read = "";
            while ((read = in.readLine()) != null) {
                content.append(read);
            }
            in.close();
            JSONObject rObj = new JSONObject(content.toString());
            result = rObj.getString("msg");
        } else result = "请求失败了";
        entity.consumeContent();
        client.getConnectionManager().shutdown();
        request = null;
        return result;
    }
public void storeArticles(Context ctx, RSSFeed feed) throws RSSHandlerError {
        try {
            mFeed = feed;
            db = new RSSDB(ctx);
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(this);
            InputStream stream = feed.url.openStream();
            InputSource source = new InputSource(stream);
            xr.parse(source);
        } catch (IOException e) {
            Log.e("GeneriCast", e.toString());
            throw new RSSHandlerError("IOError");
        } catch (SAXException e) {
            Log.e("GeneriCast", e.toString());
            throw new RSSHandlerError("ParsingError");
        } catch (ParserConfigurationException e) {
            Log.e("GeneriCast", e.toString());
            throw new RSSHandlerError("ParsingError");
        }
    }
public static void unzip2(String strZipFile, String folder) throws IOException, ArchiveException {
        FileUtil.fileExists(strZipFile, true);
        final InputStream is = new FileInputStream(strZipFile);
        ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("zip", is);
        ZipArchiveEntry entry = null;
        OutputStream out = null;
        while ((entry = (ZipArchiveEntry) in.getNextEntry()) != null) {
            File zipPath = new File(folder);
            File destinationFilePath = new File(zipPath, entry.getName());
            destinationFilePath.getParentFile().mkdirs();
            if (entry.isDirectory()) {
                continue;
            } else {
                out = new FileOutputStream(new File(folder, entry.getName()));
                IOUtils.copy(in, out);
                out.close();
            }
        }
        in.close();
    }
public static void copyFile(File sourceFile, File destinationFile) throws IOException {
        if (!destinationFile.exists()) {
            destinationFile.createNewFile();
        }
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destinationFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }
public void run() {
        isRunning = true;
        try {
            URL url = new URL("http://dcg.ethz.ch/projects/sinalgo/version");
            URLConnection con = url.openConnection();
            con.setDoOutput(true);
            con.setDoInput(true);
            con.connect();
            PrintStream ps = new PrintStream(con.getOutputStream());
            ps.println("GET index.html HTTP/1.1");
            ps.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String line = in.readLine();
            if (line != null) {
                if (line.equals(Configuration.versionString)) {
                    if (displayIfOK) {
                        Main.info("You are using the most recent version of Sinalgo.");
                    }
                } else {
                    String msg = "\n" + "+----------------------------------------------------------------------\n" + "| You are currently running Sinalgo " + Configuration.versionString + ".\n" + "| A more recent version of Sinalgo is available (" + line + ")\n" + "+---------------------------------------------------------------------\n" + "| To download the latest version, please visit\n" + "| http://sourceforge.net/projects/sinalgo/\n" + "+---------------------------------------------------------------------\n" + "| You may turn off these version checks through the 'Settings' dialog.\n" + "| Note:   Sinalgo automatically tests for updates at most once\n" + "|         every 24 hours.\n" + "+---------------------------------------------------------------------\n";
                    Main.warning(msg);
                }
            }
        } catch (Exception e) {
            String msg = "\n" + ">----------------------------------------------------------------------\n" + "> Unable to test for updates of Sinalgo. The installed version\n" + "> is " + Configuration.versionString + "\n" + ">---------------------------------------------------------------------\n" + "> To check for more recent versions, please visit\n" + "> http://sourceforge.net/projects/sinalgo/\n" + ">---------------------------------------------------------------------\n" + "> You may turn off these version checks through the 'Settings' dialog.\n" + "| Note:   Sinalgo automatically tests for updates at most once\n" + "|         every 24 hours.\n" + ">---------------------------------------------------------------------\n";
            Main.warning(msg);
        } finally {
            isRunning = false;
            AppConfig.getAppConfig().timeStampOfLastUpdateCheck = System.currentTimeMillis();
        }
    }
public boolean deleteRoleType(int id, int namespaceId, boolean removeReferencesInRoleTypes, DTSPermission permit) throws SQLException, PermissionException, DTSValidationException {
        checkPermission(permit, String.valueOf(namespaceId));
        boolean exist = isRoleTypeUsed(namespaceId, id);
        if (exist) {
            throw new DTSValidationException(ApelMsgHandler.getInstance().getMsg("DTS-0034"));
        }
        if (!removeReferencesInRoleTypes) {
            StringBuffer msgBuf = new StringBuffer();
            DTSTransferObject[] objects = fetchRightIdentityReferences(namespaceId, id);
            if (objects.length > 0) {
                msgBuf.append("Role Type is Right Identity in one or more Role Types.");
            }
            objects = fetchParentReferences(namespaceId, id);
            if (objects.length > 0) {
                if (msgBuf.length() > 0) {
                    msgBuf.append("\n");
                }
                msgBuf.append("Role Type is Parent of one or more Role Types.");
            }
            if (msgBuf.length() > 0) {
                throw new DTSValidationException(msgBuf.toString());
            }
        }
        String sqlRightId = getDAO().getStatement(ROLE_TYPE_TABLE_KEY, "DELETE_RIGHT_IDENTITY_REF");
        String sqlParent = getDAO().getStatement(ROLE_TYPE_TABLE_KEY, "DELETE_PARENT_REF");
        String sql = getDAO().getStatement(ROLE_TYPE_TABLE_KEY, "DELETE");
        PreparedStatement pstmt = null;
        boolean success = false;
        long typeGid = getGID(namespaceId, id);
        conn.setAutoCommit(false);
        int defaultLevel = conn.getTransactionIsolation();
        conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        try {
            pstmt = conn.prepareStatement(sqlRightId);
            pstmt.setLong(1, typeGid);
            pstmt.executeUpdate();
            pstmt.close();
            pstmt = conn.prepareStatement(sqlParent);
            pstmt.setLong(1, typeGid);
            pstmt.executeUpdate();
            pstmt.close();
            pstmt = conn.prepareStatement(sql);
            pstmt.setLong(1, typeGid);
            int count = pstmt.executeUpdate();
            success = (count == 1);
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            throw e;
        } finally {
            conn.setTransactionIsolation(defaultLevel);
            conn.setAutoCommit(true);
            closeStatement(pstmt);
        }
        return success;
    }
public static Properties load(String propsName) {
        Properties props = new Properties();
        URL url = ClassLoader.getSystemResource(propsName);
        try {
            props.load(url.openStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return props;
    }
public void buildCache() {
        XMLCacheBuilder cacheBuilder = CompositePageUtil.getCacheBuilder();
        String postFix = "";
        if (cacheBuilder.getPostFix() != null && !cacheBuilder.getPostFix().equals("")) {
            postFix = "." + cacheBuilder.getPostFix();
        }
        String basePath = cacheBuilder.getBasePath();
        List actions = CompositePageUtil.getXMLActions();
        for (int i = 0; i < actions.size(); i++) {
            try {
                XMLAction action = (XMLAction) actions.get(i);
                if (action.getEscapeCacheBuilder() != null && action.getEscapeCacheBuilder().equals("true")) continue;
                String actionUrl = basePath + action.getName() + postFix;
                URL url = new URL(actionUrl);
                HttpURLConnection huc = (HttpURLConnection) url.openConnection();
                huc.setDoInput(true);
                huc.setDoOutput(true);
                huc.setUseCaches(false);
                huc.setRequestProperty("Content-Type", "text/html");
                DataOutputStream dos = new DataOutputStream(huc.getOutputStream());
                dos.flush();
                dos.close();
                huc.disconnect();
            } catch (MalformedURLException e) {
                logger.error(e);
                e.printStackTrace();
            } catch (IOException e) {
                logger.equals(e);
                e.printStackTrace();
            }
        }
    }