Olá todos
Voltando ao forum gostaria de sugerir que ficasse como padrão uma pequena modificação que fiz na classe FTP. Esta classe tem um atributo que é o ProgressInformation, mas esse atributo só mostra quanto foi transferido do arquivo e não a porcentagem da transferência. Fiz uma pequena modificação no método receiveFile da classe FTP. Eu passo mais um parâmetro (um objeto ProgressBar) para que este me mostre a porcentagen da transferência do arquivo. Abaixo segue a modificação que fiz e fica aqui a sugestão para torna-la padrão.
public int receiveFile(String pathName, Stream outputStream, ProgressBar pbar)
throws FTPConnectionClosedException, totalcross.io.IOException,
InvalidNumberException {
if (pathName == null)
throw new NullPointerException(
"Argument 'pathName' cannot have a null value.");
if (outputStream == null)
throw new NullPointerException(
"Argument 'outputStream' cannot have a null value.");
setType(BINARY);
Socket socket = openReturningPath(true);
//Kalil Maciel
String fsize = sendCommand("SIZE ", pathName, COMPLETED);
int fileSize = Convert.toInt(Convert.tokenizeString(fsize, " ")[1]);
sendCommand("RETR ", pathName, WAITING_FOR_REPLY);
int count;
int total = 0;
log("0 bytes received");
if (progressInfo != null)
progressInfo.transfering(0);
int tries = 3;
if (buffer == null)
buffer = new byte[2048];
while ((count = socket.readBytes(buffer)) >= 0) // guich@561_8: != -1 ->
// > 0
{
if (count > 0) {
tries = 3;
total += count;
logReplace(total + " bytes received");
if (progressInfo != null)
progressInfo.transfering(total);
outputStream.writeBytes(buffer, 0, count);
pbar.setValue((total*100)/fileSize); //KalilMaciel
} else if (tries-- == 0) {
try {
checkResponse(COMPLETED);
break;
} catch (totalcross.io.IOException e) {
log("Cannot read from server.|Received " + total
+ " bytes. Error: " + e.getMessage());
throw e;
}
}
}
socket.close();
return total;
}
Até mais galera
