JProgressBar with Sockets anyone?

Hello to everyone

I am trying to create a JProgressBar in order to indicate how much of a file has been transfered via download. Networking operations are handled through the Java Sockets. I assume that i have to set the minimum value of the progress bar to zero (0) and the maximum value has to take the downloaded file's size. This is done easily. What i am interested in, is how to project the bytes received by the Socket's input stream as progress on the bar (Could i read the traffic received in real time and do so?)

I am not sure if the whole idea is correct but if anyone has any suggestions on the topic or a better way of doing so, could you please share your ideas? :-)

Thans to all who might even bother looking into this.

Kind Regards

Christophoros

[801 byte] By [christophorospa] at [2007-11-27 4:01:12]
# 1
Create a class that reads blocks (uses a buffer of lets say 10KB to read data) from the socket, and which notifies listeners each time a block has been read.Kaj
kajbja at 2007-7-12 9:05:54 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi Kaj, do you have in mind where can i find a snippet of such code as i am not quite sure how to do so? Also could i use the buffer i am storing my input stream?

in = socket.getInputStream();

bufferedInput = new BufferedInputStream(in, 64 * 1024);

Kind Regards

Christophoros

christophorospa at 2007-7-12 9:05:54 > top of Java-index,Java Essentials,Java Programming...
# 3

> Hi Kaj, do you have in mind where can i find a

> snippet of such code as i am not quite sure how to do

> so?

Sorry, but no. I don't know where you can find that, but it's pretty easy to do (if you know what to do)

> Also could i use the buffer i am storing my input

> stream?

> > in = socket.getInputStream();

> bufferedInput = new BufferedInputStream(in, 64 *

> 1024);

>

You should call read(byte[]) on the bufferedInputStream, and you know that you have read e.g. 10KB (if the byte[] size is 1024 * 10). Notify any listeners (perform a callback to a registered interface), and then handle the block (write it to disk or whatever you want to do)

Kaj

kajbja at 2007-7-12 9:05:54 > top of Java-index,Java Essentials,Java Programming...
# 4
javx.swing.ProgressMonitorInputStream
ejpa at 2007-7-12 9:05:54 > top of Java-index,Java Essentials,Java Programming...
# 5

EJP, thanks a lot. I think that would do the work.

Does anybody know if there is something similar to javax.swing.ProgressMonitorInputStream

in SWT?

Never mind, i have found it :-)

To anyone who might be interested its ProgressMonitorDialog(Shell parent)

but not sure if it can show the input stream utilization progress

Message was edited by:

christophorosp

christophorospa at 2007-7-12 9:05:54 > top of Java-index,Java Essentials,Java Programming...
# 6
> javx.swing.ProgressMonitorInputStreamCool. Had never seen that class (but it was also a long time ago since I last wrote an application that needed progress information from a stream)
kajbja at 2007-7-12 9:05:54 > top of Java-index,Java Essentials,Java Programming...