commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: [net]
Date Wed, 06 Oct 2010 14:49:58 GMT
Hash: SHA1


On 10/5/2010 10:48 PM, Pablo Pinto wrote:
> I'm using the FTP API and I need to use a limited bandwidth.
> The following code works pretty good except for one problem. At
> the beginning of the transference the program buffers 64KB of data using all
> the available bandwidth. After that I can control the bandwidth.
> OutputStream outputStream = new FileOutputStream(localFile);
> InputStream inputStream = client.retrieveFileStream(remoteFile);

What type of InputStream are you getting back from
client.retrieveFileStream? Maybe you can cast it to it's real type and
call a method like setBufferSize?

> byte buf[] = new byte[bufferSize];

What is the value of bufferSize?

> int bytesRead =;
> while (bytesRead != -1)
> {
> outputStream.write(buf, 0, bytesRead);
> Thread.sleep(delay);

You could make this smarter by timing the entire transaction and
adjusting the sleep delay to attempt to achieve a specific bandwidth target.

> bytesRead =;

Might I suggest a shorter loop?

int bytesRead;
while (-1 != (bytesRead !=
  outputStream.write(buf, 0, bytesRead);
  // sleep logic

inputStream.close(); // probably should be in a finally block

> Is it possible to decrease the amount of data that is buffered at the
> begining?

That's up to the InputStream implementation provided by the "client" object.

- -chris
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message