Why read() doesn't read?

Hi!
Please check out the code piece:
URL aurl = new URL("http://somesite.com/mypic.jpg");
URLConnection uc = aurl.openConnection();
uc.connect();
BufferedInputStream bis = new BufferedInputStream(uc.getInputStream());
File f = new File("mypiccopy.jpg");
FileOutputStream fos = new FileOutputStream(f);
//now comes the hard part:
int avail = 1;
byte mybyte;
while(avail > 0) {
    avail = bis.available(); //..does return the num of available bytes
    mybyte = new byte[avail];
    bis.read(mybyte,0,avail); //..is supposed to read from buffer
    fos.write(mybyte); //..is supposed to write to the file
fos.close();
bis.close();It does return the available number of bytes, but never reades or writes anything. The size of the file will be 0.
What's wrong??

But the code is still bad!
Having added the outputting line slowed the program down so that there always was some input available within every exceution of the loop - but that is only by chance!
If once the connection was slower than your client -maybe due to some network problem- , avail would get set to 0 and your loop would get prematruely terminated.
The point is that available() "returns the number of bytes that can be read from this input stream without blocking"
and you might need blocking (like when you try to read more bytes than available) form the channel.

Similar Messages

  • I have just started shooting Raw.  Why IPhoto doesn't read my RAW files?

    I have a Mac OS X - 10.6.8.  Processor 3.06 GHz Intel Core 2 Duo.  Memory 4Go 1067 MHz DDR3.  IPhoto '09.
    I have started shooting RAW and IPhoto doesn't read my the RAW files?

    Lightroom 1.4.1 does not support native (NEF) files from the D700 because the camera didn't even exist when it was released. To get support you have two options: upgrade to Lr 2.x (paid for upgrade) or convert your NEF files to DNG.
    DNG converter 5.4 can be downloaded from http://www.adobe.com/downloads/ (see right hand side of page)

  • Why Firefox doesn't read keyboard input properly on Windows when chained deadkeys are involved?

    I'm trying to customize my keyboard layout on Windows. I have finally installed my new layout. However some of key combinations doesn't work on some applications. One of them is Firefox. It seems it doesn't handle chained deadkeys. And for some reason RightAlt + Q which sould produce "\" produces some wierd combination – this parcitual wierd issue is specific to Firefox. I can send an installer of the keyboard.
    Thank you for help

    Hello,
    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information. <br>
    '''Note''': ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • Why doesn't Reader 10.1.8 open on Vista?

    I have Vista Home Premium with Service Pack 2.  The Adobe site directs me to Acrobat 10.1.4 to download on this system.  I successfully download and the installation works fine.  Within a few days the autoupdate feature appears to upgrade to version 10.1.8, afterwhich Reader will not load.  I have tried to open Reader from the program listing and by double clicking on existing pdf files.  In all cases, I get the cursor "working" circle for a second or two, followed by nothing.  Trying again gets the same response.  Checking the Task Manager, I see multiple Adobe processes running, but no Adobe on the applications list.  If I uninstall 10.1.8 and download 10.1.4 again from the Adobe site, it works fine for a while, until the 10.1.8 auto update installs.  I do not see a way to turn off the auto update.
    Any suggestions?

    Some things to try...
    Using Windows Explorer navigate to C:\Program Files (x86)\Adobe\Reader 10.0\Reader, then double-click on Eula.exe and accept the license agreement
    Can you open Adobe Reader by itself?  If so, try disabling Protected Mode [Edit | Preferences | Security (Enhanced)].
    If you cannot open Reader by itself, try to disable Protected Mode in the registry; download, unzip, then run the attached registry script
    It could even be a malware issue; see http://helpx.adobe.com/acrobat/kb/reader-core-dll-error.html

  • K9N Platinum doesn't read SPD correctly

    K9N Platinum doesn't read SPD correctly. When i put any RAM to my computer and set timings to auto it always set timing to 5-6-5-15 ignoring SPD on RAM/RAMs.
    Is it only my board problem? or all K9N Platinums?
    I have 601-7250-020....
    i use 1.5 bios,and i am going to update to 1.6 today.

    Yes you are right: http://www.corsairmemory.com/corsair/products/specs/TWIN2X2048-5400C4.pdf
    However, MSI could change something in the BIOS to make your memory work properly.
    As the Jdec standard is Intel system testing only (if I'm not mistaken) it could well be that the AMD CPU can't work with those values, so it ups them a little.
    Don't forget, Intel uses "CPU -> Chipset -> Memory", but AMD uses "CPU -> Memory"
    The only one that can answer this is Corsair, so I suggest you ask them why the SPD is different on AMD's.
    They know that, we don't.
    But it's not strange that AMD's have higher timings.
    In any case, it has nothing to do with the board, as the AMD's have an in-CPU memory controller! Intels do not have this.

  • How can I synchronize my iPhoto events? my iTunes doesn't read them and with the app Images in the iPad I can only find Photos, Albums, Faces and Places, not Events.

    How can I synchronize my iPhoto events? my iTunes doesn't read them and with the app Images in the iPad I can only find Photos, Albums, Faces and Places, not Events.

    I had a problem a couple of months ago when iPhotos suddenly rearranged the order of my Events (Why won't iPhoto let me arrange my photos?) .  I was told "Use albums not events - events are not a good way to organize - albums and folder are designed for organisation and are very flexible".
    Haha!  I should have paid attention and read between the lines!  My iPhotos were highly organised groupings - not according to date but the way I wanted them - and it was so easy to do!  I see now that if I had them all in albums, as per the Apple Apologist suggestion, I wouldn't have this unholy mess I have been left with just to make iPhone & iCloud users happy.  I am now going through Photos and making Albums (of what used to be in my Events)  ... maybe I'll get this finished before they do another non user friendly update!

  • Why can't I read or send messages on my IPad ?

    Why Can't I read or send my messages on my I Pad?

    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
    http://tinyurl.com/a7odey8
    Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268
    iOS: FaceTime is 'Unable to verify email because it is in use'
    http://support.apple.com/kb/TS3510
    Using FaceTime and iMessage behind a firewall
    http://support.apple.com/kb/HT4245
    iOS: About Messages
    http://support.apple.com/kb/HT3529
    Set up iMessage
    http://www.apple.com/ca/ios/messages/
    iOS 6 and OS X Mountain Lion: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538
    How to Set Up & Use iMessage on iPhone, iPad, & iPod touch with iOS
    http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/
    Troubleshooting Messages
    http://support.apple.com/kb/TS2755
    Troubleshooting iMessage Issues: Some Useful Tips You Should Try
    http://www.igeeksblog.com/troubleshooting-imessage-issues/
    Setting Up Multiple iOS Devices for iMessage and Facetime
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    FaceTime and iMessage not accepting Apple ID password
    http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
    FaceTime, Game Center, Messages: Troubleshooting sign in issues
    http://support.apple.com/kb/TS3970
    Unable to use FaceTime and iMessage with my apple ID
    https://discussions.apple.com/thread/4649373?tstart=90
    How to Block Someone on FaceTime
    http://www.ehow.com/how_10033185_block-someone-facetime.html
    My Facetime Doesn't Ring
    https://discussions.apple.com/message/19087457
    Send an iMessage as a Text Message Instead with a Quick Tap & Hold
    http://osxdaily.com/2012/11/18/send-imessage-as-text-message/
    To send messages to non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
    How to Send SMS from iPad
    http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
    You can check the status of the FaceTime/iMessage servers at this link.
    http://www.apple.com/support/systemstatus/
     Cheers, Tom

  • Why does my Adobe Reader (10.1.3) freeze-up when I down load statements from some websites?

    Why does my Adobe Reader (10.1.3) freeze-up when I down load statements from some websites?
    When I down load statements from some websites, the pdf freezes and I get a message that the website is not responding and that windows is checking for a solution for this problem. I have uninstalled and reinstalled many times. I really like the Adobe Reader, but I need answers on why this is happening and how to fix it. AN AUTOMATIC UPDATE FROM 08/23/11 DOESN’T CUT IT!!

    Acrobat Cleaner Tool
    Mylenium

  • Doesn't read all?! - "PERFECT TEXTAREA"

    If you can remember, I had the problem, that I needed a TextArea without Border - I have had some time and so I developped this: - it's an Applet, which reads from a txt file - and saves it to a normal TextArea - then it reads from the TextArea and creates one ( Graphics g), which doesn't have any border - the only problem is, that this code doesn't read all of the TextArea - only the first (approximatly 20 letters) . then it stops and I don't know why ... I hope you may help me :)
    Thx Quaxi
    import java.awt.*;
    import java.applet.*;
    import java.io.*;
    import java.net.*;
    public class Main extends Applet
    TextArea Start= new TextArea();
    String Datei=new String();
    int Anfang;
    int Ende;
    public void init()
         Start.setSize(10,10);
         Start.setLocation(130,30);
         Start.setVisible(false);
         Start.setEditable(false);
         Start.setEnabled(false);
         add(Start);
         this.setBackground(new Color(30,30,90));
              this.setForeground(Color.white);
         Lesen();     
    public void Lesen()
    try
    InputStream pageReader = new URL("http://www.reflex.at/~michael.chvatal/Neu/Test.txt").openStream();
    byte[] readDataBuffer=new byte[pageReader.available()];
    int size;
    while(true)
    size = pageReader.read(readDataBuffer);
    if(size == -1){
    break;
    Datei = new String(readDataBuffer, 0, size);
    catch(IOException e)
    Start.setText(e.toString());     
    Start.setText(Datei);     
    Start.setText(Start.getText().replace('\n','�'));
    //� is only a letter, I hope nobody will use in a Txt File. :)
    public void paint(Graphics g)
    int i=0;
    Start.selectAll();
    Anfang = 0;
    for (i=1;i<=5;i++)
    Start.select(Anfang,Start.getSelectedText().indexOf("�"));
    g.drawString(Start.getSelectedText(),30,i*50);
    Anfang=Start.getSelectionEnd()+1;
    Start.selectAll();
    Start.select(Anfang,Start.getSelectionEnd());

    When I run this code I can see that the stream reads all text file.
              try
                   InputStream pageReader = new URL("http://www.reflex.at/~michael.chvatal/Neu/Test.txt").openStream();
                   byte[] readDataBuffer=new byte[pageReader.available()];
                   int size;
                   while(true)
                        size = pageReader.read(readDataBuffer);
                        if(size == -1)
                             break;
                        Datei = new String(readDataBuffer, 0, size);
              catch(IOException e)
              System.out.println("datei:\n" + Datei);

  • My 645 ultra doesn't read PC2700 DDR

    assaf or anyone please help. I have had my board for a while and I originally bought some OZ pc2700 ram and it turned out that people read that it was pc2100 that runs at 333. So I figured that is why bios was reading it by speed as 266. I bought some Samsung true PC2700 and installed it and it still reads it in bios as 266.  I am keeping it overclocked to 333 but still why is it not reading it right. I would like to OC my ram some and it doesn't even read it right in bios.  Please help, I put it in my cousins EPOX board and it read it as 333.  

    I ran the memory benchmark 3 different times.  The first time was by speed. Second time when I OC'd to 333.  The third time was with the Timing set to ULTRA with being at 333.
    By speed (266):
    Int ALU/Ram Bandwidth 986 MB/s
    Float FPU/Ram Bandwidth 1016 MB/s
    3:4 Ratio which makes it 333:
    Int ALU/Ram Bandwidth 1151 MB/s
    Float FPU/Ram Bandwidth 1182 MB/s
    3:4 Ratio (333) with ULTRA Timing setting:
    Int ALU/Ram Bandwidth 1246 MB/s
    Float FPU/Ram Bandwidth 1261 MB/s

  • I have a document that in Word required a password to open. I copied and pasted it to Pages. Put the password protection on. Now if I click on that filename in Finder it automatically opens.Why. Anyone can read it. How do I protect it again?

    I have a document that in Word required a password to open. I copied and pasted it to Pages. Put the password protection on. Now if I click on that filename in Finder it automatically opens.Why. Anyone can read it. How do i protect it again?

    You saved it after setting the Password? :
    Inspector > Document > Document > Require Password to Open
    I just tested it and it shows up ijn The Finder with a padlock on the file icon and does require a password to open.
    Peter

  • Why does my card reader not work on my iPad since upgrade?

    I use my iPad mini to download photos from my camera when I'm on the road. In the summer I bought the "3 in 1 Card Reader Adapter Cable Camera Connection Kit, 3 Port Card Reader for iPad 4 and iPad Mini by Eurekka" and it worked wonderfully. I was able to download photos (jpg and RAW) directly to the iPad and off the camera, and once home it was a flawless upload to my iMac.
    However, once I upgraded to iOS 7 last week I get a message saying the device is not supported. What gives? Will this be fixed or will Apple products only accept Apple accessories from now on?

    No but I was just trying to find a way in to your help desk. I didn't find 
    your web page very helpful in this regard.
    Douglas Whiteley
    In a message dated 10/05/2012 20:43:50 GMT Daylight Time, [email protected] 
    writes:
    Re:  why does my adobe reader not work
    created by Claudio  González
    (http://forums.adobe.com/people/Claudio+González)  in Adobe Reader - View the full  discussion
    (http://forums.adobe.com/message/4395059#4395059)

  • Adobe Reader doesn't work after windows 7 update

    Hello,
    My Adobe Reader X was working fine, until one night where Windows 7 automatically updated, and after that Adobe Reader doesn't work anymore. It doesn't respond AT ALL when I click on it, and I cannot view PDF files anymore.
    I uninstalled it, and re-installed it --- still doesn't work. I tried downloading version 9, but still it doesn't work.
    I also tried to do system restore, but somehow it won't let me --- it says it failed to do so.
    When I try to open PDF files in IE 10, it says "There is a problem with Adobe Acrobat/Reader..." and an error code of 103:103.
    Could anyone help me?
    Thanks!

    You can try running cleaner on your machine
    http://labs.adobe.com/downloads/acrobatcleaner.html
    and then again install latest Reader from
    http://get.adobe.com/reader/enterprise/

  • Why won't Adobe reader no longer let me view previously download (from Safari) pdf's? I am running OSX 10.8.5 and have uninstalled and reinstalled latest version of Reader?

    Why won't Adobe reader no longer let me view previously download (from Safari) pdf's? I am running OSX 10.8.5 and have uninstalled and reinstalled latest version of Reader. I get this error message "Adobe Reader could not open 'OD Test Bed Proposals_0.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."  I have tried changing the 'open with' options too. Thanks

    Try this:
    Go to: Mac HD/Library/Internet Plug-ins
    Trash the AdobePDFViewer.plugin and AdobePDFViewerNPAPI.plugin files
    Empty the trash
    Relaunch Safari. You can now download undamaged PDFs.

  • Optical Drive doesn't read DVD's

    Hi, I own an HP Pavillion dv7 1279wm entertainment laptop. It came installed with Vista, but I installed a free upgrade to Windows 7 that I got from HP. I had a problem where the drive would not read anything; the disc would spin, but eventually the tray would automatically open and tell me to insert a disc. After using Microsoft FixIt, I was able to read CDs, but encountered the same problem when trying to load a DVD. Previous to using Microsoft FixIt, I did use device manager to uninstall the drive and then reboot so Windows 7 would automatically update the driver. I'm thinking that means that it's not a software problem, but if you can think of anything else I can do (short of swapping out drives because I don't have access to another drive) to rule out it being a software problem please let me know. I realize that combo drives typically use different lasers to read CDs and DVDs, so my guess is that the laser that reads DVDs has failed. If that is the case, where can I find the correct replacement part and how do I install it?
    Thanks,
    Kevin

    Hi Kevin,
    If you eject the optical drive tray, you should see just one laser situated towards the centre of the tray - different voltages are applied to this depending on whether it's reading a CD or DVD.
    First of all, use a soft, non abrasive material such as cotton or a cotton bud and gently clean the lens.
    Check if this has made any difference.
    If it still doesn't read DVDs, try following the procedure under the sub-heading 'Let me fix it myself' on the link below to remove the Upper and Lower filters, restart the notebook and see if this helps the issue.
    http://support.microsoft.com/kb/982116
    If it still doesn't read DVDs, the following procedure will test if your notebook can start from a bootable disc in the optical drive - the advantage of trying this is that it will rule out any possible Windows driver error as the CD/DVD drive is under the control of the Bios when starting the notebook.  So if you find that the notebook will not boot from the DVD, then it's almost certainly a Hardware fault in the optical drive itself and it will need to be replaced.
    Using another PC to create a Windows 7 Rescue DVD.  Download the relevant ISO from the link below.
    Windows 7 32bit
    Windows 7 64bit
    You need use an application such as ImgBurn to correctly burn the ISO to a DVD - a guide on using ImgBurn to write an ISO to a disc is Here.  Once created, insert the DVD and then restart the notebook and see if it boots from this disc - if it does, let the first screen come up ( this will show repair options etc ) then just remove the DVD and restart the notebook.  If the notebook will not boot from the DVD, it may just load straight into Windows.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

Maybe you are looking for

  • Problem with a Link Wiki Oracle HW

    Hello, a partner in Spain is asking about a link that doesn't work (It's the wiki for Oracle hardware): https://beehiveonline.oracle.com/teamcollab/wiki/Oracle_Hardware_Technical_Resource_Center_Workspace:Home Do you know if the wiki still exists or

  • Flash Player 11 Problem

    24/Oct/2011 18:23 TO - Adobe 10-24-2011 Flash Player 11 ****DOES NOT**** install. I get a message that FP11 will install in less than a minute. I go to read the license agreement, and...NOTHING. Actually, I'm incorrect. I get a web page that lists yo

  • IWeb 08 and accent... crap!

    Hi there I just bought iWeb08 and I had to rebuild my site for several reasons. As you know, iWeb uses the page name as a filename. And since almost all my pages have accent (I'm french after all :D), they are no longer supported in any browser. But

  • Invoice text

    Hi Everyone, I have an issue where invoice text is maintained in contract but not printing in invoice My issue is how to see invoice text in contract?and why it is not printing in invoice?

  • The Application Email (processcom.android.email)has stopped.....

    I know many people have posted about this same problem. And the common fix seems to be wiping the email out completely and resetting it up. I have done this before and it did work. And can restart my Verizon email with no problem.  However, I now hav