Barra de Progresso com Download de FTP

0 respostas
javer

Alguém teria um exemplo de como mostrar uma barra de progresso a fazer a leitura de um arquivo em um servidor FTP?

Eu já tenho ele funcionando mas tem arquivo muito grande (20 mil linhas) que precisa que o usuário acompanhe o download (na verdade é a leitura de linha a linha do arquivo) e preciso mostrar o progresso numa AsyncTask.

No momento eu mostro uma ProgressBar somente dizendo pra ele aguardar.

Estou usando o Apache Commons Net para o download/upload no FTP.
public ArrayList<String> lerArquivo(String arquivo) throws IOException {
		ArrayList<String> rows = new ArrayList<String>();
		boolean connected = isFtpConnected();

		if (connected) {
			mFTPClient.setBufferSize(1024 * 1024);
			InputStream stream = mFTPClient.retrieveFileStream(arquivo.toUpperCase());
			if (stream != null) {
				Scanner fileScanner = new Scanner(new InputStreamReader(stream));
				while (fileScanner.hasNextLine()) {
					String rowContent = fileScanner.nextLine();
					rows.add(rowContent);
				}
				fileScanner.close();
			}

			if (mFTPClient != null) {
				mFTPClient.logout();
				mFTPClient.disconnect();
			}
		}

		return rows;
	}
Na minha task:
...
		@Override
		protected Integer doInBackground(String... params) {
			if (bean.trim().equals("")) {
				bean = params[0];
			}
			String file = "USERS.TXT";
			int total = 0;
			try {
				FtpServerUtil ftp = new FtpServerUtil();
				ArrayList<String> fileRows = ftp.lerArquivo(file);
				total = insertRecords(bean, fileRows);
			} catch (IOException e) {
				Log.e(Const.TAG, "Lendo arquivo no FTP", e);
			}

			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					Log.i(Const.TAG, "Na UI...");
				}
			});
			return total;
		}
Criado 17 de abril de 2015
Respostas 0
Participantes 1