semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public byte[] getHTTPByte(String sUrl) {
        HttpURLConnection connection = null;
        InputStream inputStream = null;
        ByteArrayOutputStream os = null;
        try {
            URL url = new URL(sUrl);
            connection = (HttpURLConnection) url.openConnection();
            connection.connect();
            int httpStatus = connection.getResponseCode();
            if (httpStatus != 200) log.info("getHTTPConent error httpStatus - " + httpStatus);
            inputStream = new BufferedInputStream(connection.getInputStream());
            os = new ByteArrayOutputStream();
            InputStream is = new BufferedInputStream(inputStream);
            byte bytes[] = new byte[40960];
            int nRead = -1;
            while ((nRead = is.read(bytes, 0, 40960)) > 0) {
                os.write(bytes, 0, nRead);
            }
            os.close();
            is.close();
            inputStream.close();
        } catch (IOException e) {
            log.warn("SpiderUtil getHTTPConent IOException -> ", e);
        } finally {
            if (inputStream != null) try {
                os.close();
                inputStream.close();
            } catch (IOException e) {
            }
        }
        return os.toByteArray();
    }
public String getHTTPContent(String sUrl, String encode, String cookie, String host, String referer) {
        HttpURLConnection connection = null;
        InputStream in = null;
        StringBuffer strResult = new StringBuffer();
        try {
            URL url = new URL(sUrl);
            connection = (HttpURLConnection) url.openConnection();
            if (!isStringNull(host)) this.setHttpInfo(connection, cookie, host, referer);
            connection.connect();
            int httpStatus = connection.getResponseCode();
            if (httpStatus != 200) log.info("getHTTPConent error httpStatus - " + httpStatus);
            in = new BufferedInputStream(connection.getInputStream());
            String inputLine = null;
            byte[] b = new byte[40960];
            int len = 0;
            while ((len = in.read(b)) > 0) {
                inputLine = new String(b, 0, len, encode);
                strResult.append(inputLine.replaceAll("[\t\n\r ]", " "));
            }
            in.close();
        } catch (IOException e) {
            log.warn("SpiderUtil getHTTPConent IOException -> ", e);
        } finally {
            if (in != null) try {
                in.close();
            } catch (IOException e) {
            }
        }
        return strResult.toString();
    }
public int getHttpStatus(ProxyInfo proxyInfo, String sUrl, String cookie, String host) {
        HttpURLConnection connection = null;
        try {
            if (proxyInfo == null) {
                URL url = new URL(sUrl);
                connection = (HttpURLConnection) url.openConnection();
            } else {
                InetSocketAddress addr = new InetSocketAddress(proxyInfo.getPxIp(), proxyInfo.getPxPort());
                Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
                URL url = new URL(sUrl);
                connection = (HttpURLConnection) url.openConnection(proxy);
            }
            if (!isStringNull(host)) setHttpInfo(connection, cookie, host, "");
            connection.setConnectTimeout(90 * 1000);
            connection.setReadTimeout(90 * 1000);
            connection.connect();
            connection.getInputStream();
            return connection.getResponseCode();
        } catch (IOException e) {
            log.info(proxyInfo + " getHTTPConent Error ");
            return 0;
        } catch (Exception e) {
            log.info(proxyInfo + " getHTTPConent Error ");
            return 0;
        }
    }
private void copyFile(File in, File out) throws IOException {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
public void getWebByUrl(String strUrl, String charset, String fileIndex) {
        try {
            System.out.println("Getting web by url: " + strUrl);
            addReport("Getting web by url: " + strUrl + "\n");
            URL url = new URL(strUrl);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            InputStream is = null;
            is = url.openStream();
            String filePath = fPath + "/web" + fileIndex + ".htm";
            PrintWriter pw = null;
            FileOutputStream fos = new FileOutputStream(filePath);
            OutputStreamWriter writer = new OutputStreamWriter(fos);
            pw = new PrintWriter(writer);
            BufferedReader bReader = new BufferedReader(new InputStreamReader(is));
            StringBuffer sb = new StringBuffer();
            String rLine = null;
            String tmp_rLine = null;
            while ((rLine = bReader.readLine()) != null) {
                tmp_rLine = rLine;
                int str_len = tmp_rLine.length();
                if (str_len > 0) {
                    sb.append("\n" + tmp_rLine);
                    pw.println(tmp_rLine);
                    pw.flush();
                    if (deepUrls.get(strUrl) < webDepth) getUrlByString(tmp_rLine, strUrl);
                }
                tmp_rLine = null;
            }
            is.close();
            pw.close();
            System.out.println("Get web successfully! " + strUrl);
            addReport("Get web successfully! " + strUrl + "\n");
            addWebSuccessed();
        } catch (Exception e) {
            System.out.println("Get web failed!       " + strUrl);
            addReport("Get web failed!       " + strUrl + "\n");
            addWebFailed();
        }
    }
public static Dimension getJPEGDimension(String urls) throws IOException {
        URL url;
        Dimension d = null;
        try {
            url = new URL(urls);
            InputStream fis = url.openStream();
            if (fis.read() != 255 || fis.read() != 216) throw new RuntimeException("SOI (Start Of Image) marker 0xff 0xd8 missing");
            while (fis.read() == 255) {
                int marker = fis.read();
                int len = fis.read() << 8 | fis.read();
                if (marker == 192) {
                    fis.skip(1);
                    int height = fis.read() << 8 | fis.read();
                    int width = fis.read() << 8 | fis.read();
                    d = new Dimension(width, height);
                    break;
                }
                fis.skip(len - 2);
            }
            fis.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return d;
    }
public static synchronized String encrypt(String x) throws Exception {
        MessageDigest d = MessageDigest.getInstance("SHA-1");
        d.reset();
        d.update(String.valueOf(x).getBytes());
        return byteArrayToHexString(d.digest());
    }
public void truncateLog(long finalZxid) throws IOException {
        long highestZxid = 0;
        for (File f : dataDir.listFiles()) {
            long zxid = isValidSnapshot(f);
            if (zxid == -1) {
                LOG.warn("Skipping " + f);
                continue;
            }
            if (zxid > highestZxid) {
                highestZxid = zxid;
            }
        }
        File[] files = getLogFiles(dataLogDir.listFiles(), highestZxid);
        boolean truncated = false;
        for (File f : files) {
            FileInputStream fin = new FileInputStream(f);
            InputArchive ia = BinaryInputArchive.getArchive(fin);
            FileChannel fchan = fin.getChannel();
            try {
                while (true) {
                    byte[] bytes = ia.readBuffer("txtEntry");
                    if (bytes.length == 0) {
                        throw new EOFException();
                    }
                    InputArchive iab = BinaryInputArchive.getArchive(new ByteArrayInputStream(bytes));
                    TxnHeader hdr = new TxnHeader();
                    deserializeTxn(iab, hdr);
                    if (ia.readByte("EOF") != 'B') {
                        throw new EOFException();
                    }
                    if (hdr.getZxid() == finalZxid) {
                        long pos = fchan.position();
                        fin.close();
                        FileOutputStream fout = new FileOutputStream(f);
                        FileChannel fchanOut = fout.getChannel();
                        fchanOut.truncate(pos);
                        truncated = true;
                        break;
                    }
                }
            } catch (EOFException eof) {
            }
            if (truncated == true) {
                break;
            }
        }
        if (truncated == false) {
            LOG.error("Not able to truncate the log " + Long.toHexString(finalZxid));
            System.exit(13);
        }
    }
public void getZipFiles(String filename) {
        try {
            String destinationname = "c:\\mods\\peu\\";
            byte[] buf = new byte[1024];
            ZipInputStream zipinputstream = null;
            ZipEntry zipentry;
            zipinputstream = new ZipInputStream(new FileInputStream(filename));
            zipentry = zipinputstream.getNextEntry();
            while (zipentry != null) {
                String entryName = zipentry.getName();
                System.out.println("entryname " + entryName);
                int n;
                FileOutputStream fileoutputstream;
                File newFile = new File(entryName);
                String directory = newFile.getParent();
                if (directory == null) {
                    if (newFile.isDirectory()) break;
                }
                fileoutputstream = new FileOutputStream(destinationname + entryName);
                while ((n = zipinputstream.read(buf, 0, 1024)) > -1) fileoutputstream.write(buf, 0, n);
                fileoutputstream.close();
                zipinputstream.closeEntry();
                zipentry = zipinputstream.getNextEntry();
            }
            zipinputstream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
@Override
    public boolean postPage() {
        MySpaceBlogExporterGuiApp.getApplication().getWizContainer().showStatus(myResourceMap.getString("CheckingBlogUrl.text"));
        URL url;
        try {
            url = new URL(txtBlogUrl.getText());
            URLConnection con = url.openConnection();
            con.getContentType();
            String newLink = con.getURL().toString();
            if (!newLink.equalsIgnoreCase(txtBlogUrl.getText())) {
                JOptionPane.showMessageDialog(new JFrame(), myResourceMap.getString("InvalidBlogUrl.text"), "Error", JOptionPane.ERROR_MESSAGE);
                return false;
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(new JFrame(), myResourceMap.getString("InvalidUrl.text"), "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        } finally {
            MySpaceBlogExporterGuiApp.getApplication().getWizContainer().hideStatus();
        }
        if (txtBlogUrl.getText().toLowerCase().indexOf("friendid") > 0) {
            JOptionPane.showMessageDialog(new JFrame(), myResourceMap.getString("InvalidBlogUrl.text"), "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }
        MySpaceBlogExporterGuiApp.getApplication().getMySpaceBlogExporter().setBlogUrl(txtBlogUrl.getText());
        return true;
    }
protected String issueCommandToServer(String command, ChangeCapsule changeCapsule) throws IOException {
        URLConnection urlConn = serverURL.openConnection();
        urlConn.setDoInput(true);
        urlConn.setDoOutput(true);
        urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
        String content = ApplyChangesServlet.PARAMETER_COMMAND + "=" + command;
        content += "&" + ApplyChangesServlet.PARAMETER_CAPSULE + "=" + URLEncoder.encode(changeCapsule.toJSON(), "UTF-8");
        wr.write(content);
        wr.flush();
        BufferedReader input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
        StringBuffer response = new StringBuffer();
        String str;
        while (null != ((str = input.readLine()))) {
            response.append(str);
        }
        wr.close();
        input.close();
        return response.toString();
    }
private void download(String fileName, HttpServletResponse response) throws IOException {
        TelnetInputStream ftpIn = ftpClient_sun.get(fileName);
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
        OutputStream out = null;
        try {
            out = response.getOutputStream();
            IOUtils.copy(ftpIn, out);
        } finally {
            if (ftpIn != null) {
                ftpIn.close();
            }
        }
    }
private void show(String fileName, HttpServletResponse response) throws IOException {
        TelnetInputStream ftpIn = ftpClient_sun.get(fileName);
        OutputStream out = null;
        try {
            out = response.getOutputStream();
            IOUtils.copy(ftpIn, out);
        } finally {
            if (ftpIn != null) {
                ftpIn.close();
            }
        }
    }
public static String connRemote(JSONObject jsonObject, String OPCode) {
        String retSrc = "";
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(AZConstants.validateURL);
            HttpParams httpParams = new BasicHttpParams();
            List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
            nameValuePair.add(new BasicNameValuePair(AZConstants.ACTION_TYPE, OPCode));
            nameValuePair.add(new BasicNameValuePair(AZConstants.PARAM, jsonObject.toString()));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
            httpPost.setParams(httpParams);
            HttpResponse response = httpClient.execute(httpPost);
            retSrc = EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
        return retSrc;
    }
public static String connRemote(JSONObject jsonObject, String OPCode, List<NameValuePair> nameValuePair) {
        String retSrc = "";
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(AZConstants.validateURL);
            HttpParams httpParams = new BasicHttpParams();
            nameValuePair.add(new BasicNameValuePair(AZConstants.ACTION_TYPE, OPCode));
            nameValuePair.add(new BasicNameValuePair(AZConstants.PARAM, jsonObject.toString()));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
            httpPost.setParams(httpParams);
            HttpResponse response = httpClient.execute(httpPost);
            retSrc = EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
        return retSrc;
    }
private void loadInitialDbState() throws IOException {
        InputStream in = SchemaAndDataPopulator.class.getClassLoader().getResourceAsStream(resourceName);
        StringWriter writer = new StringWriter();
        IOUtils.copy(in, writer);
        for (String statement : writer.toString().split(SQL_STATEMENT_DELIMITER)) {
            logger.info("Executing SQL Statement {}", statement);
            template.execute(statement);
        }
    }
public SM2Client(String umn, String authorizationID, String protocol, String serverName, Map props, CallbackHandler handler) {
        super(SM2_MECHANISM + "-" + umn, authorizationID, protocol, serverName, props, handler);
        this.umn = umn;
        complete = false;
        state = 0;
        if (sha == null) try {
            sha = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException x) {
            cat.error("SM2Client()", x);
            throw new RuntimeException(String.valueOf(x));
        }
        sha.update(String.valueOf(umn).getBytes());
        sha.update(String.valueOf(authorizationID).getBytes());
        sha.update(String.valueOf(protocol).getBytes());
        sha.update(String.valueOf(serverName).getBytes());
        sha.update(String.valueOf(properties).getBytes());
        sha.update(String.valueOf(Thread.currentThread().getName()).getBytes());
        uid = new BigInteger(1, sha.digest()).toString(26);
        Ec = null;
    }
@Override
    public byte[] read(String path) throws PersistenceException {
        InputStream reader = null;
        ByteArrayOutputStream sw = new ByteArrayOutputStream();
        try {
            reader = new FileInputStream(path);
            IOUtils.copy(reader, sw);
        } catch (Exception e) {
            LOGGER.error("fail to read file - " + path, e);
            throw new PersistenceException(e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    LOGGER.error("fail to close reader", e);
                }
            }
        }
        return sw.toByteArray();
    }
@Override
    public void write(String path, InputStream is) throws PersistenceException {
        Writer out = null;
        try {
            out = new OutputStreamWriter(new FileOutputStream(path), "utf-8");
            IOUtils.copy(is, out);
        } catch (IOException e) {
            LOGGER.error("fail to write file", e);
            throw new PersistenceException(e);
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    out = null;
                }
            }
        }
    }
public static String createNormalizedJarDescriptorDigest(String path) throws Exception {
        String descriptor = createNormalizedDescriptor(new JarFile2(path));
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(descriptor.getBytes());
            byte[] messageDigest = digest.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
public static BufferedInputStream getEventAttacchment(final String url) throws IOException {
        int slashIndex = url.lastIndexOf("/");
        String encodedUrl = url.substring(0, slashIndex + 1) + URLEncoder.encode(url.substring(slashIndex + 1), "UTF-8");
        String urlwithtoken = encodedUrl + "?ticket=" + getToken();
        BufferedInputStream in = new BufferedInputStream(new URL(urlwithtoken).openStream());
        return in;
    }
protected GVTFontFamily getFontFamily(BridgeContext ctx, ParsedURL purl) {
        String purlStr = purl.toString();
        Element e = getBaseElement(ctx);
        SVGDocument svgDoc = (SVGDocument) e.getOwnerDocument();
        String docURL = svgDoc.getURL();
        ParsedURL pDocURL = null;
        if (docURL != null) pDocURL = new ParsedURL(docURL);
        String baseURI = XMLBaseSupport.getCascadedXMLBase(e);
        purl = new ParsedURL(baseURI, purlStr);
        UserAgent userAgent = ctx.getUserAgent();
        try {
            userAgent.checkLoadExternalResource(purl, pDocURL);
        } catch (SecurityException ex) {
            userAgent.displayError(ex);
            return null;
        }
        if (purl.getRef() != null) {
            Element ref = ctx.getReferencedElement(e, purlStr);
            if (!ref.getNamespaceURI().equals(SVG_NAMESPACE_URI) || !ref.getLocalName().equals(SVG_FONT_TAG)) {
                return null;
            }
            SVGDocument doc = (SVGDocument) e.getOwnerDocument();
            SVGDocument rdoc = (SVGDocument) ref.getOwnerDocument();
            Element fontElt = ref;
            if (doc != rdoc) {
                fontElt = (Element) doc.importNode(ref, true);
                String base = XMLBaseSupport.getCascadedXMLBase(ref);
                Element g = doc.createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
                g.appendChild(fontElt);
                g.setAttributeNS(XMLBaseSupport.XML_NAMESPACE_URI, "xml:base", base);
                CSSUtilities.computeStyleAndURIs(ref, fontElt, purlStr);
            }
            Element fontFaceElt = null;
            for (Node n = fontElt.getFirstChild(); n != null; n = n.getNextSibling()) {
                if ((n.getNodeType() == Node.ELEMENT_NODE) && n.getNamespaceURI().equals(SVG_NAMESPACE_URI) && n.getLocalName().equals(SVG_FONT_FACE_TAG)) {
                    fontFaceElt = (Element) n;
                    break;
                }
            }
            SVGFontFaceElementBridge fontFaceBridge;
            fontFaceBridge = (SVGFontFaceElementBridge) ctx.getBridge(SVG_NAMESPACE_URI, SVG_FONT_FACE_TAG);
            GVTFontFace gff = fontFaceBridge.createFontFace(ctx, fontFaceElt);
            return new SVGFontFamily(gff, fontElt, ctx);
        }
        try {
            Font font = Font.createFont(Font.TRUETYPE_FONT, purl.openStream());
            return new AWTFontFamily(this, font);
        } catch (Exception ex) {
        }
        return null;
    }
public static void main(String[] args) throws Exception {
        int result = 20;
        if (args.length == 1) {
            StringBuffer urlString = new StringBuffer(args[0]);
            if (urlString.lastIndexOf("/") != urlString.length() - 1) {
                urlString.append('/');
            }
            urlString.append("GetConfig.jsp");
            URLConnection conn = new URL(urlString.toString()).openConnection();
            System.out.println(Configuration.readObject(conn.getInputStream()));
            result = 0;
        } else {
            System.err.println("usage: GetConfig <URL>");
        }
        System.exit(result);
    }
protected static boolean isLatestVersion(double myVersion, String referenceAddress) {
        Scanner scanner = null;
        try {
            URL url = new URL(referenceAddress);
            InputStream iS = url.openStream();
            scanner = new Scanner(iS);
            String firstLine = scanner.nextLine();
            double latestVersion = Double.valueOf(firstLine.trim());
            double thisVersion = OpenSONAR.VERSION;
            return thisVersion >= latestVersion;
        } catch (UnknownHostException e) {
            System.out.println("Unknown Host!!!");
            return false;
        } catch (Exception e) {
            System.out.println("Can't decide latest version");
            e.printStackTrace();
            return false;
        }
    }
public static void copyFile(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            int maxCount = (64 * 1024 * 1024) - (32 * 1024);
            long size = inChannel.size();
            long position = 0;
            while (position < size) {
                position += inChannel.transferTo(position, maxCount, outChannel);
            }
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }