Stopping a Thread when downloading

Hi everyone!
I'm develop a app to connect to a FTP Server and dowload and upload files. When I click on Cancel button, the app will still running but the download will stop.
So, my problem is: How can I stop a Thread when i'm donwloading a file?
I'm using Commons Net 3.0.1 to connect from a FTP. I have tried logout(), disconnect(), abort()... Into Threads I have tried interrupt(), yield(), stop(), destroy()... But not works!
The "safe way to stop a Thread" don't work for me, becouse I'm not using a While but yes this line code to download the file:
ftp.retrieveFile(TARGET, SOURCE);
When I click on cancel button the donwload still running in background.
PS: Sorry for my english :)

Problem solved! Using the method retrieveFileStream() and the famous "the safe way to stop a Thread" I can stop it without need to close my app!
The code was (adapted):
OutputStream os;
InputStream is;
localDownload = new FileOutputStream(new File(LOCAL, NOME_ARQUIVO));
os = localDownload;
is = ftp.retrieveFileStream(LOCAL_FTP+NOME_ARQUIVO_FTP);
if(is != null){
     int bytesRead = -1;
     final byte[] buffer = new byte[4096];
     while ((bytesRead = is.read(buffer)) != -1){
          if(cancelado == false)
               os.write(buffer, 0, bytesRead);
          else
               cancelado = false;
is.close();
ftp.completePendingCommand();PS: The method completePendingCommand() is fundamental for the download can be stoped.
Again: sorry for my english :)
Edited by: 866587 on 17/06/2011 09:53

Similar Messages

  • "stopped (error = -34) " when downloading tv show

    I've bought every season of grey's anatomy on itunes so I can watch it on my computer. For some reason there are three specific episodes from season two that won't download. Each time I try a window comes up saying
    "there was a problem downloading "name of show". The disk you are attempting to use is full. Removing files and emptying recycle bin will free up additional space"
    I'm not even trying to use a disk!!!! How do I fix this and get my last 3 shows?

    By "disk" it means your hard drive. A hard drive is a disk.
    Basically, you've run out of room on your hard drive. Your download will not fit. You will need to remove some items before the download can complete.
    Once you've deleted quite a bit of data on your hard drive, you can continue the download by going to Store > Check for Purchased in the iTunes menu bar.

  • Why can I not print out a pdf-file (train ticket NS) when downloaded with Firefox? (file says (SECURED)

    When ordering and paying a train ticket by internet they send a pdf-file, which one must download and print. When downloading this with Firefox (from my e-mail account) the pdf-file says (SECURED) and I cannot print out the ticket (pdf-file). (Adobe program stops automatically).
    When downloading this same pdf-file in Safari, I encounter no problems.

    Current Firefox versions have enabled a built-in PDF Viewer that doesn't have all features that other PDF readers like the Adobe Reader have or may not function properly otherwise.
    You can change the action for Portable Document Format (PDF) from Preview in Firefox to use the Adobe Reader application or set to "Always Ask" in "Firefox > Preferences > Applications".
    *https://support.mozilla.org/kb/change-firefox-behavior-when-open-file
    See also:
    *https://support.mozilla.org/kb/view-pdf-files-firefox-without-downloading-them

  • My iPad has stopped asking for my apple I'd password when downloading apps.  I want it to ask for password because my kids keep downloading apps without asking.  How do I rectify this?

    My apple I'd has stopped asking for my password when downloading apps to my iPad.  I want it to ask every time.  I edited it unknowingly and I need to change it back.  Please help! Thx

    Assuming that you've got the relevant iOS version on the iPad, then you can change it from a 15 minute period during which it doesn't need to be re-entered to immediately via Settings > General > Restrictions > Require Password

  • Mac adds automatically a suffix when downloading a file. How to stop the Mac from doing this?

    I want to download a gps-file for my tomtom navigation system.
    These files have the suffix .itn
    When downloading, OS X transforms the file from filename.itn  to   filename.itn.txt automatically, therefore adds an ".txt", and opens the texteditor with the file.
    I just want OS X to leave the file as it ist and add or do nothing to or with it. Just put it in the download-folder.
    When hiding the suffix with apple-i, the file is no longer readable for the navi system. There ist no option to tell the mac just to do nothing; you just can select a different app. But this is not the solution.
    What can I do?
    Thanks
    Mathias

    Limnos wrote:
    I use a much older version of Safari when I do use it. I have that unchcked but when I download a file Safari just downloads it without any prompt for a file name.  What the OP needs is a way to change how Safari handles downloads so it either identifies them correctly and stops adding the wrong extenion to a file, or a way to edit the file name at download time. My old version doesn't have any apparent way to configure either of these, but I can do it in Firefox.
    What?
    The file has a name prior to downloading, Safari does not ask for one to be added at download time (neither do other browsers), once the file has been downloaded the extension can be corrected.

  • TS1539 How do we deal with Error 50 when downloading a movie rental then stopped with error 50 and when I try to resume the downld, it doesn't do it?

    How do we deal with Error 50 when downloading a movie rental then stopped with error 50 and when I try to resume the downld, it doesn't do it?

    Yeah this "fix" is bunk. The movie is downloading just fine, but the extra features is the one giving me this error code. It is NOT my firewall. If it was, then both files wouldn't download. Plus, I already have the firewall "issue" tacked down and fixed. Have had it fixed for months now. No, this is due to the "new" itunes version 11 software. The only conclusion to fix this issue is UPgrading from 11 back to 10.7 which is what I am going to do. This is completely ridiculous! Come on, Apple, get itunes working once and for all, and fire the people responsible for itunes 11, just like you did to the guy who was responsible for apple maps. Thankfully Google came back to the rescue with google maps app.

  • How do I stop google crome from being added to my computer when downloading Adobe Reader?

    How do I stop google crome from being added to my computer when downloading Adobe Reader?

    By unchecking the box on the download page.
    Or by downloading the offline installer from the FTP site or http://get.adobe.com/reader/enterprise/

  • Hi, on my fathers pc sometimes when downloading multiple tabs start opening and I cannot stop this happening. Could anybody please help me?

    Hi, on my fathers pc sometimes when downloading multiple tabs start opening and I cannot stop this happening. Could anybody please help me? for example, trying to download TomTom Start 25 user manual

    You get that problem if you select the Firefox program to handle a file if you get an "open with" dialog.
    *https://support.mozilla.com/kb/Firefox+keeps+opening+many+tabs+or+windows

  • I have 2 iPads. When downloading an app on one, it also appears on the other. I don't want to create a second iTunes account. How do I stop this?

    I have 2 iPads. When downloading an app on one, it also appears on the other. I don't want to create a second iTunes account. How do I stop this?

    On the device you do not want the auto downloads to be installed on: Settings/iTunes & App Store. Deselect what you do not want to be automatically downloaded.

  • HT1222 Hi Does anyone know how can I stop my iPhone 4s downloading automatic system update so reducing my network speed when plugged in to charge or connected to the pc ??? I'm really ok with my iOS 5.0.1 and I don't need 5.1

    Hi Does anyone know how can I stop my iPhone 4s downloading automatic system update so reducing my network speed when plugged in to charge or connected to the pc ??? I'm really ok with my iOS 5.0.1 and I don't need 5.1

    Setting up and troubleshooting Mail
    http://www.apple.com/support/ipad/assistant/mail/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Try this first - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.)
    Or this - Delete the account in Mail and then set it up again. Settings->Mail, Contacts, Calendars -> Accounts   Tap on the Account, then on the red button that says Remove Account.
     Cheers, Tom

  • HT5485 When downloading itunes 10.7, the download stops at the publishing prompt.  what can I do?

    When downloading itunes 10.7 on my pc, the download stops at the publishing prompt.  What can I do?

    iTunes 10.7 and the iPhone 5 require Mac OS X 10.6.8 or newer. Mac OS X 10.6.8 requires an Intel Mac with at least 1GB of RAM; to get it, click here, buy and install the DVD, and run Software Update.
    (79811)

  • Why my creative cloud icon disappear and stopped working when downloading software?

      Why my creative cloud icon disappear and stopped working when downloading software?

    You can try this step :
    Rename the opm.db file.
    Close the Creative Cloud application if it's running.
    Navigate to the OOBE folder.
    Windows: [System drive]:\Users\[username]\AppData\Local\Adobe\OOBE
    Mac OS: /User/<username>/Library/Application Support/Adobe/OOBE folder
    Rename the opm.db file to opm_old.db
    Launch Creative Cloud
    https://forums.adobe.com/message/5484303#5484303#5484303
    Regards
    Rajshree

  • How do i stop firefox from blocking my taskbar when downloading?

    Every time I download anything using Firefox, the downloads dialogue box blocks use of both my popup taskbar or the side to side scroll bar making me clear the downloads list EVERY TIME I do a download. I hate that the previous version of Firefox did this, and see that no one has bothered to fix this annoying glitch in the new version. It's maddening trying to save large pics as you can't see them until you clear the downloads list.

    The downloads manager is a regular dialog box, unlike the door hanger variety, so you can put it wherever you want it. You can resize it, and the resizing should stick on subsequent usage. You can toggle it on or off anytime with "Ctrl+J", and you have some control when it appears automatically or closes automatically.
    Tools > Options > General > (Downloads section)...
    If you are still using the "Firefox" button introduced in Firefox 4
    "Firefox" button > Options (2nd column) > Options > (Downloads section)...
    Mine is set as follows
    [x] Show the Downloads window when downloading a file
    [_] Close it when all downloads are finished
    I'm on high speed access so if I download something, I'm probably waiting for it so don't mind the window.

  • HT204370 i keep getting stopped (err = -50) when i try downloading movies i just purchased. whenever i resume the download it stops right away

    does anyone else get this error message?

    Hi ..
    Try here >  iTunes Store: "Error (-50)" when downloading purchased content

  • When downloading on my Mac the Adobe Photoshop Lightroom 4

    i got the following error message: "Operation could not be completed (com.apple.installer.pagecontroller error-1)
    Couldn't open "Adobe Photoshop Lghtroom 4.pkg"

    Okay thank you. So will OS X Mountain Lion what I should be buying then?
    Date: Sat, 8 Sep 2012 19:50:39 -0600
    From: [email protected]
    To: [email protected]
    Subject: when downloading on my Mac the Adobe Photoshop Lightroom 4
        Re: when downloading on my Mac the Adobe Photoshop Lightroom 4
        created by John Waller in Photoshop Lightroom - View the full discussion
    Google the error message. http://forums.adobe.com/message/4450305 You are getting this error message because your computer doesn't meet the minimum system requirement. Check the link for tech specs :- http://www.adobe.com/products/photoshop-lightroom/tech-specs.html You need OSX 10.6.8 or later
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4683881#4683881
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4683881#4683881. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Photoshop Lightroom by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

Maybe you are looking for

  • How do I add photos from one iphoto library to another library

    I own 2 macs and want to take the photos from one library and add them to a different library on a different Mac.  How do I do it?  I've copied the iphoto library from computer 1 to computer 2 but haven't yet done anything with the file.

  • Oracle 9.2.0.6 , JDK 5 and JDBC driver

    Hi Friends, At my work place they have Oracle 9.2.0.6 and now they want to user JDK 5. I find that JDBC driver only supports JDK 1.4. Can some one suggest what I need to do so that later I should not face unknown issues Thx V

  • ORA-20100: ORA-01116: error in opening database file

    Hi - I'm hitting this error for the first time. Anyone encountered this before? Any suggestions will be very appreciated. Thanks! 141 EXCEPTION 142 143 when others then 144 raise_application_error('-20100',SQLERRM); 145 End; 146 / 20080207 20080312 D

  • Srvctl stop

    Hi All, I have an interesting one here: I created a 10.2.0.4 2 node RAC database on Win2003 R2 SP2 from a backup of our PROD system and the creation went fine. If I issue a srvctl stop database -d SYNPROD_NY the database comes down fine ane everythin

  • Moving Abroad - Power cord question

    Hi, I have recently moved to Spain and my lovely iMac arrived shortly after me yesterday. And to be honest I've just realised that it won't be as simple as just changing the plug to use power outlets here. What is my best course of action? Is it OK t