semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static Vector getKeywordsFromURLFast(String p_url) throws Exception {
        URL x_url = new URL(p_url);
        URLConnection x_conn = x_url.openConnection();
        InputStreamReader x_is_reader = new InputStreamReader(x_conn.getInputStream());
        BufferedReader x_reader = new BufferedReader(x_is_reader);
        String x_line = null;
        String x_title_line = null;
        String x_lc_line = null;
        Vector x_words = new Vector(1000);
        int x_body = -1;
        int x_title = -1;
        boolean x_bod = false;
        int x_end = -1;
        while ((x_line = x_reader.readLine()) != null) {
            x_lc_line = x_line.toLowerCase();
            x_title = x_lc_line.indexOf("<title");
            if (x_title != -1) {
                x_end = x_lc_line.indexOf("</title>");
                x_title_line = x_line.substring((x_title + 7), (x_end == -1 ? x_line.length() : x_end));
            }
            x_body = x_lc_line.indexOf("<body");
            if (x_body != -1) {
                x_bod = true;
                x_line = x_line.substring(x_body + 5);
                break;
            }
        }
        boolean x_status = false;
        x_end = -1;
        String[] x_temp_words;
        if (x_bod == false) {
            if (x_title_line != null) {
                x_words = new Vector();
                x_temp_words = extractWordsFromSpacedList(x_title_line);
                for (int i = 0; i < x_temp_words.length; i++) x_words.addElement(x_temp_words[i]);
                x_words.addElement(x_title_line);
                return x_words;
            } else {
                return null;
            }
        }
        StringBuffer x_buf = new StringBuffer(35);
        do {
            x_lc_line = x_line.toLowerCase();
            x_end = x_lc_line.indexOf("</body>");
            if (x_end != -1) {
                extractOutsideTextFast(x_line.substring(0, x_end), '<', '>', x_words, x_status, x_buf);
                break;
            }
            x_status = extractOutsideTextFast(x_line, '<', '>', x_words, x_status, x_buf);
        } while ((x_line = x_reader.readLine()) != null);
        if (x_title_line != null) x_words.addElement(x_title_line);
        return x_words;
    }
public static String toMD5Sum(String arg0) {
        String ret;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(arg0.getBytes());
            ret = toHexString(md.digest());
        } catch (Exception e) {
            ret = arg0;
        }
        return ret;
    }
private void handleURL() throws JspException, IOException {
        Map in_map = prepareInputMap();
        String in_str = JSONTransformer.serialize(in_map);
        byte[] input = in_str.getBytes("UTF-8");
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setUseCaches(false);
        conn.connect();
        OutputStream os = conn.getOutputStream();
        os.write(input);
        os.close();
        InputStream is = conn.getInputStream();
        InputStreamReader reader = new InputStreamReader(is, "UTF-8");
        StringBuffer s_buf = new StringBuffer();
        char[] tmp_buf = new char[1024];
        int count;
        while ((count = reader.read(tmp_buf)) != -1) {
            if (count == 0) continue;
            s_buf.append(tmp_buf, 0, count);
        }
        reader.close();
        Map out_map = null;
        try {
            out_map = JSONTransformer.parseObject(s_buf.toString());
        } catch (ParseException e) {
            returnErrorResult(e.getMessage());
        }
        handleResultMap(out_map);
    }
public static InputStream getInputStream(String fileName) throws IOException {
        InputStream input;
        if (fileName.startsWith("http:")) {
            URL url = new URL(fileName);
            URLConnection connection = url.openConnection();
            input = connection.getInputStream();
        } else {
            input = new FileInputStream(fileName);
        }
        return input;
    }
private static String sendGetRequest(String endpoint, String requestParameters) throws Exception {
        String result = null;
        if (endpoint.startsWith("http://")) {
            StringBuffer data = new StringBuffer();
            String urlStr = prepareUrl(endpoint, requestParameters);
            URL url = new URL(urlStr);
            URLConnection conn = url.openConnection();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = rd.readLine()) != null) {
                sb.append(line);
            }
            rd.close();
            result = sb.toString();
        }
        return result;
    }
@Override
    public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
        URL url = new URL(System.getenv("plugg_home") + "/" + systemId);
        System.out.println("SystemId = " + systemId);
        return new InputSource(url.openStream());
    }
protected void migrateOnDemand() {
        try {
            if (fso.fileExists(prefix + ".fat") && !fso.fileExists(prefix + EXTENSIONS[UBM_FILE])) {
                RandomAccessFile ubm, meta, ctr, rbm;
                InputStream inputStream;
                OutputStream outputStream;
                fso.renameFile(prefix + ".fat", prefix + EXTENSIONS[UBM_FILE]);
                ubm = fso.openFile(prefix + EXTENSIONS[UBM_FILE], "rw");
                meta = fso.openFile(prefix + EXTENSIONS[MTD_FILE], "rw");
                ctr = fso.openFile(prefix + EXTENSIONS[CTR_FILE], "rw");
                ubm.seek(ubm.length() - 16);
                meta.writeInt(blockSize = ubm.readInt());
                meta.writeInt(size = ubm.readInt());
                ctr.setLength(ubm.readLong() + blockSize);
                ctr.close();
                meta.close();
                ubm.setLength(ubm.length() - 16);
                ubm.seek(0);
                rbm = fso.openFile(prefix + EXTENSIONS[UBM_FILE], "rw");
                inputStream = new BufferedInputStream(new RandomAccessFileInputStream(ubm));
                outputStream = new BufferedOutputStream(new RandomAccessFileOutputStream(rbm));
                for (int b; (b = inputStream.read()) != -1; ) outputStream.write(b);
                outputStream.close();
                inputStream.close();
                rbm.close();
                ubm.close();
            }
        } catch (IOException ie) {
            throw new WrappingRuntimeException(ie);
        }
    }
public void readURL(URL url) throws IOException, ParserConfigurationException, SAXException {
        URLConnection connection;
        if (proxy == null) {
            connection = url.openConnection();
        } else {
            connection = url.openConnection(proxy);
        }
        connection.setConnectTimeout(connectTimeout);
        connection.setReadTimeout(readTimeout);
        connection.connect();
        InputStream in = connection.getInputStream();
        readInputStream(in);
    }
public String encrypt(String pstrPlainText) throws Exception {
        if (pstrPlainText == null) {
            return "";
        }
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(pstrPlainText.getBytes("UTF-8"));
        byte raw[] = md.digest();
        return (new BASE64Encoder()).encode(raw);
    }
public static String getSHA1(String data) throws NoSuchAlgorithmException {
        String addr;
        data = data.toLowerCase(Locale.getDefault());
        if (data.startsWith("mailto:")) {
            addr = data.substring(7);
        } else {
            addr = data;
        }
        MessageDigest md = MessageDigest.getInstance("SHA");
        StringBuffer sb = new StringBuffer();
        md.update(addr.getBytes());
        byte[] digest = md.digest();
        for (int i = 0; i < digest.length; i++) {
            String hex = Integer.toHexString(digest[i]);
            if (hex.length() == 1) {
                hex = "0" + hex;
            }
            hex = hex.substring(hex.length() - 2);
            sb.append(hex);
        }
        return sb.toString();
    }
private void copyFile(File orig, File dest) {
        byte[] buffer = new byte[1024];
        try {
            FileInputStream fis = new FileInputStream(orig);
            FileOutputStream fos = new FileOutputStream(dest, true);
            int readBytes = 0;
            do {
                readBytes = fis.read(buffer);
                if (readBytes > 0) fos.write(buffer, 0, readBytes);
            } while (readBytes > 0);
            fos.close();
            fis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public void run() {
        try {
            textUpdater.start();
            int cnt;
            byte[] buf = new byte[4096];
            File file = null;
            ZipInputStream zis = new ZipInputStream(new FileInputStream(new File(filename)));
            ZipEntry ze = zis.getNextEntry();
            FileOutputStream fos;
            while (ze != null) {
                if (ze.isDirectory()) {
                    file = new File(ze.getName());
                    if (!file.exists()) {
                        textUpdater.appendText("Creating directory: " + ze.getName() + "\n");
                        file.mkdirs();
                    }
                } else {
                    textUpdater.appendText("Extracting file: " + ze.getName() + "\n");
                    fos = new FileOutputStream(dstdir + File.separator + ze.getName());
                    while ((cnt = zis.read(buf, 0, buf.length)) != -1) fos.write(buf, 0, cnt);
                    fos.close();
                }
                zis.closeEntry();
                ze = zis.getNextEntry();
            }
            zis.close();
            if (complete != null) textUpdater.appendText(complete + "\n");
        } catch (Exception e) {
            e.printStackTrace();
        }
        textUpdater.setFinished(true);
    }
public Blowfish(String password) {
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("SHA1");
            digest.update(password.getBytes());
        } catch (Exception e) {
            System.out.println(e);
        }
        m_bfish = new BlowfishCBC(digest.digest(), 0);
        digest.reset();
    }
private static boolean validateSshaPwd(String sSshaPwd, String sUserPwd) {
        boolean b = false;
        if (sSshaPwd != null && sUserPwd != null) {
            if (sSshaPwd.startsWith(SSHA_PREFIX)) {
                sSshaPwd = sSshaPwd.substring(SSHA_PREFIX.length());
                try {
                    MessageDigest md = MessageDigest.getInstance("SHA-1");
                    BASE64Decoder decoder = new BASE64Decoder();
                    byte[] ba = decoder.decodeBuffer(sSshaPwd);
                    byte[] hash = new byte[FIXED_HASH_SIZE];
                    byte[] salt = new byte[FIXED_SALT_SIZE];
                    System.arraycopy(ba, 0, hash, 0, FIXED_HASH_SIZE);
                    System.arraycopy(ba, FIXED_HASH_SIZE, salt, 0, FIXED_SALT_SIZE);
                    md.update(sUserPwd.getBytes());
                    md.update(salt);
                    byte[] baPwdHash = md.digest();
                    b = MessageDigest.isEqual(hash, baPwdHash);
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }
        }
        return b;
    }
private int renumberOrderBy(long tableID) throws SnapInException {
        int count = 0;
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            con = getDataSource().getConnection();
            con.setAutoCommit(false);
            stmt = con.createStatement();
            StringBuffer query = new StringBuffer();
            query.append("SELECT ").append(DatabaseConstants.TableFieldName_JV_FIELDBEHAVIOR_ID).append(" FROM ").append(DatabaseConstants.TableName_JV_FIELDBEHAVIOR).append(" WHERE ").append(DatabaseConstants.TableFieldName_JV_FIELDBEHAVIOR_TABLEID).append(" = ").append(tableID).append(" ORDER BY ").append(DatabaseConstants.TableFieldName_JV_FIELDBEHAVIOR_ORDERBY);
            Vector rowIDVector = new Vector();
            rs = stmt.executeQuery(query.toString());
            while (rs.next()) {
                count++;
                rowIDVector.add(rs.getLong(DatabaseConstants.TableFieldName_JV_FIELDBEHAVIOR_ID) + "");
            }
            StringBuffer updateString = new StringBuffer();
            updateString.append("UPDATE ").append(DatabaseConstants.TableName_JV_FIELDBEHAVIOR).append(" SET ").append(DatabaseConstants.TableFieldName_JV_FIELDBEHAVIOR_ORDERBY).append(" = ? WHERE ").append(DatabaseConstants.TableFieldName_JV_FIELDBEHAVIOR_ID).append(" = ?");
            PreparedStatement pstmt = con.prepareStatement(updateString.toString());
            int orderByValue = ORDERBY_BY_DELTA_VALUE;
            Enumeration en = rowIDVector.elements();
            while (en.hasMoreElements()) {
                pstmt.setInt(1, orderByValue);
                pstmt.setString(2, en.nextElement().toString());
                orderByValue += ORDERBY_BY_DELTA_VALUE;
                pstmt.executeUpdate();
            }
            con.setAutoCommit(true);
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (java.sql.SQLException e) {
            if (con == null) {
                logger.error("java.sql.SQLException", e);
            } else {
                try {
                    logger.error("Transaction is being rolled back.");
                    con.rollback();
                    con.setAutoCommit(true);
                } catch (java.sql.SQLException e2) {
                    logger.error("java.sql.SQLException", e2);
                }
            }
        } catch (Exception e) {
            logger.error("Error occured during RenumberOrderBy", e);
        } finally {
            getDataSourceHelper().releaseResources(con, stmt, rs);
        }
        return count;
    }
static String fetchURLComposeExternPackageList(String urlpath, String pkglisturlpath) {
        String link = pkglisturlpath + "package-list";
        try {
            boolean relative = isRelativePath(urlpath);
            readPackageList((new URL(link)).openStream(), urlpath, relative);
        } catch (MalformedURLException exc) {
            return getText("doclet.MalformedURL", link);
        } catch (IOException exc) {
            return getText("doclet.URL_error", link);
        }
        return null;
    }
static void sort(int[] a) {
        int i = 0;
        while (i < a.length - 1) {
            int j = 0;
            while (j < (a.length - i) - 1) {
                if (a[j] > a[j + 1]) {
                    int aux = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = aux;
                }
                j = j + 1;
            }
            i = i + 1;
        }
    }
@Override
    public void doHandler(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        if (request.getRequestURI().indexOf("png") != -1) {
            response.setContentType("image/png");
        } else if (request.getRequestURI().indexOf("gif") != -1) {
            response.setContentType("image/gif");
        } else {
            response.setContentType("image/x-icon");
        }
        BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
        try {
            URL url = new URL("http://" + configCenter.getUcoolOnlineIp() + request.getRequestURI());
            BufferedInputStream in = new BufferedInputStream(url.openStream());
            byte[] data = new byte[4096];
            int size = in.read(data);
            while (size != -1) {
                bos.write(data, 0, size);
                size = in.read(data);
            }
            in.close();
            bos.flush();
            bos.close();
            in.close();
        } catch (Exception e) {
        }
        bos.flush();
    }
@Override
    public void login() {
        loginsuccessful = false;
        try {
            HttpParams params = new BasicHttpParams();
            params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
            DefaultHttpClient httpclient = new DefaultHttpClient(params);
            NULogger.getLogger().info("Trying to log in to HotFile");
            HttpPost httppost = new HttpPost("http://www.hotfile.com/login.php");
            httppost.setHeader("Referer", "http://www.hotfile.com/");
            httppost.setHeader("Cache-Control", "max-age=0");
            httppost.setHeader("Origin", "http://www.hotfile.com/");
            httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            formparams.add(new BasicNameValuePair("returnto", "%2F"));
            formparams.add(new BasicNameValuePair("user", getUsername()));
            formparams.add(new BasicNameValuePair("pass", getPassword()));
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
            httppost.setEntity(entity);
            HttpResponse httpresponse = httpclient.execute(httppost);
            if (httpresponse.getFirstHeader("Set-Cookie") == null) {
                NULogger.getLogger().info("HotFile Login not successful");
                loginsuccessful = false;
                username = "";
                password = "";
                JOptionPane.showMessageDialog(NeembuuUploader.getInstance(), "<html><b>" + HOSTNAME + "</b> " + TranslationProvider.get("neembuuuploader.accounts.loginerror") + "</html>", HOSTNAME, JOptionPane.WARNING_MESSAGE);
                AccountsManager.getInstance().setVisible(true);
            } else {
                Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
                while (it.hasNext()) {
                    hfcookie = it.next();
                    if (hfcookie.getName().equals("auth")) {
                        NULogger.getLogger().log(Level.INFO, "hotfile login successful auth:{0}", hfcookie.getValue());
                        loginsuccessful = true;
                        HostsPanel.getInstance().hotFileCheckBox.setEnabled(true);
                        username = getUsername();
                        password = getPassword();
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            NULogger.getLogger().log(Level.SEVERE, "{0}: Error in Hotfile Login", getClass().getName());
        }
    }
@Provides
    @Singleton
    Properties provideCfg() {
        InputStream propStream = null;
        URL url = Thread.currentThread().getContextClassLoader().getResource(PROPERTY_FILE);
        Properties cfg = new Properties();
        if (url != null) {
            try {
                log.info("Loading app config from properties: " + url.toURI());
                propStream = url.openStream();
                cfg.load(propStream);
                return cfg;
            } catch (Exception e) {
                log.warn(e);
            }
        }
        if (cfg.size() < 1) {
            log.info(PROPERTY_FILE + " doesnt contain any configuration for application properties.");
        }
        return cfg;
    }
@Test
    public void testStandardTee() throws Exception {
        final byte[] test = "test".getBytes();
        final InputStream source = new ByteArrayInputStream(test);
        final ByteArrayOutputStream destination1 = new ByteArrayOutputStream();
        final ByteArrayOutputStream destination2 = new ByteArrayOutputStream();
        final TeeOutputStream tee = new TeeOutputStream(destination1, destination2);
        org.apache.commons.io.IOUtils.copy(source, tee);
        tee.close();
        assertArrayEquals("the two arrays are equals", test, destination1.toByteArray());
        assertArrayEquals("the two arrays are equals", test, destination2.toByteArray());
        assertEquals("byte count", test.length, tee.getSize());
    }
private boolean importTablesData(Connection conn) {
        try {
            boolean status = true;
            boolean autoCommit = conn.getAutoCommit();
            conn.setAutoCommit(false);
            String dbType = this.getFromSession("database");
            List statements = ParseDBDumpFile.parse(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/database/" + dbType + "/" + dbType + "_data_dump.sql");
            for (Iterator iter = statements.iterator(); iter.hasNext(); ) {
                String query = (String) iter.next();
                if (query == null || "".equals(query.trim())) {
                    continue;
                }
                query = query.trim();
                Statement s = conn.createStatement();
                try {
                    if (query.startsWith("UPDATE") || query.startsWith("INSERT") || query.startsWith("SET")) {
                        s.executeUpdate(query);
                    } else if (query.startsWith("SELECT")) {
                        s.executeQuery(query);
                    } else {
                        throw new SQLException("Invalid query: " + query);
                    }
                } catch (SQLException ex) {
                    status = false;
                    conn.rollback();
                    logger.error("Error importing data for " + query + ": " + ex, ex);
                    this.context.put("exceptionMessage", ex.getMessage() + "\n" + query);
                    break;
                } finally {
                    s.close();
                }
            }
            conn.setAutoCommit(autoCommit);
            return status;
        } catch (Exception e) {
            throw new ForumException(e);
        }
    }
public static String postRequest(String urlString, HashMap data) {
        String returnData = "";
        try {
            URL url = new URL(urlString);
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
            PrintWriter out = new PrintWriter(connection.getOutputStream());
            Object[] keySet = data.keySet().toArray();
            Object[] values = data.values().toArray();
            for (int count = 0; count < keySet.length; count++) {
                out.print(URLEncoder.encode((String) keySet[count]) + "=" + URLEncoder.encode((String) values[count]));
                if ((count + 1) < keySet.length) out.print("&");
            }
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                returnData += inputLine;
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
            returnData = null;
        }
        return (returnData);
    }