semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void viewFile(int file_nx) {
            FTPClient ftp = new FTPClient();
            boolean error = false;
            try {
                int reply;
                ftp.connect("tgftp.nws.noaa.gov");
                ftp.login("anonymous", "");
                Log.d("WXDroid", "Connected to tgftp.nws.noaa.gov.");
                Log.d("WXDroid", ftp.getReplyString());
                reply = ftp.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftp.disconnect();
                    System.err.println("FTP server refused connection.");
                    System.exit(1);
                }
                ftp.changeWorkingDirectory("fax");
                Log.d("WXDroid", "working directory: " + ftp.printWorkingDirectory());
                ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
                InputStream img_file = ftp.retrieveFileStream("PYAA10.gif");
                Intent intent = new Intent();
                intent.setClass(WXdroid.this, showProgressFTP.class);
                startActivity(intent);
                String storage_state = Environment.getExternalStorageState();
                if (storage_state.contains("mounted")) {
                    String filepath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/NOAAWX/";
                    File imageDirectory = new File(filepath);
                    File local_file = new File(filepath + "PYAA10.gif");
                    OutputStream out = new FileOutputStream(local_file);
                    byte[] buffer = new byte[1024];
                    int count;
                    while ((count = img_file.read(buffer)) != -1) {
                        if (Thread.interrupted() == true) {
                            String functionName = Thread.currentThread().getStackTrace()[2].getMethodName() + "()";
                            throw new InterruptedException("The function " + functionName + " was interrupted.");
                        }
                        out.write(buffer, 0, count);
                    }
                    showImage();
                    out.flush();
                    out.close();
                    img_file.close();
                    Log.d("WXDroid", "file saved: " + filepath + " " + local_file);
                } else {
                    Log.d("WXDroid", "The SD card is not mounted");
                }
                ftp.logout();
                ftp.disconnect();
            } catch (IOException e) {
                error = true;
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                if (ftp.isConnected()) {
                    try {
                        ftp.disconnect();
                    } catch (IOException ioe) {
                    }
                }
            }
        }
public String getImageURL(String text) {
        String imgURL = "";
        try {
            URL url = new URL("http://images.search.yahoo.com/search/images?p=" + URLEncoder.encode(text));
            URLConnection connection = url.openConnection();
            DataInputStream in = new DataInputStream(connection.getInputStream());
            String line;
            Pattern imgPattern = Pattern.compile("isrc=\"([^\"]*)\"");
            while ((line = in.readLine()) != null) {
                Matcher match = imgPattern.matcher(line);
                if (match.find()) {
                    imgURL = match.group(1);
                    break;
                }
            }
            in.close();
        } catch (Exception e) {
        }
        return imgURL;
    }
@Override
    public void vote(String urlString, Map<String, String> headData, Map<String, String> paramData) {
        HttpURLConnection httpConn = null;
        try {
            URL url = new URL(urlString);
            httpConn = (HttpURLConnection) url.openConnection();
            String cookies = getCookies(httpConn);
            System.out.println(cookies);
            BufferedReader post = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "GB2312"));
            String text = null;
            while ((text = post.readLine()) != null) {
                System.out.println(text);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
            throw new VoteBeanException("网址不正确", e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new VoteBeanException("不能打开网址", e);
        }
    }
public List<SatelliteElementSet> parseTLE(String urlString) throws IOException {
        List<SatelliteElementSet> elementSets = new ArrayList<SatelliteElementSet>();
        BufferedReader reader = null;
        try {
            String line = null;
            int i = 0;
            URL url = new URL(urlString);
            String[] lines = new String[3];
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((line = reader.readLine()) != null) {
                i++;
                switch(i) {
                    case 1:
                        {
                            lines[0] = line;
                            break;
                        }
                    case 2:
                        {
                            lines[1] = line;
                            break;
                        }
                    case 3:
                        {
                            lines[2] = line;
                            Long catnum = Long.parseLong(StringUtils.strip(lines[1].substring(2, 7)));
                            long setnum = Long.parseLong(StringUtils.strip(lines[1].substring(64, 68)));
                            elementSets.add(new SatelliteElementSet(catnum, lines, setnum, Calendar.getInstance(TZ).getTime()));
                            i = 0;
                            break;
                        }
                    default:
                        {
                            throw new IOException("TLE string did not contain three elements");
                        }
                }
            }
        } finally {
            if (null != reader) {
                reader.close();
            }
        }
        return elementSets;
    }
public FlickrObject perform(boolean chkResponse) throws FlickrException {
        validate();
        String data = getRequestData();
        OutputStream os = null;
        InputStream is = null;
        try {
            URL url = null;
            try {
                url = new URL(m_url);
            } catch (MalformedURLException mux) {
                IllegalStateException iax = new IllegalStateException();
                iax.initCause(mux);
                throw iax;
            }
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            con.setDoOutput(true);
            con.setRequestMethod("POST");
            os = con.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os);
            osw.write(data);
            osw.flush();
            is = con.getInputStream();
            return processRespons(is, chkResponse);
        } catch (FlickrException fx) {
            throw fx;
        } catch (IOException iox) {
            throw new FlickrException(iox);
        } finally {
            if (os != null) try {
                os.close();
            } catch (IOException _) {
            }
            if (is != null) try {
                is.close();
            } catch (IOException _) {
            }
        }
    }
private final void saveCopy(String source, String destination) {
        BufferedInputStream from = null;
        BufferedOutputStream to = null;
        try {
            from = new BufferedInputStream(new FileInputStream(source));
            to = new BufferedOutputStream(new FileOutputStream(destination));
            byte[] buffer = new byte[65535];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) to.write(buffer, 0, bytes_read);
        } catch (Exception e) {
            LogWriter.writeLog("Exception " + e + " copying file");
        }
        try {
            to.close();
            from.close();
        } catch (Exception e) {
            LogWriter.writeLog("Exception " + e + " closing files");
        }
        to = null;
        from = null;
    }
public final void saveAsCopy(String current_image, String destination) {
        BufferedInputStream from = null;
        BufferedOutputStream to = null;
        String source = temp_dir + key + current_image;
        try {
            from = new BufferedInputStream(new FileInputStream(source));
            to = new BufferedOutputStream(new FileOutputStream(destination));
            byte[] buffer = new byte[65535];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) to.write(buffer, 0, bytes_read);
        } catch (Exception e) {
            LogWriter.writeLog("Exception " + e + " copying file");
        }
        try {
            to.close();
            from.close();
        } catch (Exception e) {
            LogWriter.writeLog("Exception " + e + " closing files");
        }
    }
public static final void copy(String source, String destination) {
        BufferedInputStream from = null;
        BufferedOutputStream to = null;
        try {
            from = new BufferedInputStream(new FileInputStream(source));
            to = new BufferedOutputStream(new FileOutputStream(destination));
            byte[] buffer = new byte[65535];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) to.write(buffer, 0, bytes_read);
        } catch (Exception e) {
            LogWriter.writeLog("Exception " + e + " copying file");
        }
        try {
            to.close();
            from.close();
        } catch (Exception e) {
            LogWriter.writeLog("Exception " + e + " closing files");
        }
    }
public static void doVersionCheck(View view) {
        view.showWaitCursor();
        try {
            URL url = new URL(jEdit.getProperty("version-check.url"));
            InputStream in = url.openStream();
            BufferedReader bin = new BufferedReader(new InputStreamReader(in));
            String line;
            String develBuild = null;
            String stableBuild = null;
            while ((line = bin.readLine()) != null) {
                if (line.startsWith(".build")) develBuild = line.substring(6).trim(); else if (line.startsWith(".stablebuild")) stableBuild = line.substring(12).trim();
            }
            bin.close();
            if (develBuild != null && stableBuild != null) {
                doVersionCheck(view, stableBuild, develBuild);
            }
        } catch (IOException e) {
            String[] args = { jEdit.getProperty("version-check.url"), e.toString() };
            GUIUtilities.error(view, "read-error", args);
        }
        view.hideWaitCursor();
    }
public static void copyFile(File src, File dest) throws IOException {
        FileInputStream fis = new FileInputStream(src);
        FileOutputStream fos = new FileOutputStream(dest);
        java.nio.channels.FileChannel channelSrc = fis.getChannel();
        java.nio.channels.FileChannel channelDest = fos.getChannel();
        channelSrc.transferTo(0, channelSrc.size(), channelDest);
        fis.close();
        fos.close();
    }
public DataRecord addRecord(InputStream input) throws DataStoreException {
        File temporary = null;
        try {
            temporary = newTemporaryFile();
            DataIdentifier tempId = new DataIdentifier(temporary.getName());
            usesIdentifier(tempId);
            long length = 0;
            MessageDigest digest = MessageDigest.getInstance(DIGEST);
            OutputStream output = new DigestOutputStream(new FileOutputStream(temporary), digest);
            try {
                length = IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            DataIdentifier identifier = new DataIdentifier(digest.digest());
            File file;
            synchronized (this) {
                usesIdentifier(identifier);
                file = getFile(identifier);
                System.out.println("new file name: " + file.getName());
                File parent = file.getParentFile();
                System.out.println("parent file: " + file.getParentFile().getName());
                if (!parent.isDirectory()) {
                    parent.mkdirs();
                }
                if (!file.exists()) {
                    temporary.renameTo(file);
                    if (!file.exists()) {
                        throw new IOException("Can not rename " + temporary.getAbsolutePath() + " to " + file.getAbsolutePath() + " (media read only?)");
                    }
                } else {
                    long now = System.currentTimeMillis();
                    if (file.lastModified() < now) {
                        file.setLastModified(now);
                    }
                }
                if (!file.isFile()) {
                    throw new IOException("Not a file: " + file);
                }
                if (file.length() != length) {
                    throw new IOException(DIGEST + " collision: " + file);
                }
            }
            inUse.remove(tempId);
            return new FileDataRecord(identifier, file);
        } catch (NoSuchAlgorithmException e) {
            throw new DataStoreException(DIGEST + " not available", e);
        } catch (IOException e) {
            throw new DataStoreException("Could not add record", e);
        } finally {
            if (temporary != null) {
                temporary.delete();
            }
        }
    }
public static String MD5Digest(String source) {
        MessageDigest digest;
        try {
            digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(source.getBytes("UTF8"));
            byte[] hash = digest.digest();
            String strHash = byteArrayToHexString(hash);
            return strHash;
        } catch (NoSuchAlgorithmException e) {
            String msg = "%s: %s";
            msg = String.format(msg, e.getClass().getName(), e.getMessage());
            logger.error(msg);
            return null;
        } catch (UnsupportedEncodingException e) {
            String msg = "%s: %s";
            msg = String.format(msg, e.getClass().getName(), e.getMessage());
            logger.error(msg);
            return null;
        }
    }
public JobOfferPage(JobPageLink link) {
        this.link = link;
        try {
            URL url = new URL(link.getUrl());
            URLConnection urlConn = url.openConnection();
            urlConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)");
            urlConn.setRequestProperty("Accept-Language", "en-us");
            this.content = (String) url.getContent();
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.jobOfferHtmlList = extractJobOfferHtmlList();
    }
private void loginImageShack() throws Exception {
        loginsuccessful = false;
        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 imageshack.us");
        HttpPost httppost = new HttpPost("http://imageshack.us/auth.php");
        httppost.setHeader("Referer", "http://www.uploading.com/");
        httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        httppost.setHeader("Cookie", newcookie + ";" + phpsessioncookie + ";" + imgshckcookie + ";" + uncookie + ";" + latestcookie + ";" + langcookie);
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("username", getUsername()));
        formparams.add(new BasicNameValuePair("password", getPassword()));
        formparams.add(new BasicNameValuePair("stay_logged_in", ""));
        formparams.add(new BasicNameValuePair("format", "json"));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);
        HttpEntity en = httpresponse.getEntity();
        uploadresponse = EntityUtils.toString(en);
        NULogger.getLogger().log(Level.INFO, "Upload response : {0}", uploadresponse);
        NULogger.getLogger().info("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("myid")) {
                myidcookie = escookie.getValue();
                NULogger.getLogger().info(myidcookie);
                loginsuccessful = true;
            }
            if (escookie.getName().equalsIgnoreCase("myimages")) {
                myimagescookie = escookie.getValue();
                NULogger.getLogger().info(myimagescookie);
            }
            if (escookie.getName().equalsIgnoreCase("isUSER")) {
                usercookie = escookie.getValue();
                NULogger.getLogger().info(usercookie);
            }
        }
        if (loginsuccessful) {
            NULogger.getLogger().info("ImageShack Login Success");
            loginsuccessful = true;
            username = getUsername();
            password = getPassword();
        } else {
            NULogger.getLogger().info("ImageShack Login failed");
            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);
        }
    }
private static void fileUpload() throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        file = new File("h:\\Rock Lee.jpg");
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("file", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into bayfiles.com");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            uploadresponse = EntityUtils.toString(resEntity);
        }
        System.out.println("Upload response : " + uploadresponse);
        downloadlink = parseResponse(uploadresponse, "\"downloadUrl\":\"", "\"");
        downloadlink = downloadlink.replaceAll("\\\\", "");
        deletelink = parseResponse(uploadresponse, "\"deleteUrl\":\"", "\"");
        deletelink = deletelink.replaceAll("\\\\", "");
        System.out.println("Download link : " + downloadlink);
        System.out.println("Delete link : " + deletelink);
    }
public static void loginBayFiles() throws Exception {
        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);
        System.out.println("Trying to log in to bayfiles.com");
        HttpPost httppost = new HttpPost("http://bayfiles.com/ajax_login");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("action", "login"));
        formparams.add(new BasicNameValuePair("username", ""));
        formparams.add(new BasicNameValuePair("password", ""));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);
        System.out.println("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("SESSID")) {
                sessioncookie = "SESSID=" + escookie.getValue();
                System.out.println(sessioncookie);
                login = true;
                System.out.println("BayFiles.com Login success :)");
            }
        }
        if (!login) {
            System.out.println("BayFiles.com Login failed :(");
        }
    }
public void testHttpsConnection() {
        try {
            URL url = new URL("https://addons.mozilla.org/zh-CN/firefox/");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.getOutputStream().write("hello".getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private URLConnection openConnection(final URL url) throws IOException {
        try {
            return (URLConnection) AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws IOException {
                    return url.openConnection();
                }
            });
        } catch (PrivilegedActionException e) {
            throw (IOException) e.getException();
        }
    }
public void deleteGroup(String groupID) throws XregistryException {
        try {
            Connection connection = context.createConnection();
            connection.setAutoCommit(false);
            try {
                PreparedStatement statement1 = connection.prepareStatement(DELETE_GROUP_SQL_MAIN);
                statement1.setString(1, groupID);
                int updateCount = statement1.executeUpdate();
                if (updateCount == 0) {
                    throw new XregistryException("Database is not updated, Can not find such Group " + groupID);
                }
                if (cascadingDeletes) {
                    PreparedStatement statement2 = connection.prepareStatement(DELETE_GROUP_SQL_DEPEND);
                    statement2.setString(1, groupID);
                    statement2.setString(2, groupID);
                    statement2.executeUpdate();
                }
                connection.commit();
                groups.remove(groupID);
                log.info("Delete Group " + groupID + (cascadingDeletes ? " with cascading deletes " : ""));
            } catch (SQLException e) {
                connection.rollback();
                throw new XregistryException(e);
            } finally {
                context.closeConnection(connection);
            }
        } catch (SQLException e) {
            throw new XregistryException(e);
        }
    }