Bug with InputStream.read after BufferedReader.readLine in a Thread ?

I just found something strange when reading bytes on a socket after reading lines.
I'll show you an example :
In this example, when a connexion is established, I launch a thread where a single line of String then 3 bytes are read from the socket. I use BufferedReader.readLine for the String line then just InputStream.read to read the 3 bytes.
The results are quite random. Sometimes it works, sometimes not (most times it doesn't)... it seems to always work under linux (but haven't tested it as many times than on windows). Most of the time the program is stuck on the "socket.getInputStream().read(bytes);" line with 0 bytes available. I tried to do the same thing outside of a thread, I thought it worked better beaucause I was able to run it without any problem but it doesn't work anymore when I test it again.
I can't say if I'm doing something wrong or if it's a java bug (I've got JDK 1.6.0_03-b05).
Can you please have a look a this little example and maybe test it and let me know if it works or not. I tried to code my own readLine function and it seems to work with it but I'd like to know if it's a bug or what. Thank you.
Server side :
import java.io.*;
import java.net.*;
public class testServer extends Thread {
     private Socket socket;
     public testServer(Socket testSocket)
          socket = testSocket;
     public void readData() throws Exception
          BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
          String str;
          str = br.readLine();
          System.out.println(str);
          System.out.println("Bytes available : " + socket.getInputStream().available());
                //Try to read the bytes
                byte[] bytes = new byte[3];
                //STOPS THERE UNDER WINDOWS, BUT WORKS WITH LINUX
          socket.getInputStream().read(bytes);
                //Simple "ack" to say to the client that he can close the connexion
          socket.getOutputStream().write(0);
          socket.getOutputStream().flush();
                //Print the bytes values
          for(byte value : bytes)
               System.out.println(value);
     public void run()
          try {
               readData();
          } catch (Exception e) {
               e.printStackTrace();
     public static void main(String[] args) {
          try {
               ServerSocket welcomeSocket = new ServerSocket(3333);
               while(true)
                    new testServer(welcomeSocket.accept()).start();
          } catch (Exception e) {
               e.printStackTrace();
}client side :
import java.io.*;
import java.net.*;
public class testClient {
     public static void main(String[] args) {
          try {
                        //Some test values
               byte[] testValues = new byte[]{1,2,3};
               Socket socket = new Socket(InetAddress.getLocalHost(), 3333);
                        //Send the line through the socket
               BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
               bw.write("HELLO WORLD\r\n");
               bw.flush();
                        //then the bytes
               socket.getOutputStream().write(testValues);
               socket.getOutputStream().flush();
                        //Just waits for the server's ack to close the connexion
               socket.getInputStream().read();
               socket.close();
          } catch (Exception e) {
               e.printStackTrace();
}

It's your bug.
When you create a BufferedReader and ask it to read a line, the first thing it does is to read a whole buffer full of data (hence the name of the class) from its underlying input stream. That's probably about 4000 characters or something like that. It stores that internally and then starts doling it out in response to calls to readLine() and so on.
Then when you go back to reading from the underlying input stream, those 4000 or so characters are already gone from it. You have no access to the data the BufferedReader is hanging on to this way. All you can do is to start reading at the point after that whole buffer, which is not what you want.

Similar Messages

  • Downloaded Reader XI and started to recieve error 40000015, found the fourm with the patch to the registery fix, now it tells me unable to connect to the server. To many bugs with the reader, how do reinstall an older version?

    downloaded Reader XI and started to recieve error 40000015, found the fourm with the patch to the registery fix, now it tells me unable to connect to the server. To many bugs with the reader, how do reinstall an older version?
    I click on the launcher and nothing happens, 15 min later it will tell cant connect to the server.
    My computer is a windows 8.1; 64 bit operating system. I am stationed in South Korea, but that should not affect the program. Help please.
    John

    Hi johnd83157268,
    Sorry for the inconvenience that has caused to you.
    Could you please let me know what changes have you made in the registry.
    You might need to uninstall Adobe Reader from Control Panel and try install it again from the following link:
    Adobe Reader Install for all versions
    Please ensure that you are logged in as administrator and anti-virus is disabled as that might interrupt installation.
    Try again and then let me know.
    Regards,
    Anubha

  • How to make pdf file auto open with adobe reader after downloaded

    how to make pdf file auto open with adobe reader after downloaded

    I note from your system details that you have the plugin for adobe pdf s so I would have expected the files should open in firefox '''without''' you needing to explicitly download them.
    Once the files are open in firefox, you will also get the option to save them permanently to a location on your computer. If you wish I suppose you could set the file type pdf to be associated with and be opened by firefox instead of with the Adobe Acrobat Reader, but that would just seem to be an additional complexity.

  • Cannont update E70 nad bug with phone code after b...

    launch NokiaSoftwareUpdate v1.4.39pl
    accept and start update to software 3.0633.09.04 ( using USB cable)
    time remaning 15 mintes ... nokia have white screen , during proceed to 9 minutes , and e70 is reset after reset , on e70 screen show :
    AFE_TEST_SERVER ,w19_06,(c) NMP
    test mode
    nokia
    update show information with 2 steps about put out a battery ,
    after hard reset phone is run but its a problem with PHONE CODE
    after i configure a phone i change default code to my code xxxxxx
    but after bad update code is reset to unknown code
    other bug i found my personal code enter when i change a phone code and enter twice new code show me msg error [-6]
    but old code enter correctly becouse if i use another code then after put twice new code show me message a invalid code .

    Can you please try generating and re-inserting the FB code on your page. The FB Likebox at the above link doesn't load for me from any of the mobile devices nor through a desktop. You can get the code here.
    https://developers.facebook.com/docs/reference/plugins/like-box/
    I was referring to the following Facebook Page URL that you are currently pulling the Streams and Likes for - http://www.facebook.com/phillyweddingdj which appears to be invalid. If you generate the code for it at the above mentioned plugin page, the preview doesn't generate. Visiting this link takes you to FB homepage instead.
    This is how the Likebox code should look like with minimum customization that you need to insert through Object -> Insert HTML option, notice the highlighted part that needs to be modified with a valid FB Page URL:
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    <div class="fb-like-box" data-href="http://www.facebook.com/myfbpage" data-width="292" data-show-faces="true" data-stream="true" data-header="true"></div>
    </div>
    Thanks,
    Vinayak

  • Throwing away data after BufferedReader().readline()

    I'm reading very large files - over 1GB. I'm reading sequentially and then writing to another file to create smaller files. Since the input file is so big, I'd like to just remove from memory the already read lines. Is there a way to do this using BufferedReader()?
    Here is my BufferedReader line:
          br = new BufferedReader(new FileReader(new File(rawBill)));Then I have the standard while loop:
                   while ((line = br.readLine()) != null) {
                                       ... write to another file here once all required data is read.
                            }Thanks.

    jverd: I didn't realized the line variable would be
    eligible for GC. Seems like it's just getting
    rewritten to with the next line from the input file.
    It's always holding some data it is not nulled out.Variables are never eligible for GC. Objects are.
    Every time through that loop, a String object is created, and the variable line is pointed at it. The next time through, a new object is created, and line is pointed at the new string. Since line is now no longer pointing at the previous String object, that object is now eligible for GC, unless you pointed some other reference varialbe to it, that survives across loop iterations.
    As long as you don't do something to "save" that String object, at any given time, there's only one that's not eligible for GC. All the previous ones are eligible.
    My issue is with the input file. I assume
    BufferedReader just continuously reads/stores the
    data from the file when all the readLine calls get to
    the end of the designated buffer size? No. BufferedReader just does physical reads in relatively large chunks, the size of which is independent of how many bytes you're actually trying to read. For example, when you call readLine, it may physically read 512 bytes from the file, but the line you're reading may only be 80 bytes long. This helps minimize the overhead of physical reads from the network or file system.
    I don't think
    the previously read data is purged upon the next IO
    read from the file. It would be great if there was
    a method on BufferedReader which would purge all
    previously held data. I don't know what you mean by "purging" data. I don't think that's an issue that applies here.

  • Repeated Error Message with Adobe Reader after opening up PDF files

    After experiencing this problem, not being that computer savvy I figured I'd remove the existing Adobe Reader from my computer and download a new version in the hopes of eliminating the problem. When I do so, I get message "The patch package could not be opened. verify that the patch package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer Patch Package."

    Ankit,
    Here are my responses as best as I can address them:
    1. Adobe 10.0.1
    2. I believe it is Windows XP
    3. I was unable to remove the existing Adobe version because of the "patch
    package could not be opened......" I believe i may have inadvertently
    downloaded this patch via www.secunia.ocom "Personal Software Inspector"
    program (Untitled (1)).. Using the older version alone when opening up PDF
    documents resulting in their closing and my getting an error message
    ("Untitled and Untitled (2))..
    4. I was able to successfully download Adobe 10.1.0. However, it won't allow
    me to download required updates.
    As a result of this mess, I have the 2 versions of Adobe on my computer,
    which is allowing me to open up PDF files on my computere.
    Again, I'm not terribly computer savvy. I'm simply trying to find a way to
    remove the old version and work with the new version.
    Hope this helps, as I'm stumped. Thanx for your assistance.
    Norm Green

  • Livecycle ES Form bug with Adobe Reader 9

    My firm is currently upgrading certain people to Adobe Reader 9.  I have created fillabe forms using Livecycle ES (Adobe Professional 8) and distribute these forms using the "distribute" function in Adobe Professional 8.  The forms are sent back using a submit button with a "mailto" script.  When the users send the form back to me using this submit button (and using Adobe Reader 8), the form was submitted automatically without opening new email message box.  Now, the updraded users (adobe 9) are hitting the submit button and it is opening up a new email message box instead of sending the form automatically through the email server (outlook). What can I do to make the submit button work correctly with Adobe 9?  or is there a default setting in Adobe 9 that needs to be changed? I have already tried extending user rights and that did not change the way the form was sent back to me. Thanks, Jen

    Actually, this was an upgrade when the users were upgraded to Adobe Reader 8.  I distribute the form via Adobe 8 Professional.  I have 2 submit buttons on my form.  The 1st submit button is visible and the users click.  If all required fields are filled out, then the 2nd submit button (which is invisible) sends the form back to me via email (using the script mailto:[email protected]).  This is done so that the form cannot be sent without filling out the required fields.  Also, I distribute the form via the distribution function in Adobe Professional 8, so that a Dataset file is set up for returned forms. I really like this function, but now Adobe Reader 9 doesn't allow it.
    If anyone has a fix for this, please help.
    Thanks,
    Jen

  • Problems with mail fetching after 2.1 firmware (NEW THREAD)

    That other post is getting way too long. So here is another one that I hope people jump on.
    As many of you can relate, my iPhone no longer fetches mail at the scheduled intervals when "sleeping". I must manually check for new mail now. This is obviously a significant feature that is now gone since the 2.1 firmware update.
    Any word on a fix yet for this?!? Is one even in the works? Was this an intentional change to the firmware by apple? I called iPhone support and the tech was no help at all. He had zero answers or solutions for me.

    Most interesting that people at Apple have time to delete posts here, but not respond to our problems.
    Apple, why don't you answer some of these people???
    What other posts don't people get to see?

  • Bug in Adobe Reader when displaying lines?

    Hi there!
    I'm creating a complex document with Apache FOP, using tables with visible and hidden borders. Although, all lines have the same attributes, Adobe Reader renders them in different thikness. In the FOP forum, there has been a lot of discussions about this issue. Conclusion is, that it is not supposed to be a FOP bug. Some other readers render the created documents well. You might want to read about it here: http://apache-fop.1065347.n5.nabble.com/Cell-border-rendering-error-thicker-with-number-co lumn-spanned-tp17999p37229.html. Displaying on screen, it is possible to avoid this by not using "Enhance thin lines". However, printed documents allways show these lines in different thikness. To avoid this being a FOP bug, there is a simple example document, producing the bug with Adobe Reader. It can be found here: http://mail-archives.apache.org/mod_mbox/xmlgraphics-fop-users/201211.mbox/raw/%3c5095C97A .[email protected]%3e/2. The document is hand crafted. To see the issue, turn on "Enhance thin lines" and try different zoom values. If this document contains incorrect contents, I'll be happy, if you let me know.
    Regards.

    You will not get a response from the bug report but they DO read the reports and use them to make future updates.
    I notice a lot of the other issues reported here have not been responded to either.
    Is that the normal process?
    I haven't noticed that at all. In fact, most posts here get results as long as the poster gives enough details. Keep in mind that the answers are coming from fellow users and it is not an official avenue to contact Adobe personnel.

  • Bug in the ServerSocket InputStream.read()

    I believe there is a bug in the ServerSocket InputStream.read() method.
    This is demonstrated under Windows XP, running 1.4.0_01-b03
    I am looking for confirmation and an examination of my assumptions for this.
    There is nothing that suggests the InputStream.read() method should block on a EOL, yet it does.
    This is demonstrated with the following code.
    To reproduce uncomment one of the 'Case' sections in the MyServer code. Compile both classes. Run the MyServer then MyClient code.
    The expected result for ALL cases should be
    ***socket start
    text1
    text2
    But for the first case the last line is not printed. Note that for case 3 it does work, and the only exception is that available() is called.
    The InputStream of the server resolves to java.net.SocketInputStream. The read() method calls the read(byte, int, int) method (which how I guessed that calling available would produce different results.)
    //-----------------Client
        import java.io.*;
        import java.net.*;
        public class MyClient
            private MyClient() {}
            static public void main(String argv[])
                try
                    Socket s = new Socket("127.0.0.1", 50080);
                    OutputStream os = s.getOutputStream();
                    String text = "text1\r\ntext2";
                    os.write(text.getBytes());
                    os.flush();  // We know it was sent.
                    // Important!  The socket remains open!
                    while(true)
                        Thread.currentThread().sleep(60 * 1000);
                catch(Throwable e)
                    e.printStackTrace();
    //----------- Server
        import java.net.*;
        public class MyServer implements Runnable
            Socket s;
            public MyServer(Socket s)
                this.s = s;
            static public void main(String argv[])
                try
                    ServerSocket ss=new ServerSocket(50080);
                    while(true)
                        Socket s=ss.accept();
                        Thread t = new Thread(new MyServer(s));
                        t.start();
                catch(Throwable e)
                    e.printStackTrace();
            public void run()
                try
                    System.out.println("***socket start");
                    java.io.InputStream ins=s.getInputStream();
                    // Case 1: Does NOT work
                    int j;
                    while((j=ins.read())!=-1)
                        System.out.write(j);
                    // Case 3: Does work
                    while (true)
                        int len = ins.available();
                        if ((len < 0) || s.isClosed()) break;
                        byte b[] = new byte[len];
                        ins.read(b);
                        for (int i=0; i < len; i++)
                            System.out.print((char)b);
    // Case 3: Does work
    while (true)
    int len = ins.available();
    if ((len < 0) || s.isClosed()) break;
    for (int i=0; i < len; i++)
    int b = ins.read();
    System.out.print((char)b);
    System.out.println("***socket end");
    catch(Throwable e)
    e.printStackTrace();

    System.out is line buffered. (I can only hope that I might have noticed this myself if I had been smart enough to use the same output method.)
    Ok so it isn't a socket problem. But I still don't see anything that documents the behavior.
    System.out is documented as a java.io.PrintStream. And that is actually the class that implements it.
    Nothing in the documentation for PrintStream, the methods, the FilterOutputStream or even OutputStream would suggest the different behavior.
    C works the same way; this never prints "world" on most systems:C works that way because of the way file descriptors work and the way that the buffers for those are handled. And how it works is undefined, a C implementation is allowed to handle it anyway it wants.
    But this Java and not C. That means at a minimum that the behavior must be the same on all OSs. But given that the behavior is not documented then it could be that it is left to the implementation of the C library that the java io library is built upon. And that is not a good thing (in terms of normal java.)
    The following demonstrates the behavior using the two output methods...
          String text = "text1\r\ntext2";
          byte[] b = text.getBytes();
          System.out.println("--- print using print() sleep for 10 secs after");
          for (int i=0; i < b.length; i++)
             System.out.print((char)b);
    Thread.currentThread().sleep(10 *1000);
    System.out.println();
    System.out.println("--- print using write() sleep for 10 secs after");
    for (int i=0; i < b.length; i++)
    System.out.write((int)b[i]);
    Thread.currentThread().sleep(10 *1000);
    System.out.println();
    System.out.println("--- done");

  • Adobe Reader / Pro XI bug with PDF as embedded object in Microsoft Excel

    We are using Adobe Reader and Adobe Pro version 11.0.06, Windows 7 Enterprise 64-bit, with a mixture of MS Office 2010 and 2013.
    We have been able to reproduce a bug using Reader/Pro together with Excel, where Reader/Pro freezes when we preform the following tasks.
    Open an Excel file where a PDF file is attached as an object in the spreadsheet
    Double click and open the PDF file attached, PDF is opened in Adobe Reader/Pro
    From Adobe Reader/Pro, click on the document on the Page Thumbnails, scroll the document up and down for a few times
    Close the Adobe Reader/Pro, it freezes and the adobe process is starting to consume the system memory
    This problem is happening on multiple machines with Adobe Reader/Pro 11.0.06 installed, regardless of the Office version and is reproducible. We did not see such issue on Adobe X.
    Is there anyone reported the same?

    Hello,
    I know this problem was reported many months ago, but I am also experiencing this exact same issue, and have found no resolution to it yet. My user has a simple PDF embedded into an Excel 2010 document. Double click the PDF and it opens properly in Acrobat. If I close Acrobat, Excel freezes in the background (not responding). I have to force quit Excel to get back to Excel.
    Also, if I double click on Acrobat again to re-open the application, it won't open. If I check Task Manager after Excel crashes, I can see that Acrobat.exe is still running in memory, and I have to force-quit it before I can re-open Acorbat.
    Any progress on this issue?

  • When pdf file is opened with Adobe reader, it shows extra whitespace after "w"

    I am unable to attach the pdf file here. But my pdf file is having a hyperlink "http://www.google.co.in/". When i open it with Adobe reader, its shown as "http://w w w .google.co.in/", if the same pdf file is opened in some other pdf reader, the link is properly shown and i can click over it to browse. This is a bug in Adobe Reader.
    Please revert back mentioning where should i attach the pdf file.

    I have created the pdf files using txTextControl.ServerTextControl
    The additional space after the "w" is a result of charaster spacing, there is no whitespace in pdf file after "w"
    If i open the same pdf in some other pdf reader like Sumatra pdf reader, it gets opened without any white space after "w".
    However, there is no space after the "w" in the PDF document, its the adobe  reader issue.

  • Exchange SBS2003: Email that is deleted in Outlook 2010 is not deleted on iPhone 4, or marked read after upgrading to 6.0.1.  Win 7 64bit.  2 Other users in our office with iPhone 4 and iPhone 4s aren't having this issue.  They didn't upgrade to 6.0.1.

    Exchange SBS2003: Email that is deleted in Outlook 2010 is not deleted on iPhone 4, or marked read after upgrading to 6.0.1.  Win 7 64bit.  2 other users in our office with iPhone 4 and iPhone 4s aren't having this issue.  They didn't upgrade to 6.0.1 though.  Mail that is deleted or read on the iPhone 4 is deleted or marked read in Outlook 2010.  So it's a one-way problem.

    Exchange SBS2003: Email that is deleted in Outlook 2010 is not deleted on iPhone 4, or marked read after upgrading to 6.0.1.  Win 7 64bit.  2 other users in our office with iPhone 4 and iPhone 4s aren't having this issue.  They didn't upgrade to 6.0.1 though.  Mail that is deleted or read on the iPhone 4 is deleted or marked read in Outlook 2010.  So it's a one-way problem.

  • Unresolved bug in adobe reader x with non-default windows zoom level

    This seems to have already been brought up here about a year ago: http://forums.adobe.com/thread/776060.
    I am using Windows 7 Professional 64-bit with Firefox 12.0 and Adobe Reader 10.1.3. Here is a description of the problem:
    Whenever I open any PDF file in a browser (firefox or IE) using the adobe reader I am unable to select text, save the file or interact with the content in any meaningful way because the plugin does not recognise my cursor position. If I click on some text in a PDF document, the reader will immediately highlight a region of text between where I clicked and where it thinks I started clicking from (above 20% of the screen above and to the left of where I actually clicked on the page). If I roll my mouse over the region where the dashboard normally appears, the dash does appear as intended and the cursor changes in response to hover over buttons, as if everything were working, but I am unable to click on anything (clicking does nothing). If I click and hold the dashboard when it appears, it immediately jumps to another region of the page, as if it thinks I moved the mouse (20% up and to the left again). I have recently reformatted and am now using a fresh install, and the issue remains. My desktop zoom level in windows is 150%. The problem appears only inside the browser; viewing PDFs directly in Acrobat Reader X works without issue.
    I can resolve the problem either of two ways:
    a) Reverting back to the default windows zoom level (125%).
    b) right-clicking on the Adobe Reader X icon, navigating to the compatibility tab and clicking "Disable Display Scaling on high DPI settings"
    The workaround is easy but it's disappointing that adobe hasn't fixed this. Please consider that it would mostly affect individuals who are vision impaired and might not have the know-how to resolve the problem or check for solutions online, let alone post comments such as this. As far as I can tell this problem severely impaires the functionality of adobe in any browser on any non-standard zoom windows installation.

    Please be sure to post your issue in the following Feature Request/Bug Report Form.

  • Pages is sending my documents in docx format, but windows unable to open them. They arrive blank or can only be read as a single line at a time. When view prior to sending the document is divided with black lines after each sentence.

    Pages is sending my documents in docx format, but windows unable to open them. They arrive blank or can only be read as a single line at a time. When viewed prior to sending, the document is divided with black lines after each sentence.

    Windows will only be able to open these if you have Word 2007+. Older versions of Word, for example Word 2003 would require a compatibility pack.
    Perhaps you can try 'Saving As' a different file type instead?
    Regards,
    Steve

Maybe you are looking for

  • How do i back up iphone and ipod to time capsule?

    Set up my time capsule and go to go with macbookpro.  Downloaded Airport to iphone and do not know how to back up to this network.  Still backing only to cloud.

  • How Encrypt a File Using Key?

    Hi Guys, Here is my problem. I have to create a bank's document encrypted to send to a legacy system. ( Using a KEY to validate the roll process) I'm thinking to use two scenarios: 1 - Generate the file via ABAP and sent it to a folder in a server to

  • 27" Monitor

    I am thinking of buying a 27" 2560 x 1440 monitor for indesign and photoshop work. It seems to me that the Dell UltraSharp U2713HM is currently best buy. http://www.pcmag.com/article2/0,2817,2411736,00.asp Tell me what you think.

  • Error Posting form from Portlet

    Hello, I am running JDEV 11.1.1.4.0 on Windows 7 Prof. I have a jspx that has a form using adf. When I run this form by itself from portlet project it works fine, page shows form and when i submit form data is set back to managed bean and method is e

  • Unable to start OPMN service

    Hi group, I have applied patch 12.1.2 and followed some steps to configure SOA Gateway and after that I am unable to start Apache Server. I have enabled "debug" option in opmn.xml file as follow: <debug path="F:\ORAEBS_APPS\inst\apps\EBSTEST_srvoracl