I have a SwingWorker where I download a file using FTP. It writes the data to an output stream. How can I track how much data has been downloaded so I can update a progress bar?
Why would http://pastebin.com/me89f548 not work (IndexOutOfBounds)
I have a SwingWorker where I download a file using FTP. It writes the data to an output stream. How can I track how much data has been downloaded so I can update a progress bar?
Why would http://pastebin.com/me89f548 not work (IndexOutOfBounds)
Last edited by galaxyAbstractor; 02-03-2010 at 02:21 PM.
What line is the exception being thrown on/what's the stack? Where is size set?
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
line 18.Line 67 == line 18 in the paste.2010-feb-03 21:59:11 simpleide.DownloadThread downloadFile
ALLVARLIG: null
java.lang.IndexOutOfBoundsException
at java.io.ByteArrayOutputStream.write(ByteArrayOutpu tStream.java:8
at simpleide.DownloadThread.downloadFile(DownloadThre ad.java:67)
at simpleide.DownloadThread.doInBackground(DownloadTh read.java:44)
at simpleide.DownloadThread.doInBackground(DownloadTh read.java:21)
at javax.swing.SwingWorker$1.call(SwingWorker.java:27
at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:13
at javax.swing.SwingWorker.run(SwingWorker.java:317)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:90
at java.lang.Thread.run(Thread.java:619)
size is set from where I call it, but I removed it for now...
Change line 18 to:
I'm sure you'll realize why and smack yourself in the head.Code:out.write(buffer, 0, bytesRead);
Last edited by misson; 02-03-2010 at 05:15 PM.
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
Ok that didn't work. If the file was larger than a 32-bit integer can hold it doesn't work...
I got
now... Can I somehow track progress anyways? I could use ftp.retriveFileInputStream() to get an inputstream, but I don't see that leading anywhere?Code:try { Main.bar.setIndeterminate(true); FileOutputStream out = new FileOutputStream(new File(localFile)); ftp.connect(host, port); ftp.login(username, password); ftp.retrieveFile(file, out); Main.bar.setIndeterminate(false); } catch (Exception ex) { Logger.getLogger(DownloadThread.class.getName()).log(Level.SEVERE, null, ex); }
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.