URL stream breaks on reading

Okay, I have a routine that works perfectly! Until a file is a certain size. I know it works on files that are 4k but not on 10k.
What happens is it fetches the first part of the file and then just blocks (which it is supposed to until the file comes across, but it never does). It's like the stream breaks or something.
        URLConnection connection = contentURL.openConnection();
        byte[] data = new byte[ connection.getContentLength() ];
        InputStream istream = connection.getInputStream();
        while ( istream.available() < connection.getContentLength() ) {
            try {
                wait( 10 );
            } catch ( Exception e ) {}
        istream.read( data );
        istream.close();If anyone has code to fetch a file via URL I be grateful for help. This is a critcial part of my project and I'd like to be able to use files greater than about 4k.
Thanks a ton.

Sounds like there is a buffer of 4K. Just read whenever there is something to read:
URLConnection connection = contentURL.openConnection();
byte[] data = new byte[ connection.getContentLength() ];
InputStream istream = connection.getInputStream();
int offset = 0;
int read;
while ((read = istream.read(data, offset, data.length-offset)) != -1 && offset < data.length) {
  offset += read;
istream.close();
// the last part should not occur, just to verify it worked
if (read != -1 || offset != data.length)
  System.out.println("Something went wrong");

Similar Messages

  • URL Stream dropping initial bytes

    I am new to Flash world. I am using URLStream function to
    fetch data from the server.
    The response from the server start with <?xml
    version="1.0" encoding="UTF-8"?>.
    I am using
    while (stream.bytesAvailable)
    bytesRead
    = stream.readByte();
    // trace (" Read " + i + " byte " );
    i += 1;
    I am missing the <?x , 3 bytes of data . I can see the
    data in the network protocol analyzers packets.
    Is there any setting or special way of handling to get these
    bytes? I am suspecting URLStream works little differently, than the
    regular socket i/o. Any help/pointers in this direction will be of
    great help.

    The problem is that the available call is working as documented and you are misusing it. It is supposed to return the number of bytes that can be read without blocking. When it returns 0 it means a read will block. It doesn't mean you have read the whole thing.
    Also your write parameters are incorrect. Try this:
    public static synchronized byte[] getBytes (URL fileURL) {
            InputStream bis = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();;
             try {
                 bis =fileURL.openStream();
                 while(true) {
                   byte byArray[] = new byte[8192];
                     int read = bis.read(byArray);
                     if (read == -1) {break;}
                     bos.write(byArray,0,read);
                 return bos.toByteArray();etc as you have it. If you are sleeping you are blocking, why not block on the read?

  • URL stream won't work in iTunes 11

    Hello everybody,
    We have a strange thing! We used a MacBook Pro and a iMac both are updated to OS X Lion 10.8.2 with on both computers iTunes 11.0.1.
    Now here is the thing! We add the URL stream ' http://icecast.omroep.nl/3fm-bb-mp3 ' to both our mac's. But it only play's on our MacBook Pro. But on our iMac the stream icecast.omroep.nl/3fm-bb-mp3 won't play at all!
    We tried everything... deleting the preference, setting the flash systempreference and add there the icecast.omroep.nl/3fm-bb-mp3 line. But nothing helps?
    The stream only works on our MacBook Pro??? What can that be?? Please help.....

    Hi,
    I did had the same problem. But i have the solution!
    Just make a new textfile with the name 3fm.pls and put the code in it:
    -----< knip >-------
    [playlist]
    File1=http://icecast.omroep.nl/3fm-bb-mp3
    Title1=Radio 3FM
    Length1=-1
    NumberOfEntries=1
    Version=2
    -----< knip >-------

  • Attempt to open links from our bank or utility company to view bill. etc. gets only a blank screen; instead of a url the address bar reads "About: blank"

    We signed up for on-line billing from our utility company; when I log into their website and click onto the link to "view my bill" Firefox opens a new tab, but nothing loads on the screen; the "address" bar near the top of the screen where you'd usually see the url for the tab reads simply "About:blank" . I have the same issue with messages received from our bank, which are usually sent as .pdf files. I frequently open .pdf files from other sites without any problems, so my copy of Adobe Reader seems to be working okay.
    Any suggestions greatly appreciated.

    We signed up for on-line billing from our utility company; when I log into their website and click onto the link to "view my bill" Firefox opens a new tab, but nothing loads on the screen; the "address" bar near the top of the screen where you'd usually see the url for the tab reads simply "About:blank" . I have the same issue with messages received from our bank, which are usually sent as .pdf files. I frequently open .pdf files from other sites without any problems, so my copy of Adobe Reader seems to be working okay.
    Any suggestions greatly appreciated.

  • PROTOCOL_ERROR line 627 of URL.cpp unexpected EOF reading HTTP status

    Hello,
    I'm having a problem getting the NSAPI plugin talking with the WLS6.1sp3 Application
    server.
    The iPlanet Server logs the error:
    *******Exception type [PROTOCOL_ERROR] raised at line 627 of URL.cpp
    Thu Oct 31 10:20:03 2002 got exception in sendRequest phase: PROTOCOL_ERROR [line
    627 of URL.cpp]: unexpected EOF reading HTTP status at line 1048
    Thu Oct 31 10:20:03 2002 Failing over after sendRequest exception
    The Application Server logs:
    <Oct 31, 2002 10:20:03 AM MST> <Error> <HTTP> <Connection failure
    java.lang.NullPointerException
    at weblogic.servlet.internal.ServletRequestImpl.setField(ServletRequestImpl.java:1733)
    at weblogic.servlet.internal.RequestParser.parse(RequestParser.java:254)
    at weblogic.servlet.internal.MuxableSocketHTTP.dispatch(MuxableSocketHTTP.java:355)
    at weblogic.socket.PosixSocketMuxer.deliverGoodNews(PosixSocketMuxer.java:455)
    at weblogic.socket.PosixSocketMuxer.processSockets(PosixSocketMuxer.java:384)
    at weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:24)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    Thanks in advance!
    Steve

    FYI, this was determined to be a bug in WebLogic 6.1sp3. BEA provided us with a
    patch.
    "Steve Wall" <[email protected]> wrote:
    >
    Hello,
    I'm having a problem getting the NSAPI plugin talking with the WLS6.1sp3
    Application
    server.
    The iPlanet Server logs the error:
    *******Exception type [PROTOCOL_ERROR] raised at line 627 of URL.cpp
    Thu Oct 31 10:20:03 2002 got exception in sendRequest phase: PROTOCOL_ERROR
    [line
    627 of URL.cpp]: unexpected EOF reading HTTP status at line 1048
    Thu Oct 31 10:20:03 2002 Failing over after sendRequest exception
    The Application Server logs:
    <Oct 31, 2002 10:20:03 AM MST> <Error> <HTTP> <Connection failure
    java.lang.NullPointerException
    at weblogic.servlet.internal.ServletRequestImpl.setField(ServletRequestImpl.java:1733)
    at weblogic.servlet.internal.RequestParser.parse(RequestParser.java:254)
    at weblogic.servlet.internal.MuxableSocketHTTP.dispatch(MuxableSocketHTTP.java:355)
    at weblogic.socket.PosixSocketMuxer.deliverGoodNews(PosixSocketMuxer.java:455)
    at weblogic.socket.PosixSocketMuxer.processSockets(PosixSocketMuxer.java:384)
    at weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:24)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    Thanks in advance!
    Steve

  • How do I paste a url into an RSS reader?

    A blog I like said, "To subscribe to this blog, right-click the orange RSS button and paste the url into your RSS reader." I see the RSS button, but don't know what an RSS reader is."

    If that RSS feed is send with the correct MIME type then clicking that link with the mouse should open a preview window with a button to subscribe to that feed.
    See also [[Live Bookmarks]]

  • URL stream throws exception when trying to read from input stream

    Hi guys,
    I tried reading from an input stream which returned a 401. Actually, the server side returns 401 whenever the application server cannot fulfill the client's request, however the 401 contains a message which I will like to read.
    I have tried this with mozilla and the return message is properly displayed even at 401. How can I read this message?

    Oracle home is pointing to wrong location.When we made the change to corrent location.Then we rebuilt the jar file started the managed server it is working fine.

  • Why do my ATV's play music sourced from a computer OK but when the same computer plays the same library through Airplay to the same ATV's the streaming breaks down?

    Does anyone know why my ATV's (connected to AV & hifi systems) can play music from a computer OK but when I try to use the same computer and library and play them through the same ATV's using Airplay the streaming often breaks down? Although I could live with the current situation I am missing the opportunity for simultaneous multi-zone playing with single volume control via the Remote App on my iPhoneS. Just find it curious as all the elements of the system are the same, ATV's, computer, router etc and would have expected the quality and efficiency to be the same under both modes of operation.

    Welcome to the Apple community.
    Yes, the quality and efficiency of the audio should be the same for both methods. The fact that it isn't may suggest that you have a problem on your network. Have you checked for interference.

  • Since the last update (10.4.11) most URL streams don´t work with QT 7.3

    Hi,
    since I updated the last time (OS X 10.4.11) in most URL the QT-streams don´t work, for ex. also in YOUTUBE. I allways see the QT-sign overlayed with a questionmark. On apple-URL´s evrything works fine. Before updaing, evrything worked perfectly anywhere.
    THNX for help

    QT with a ? refers to Flash video.
    These are the downloads and the settings you need in order to view/hear pretty much everything that the net can throw at you: The setup described below has proved repeatedly successful on both PPC and Intel macs, but nothing in life carries a guarantee!
    It is known to work in the great majority of cases with Safari 3.0.4, QT 7.3 and OS 10.4.11.
    Assuming you already run Tiger versions OS 10.4.9 or above (this has not yet been verified with Leopard) and have Quicktime 7.2 or above, and are using Safari 2 or 3, download and install (or re-install even if you already had them) the latest versions, suitable for your flavor of Mac, of:
    RealPlayer 10 for Mac from http://forms.real.com/real/player/blackjack.html?platform2=Mac%20OS%20X&product= RealPlayer%2010&proc=g3&lang=&show_list=0&src=macjack
    Flip4Mac WMV Player from http://www.microsoft.com/windows/windowsmedia/player/wmcomponents.mspx (Windows Media Player for the Mac is no longer supported, even by Microsoft)
    Perian from http://perian.org/
    Adobe FlashPlayer from http://www.adobe.com/shockwave/download/download.cgi?P1ProdVersion=ShockwaveFlash
    (You can check here: http://www.adobe.com/products/flash/about/ to see which version you should install for your Mac and OS.)
    In Quicktime Preferences, under advanced, UNcheck Enable Flash, and under Mime settings/Miscellananeous only check Quicktime HTML (QHTM).
    In Macintosh HD/Library/Quicktime/ delete any files relating to DivX (Perian already has them).
    Now go to Safari Preferences/Security, and tick the boxes under Web Content (all 4 of them).
    Lastly open Audio Midi Setup (which you will find in the Utilities Folder of your Applications Folder) and click on Audio Devices. Make sure that both Audio Input and Audio Output, under Format, are set to 44100 Hz.
    Important: Now repair permissions and restart.
    The world should now be your oyster!
    You should also have the free VLC Player from http://www.videolan.org/ in your armory, as this plays almost anything that DVD Player might not.

  • Music stream breaks when output is bluetooth over wifi

    Hi,
    I own Iphone 4s which runs IOS 6.
    I’m streaming music to bluetooth device from sky.fm, audio galaxy and similar applications.
    When the iphone is connected to the network via wifi, the music stops every ~2 minutes,for a second or less – very annoying.
    This doesn’t happen when I’m connected to the network via 3g.
    I've tried to disable all services which polls for data (e.g. mail) but nothing help
    Any advice,

    Didn't think of that, thanks. Great workaround.I'm going to call Sky, see if they have any firmware updates or other solution. Surely they wouldn't leave such a big knows issue unfixed. I'll report back with what they say. Edit:Just got off the phone from Sky technical support.This issue was first reported Nov/Dec 2014.The chap I spoke to does not know of a fix, or whether a fix is being worked on, or if a fix will ever be worked on.He has not way of contacting the development team to find out any of this information.He said firmware updates are pushed out to routers every now and again. He does not know when this is going to happen and does not have a way to notify about firmware updates installed on my router. (This terrifies me. Sky have a backdoor into my router and can install any code they wish, without even telling me what they changed/installed). There is no way to turn these auto-updates off either. Here's a key thing he did say though:He said he was not at liberty to provide my ADSL credentials, but if I chose to extract them from the router and install my own router instead, they would not have any problem with that.When I told him that this was against their TOS and they could terminate my contract for doing this, he went silent and just said "errr..." Allowing Sky, their subcontractors and anyone else they choose to install any code they wish to my router whenever they please and have free open access to my entire LAN is a total deal breaker for me. That router is getting unplugged today and I'm putting a new router on the credit card. I told tech support this. I said if they have a problem with that, let's go the legal route. I literally have a recorded call where they give me permission to install my own router. 

  • Clip Notes streaming export causes Reader media clip error

    MacPro HDV captured into PPCS4, export OK to Adobe Clip Notes streaming, uploads .mov file to my FTP site OK. The .mov clip plays fine locally in QT. When I open the clip notes pdf in Acrobat 9 Reader for Mac or Acrobat 8 Pro on Vista, both give the same error on opening: Javascript window - error reading media clip. The clip does not load into the pdf, and I can not get error information to debug.
    Answer: I need QT streaming server. The Clip Notes streaming is true streaming, not progressive-download or pseudo-streaming. I did not see this in the Premiere CS4 documentation.

    I'm using Vista 64.
    I was having the same problem with the transport controls not showing up.
    I set AcroRd32.exe to run in XP mode and that fixed the problem with the embedded movie file.
    Transport controls show up.
    Thanks.
    I hoped that would also fix the QT streaming problem.
    However, if I select "Streaming" and upload it to my server then when the Clip Notes tries to play the file it says "
    This happened also before I set AcroRd32 to XP mode.
    No problem with "Clip Notes Windows Media" format.  It uploads and plays fine.
    The .mov file is on the server.   I can play it fine in a browser.
    Any ideas why Adobe Reader won't play a streaming .mov file in Clip Notes, but will play a streaming .wmv file?
    You really need to use QT so you can scrub the timeline.
    .wmv files don't let you scrub!
    Adobe why haven't you after all these years made Clip Notes use flash?
    If you did it would truly be cross-platform.
    Thanks.

  • I can't open certain url links in Adobe Reader 11.0.6 on Mac os x 10.7.5

    I have pdf documents which contain url links.
    I can open the ones without a space but not the ones that contain a space
    Would appreciate any help or advice with this.
    Thanks

    This happens because these are not true links. Links created with Acrobat using the link tool do not have this problem. Acrobat and Reader have a feature that tries to automatically recognize urls so they can act as links, but it fails when the link contains a space.

  • Counting Number of Rows in a URL stream

    Hi.
    I have a URL reader, and i need to know how many rows it reads when it goes through.
    Has anyone had to do this before? I'm not sure if theres an inbuilt lineCounter in the BufferedReader (i read through the documenation and couldn't find anything).
    Any suggestions on how i could go about doing this?
    Thanks.

    I'm not sure if theres an inbuilt lineCounter in the BufferedReader No there isn't. You just read a line and count the number of lines yourself.

  • How to detect line break while reading input ?

    Hi all,
    I am reading the user input from standard input.
    I want to detect the line break. So that I can stop reading input and proceed processing the string.
    Actually I am getting the SQL query as input and after that I am executing the same by passing it to a function.
    Pl. do reply me.
       Scanner scanner = new Scanner(System.in);             
            while(scanner.hasNext())
                 temp=scanner.next();
                  sql=sql.concat(" "+temp);
                 if(scanner.next=="\n")
                            break;
           System.out.println(sql);
           sqlTool.executeSQL(sql);
    The above is not working properly.

    But if new line comes, what will be it's value?Empty lines are discarded by the scanner.
    Kaj

  • Specifying byte stream type for Read File with Type Descriptor

    Hi.
    I'm trying to write a VI that reads an image file format that can have
    different datatypes. What I have so far is that I open the file, read
    the header, and get the width, height, number of frames, and datatype.
    I calculate number of pixels by nrows*ncols*nframes with no problem,
    but I'm not sure how to tell Read File the correct datatype to read
    the data into.
    I tried using a Case structure where I have a Read File in each case
    with the correct type constant as input for that case. The problem is
    that the tunnel graduates the datatype to the highest representation.
    I found in Application Note 154 the discussion about Type Descriptors.
    Is there a way to generate a Type Descriptor and output it from a C
    ase
    structure? I tried just returning the value (e.g. 0x0402 for a Word),
    but Read File will just see that the byte stream type is a uint32.
    Is there any other way to do this?
    Thanks for any help.

    I converted the code to LabVIEW 6.1 for you and attached it below.
    Don't worry about being a newbie. We all start there. Keep asking this type of question and you won't stay there long.
    As you are discovering, being strictly typed means that you must rewrite code even for a simple data type change, or convert everything to the same data type first. For image data, conversion can result in a lot of extra space being wasted. Use a modified version of the GLV_WaveformBuffer.vi to hold your data. Use the array functions, which operate inline, to add to and delete the data wires in the buffer. This allows you to save several different data types. You will need several different inputs and outputs to handle these data types. I ha
    ve also attached a similar file created for exactly the problem you have - storing arrays of different data types (data from NI-SCOPE devices, in this case - can be float, I8, I16, or I32).
    Routines that take any type work in one of two ways. LabVIEW primitives, such as plus and minus operators, work by figuring out the type and doing the right thing in the C code layer of the LabVIEW environment. Users of LabVIEW can't do this. Users can make polymorphic VIs. Polymorphic VIs are actually a single VI for every data type that are referenced by a "wrapper", the polymorphic VI. Users still need to write a different VI for every data type they need.
    Take home message - if you need to work with different data types, you will need to rewrite your code for every data type or convert your data to a common data type. Polymorphic VIs and case statements are your friend.
    Let me know if you need more help.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    GigaLabVIEW61.zip ‏362 KB
    sfpScpChan_Waveform_Buffer.zip ‏74 KB

Maybe you are looking for

  • Please can anybody help????

    I have not long installed i tunes to my pc but everytime i try to insert a cd to import or even current music files that i already have on my pc i get an message saying "attempting to copy the disc "c\" failed. The file name was invalid or too long"

  • Image rendering in flash

    We are building a flash based product where we need to create icons for various modules. we are having challenges in look and feel of the icons- what looks really good on Adobe Illustrator/ Photoshop looks jagged on flashPlayer. A challenge we have i

  • Lines showing momentarily on one we site

    I regularly access a forum without any problems but on my new i-mac all the posts are momentarily enclosed in black lines for a fraction of a second then the page appears as normal. As I go back and forwards to the many posts this is a strain and an

  • Set Decision Step in WF via Terminating Event

    Hi All, I have a custom Work flow in which I am trying to terminate a Decision Step via a terminating event. Following Pre- requisites have been set: 1) In the Control task for the decision step I have assigned the terminating event. 2) Required link

  • Installed fonts dont show in font list

    I am trying to share a font through a shared library. It is Helvetica Neue.dfont in the folder on my computer. Helvetica Neue Black and some others show up in the font list inside flash, but Helvetica Neue Oblique does not. I cannot figure out what t