semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void get(String path, File fileToGet) throws IOException {
        FTPClient ftp = new FTPClient();
        try {
            int reply = 0;
            ftp.connect(this.endpointURL, this.endpointPort);
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("Ftp get server refused connection.");
            }
            if (!ftp.login("anonymous", "")) {
                ftp.logout();
                throw new IOException("FTP: server wrong passwd");
            }
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ftp.enterLocalPassiveMode();
            OutputStream output = new FileOutputStream(fileToGet.getName());
            if (ftp.retrieveFile(path, output) != true) {
                ftp.logout();
                output.close();
                throw new IOException("FTP get exception, maybe file not found");
            }
            ftp.logout();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }
public void delete(String fileToDelete) throws IOException {
        FTPClient ftp = new FTPClient();
        try {
            int reply = 0;
            ftp.connect(this.endpointURL, this.endpointPort);
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("Ftp delete server refused connection.");
            }
            if (!ftp.login("anonymous", "")) {
                ftp.logout();
                throw new IOException("FTP: server wrong passwd");
            }
            ftp.enterLocalPassiveMode();
            log.debug("Deleted: " + ftp.deleteFile(fileToDelete));
            ftp.logout();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }
public int exists(String fileToCheck) throws IOException {
        FTPClient ftp = new FTPClient();
        int found = 0;
        try {
            int reply = 0;
            ftp.connect(this.endpointURL, this.endpointPort);
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("Ftp exists server refused connection.");
            }
            if (!ftp.login("anonymous", "")) {
                ftp.logout();
                throw new IOException("FTP: server wrong passwd");
            }
            ftp.enterLocalPassiveMode();
            if (ftp.listNames(fileToCheck) != null) {
                found = 1;
            }
            ftp.logout();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
        return found;
    }
public void run() {
                        try {
                            HttpPost httpPostRequest = new HttpPost(Feesh.device_URL);
                            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                            nameValuePairs.add(new BasicNameValuePair("c", "feed"));
                            nameValuePairs.add(new BasicNameValuePair("amount", String.valueOf(foodAmount)));
                            nameValuePairs.add(new BasicNameValuePair("type", String.valueOf(foodType)));
                            httpPostRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                            HttpResponse httpResponse = (HttpResponse) new DefaultHttpClient().execute(httpPostRequest);
                            HttpEntity entity = httpResponse.getEntity();
                            String resultString = "";
                            if (entity != null) {
                                InputStream instream = entity.getContent();
                                resultString = convertStreamToString(instream);
                                instream.close();
                            }
                            Message msg_toast = new Message();
                            msg_toast.obj = resultString;
                            toast_handler.sendMessage(msg_toast);
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        } catch (ClientProtocolException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
private static JSONObject sendCouchRequest(HttpUriRequest request) {
        try {
            HttpResponse httpResponse = (HttpResponse) new DefaultHttpClient().execute(request);
            HttpEntity entity = httpResponse.getEntity();
            if (entity != null) {
                InputStream instream = entity.getContent();
                String resultString = convertStreamToString(instream);
                instream.close();
                JSONObject jsonResult = new JSONObject(resultString);
                return jsonResult;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
public static void main(String[] args) throws IOException, WrongFormatException, URISyntaxException {
        System.out.println(new URI("google.com.ua.css").toString());
        Scanner scc = new Scanner(System.in);
        System.err.print(scc.nextLine().substring(1));
        ServerSocket s = new ServerSocket(5354);
        while (true) {
            Socket client = s.accept();
            InputStream iStream = client.getInputStream();
            BufferedReader bf = new BufferedReader(new InputStreamReader(iStream));
            String line = "";
            while (!(line = bf.readLine()).equals("")) {
                System.out.println(line);
            }
            System.out.println("end of request");
            new PrintWriter(client.getOutputStream()).println("hi");
            bf.close();
        }
    }
public boolean connect() {
        boolean isConnected = false;
        try {
            try {
                this.ftpClient.connect(this.server, this.port);
            } catch (SocketException e) {
                status = ErrorResult.CONNECTNOTPOSSIBLE.code;
                return false;
            } catch (IOException e) {
                status = ErrorResult.CONNECTNOTPOSSIBLE.code;
                return false;
            }
            int reply = this.ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                this.disconnect();
                status = ErrorResult.CONNECTNOTCORRECT.code;
                return false;
            }
            try {
                if (this.account == null) {
                    if (!this.ftpClient.login(this.username, this.passwd)) {
                        status = ErrorResult.LOGINNOTCORRECT.code;
                        this.ftpClient.logout();
                        return false;
                    }
                } else if (!this.ftpClient.login(this.username, this.passwd, this.account)) {
                    status = ErrorResult.LOGINACCTNOTCORRECT.code;
                    this.ftpClient.logout();
                    return false;
                }
            } catch (IOException e) {
                status = ErrorResult.ERRORWHILECONNECT.code;
                try {
                    this.ftpClient.logout();
                } catch (IOException e1) {
                }
                return false;
            }
            isConnected = true;
            return true;
        } finally {
            if ((!isConnected) && this.ftpClient.isConnected()) {
                this.disconnect();
            }
        }
    }
public static void copy(File from_file, File to_file) throws IOException {
        from_file = checkFile(from_file);
        if (to_file.isDirectory()) to_file = new File(to_file, from_file.getName());
        if (to_file.exists()) {
            if (!to_file.canWrite()) abort("FileCopy: destination file is unwriteable: " + to_file.getName());
        } else {
            String parent = to_file.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) abort("FileCopy: destination directory doesn't exist: " + parent);
            if (dir.isFile()) abort("FileCopy: destination is not a directory: " + parent);
            if (!dir.canWrite()) abort("FileCopy: destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(from_file);
            to = new FileOutputStream(to_file);
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) {
                to.write(buffer, 0, bytes_read);
            }
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
            }
        }
    }
public static void fileCopy(String fromPath, String toPath) throws IOException {
        File inputFile = new File(fromPath);
        File outputFile = new File(toPath);
        FileReader in = new FileReader(inputFile);
        FileWriter out = new FileWriter(outputFile);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
    }
public static void copyFile(File src, File dst) throws IOException {
        try {
            InputStream in = new FileInputStream(src);
            OutputStream out = new FileOutputStream(dst);
            byte[] buf = new byte[TEMP_FILE_BUFFER_SIZE];
            int len;
            while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            in.close();
            out.close();
        } catch (FileNotFoundException e1) {
            MLUtil.runtimeError(e1, src.toString());
        } catch (IOException e2) {
            MLUtil.runtimeError(e2, src.toString());
        }
    }
public void actualizar() throws SQLException, ClassNotFoundException, Exception {
        Connection conn = null;
        PreparedStatement ms = null;
        registroActualizado = false;
        try {
            conn = ToolsBD.getConn();
            conn.setAutoCommit(false);
            Date fechaSystem = new Date();
            DateFormat aaaammdd = new SimpleDateFormat("yyyyMMdd");
            int fzafsis = Integer.parseInt(aaaammdd.format(fechaSystem));
            DateFormat hhmmss = new SimpleDateFormat("HHmmss");
            DateFormat sss = new SimpleDateFormat("S");
            String ss = sss.format(fechaSystem);
            if (ss.length() > 2) {
                ss = ss.substring(0, 2);
            }
            int fzahsis = Integer.parseInt(hhmmss.format(fechaSystem) + ss);
            ms = conn.prepareStatement(SENTENCIA_UPDATE);
            ms.setString(1, descartadoEntrada);
            ms.setString(2, usuarioEntrada);
            ms.setString(3, motivosDescarteEntrada);
            ms.setInt(4, Integer.parseInt(anoOficio));
            ms.setInt(5, Integer.parseInt(oficinaOficio));
            ms.setInt(6, Integer.parseInt(numeroOficio));
            ms.setInt(7, anoEntrada != null ? Integer.parseInt(anoEntrada) : 0);
            ms.setInt(8, oficinaEntrada != null ? Integer.parseInt(oficinaEntrada) : 0);
            ms.setInt(9, numeroEntrada != null ? Integer.parseInt(numeroEntrada) : 0);
            int afectados = ms.executeUpdate();
            if (afectados > 0) {
                registroActualizado = true;
            } else {
                registroActualizado = false;
            }
            conn.commit();
        } catch (Exception ex) {
            System.out.println("Error inesperat, no s'ha desat el registre: " + ex.getMessage());
            ex.printStackTrace();
            registroActualizado = false;
            errores.put("", "Error inesperat, no s'ha desat el registre" + ": " + ex.getClass() + "->" + ex.getMessage());
            try {
                if (conn != null) conn.rollback();
            } catch (SQLException sqle) {
                throw new RemoteException("S'ha produït un error i no s'han pogut tornar enrere els canvis efectuats", sqle);
            }
            throw new RemoteException("Error inesperat, no s'ha modifcat el registre", ex);
        } finally {
            ToolsBD.closeConn(conn, ms, null);
        }
    }
private void removeSessionId(InputStream inputStream, Output output) throws IOException {
        String jsessionid = RewriteUtils.getSessionId(target);
        boolean textContentType = ResourceUtils.isTextContentType(httpClientResponse.getHeader("Content-Type"));
        if (jsessionid == null || !textContentType) {
            IOUtils.copy(inputStream, output.getOutputStream());
        } else {
            String charset = httpClientResponse.getContentCharset();
            if (charset == null) {
                charset = "ISO-8859-1";
            }
            String content = IOUtils.toString(inputStream, charset);
            content = removeSessionId(jsessionid, content);
            if (output.getHeader("Content-length") != null) {
                output.setHeader("Content-length", Integer.toString(content.length()));
            }
            OutputStream outputStream = output.getOutputStream();
            IOUtils.write(content, outputStream, charset);
        }
        inputStream.close();
    }
private Document saveFile(Document document, File file) throws Exception {
        List<Preference> preferences = prefService.findAll();
        if (preferences != null && !preferences.isEmpty()) {
            preference = preferences.get(0);
        }
        SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATEFORMAT_YYYYMMDD);
        String repo = preference.getRepository();
        Calendar calendar = Calendar.getInstance();
        StringBuffer sbRepo = new StringBuffer(repo);
        sbRepo.append(File.separator);
        StringBuffer sbFolder = new StringBuffer(sdf.format(calendar.getTime()));
        sbFolder.append(File.separator).append(calendar.get(Calendar.HOUR_OF_DAY));
        File folder = new File(sbRepo.append(sbFolder).toString());
        if (!folder.exists()) {
            folder.mkdirs();
        }
        FileChannel fcSource = null, fcDest = null;
        try {
            StringBuffer sbFile = new StringBuffer(folder.getAbsolutePath());
            StringBuffer fname = new StringBuffer(document.getId().toString());
            fname.append(".").append(document.getExt());
            sbFile.append(File.separator).append(fname);
            fcSource = new FileInputStream(file).getChannel();
            fcDest = new FileOutputStream(sbFile.toString()).getChannel();
            fcDest.transferFrom(fcSource, 0, fcSource.size());
            document.setLocation(sbFolder.toString());
            documentService.save(document);
        } catch (FileNotFoundException notFoundEx) {
            log.error("saveFile file not found: " + document.getName(), notFoundEx);
        } catch (IOException ioEx) {
            log.error("saveFile IOException: " + document.getName(), ioEx);
        } finally {
            try {
                if (fcSource != null) {
                    fcSource.close();
                }
                if (fcDest != null) {
                    fcDest.close();
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
        return document;
    }
@Override
    protected String doInBackground(Void... params) {
        try {
            HttpGet request = new HttpGet(UPDATE_URL);
            request.setHeader("Accept", "text/plain");
            HttpResponse response = MyMovies.getHttpClient().execute(request);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode != HttpStatus.SC_OK) {
                return "Error: Failed getting update notes";
            }
            return EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }
boolean isTextPage(URL url) {
        try {
            String ct = url.openConnection().getContentType().toLowerCase();
            String s = url.toString();
            Loro.log("LoroEDI: " + "  content-type: " + ct);
            if (!ct.startsWith("text/") || s.endsWith(".jar") || s.endsWith(".lar")) {
                javax.swing.JOptionPane.showOptionDialog(null, Str.get("gui.1_browser_cannot_show_link", s), "", javax.swing.JOptionPane.DEFAULT_OPTION, javax.swing.JOptionPane.WARNING_MESSAGE, null, null, null);
                Loro.log("LoroEDI: " + "  unable to display");
                return false;
            }
        } catch (Exception ex) {
            Loro.log("LoroEDI: " + "  Exception: " + ex.getMessage());
            return false;
        }
        return true;
    }
public static File getFileFromURL(URL url) {
        File tempFile;
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {
            String tempDir = System.getProperty("java.io.tmpdir", ".");
            tempFile = File.createTempFile("xxindex", ".tmp", new File(tempDir));
            tempFile.deleteOnExit();
            InputStream is = url.openStream();
            in = new BufferedInputStream(is);
            FileOutputStream fos = new FileOutputStream(tempFile);
            out = new BufferedOutputStream(fos);
            byte[] b = new byte[1];
            while (in.read(b) >= 0) {
                out.write(b);
            }
            logger.debug(url + " written to local file " + tempFile.getAbsolutePath());
        } catch (IOException e) {
            throw new IllegalStateException("Could not create local file for URL: " + url, e);
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
            }
        }
        return tempFile;
    }
protected static void upload(FtpSiteConnector connector, File localFile, String remotePath, boolean createRootDir, IProgressMonitor monitor) throws FtpException {
        FTPClient ftp = new FTPClient();
        try {
            String hostname = connector.getUrl().getHost();
            ftp.connect(hostname);
            log.info("Connected to " + hostname);
            log.info(ftp.getReplyString());
            boolean loggedIn = ftp.login(connector.getUsername(), connector.getPassword());
            if (loggedIn) {
                log.info("User " + connector.getUsername() + " logged in");
                ftp.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
                ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
                ftp.enterLocalPassiveMode();
                FtpUtils.store(ftp, localFile, remotePath, createRootDir, monitor);
                ftp.logout();
            } else {
                throw new FtpException("Invalid login");
            }
            ftp.disconnect();
        } catch (Exception e) {
            log.error("File upload failed with message: " + e.getMessage());
            throw new FtpException("File upload failed with message: " + e.getMessage());
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException ioe) {
                    throw new FtpException("File upload failed with message: " + ioe.getMessage());
                }
            }
        }
    }
public boolean updateCalculatedHand(CalculateTransferObject query, BasicStartingHandTransferObject[] hands) throws CalculateDAOException {
        boolean retval = false;
        Connection connection = null;
        Statement statement = null;
        PreparedStatement prep = null;
        ResultSet result = null;
        StringBuffer sql = new StringBuffer(SELECT_ID_SQL);
        sql.append(appendQuery(query));
        try {
            connection = getDataSource().getConnection();
            connection.setAutoCommit(false);
            statement = connection.createStatement();
            result = statement.executeQuery(sql.toString());
            if (result.first()) {
                String id = result.getString("id");
                prep = connection.prepareStatement(UPDATE_HANDS_SQL);
                for (int i = 0; i < hands.length; i++) {
                    prep.setInt(1, hands[i].getWins());
                    prep.setInt(2, hands[i].getLoses());
                    prep.setInt(3, hands[i].getDraws());
                    prep.setString(4, id);
                    prep.setString(5, hands[i].getHand());
                    if (prep.executeUpdate() != 1) {
                        throw new SQLException("updated too many records in calculatehands, " + id + "-" + hands[i].getHand());
                    }
                }
                connection.commit();
            }
        } catch (SQLException sqle) {
            try {
                connection.rollback();
            } catch (SQLException e) {
                e.setNextException(sqle);
                throw new CalculateDAOException(e);
            }
            throw new CalculateDAOException(sqle);
        } finally {
            if (result != null) {
                try {
                    result.close();
                } catch (SQLException e) {
                    throw new CalculateDAOException(e);
                }
            }
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException e) {
                    throw new CalculateDAOException(e);
                }
            }
            if (prep != null) {
                try {
                    prep.close();
                } catch (SQLException e) {
                    throw new CalculateDAOException(e);
                }
            }
        }
        return retval;
    }
private String hashPassword(String password) {
        String passwordHash = "";
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(password.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            passwordHash = hash.toString(16);
            if (passwordHash.length() == 31) {
                passwordHash = "0" + passwordHash;
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return passwordHash;
    }
private ResponseStatus performHandshake(String url) throws IOException {
        HttpURLConnection connection = Caller.getInstance().openConnection(url);
        InputStream is = connection.getInputStream();
        BufferedReader r = new BufferedReader(new InputStreamReader(is));
        String status = r.readLine();
        int statusCode = ResponseStatus.codeForStatus(status);
        ResponseStatus responseStatus;
        if (statusCode == ResponseStatus.OK) {
            this.sessionId = r.readLine();
            this.nowPlayingUrl = r.readLine();
            this.submissionUrl = r.readLine();
            responseStatus = new ResponseStatus(statusCode);
        } else if (statusCode == ResponseStatus.FAILED) {
            responseStatus = new ResponseStatus(statusCode, status.substring(status.indexOf(' ') + 1));
        } else {
            return new ResponseStatus(statusCode);
        }
        r.close();
        return responseStatus;
    }