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
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
> 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
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