semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static ArrayList[] imageSearch(String imageQuery, int startingIndex) {
            try {
                imageQuery = URLEncoder.encode(imageQuery, "UTF-8");
            } catch (UnsupportedEncodingException e1) {
                e1.printStackTrace();
            }
            String queryS = new String();
            queryS += "http://images.google.com/images?gbv=1&start=" + startingIndex + "&q=" + imageQuery;
            String result = "";
            try {
                URL query = new URL(queryS);
                HttpURLConnection urlc = (HttpURLConnection) query.openConnection();
                urlc.setInstanceFollowRedirects(true);
                urlc.setRequestProperty("User-Agent", "");
                urlc.connect();
                BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
                StringBuffer response = new StringBuffer();
                char[] buffer = new char[1024];
                while (true) {
                    int charsRead = in.read(buffer);
                    if (charsRead == -1) {
                        break;
                    }
                    response.append(buffer, 0, charsRead);
                }
                in.close();
                result = response.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            ArrayList<String> thumbs = new ArrayList<String>();
            ArrayList<String> imgs = new ArrayList<String>();
            Matcher m = imgBlock.matcher(result);
            while (m.find()) {
                String s = m.group();
                Matcher imgM = imgurl.matcher(s);
                imgM.find();
                String url = imgM.group(1);
                Matcher srcM = imgsrc.matcher(s);
                srcM.find();
                String thumb = srcM.group(1);
                thumbs.add(thumb);
                imgs.add(url);
            }
            return new ArrayList[] { thumbs, imgs };
        }
public static byte[] crypt(String key, String salt) throws NoSuchAlgorithmException {
        int key_len = key.length();
        if (salt.startsWith(saltPrefix)) {
            salt = salt.substring(saltPrefix.length());
        }
        int salt_len = Math.min(getDollarLessLength(salt), 8);
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(key.getBytes());
        md5.update(saltPrefix.getBytes());
        md5.update(salt.getBytes(), 0, salt_len);
        MessageDigest md5_alt = MessageDigest.getInstance("MD5");
        md5_alt.update(key.getBytes());
        md5_alt.update(salt.getBytes(), 0, salt_len);
        md5_alt.update(key.getBytes());
        byte[] altResult = md5_alt.digest();
        int cnt;
        for (cnt = key_len; cnt > 16; cnt -= 16) {
            md5.update(altResult, 0, 16);
        }
        md5.update(altResult, 0, cnt);
        altResult[0] = 0;
        for (cnt = key_len; cnt > 0; cnt >>= 1) {
            md5.update(((cnt & 1) != 0) ? altResult : key.getBytes(), 0, 1);
        }
        altResult = md5.digest();
        for (cnt = 0; cnt < 1000; cnt++) {
            md5.reset();
            if ((cnt & 1) != 0) {
                md5.update(key.getBytes());
            } else {
                md5.update(altResult, 0, 16);
            }
            if ((cnt % 3) != 0) {
                md5.update(salt.getBytes(), 0, salt_len);
            }
            if ((cnt % 7) != 0) {
                md5.update(key.getBytes());
            }
            if ((cnt & 1) != 0) {
                md5.update(altResult, 0, 16);
            } else {
                md5.update(key.getBytes());
            }
            altResult = md5.digest();
        }
        StringBuilder sb = new StringBuilder();
        sb.append(saltPrefix);
        sb.append(new String(salt.getBytes(), 0, salt_len));
        sb.append('$');
        sb.append(b64From24bit(altResult[0], altResult[6], altResult[12], 4));
        sb.append(b64From24bit(altResult[1], altResult[7], altResult[13], 4));
        sb.append(b64From24bit(altResult[2], altResult[8], altResult[14], 4));
        sb.append(b64From24bit(altResult[3], altResult[9], altResult[15], 4));
        sb.append(b64From24bit(altResult[4], altResult[10], altResult[5], 4));
        sb.append(b64From24bit((byte) 0, (byte) 0, altResult[11], 2));
        return sb.toString().getBytes();
    }
private byte[] hash(String data, HashAlg alg) {
        try {
            MessageDigest digest = MessageDigest.getInstance(alg.toString());
            digest.update(data.getBytes());
            byte[] hash = digest.digest();
            return hash;
        } catch (NoSuchAlgorithmException e) {
        }
        return null;
    }
private void startOpening(final URL url) {
        final WebAccessor wa = this;
        openerThread = new Thread() {

            public void run() {
                iStream = null;
                try {
                    tryProxy = false;
                    URLConnection connection = url.openConnection();
                    if (connection instanceof HttpURLConnection) {
                        HttpURLConnection htc = (HttpURLConnection) connection;
                        contentLength = htc.getContentLength();
                    }
                    InputStream i = connection.getInputStream();
                    iStream = new LoggedInputStream(i, wa);
                } catch (ConnectException x) {
                    tryProxy = true;
                    exception = x;
                } catch (Exception x) {
                    exception = x;
                } finally {
                    if (dialog != null) {
                        Thread.yield();
                        dialog.setVisible(false);
                    }
                }
            }
        };
        openerThread.start();
    }
public void run() {
                iStream = null;
                try {
                    tryProxy = false;
                    URLConnection connection = url.openConnection();
                    if (connection instanceof HttpURLConnection) {
                        HttpURLConnection htc = (HttpURLConnection) connection;
                        contentLength = htc.getContentLength();
                    }
                    InputStream i = connection.getInputStream();
                    iStream = new LoggedInputStream(i, wa);
                } catch (ConnectException x) {
                    tryProxy = true;
                    exception = x;
                } catch (Exception x) {
                    exception = x;
                } finally {
                    if (dialog != null) {
                        Thread.yield();
                        dialog.setVisible(false);
                    }
                }
            }
private Element returnAnnoBody(final String url) {
        DOMParser parser = new DOMParser();
        try {
            URL bodyURL = new URL(url);
            URLConnection url_con = bodyURL.openConnection();
            if (useAuthorization()) {
                url_con.setRequestProperty("Authorization", "Basic " + getBasicAuthorizationString());
            }
            InputStream content = url_con.getInputStream();
            InputSource insource = new InputSource(content);
            parser.parse(insource);
        } catch (SAXException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        Document annodoc = parser.getDocument();
        return annodoc.getDocumentElement();
    }
public static InputSource openInputSource(String resource) {
        InputSource src = null;
        URL url = findResource(resource);
        if (url != null) {
            try {
                InputStream in = url.openStream();
                src = new InputSource(in);
                src.setSystemId(url.toExternalForm());
            } catch (IOException e) {
            }
        }
        return src;
    }
public void testScenario() throws Exception {
        String expression = "SELECT id, name, address, phone FROM " + TABLE + " where id > 2 and id < 12 order by id";
        SQLQuery query = new SQLQuery();
        query.setResourceID(mResourceID);
        query.addExpression(expression);
        TupleToWebRowSetCharArrays tupleToWebRowSet = new TupleToWebRowSetCharArrays();
        tupleToWebRowSet.connectDataInput(query.getDataOutput());
        DeliverToFTP deliverToFTP = new DeliverToFTP();
        deliverToFTP.connectDataInput(tupleToWebRowSet.getResultOutput());
        deliverToFTP.addFilename(FILE);
        deliverToFTP.addHost(mURL);
        PipelineWorkflow pipeline = new PipelineWorkflow();
        pipeline.add(query);
        pipeline.add(tupleToWebRowSet);
        pipeline.add(deliverToFTP);
        mDRER.execute(pipeline, RequestExecutionType.SYNCHRONOUS);
        final URL url = new URL("ftp://" + mURL + "/" + FILE);
        final URLConnection connection = url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(false);
        InputStream is = connection.getInputStream();
        WebRowSetToResultSet converter = new WebRowSetToResultSet(new InputStreamReader(is));
        converter.setResultSetType(ResultSet.TYPE_FORWARD_ONLY);
        ResultSet rs = converter.getResultSet();
        JDBCTestHelper.validateResultSet(mConnection, expression, rs, 1);
        rs.close();
    }
public void load(String fileName) {
        BufferedReader bufReader;
        loaded = false;
        vector.removeAllElements();
        try {
            if (fileName.startsWith("http:")) {
                URL url = new URL(fileName);
                bufReader = new BufferedReader(new InputStreamReader(url.openStream()));
            } else bufReader = new BufferedReader(new FileReader(fileName));
            String inputLine;
            while ((inputLine = bufReader.readLine()) != null) {
                if (listener != null) listener.handleLine(inputLine); else vector.add(inputLine);
            }
            bufReader.close();
            loaded = true;
        } catch (IOException e) {
            errorMsg = e.getMessage();
        }
    }
public synchronized String decrypt(String plaintext) throws Exception {
        MessageDigest md = null;
        String strhash = new String((new BASE64Decoder()).decodeBuffer(plaintext));
        System.out.println("strhash1122  " + strhash);
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            e.printStackTrace();
        }
        byte raw[] = md.digest();
        try {
            md.update(new String(raw).getBytes("UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("plain text  " + strhash);
        String strcode = new String(raw);
        System.out.println("strcode.." + strcode);
        return strcode;
    }
public String addShare2(String appid, String appkey, String oauth_token, String oauth_token_secret, String openid, String format, Webpage webpage) throws Exception {
        String shareUrl = "http://openapi.qzone.qq.com/share/add_share";
        String oauth_signature = "";
        long oauth_timestamp = new Date().getTime() / 1000;
        String oauth_nonce = (Math.random() + "").replaceFirst("^0.", "");
        List<NameValuePair> shareParameters = new ArrayList<NameValuePair>();
        shareParameters.add(new BasicNameValuePair("format", format));
        shareParameters.add(new BasicNameValuePair("images", webpage.images));
        shareParameters.add(new BasicNameValuePair("oauth_consumer_key", appid));
        shareParameters.add(new BasicNameValuePair("oauth_nonce", oauth_nonce));
        shareParameters.add(new BasicNameValuePair("oauth_signature_method", "HMAC-SHA1"));
        shareParameters.add(new BasicNameValuePair("oauth_timestamp", oauth_timestamp + ""));
        shareParameters.add(new BasicNameValuePair("oauth_token", oauth_token));
        shareParameters.add(new BasicNameValuePair("oauth_version", "1.0"));
        shareParameters.add(new BasicNameValuePair("openid", openid));
        shareParameters.add(new BasicNameValuePair("title", webpage.title));
        shareParameters.add(new BasicNameValuePair("url", webpage.url));
        String stepA1 = "POST";
        String stepA2 = URLEncoder.encode(shareUrl, "UTF-8");
        String stepA3 = "";
        for (int i = 0; i < shareParameters.size(); i++) {
            NameValuePair item = shareParameters.get(i);
            stepA3 += item.getName() + "=" + item.getValue();
            if (i < shareParameters.size() - 1) {
                stepA3 += "&";
            }
        }
        stepA3 = URLEncoder.encode(stepA3, "UTF-8");
        String stepA = stepA1 + "&" + stepA2 + "&" + stepA3;
        String stepB = appkey + "&" + oauth_token_secret;
        Mac mac = Mac.getInstance("HmacSHA1");
        SecretKeySpec spec = new SecretKeySpec(stepB.getBytes("US-ASCII"), "HmacSHA1");
        mac.init(spec);
        byte[] oauthSignature = mac.doFinal(stepA.getBytes("US-ASCII"));
        oauth_signature = Base64Encoder.encode(oauthSignature);
        shareParameters.add(new BasicNameValuePair("oauth_signature", oauth_signature));
        HttpPost sharePost = new HttpPost(shareUrl);
        sharePost.setHeader("Referer", "http://openapi.qzone.qq.com");
        sharePost.setHeader("Host", "openapi.qzone.qq.com");
        sharePost.setHeader("Accept-Language", "zh-cn");
        sharePost.setHeader("Content-Type", "application/x-www-form-urlencoded");
        sharePost.setEntity(new UrlEncodedFormEntity(shareParameters, "UTF-8"));
        DefaultHttpClient httpclient = HttpClientUtils.getHttpClient();
        HttpResponse loginPostRes = httpclient.execute(sharePost);
        String shareHtml = HttpClientUtils.getHtml(loginPostRes, "UTF-8", false);
        return shareHtml;
    }
public void testIntegrityViolation() throws Exception {
        if (getDialect() instanceof MySQLMyISAMDialect) {
            reportSkip("MySQL (ISAM) does not support FK violation checking", "exception conversion");
            return;
        }
        SQLExceptionConverter converter = getDialect().buildSQLExceptionConverter();
        Session session = openSession();
        session.beginTransaction();
        Connection connection = session.connection();
        PreparedStatement ps = null;
        try {
            ps = connection.prepareStatement("INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (?, ?)");
            ps.setLong(1, 52134241);
            ps.setLong(2, 5342);
            ps.executeUpdate();
            fail("INSERT should have failed");
        } catch (SQLException sqle) {
            JDBCExceptionReporter.logExceptions(sqle, "Just output!!!!");
            JDBCException jdbcException = converter.convert(sqle, null, null);
            assertEquals("Bad conversion [" + sqle.getMessage() + "]", ConstraintViolationException.class, jdbcException.getClass());
            ConstraintViolationException ex = (ConstraintViolationException) jdbcException;
            System.out.println("Violated constraint name: " + ex.getConstraintName());
        } finally {
            if (ps != null) {
                try {
                    ps.close();
                } catch (Throwable ignore) {
                }
            }
        }
        session.getTransaction().rollback();
        session.close();
    }
public void importNotesFromServer() {
        boolean downloaded = true;
        try {
            makeBackupFile();
            File f = new File(UserSettings.getInstance().getNotesFile());
            FileOutputStream fos = new FileOutputStream(f);
            String urlString = protocol + "://" + UserSettings.getInstance().getServerAddress() + UserSettings.getInstance().getServerDir() + f.getName();
            setDefaultAuthenticator();
            URL url = new URL(urlString);
            HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
            InputStream is = urlc.getInputStream();
            int nextByte = is.read();
            while (nextByte != -1) {
                fos.write(nextByte);
                nextByte = is.read();
            }
            fos.close();
            if (urlc.getResponseCode() != HttpURLConnection.HTTP_OK) {
                downloaded = false;
            }
        } catch (SSLHandshakeException e) {
            JOptionPane.showMessageDialog(null, I18N.getInstance().getString("error.sslcertificateerror"), I18N.getInstance().getString("error.title"), JOptionPane.ERROR_MESSAGE);
            downloaded = false;
        } catch (Exception e) {
            downloaded = false;
        }
        if (downloaded) {
            deleteBackupFile();
            JOptionPane.showMessageDialog(null, I18N.getInstance().getString("info.notesfiledownloaded"), I18N.getInstance().getString("info.title"), JOptionPane.INFORMATION_MESSAGE);
        } else {
            restoreFileFromBackup();
            JOptionPane.showMessageDialog(null, I18N.getInstance().getString("error.notesfilenotdownloaded"), I18N.getInstance().getString("error.title"), JOptionPane.ERROR_MESSAGE);
        }
    }
public void exportNotesToServer() {
        boolean uploaded = true;
        try {
            File f = new File(UserSettings.getInstance().getNotesFile());
            FileInputStream fis = new FileInputStream(f);
            String urlString = protocol + "://" + UserSettings.getInstance().getServerAddress() + UserSettings.getInstance().getServerDir() + f.getName();
            setDefaultAuthenticator();
            URL url = new URL(urlString);
            HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
            urlc.setDoOutput(true);
            urlc.setRequestMethod("PUT");
            OutputStream os = urlc.getOutputStream();
            int nextByte = fis.read();
            while (nextByte != -1) {
                os.write(nextByte);
                nextByte = fis.read();
            }
            fis.close();
            os.close();
            if (urlc.getResponseCode() != HttpURLConnection.HTTP_CREATED && urlc.getResponseCode() != HttpURLConnection.HTTP_NO_CONTENT) {
                uploaded = false;
            }
        } catch (SSLHandshakeException e) {
            JOptionPane.showMessageDialog(null, I18N.getInstance().getString("error.sslcertificateerror"), I18N.getInstance().getString("error.title"), JOptionPane.ERROR_MESSAGE);
            uploaded = false;
        } catch (Exception e) {
            uploaded = false;
        }
        if (uploaded) {
            JOptionPane.showMessageDialog(null, I18N.getInstance().getString("info.notesfileuploaded"), I18N.getInstance().getString("info.title"), JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, I18N.getInstance().getString("error.notesfilenotuploaded"), I18N.getInstance().getString("error.title"), JOptionPane.ERROR_MESSAGE);
        }
    }
public String doAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        UploadFileForm vo = (UploadFileForm) form;
        FormFile file = vo.getFile();
        String inforId = request.getParameter("inforId");
        System.out.println("inforId=" + inforId);
        if (file != null) {
            String realpath = getServlet().getServletContext().getRealPath("/");
            realpath = realpath.replaceAll("\\\\", "/");
            String rootFilePath = getServlet().getServletContext().getRealPath(request.getContextPath());
            rootFilePath = (new StringBuilder(String.valueOf(rootFilePath))).append(UploadFileOne.strPath).toString();
            String strAppend = (new StringBuilder(String.valueOf(UUIDGenerator.nextHex()))).append(UploadFileOne.getFileType(file)).toString();
            if (file.getFileSize() != 0) {
                file.getInputStream();
                String name = file.getFileName();
                String fullPath = realpath + "attach/" + strAppend + name;
                t_attach attach = new t_attach();
                attach.setAttach_fullname(fullPath);
                attach.setAttach_name(name);
                attach.setInfor_id(Integer.parseInt(inforId));
                attach.setInsert_day(new Date());
                attach.setUpdate_day(new Date());
                t_attach_EditMap attachEdit = new t_attach_EditMap();
                attachEdit.add(attach);
                File sysfile = new File(fullPath);
                if (!sysfile.exists()) {
                    sysfile.createNewFile();
                }
                java.io.OutputStream out = new FileOutputStream(sysfile);
                org.apache.commons.io.IOUtils.copy(file.getInputStream(), out);
                out.close();
                System.out.println("file name is :" + name);
            }
        }
        request.setAttribute("operating-status", "�����ɹ�!  ��ӭ����ʹ�á�");
        System.out.println("in the end....");
        return "aftersave";
    }
public static void main(String[] args) {
        System.out.println(args.length);
        FTPClient ftp = new FTPClient();
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
        try {
            ftp.connect("localhost");
            ftp.login("ethan", "ethan");
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ftp.enterLocalPassiveMode();
            InputStream input;
            input = new FileInputStream("d:/tech/webwork-2.2.7.zip");
            boolean is = ftp.storeFile("backup/webwork-2.2.7.zip", input);
            input.close();
            System.out.println(is);
            FTPFile[] files = ftp.listFiles("backup");
            for (FTPFile ftpFile : files) {
                long time = ftpFile.getTimestamp().getTimeInMillis();
                long days = (System.currentTimeMillis() - time) / (1000 * 60 * 60 * 24);
                if (days > 30) {
                    System.out.println(ftpFile.getName() + "is a old file");
                    ftp.deleteFile("backup/" + ftpFile.getName());
                } else {
                    System.out.println(ftpFile.getName() + "is a new file");
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                ftp.logout();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }