semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private String logonToServer(FTPClient ftpClient, String ftpAddress, int noRetries) {
        String remoteHomeDir = null;
        noRetriesSoFar = 0;
        while (true) {
            try {
                ftpClient.connect(ftpAddress, ftpPort);
                int reply = ftpClient.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftpClient.disconnect();
                    throw new IOException();
                }
                if (!ftpClient.login(user, password)) {
                    throw new IOException();
                }
                remoteHomeDir = ftpClient.printWorkingDirectory();
                msgEntry.setAppContext("logonToServer()");
                msgEntry.setMessageText("Logged into FTP server " + ftpAddress + ":" + ftpPort + " as user " + user);
                logger.logProcess(msgEntry);
                break;
            } catch (IOException e) {
                logoutAndDisconnect(ftpClient);
                if (noRetriesSoFar++ < noRetries) {
                    waitBetweenRetry();
                    notifyAndStartWaitingFlag = false;
                } else {
                    notifyAndStartWaitingFlag = true;
                    errEntry.setThrowable(e);
                    errEntry.setAppContext("logonToServer()");
                    errEntry.setAppMessage("Unable to login after " + (noRetriesSoFar - 1) + " retries. Max Retries.\n" + "Address:" + ftpAddress + "\n" + "User:" + user);
                    errEntry.setSubjectSendEmail("Unable to login to " + ftpAddress + " after " + (noRetriesSoFar - 1) + " retries.");
                    logger.logError(errEntry);
                    break;
                }
            }
        }
        return remoteHomeDir;
    }
private static Bitmap loadFromUrl(String url, String portId) {
        Bitmap bitmap = null;
        final HttpGet get = new HttpGet(url);
        HttpEntity entity = null;
        try {
            final HttpResponse response = ServiceProxy.getInstance(portId).execute(get);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                entity = response.getEntity();
                try {
                    InputStream in = entity.getContent();
                    bitmap = BitmapFactory.decodeStream(in);
                } catch (IOException e) {
                    Log.error(e);
                }
            }
        } catch (IOException e) {
            Log.error(e);
        } finally {
            if (entity != null) {
                try {
                    entity.consumeContent();
                } catch (IOException e) {
                    Log.error(e);
                }
            }
        }
        return bitmap;
    }
private void menuOpenURL() {
        animate = false;
        resetScaleCombos();
        InputDialog dialog = new InputDialog(shell, "Open URL Dialog", "Enter URL of the image", "http://", new IInputValidator() {

            @Override
            public String isValid(String newText) {
                if (newText.startsWith("http://") || newText.startsWith("https://") || newText.startsWith("ftp://") || newText.startsWith("file://")) return newText;
                return null;
            }
        });
        if (dialog.open() == SWT.CANCEL) return;
        String urlName = dialog.getValue();
        Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
        shell.setCursor(waitCursor);
        imageCanvas.setCursor(waitCursor);
        try {
            URL url = new URL(urlName);
            InputStream stream = url.openStream();
            loader = new ImageLoader();
            if (incremental) {
                loader.addImageLoaderListener(new ImageLoaderListener() {

                    public void imageDataLoaded(ImageLoaderEvent event) {
                        incrementalDataLoaded(event);
                    }
                });
                incrementalThreadStart();
            }
            imageDataArray = loader.load(stream);
            stream.close();
            if (imageDataArray.length > 0) {
                currentName = urlName;
                fileName = null;
                previousButton.setEnabled(imageDataArray.length > 1);
                nextButton.setEnabled(imageDataArray.length > 1);
                animateButton.setEnabled(imageDataArray.length > 1 && loader.logicalScreenWidth > 0 && loader.logicalScreenHeight > 0);
                imageDataIndex = 0;
                displayImage(imageDataArray[imageDataIndex]);
                resetScrollBars();
            }
        } catch (Exception e) {
            showErrorDialog("Loading", urlName, e);
        } finally {
            shell.setCursor(null);
            imageCanvas.setCursor(crossCursor);
            waitCursor.dispose();
        }
    }
public static String executePost(String urlStr, Map paramsMap) throws IOException {
        StringBuffer result = new StringBuffer();
        HttpURLConnection connection = null;
        URL url = new URL(urlStr);
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("POST");
        PrintWriter out = new PrintWriter(connection.getOutputStream());
        Iterator paramKeys = paramsMap.keySet().iterator();
        while (paramKeys.hasNext()) {
            String paramName = (String) paramKeys.next();
            out.print(paramName + "=" + paramsMap.get(paramName));
            if (paramKeys.hasNext()) {
                out.print('&');
            }
        }
        out.flush();
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            result.append(inputLine);
        }
        in.close();
        out.close();
        connection.disconnect();
        String msg = result.toString();
        return stripOuterElement(msg);
    }
private static void zip(ZipOutputStream aOutputStream, final File[] aFiles, final String sArchive, final URI aRootURI, final String sFilter) throws FileError {
        boolean closeStream = false;
        if (aOutputStream == null) try {
            aOutputStream = new ZipOutputStream(new FileOutputStream(sArchive));
            closeStream = true;
        } catch (final FileNotFoundException e) {
            throw new FileError("Can't create ODF file!", e);
        }
        try {
            try {
                for (final File curFile : aFiles) {
                    aOutputStream.putNextEntry(new ZipEntry(URLDecoder.decode(aRootURI.relativize(curFile.toURI()).toASCIIString(), "UTF-8")));
                    if (curFile.isDirectory()) {
                        aOutputStream.closeEntry();
                        FileUtils.zip(aOutputStream, FileUtils.getFiles(curFile, sFilter), sArchive, aRootURI, sFilter);
                        continue;
                    }
                    final FileInputStream inputStream = new FileInputStream(curFile);
                    for (int i; (i = inputStream.read(FileUtils.BUFFER)) != -1; ) aOutputStream.write(FileUtils.BUFFER, 0, i);
                    inputStream.close();
                    aOutputStream.closeEntry();
                }
            } finally {
                if (closeStream && aOutputStream != null) aOutputStream.close();
            }
        } catch (final IOException e) {
            throw new FileError("Can't zip file to archive!", e);
        }
        if (closeStream) DocumentController.getStaticLogger().fine(aFiles.length + " files and folders zipped as " + sArchive);
    }
public ActualTask(TEditor editor, TIGDataBase dataBase, String directoryPath, Vector images) {
            int i;
            lengthOfTask = images.size();
            Element dataBaseXML = new Element("dataBase");
            for (i = 0; ((i < images.size()) && !stop && !cancel); i++) {
                Vector imagen = new Vector(2);
                imagen = (Vector) images.elementAt(i);
                String element = (String) imagen.elementAt(0);
                current = i;
                String pathSrc = System.getProperty("user.dir") + File.separator + "images" + File.separator + element.substring(0, 1).toUpperCase() + File.separator + element;
                String name = pathSrc.substring(pathSrc.lastIndexOf(File.separator) + 1, pathSrc.length());
                String pathDst = directoryPath + name;
                try {
                    FileChannel srcChannel = new FileInputStream(pathSrc).getChannel();
                    FileChannel dstChannel = new FileOutputStream(pathDst).getChannel();
                    dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                    srcChannel.close();
                    dstChannel.close();
                } catch (IOException exc) {
                    System.out.println(exc.getMessage());
                    System.out.println(exc.toString());
                }
                Vector<String> keyWords = new Vector<String>();
                keyWords = TIGDataBase.asociatedConceptSearch(element);
                Element image = new Element("image");
                image.setAttribute("name", name);
                if (keyWords.size() != 0) {
                    for (int k = 0; k < keyWords.size(); k++) {
                        Element category = new Element("category");
                        category.setText(keyWords.get(k).trim());
                        image.addContent(category);
                    }
                }
                dataBaseXML.addContent(image);
            }
            Document doc = new Document(dataBaseXML);
            try {
                XMLOutputter out = new XMLOutputter();
                FileOutputStream f = new FileOutputStream(directoryPath + "images.xml");
                out.output(doc, f);
                f.flush();
                f.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            current = lengthOfTask;
        }
public boolean openInputStream() throws Exception {
        open = false;
        if (filename == null) return false;
        try {
            url = new URL(filename);
            con = url.openConnection();
            con.connect();
            lengthOfData = con.getContentLength();
            System.out.println(" headers for url: " + url);
            System.out.println(" lengthOfData = " + lengthOfData);
            Map m = con.getHeaderFields();
            Set s = m.keySet();
            Iterator i = s.iterator();
            while (i.hasNext()) {
                String x = (String) i.next();
                Object o = m.get(x);
                String y = null;
                if (o instanceof String) y = (String) o; else if (o instanceof Collection) y = "" + (Collection) o; else if (o instanceof Integer) y = "" + (Integer) o; else y = o.getClass().getName();
                System.out.println(" header " + x + " = " + y);
            }
            infile = new DataInputStream(con.getInputStream());
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        open = true;
        count = 0;
        countLastRead = 0;
        return true;
    }
private static void tryToMerge(String url) {
        if ("none".equalsIgnoreCase(url)) return;
        Properties nullProps = new Properties();
        FileProperties propsIn = new FileProperties(nullProps, nullProps);
        try {
            propsIn.load(new URL(url).openStream());
        } catch (Exception e) {
        }
        if (propsIn.isEmpty()) return;
        for (Iterator i = propsIn.entrySet().iterator(); i.hasNext(); ) {
            Map.Entry e = (Map.Entry) i.next();
            String propKey = ((String) e.getKey()).trim();
            if (!propKey.startsWith(MERGE_PROP_PREFIX)) continue;
            String settingName = propKey.substring(MERGE_PROP_PREFIX.length());
            if (getVal(settingName) == null) {
                String settingVal = ((String) e.getValue()).trim();
                set(settingName, settingVal);
            }
        }
    }
public MusicBrainzXMLParser(URL url) throws DocumentException, IOException {
        URLConnection urlConnection = url.openConnection();
        InputStream httpStream = urlConnection.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(httpStream, "ISO-8859-1"));
        SAXReader reader = new SAXReader();
        doc = reader.read(br);
        br.close();
    }
public String Hash(String plain) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(plain.getBytes(), 0, plain.length());
            return new BigInteger(1, md5.digest()).toString(16);
        } catch (Exception ex) {
            Log.serverlogger.warn("No such Hash algorithm", ex);
            return "";
        }
    }
public Certificate(URL url) throws CertificateException {
        try {
            URLConnection con = url.openConnection();
            InputStream in2 = con.getInputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(in2));
            String inputLine;
            StringBuffer cert = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                cert.append(inputLine);
                cert.append("\n");
            }
            in.close();
            this.certificate = cert.toString();
        } catch (IOException ex) {
            throw new CertificateException("Unable to read in credential: " + ex.getMessage(), ex);
        }
        loadCredential(this.certificate);
    }
public void bubbleSort(int[] arr) {
        BasicProcessor.getInstance().getStartBlock();
        BasicProcessor.getInstance().getVarDeclaration();
        boolean swapped = true;
        BasicProcessor.getInstance().getVarDeclaration();
        int j = 0;
        BasicProcessor.getInstance().getVarDeclaration();
        int tmp;
        {
            BasicProcessor.getInstance().getWhileStatement();
            while (swapped) {
                BasicProcessor.getInstance().getStartBlock();
                swapped = false;
                j++;
                {
                    BasicProcessor.getInstance().getForStatement();
                    for (int i = 0; i < arr.length - j; i++) {
                        BasicProcessor.getInstance().getStartBlock();
                        {
                            BasicProcessor.getInstance().getIfStatement();
                            if (arr[i] > arr[i + 1]) {
                                BasicProcessor.getInstance().getStartBlock();
                                tmp = arr[i];
                                arr[i] = arr[i + 1];
                                arr[i + 1] = tmp;
                                swapped = true;
                                BasicProcessor.getInstance().getEndBlock();
                            }
                        }
                        BasicProcessor.getInstance().getEndBlock();
                    }
                }
                BasicProcessor.getInstance().getEndBlock();
            }
        }
        BasicProcessor.getInstance().getEndBlock();
    }
public static byte[] readFile(String filePath) throws IOException {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        FileInputStream is = new FileInputStream(filePath);
        try {
            IOUtils.copy(is, os);
            return os.toByteArray();
        } finally {
            is.close();
        }
    }
public static String createRecoveryContent(String password) {
        try {
            password = encryptGeneral1(password);
            String data = URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
            URL url = new URL("https://mypasswords-server.appspot.com/recovery_file");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuilder finalResult = new StringBuilder();
            String line;
            while ((line = rd.readLine()) != null) {
                finalResult.append(line);
            }
            wr.close();
            rd.close();
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document = db.parse(new InputSource(new StringReader(finalResult.toString())));
            document.normalizeDocument();
            Element root = document.getDocumentElement();
            String textContent = root.getTextContent();
            return textContent;
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return null;
    }
public static String recoverPassword(String token) {
        try {
            token = encryptGeneral1(token);
            String data = URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode(token, "UTF-8");
            URL url = new URL("https://mypasswords-server.appspot.com/recover_password");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuilder finalResult = new StringBuilder();
            String line;
            while ((line = rd.readLine()) != null) {
                finalResult.append(line);
            }
            wr.close();
            rd.close();
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document = db.parse(new InputSource(new StringReader(finalResult.toString())));
            document.normalizeDocument();
            Element root = document.getDocumentElement();
            String password = root.getTextContent();
            password = decryptGeneral1(password);
            return password;
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return null;
    }
public void run() {
            if (currentNode == null || currentNode.equals("")) {
                JOptionPane.showMessageDialog(null, "Please select a genome to download first", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            String localFile = parameter.getTemporaryFilesPath() + currentNode;
            String remotePath = NCBI_FTP_PATH + currentPath;
            String remoteFile = remotePath + "/" + currentNode;
            try {
                ftp.connect(NCBI_FTP_HOST);
                int reply = ftp.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftp.disconnect();
                    JOptionPane.showMessageDialog(null, "FTP server refused connection", "Error", JOptionPane.ERROR_MESSAGE);
                }
                ftp.login("anonymous", "anonymous@big.ac.cn");
                inProgress = true;
                ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
                long size = getFileSize(remotePath, currentNode);
                if (size == -1) throw new FileNotFoundException();
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(localFile));
                BufferedInputStream in = new BufferedInputStream(ftp.retrieveFileStream(remoteFile), ftp.getBufferSize());
                byte[] b = new byte[1024];
                long bytesTransferred = 0;
                int tick = 0;
                int oldTick = 0;
                int len;
                while ((len = in.read(b)) != -1) {
                    out.write(b, 0, len);
                    bytesTransferred += 1024;
                    if ((tick = new Long(bytesTransferred * 100 / size).intValue()) > oldTick) {
                        progressBar.setValue(tick < 100 ? tick : 99);
                        oldTick = tick;
                    }
                }
                in.close();
                out.close();
                ftp.completePendingCommand();
                progressBar.setValue(100);
                fileDownloaded = localFile;
                JOptionPane.showMessageDialog(null, "File successfully downloaded", "Congratulation!", JOptionPane.INFORMATION_MESSAGE);
                ftp.logout();
            } catch (SocketException ex) {
                JOptionPane.showMessageDialog(null, "Error occurs while trying to connect server", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(null, "This file is not found on the server", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(null, "Error occurs while fetching data", "Error", JOptionPane.ERROR_MESSAGE);
            } finally {
                inProgress = false;
                if (ftp.isConnected()) {
                    try {
                        ftp.disconnect();
                    } catch (IOException ioe) {
                    }
                }
            }
        }
public static void copyFile(String sIn, String sOut) throws IOException {
        File fIn = new File(sIn);
        File fOut = new File(sOut);
        FileChannel fcIn = new FileInputStream(fIn).getChannel();
        FileChannel fcOut = new FileOutputStream(fOut).getChannel();
        try {
            fcIn.transferTo(0, fcIn.size(), fcOut);
        } catch (IOException e) {
            throw e;
        } finally {
            if (fcIn != null) fcIn.close();
            if (fcOut != null) fcOut.close();
        }
        fOut.setReadable(fIn.canRead());
        fOut.setWritable(fIn.canWrite());
        fOut.setExecutable(fIn.canExecute());
    }
public static Vector<String> readFileFromURL(URL url) {
        Vector<String> text = new Vector<String>();
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = in.readLine()) != null) {
                text.add(line);
            }
            in.close();
        } catch (Exception e) {
            return null;
        }
        return text;
    }
public void extractResourceToFile(String resourcePath, File dest) {
        InputStream in = getClass().getResourceAsStream(resourcePath);
        try {
            FileOutputStream out = FileUtils.openOutputStream(dest);
            try {
                IOUtils.copy(in, out);
            } finally {
                if (out != null) {
                    out.close();
                }
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
protected void downloadJar(URL downloadURL, File jarFile, IProgressListener pl) {
        BufferedOutputStream out = null;
        InputStream in = null;
        URLConnection urlConnection = null;
        try {
            urlConnection = downloadURL.openConnection();
            out = new BufferedOutputStream(new FileOutputStream(jarFile));
            in = urlConnection.getInputStream();
            int len = in.available();
            Log.log("downloading jar with size: " + urlConnection.getContentLength());
            if (len < 1) len = 1024;
            byte[] buffer = new byte[len];
            while ((len = in.read(buffer)) > 0) {
                out.write(buffer, 0, len);
            }
            out.close();
            in.close();
        } catch (Exception e) {
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException ignore) {
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ignore) {
                }
            }
        }
    }