+ Reply to Thread
Results 1 to 7 of 7

Thread: Getting progress of download java

  1. #1
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Getting progress of download java

    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.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Getting progress of download java

    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.

  3. #3
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Re: Getting progress of download java

    Quote Originally Posted by misson View Post
    What line is the exception being thrown on/what's the stack? Where is size set?
    line 18.
    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)
    Line 67 == line 18 in the paste.

    size is set from where I call it, but I removed it for now...

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Getting progress of download java

    Change line 18 to:
    Code:
    out.write(buffer, 0, bytesRead);
    I'm sure you'll realize why and smack yourself in the head.
    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.

  5. #5
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Re: Getting progress of download java

    ah works now. Thanks :D.
    Last edited by galaxyAbstractor; 02-04-2010 at 04:02 AM.

  6. #6
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Re: Getting progress of download java

    Ok that didn't work. If the file was larger than a 32-bit integer can hold it doesn't work...

    I got

    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);
            }
    now... Can I somehow track progress anyways? I could use ftp.retriveFileInputStream() to get an inputstream, but I don't see that leading anywhere?

  7. #7
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Getting progress of download java

    Quote Originally Posted by vigge_sWe View Post
    Ok that didn't work. If the file was larger than a 32-bit integer can hold it doesn't work...
    How big are the files you're downloading? 32 bits for a signed integer gets you up to 2 GiB.

    If size and current are overflowing, try changing them to longs. How are you setting size?
    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.

+ Reply to Thread

Similar Threads

  1. Recieve GET POST data, java?
    By Parsa44 in forum Programming Help
    Replies: 3
    Last Post: 11-29-2009, 02:47 PM
  2. VPS - JAVA JDK Help
    By allofus in forum Programming Help
    Replies: 12
    Last Post: 03-14-2009, 12:09 PM
  3. Internet Download Manager 5.11 build 5
    By duongtata in forum Computers & Technology
    Replies: 6
    Last Post: 09-11-2007, 02:19 PM
  4. Free Software for your Computer
    By Chris S in forum Computers & Technology
    Replies: 48
    Last Post: 04-21-2006, 02:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers