BufferedReader.read blocks when wrapping InflaterInputStream

Hello,
I'm currently doing client - server communication using http chunked transfer encoding. Furthermore chunks sent are compressed using zlib in sync_flush mode. The client code reads data from an InputStream using the following code snippet:
URLConnection conn = new URL(anUrl).openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(new InflaterInputStream(conn.getInputStream())));
int read = 0;
while ((read = reader.read()) != -1)
  System.out.println((char)read);When running the above code snippet, the client will not read on a per chunk basis, but will block until receiving EOF from server. When using BufferedInputStream instead everything works fine.
Does anybody know how to overcome this problem?
Thanks!

Yes you are right!
But as i said, using BufferInputStream instead gives an important different behaviour. In this case read doesn't block until the underlying stream receives EOF. The call to read will immediately return bytes when on the server side a chunk of data has been send to the output stream.
When investigating why BufferedReader blocks, i found that StreamDecoder, a class member of InputStreamReader uses the following code to implement reading from the underlying InflaterInputStream.
  301       int implRead(char[] cbuf, int off, int end) throws IOException {
  315           for (;;) {
  316           CoderResult cr = decoder.decode(bb, cb, eof);
  317           if (cr.isUnderflow()) {
  318               if (eof)
  319                   break;
  320               if (!cb.hasRemaining())
  321                   break;
  322               if ((cb.position() > 0) && !inReady())
  323                   break;          // Block at most once
  324               int n = readBytes();
  325               if (n < 0) {
  326                   eof = true;
  327                   if ((cb.position() == 0) && (!bb.hasRemaining()))
  328                       break;
  329                   decoder.reset();
  330               }
  331               continue;
  332           }
  ...The part that will prevent BufferedReader from not blocking is "!inReady()" at line 322. This method calls, among other things, available on the underlying InflaterInputStream. But as stated there, InflaterInputStream will always return 1 until EOF and "Programs should not count on this method to return the actual number of bytes that could be read without blocking".
So in my opinion StreamDecoder's implementation won't be able to handle chunked encoding "out of the box".

Similar Messages

  • BufferedReader blocks when using Runtime.exec()

    I'm executing an external process in Linux (RH 8.0) using the Runtime.exec() method and then setup two threads to read the standard and error output of the process. Most of the time this works great but every now and then the readers block and the process never exit. I even tried seting up a timer task that will close the BufferedReader after 20 seconds but that's not enough to unblock the reader - the external process is a dummy shell script which for now just outputs a single line. Does anybody have any idea why that would happen? Any help would be appreciated!
    Cheers,
    /Francis
    P.S. Here's a snippet of the code:
    public class ProcessRunner {
      private Process _process = null;
      private StreamGobbler _errorGobbler = null;
      private StreamGobbler _outputGobbler = null;
      private String[] _commandArgs;
      public ProcessRunner(String[] args) {
        _commandArgs = args;
      public int runCommand()
        throws IOException {
        int exitCode = -1;
        _process = Runtime.getRuntime().exec(_commandArgs[0]);
        // start up stream gobblers (inspired from javaworld)
        _outputGobbler = new StreamGobbler(new BufferedReader(new InputStreamReader(_process.getInputStream())));
        _outputGobbler.setDaemon(true);
        _errorGobbler = new StreamGobbler(new BufferedReader(new InputStreamReader(_process.getErrorStream())));
        _errorGobbler.setDaemon(true);
        _outputGobbler.start();
        _errorGobbler.start();
        try {
          exitCode = _process.waitFor(); // *** THIS NEVER RETURNS ***
          if (_outputGobbler != null) {
            _outputGobbler.join();
          if (_errorGobbler != null) {
            _errorGobbler.join();
        } catch (InterruptedException exc) {
          //ok, continue
        return exitCode;
      class StreamGobbler extends Thread {
        BufferedReader reader;
        StreamGobbler(BufferedReader reader) {
          this.reader = reader;
        public void run() {
          try {
            final int buffersize = 256;
            byte[] bytes = new byte[buffersize];
            String line = null;
            while((line = reader.readLine()) != null) {    // ***THIS ALSO BLOCKS ***
              baos.write(line.getBytes(), 0, line.length());
          } catch (IOException ioe) {
            // Do something here
          } finally {
            reader.close();
            reader = null;

    I use this type of thing in my code using JDK1.3.1. Only difference is I don't use set up the readers in threads. I suspect you have a thread deadlock, but I can't see why. Do you have to have the i/o stream readers in the thread?

  • I use Safari as my browser. When on a site and I click on a PDF file I get a black screen and a notice that "Adobe Reader blocked for this website". However, this does not happen if I use Firefox.

    I use Safari as my browser. When on a site and I click on a PDF file I get a black screen and a notice that "Adobe Reader blocked for this website". However, this does not happen if I use Firefox.

    Back up all data before making any changes. Please take each of the following steps until the problem is resolved.
    Step 1
    If Adobe Reader or Acrobat is installed, and the problem is just that you can't print PDF's displayed in Safari, you may be able to print by moving the cursor to the the bottom edge of the page, somewhere near the middle. A black toolbar may appear under the cursor. Click the printer icon.
    Step 2
    There should be a setting in its preferences of the Adobe application such as Display PDF in Browser. I don't use those applications myself, so I can't be more precise. Deselect that setting, if it's selected.
    Step 3
    If you get a message such as ""Adobe Reader blocked for this website," then from the Safari menu bar, select
    Safari ▹ Preferences... ▹ Security
    and check the box marked
    Allow Plug-ins
    Then click
    Manage Website Settings...
    and make any required changes to the security settings for the Adobe PDF plugin.
    Step 4
    Triple-click anywhere in the line of text below on this page to select it, the copy the selected text to the Clipboard by pressing the key combination command-C:
    /Library/Internet Plug-ins
    In the Finder, select
    Go ▹ Go to Folder
    from the menu bar, or press the key combination shift-command-G. Paste into the text box that opens (command-V), then press return.
    From the folder that opens, move to the Trash any items that have "Adobe" or “PDF” in the name. You may be prompted for your login password. Then quit and relaunch Safari.
    Step 5
    The "Silverlight" web plugin distributed by Microsoft can interfere with PDF display in Safari, so you may need to remove it, if it's present. The same goes for a plugin called "iGetter," and perhaps others — I don't have a complete list. Don't remove Silverlight if you use the "Netflix" video-streaming service.
    Step 6
    Do as in Step 3 with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari.

  • Can I recover emails that were blocked when my storage was full?

    The storage on icloud was full for me for perhaps a number of days. I bought extra storage (20GB) and my emails are now working, but how can I recover the emails that were blocked when my storage was full?

    Yes.  I tried the refresh and checked the uninstall tab.  Still nothing.  Another thing though - when I entered my Blackberry ID, it would not let me use my screen name because it was supposedly already in use.  But I knew that because it was in use by me.  It would only let me use the same name with a numerical suffix.  So I am wondering if it thinks I am still logged on from before the upgrade.  Also, is it possible the Playbook thinks I am some other use and won't let me access my files - like photos and videos, etc.

  • How can I configure ReFS to NOT fail read operations when a checksum error is detected (on non-Storage-Spaces volumes where data integrity streams are enabled)?

    According to William Stanek, in his Windows Server 2012 R2 Inside Out: Configuration, Storage & Essentials book, this is apparently possible: (pg. 615 - here it is on Google Books: https://books.google.ca/books?id=0IyfBAAAQBAJ&pg=PT819&lpg=PT819&dq=read+operation )
        Integrity can be enabled when the system is not running on Storage Spaces. When
        integrity is enabled and ReFS detects a checksum mismatch, ReFS logs an event and
        fails the read operation by default. If you don’t want the read operation to fail, you
        can configure ReFS to continue with the read operation. A related event will be logged
        regardless.
    So then how do I configure it to do that???
    (And just to make it super-clear, I'm NOT using Storage Spaces, so there is no redundancy via mirroring/parity, and I'm not expecting any file repair - just detection of corruption. It's just a basic volume formatted with ReFS and
    with integrity streams enabled, via format E: /fs:ReFS /i:enabled
    For those who want more details, here's the situation: 
    I try to perform a read operation on a file with corrupted data (purposely done for testing using a low-level disk editor), I get a the following error message:
    And an event ID 133 from ReFSv1 gets logged in the System log:
    Clicking "Try Again" just brings up the same message, and clicking "Skip" skips the operation entirely.
    This is indeed the correct default behaviour.
    What I want instead is for the read operation to be allowed to complete, with corrupt data and all, and ONLY for the event to be logged. And according to William Stanek, this is supposed to be configurable somewhere - and after hours of searching, I haven't
    been able to find anything.

    Hi Tommy,
    >>How can I configure ReFS to NOT fail read operations when a checksum error is detected
    We can use PowerShell command Set-FileIntegrity to configure this. The specific parameter for controlling this behavior is
    -Enforce <Boolean>which indicates whether to enable blocking access to a file if integrity streams do not match the data.  
    Regarding this point, the following article can be referred to as reference.
    Set-FileIntegrity
    https://technet.microsoft.com/en-us/library/jj218351.aspx
    Best regards,
    Frank Shen
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Make few columns of Excel file read only when downloaded

    Hi Experts,
    Is there any way we can set few of the columns in excel sheet as read only when downloaded from SAP.
    We have requirement where a program will generate a report and download it into an excel file on desktop.  When the file is downloaded, two of its columns should be non editable.
    I know complete sheet of excel can be protected using OLE, can we protect few columns also using OLE?
    any idea how can it be done?

    Hi Swapnil,
    check this
    Re: OLE EXCEL : how to block cells ?
    hope it is useful to you.
    Thanks

  • "ERROR: Could not read block 64439 of relation 1663/16385/16658: Result too large"

    Hi,
    I've already archived a lot of assets in my final cut server but since one week there is a message appearing when I click on an asset and choose "Archive". The pop-up says: "ERROR: Could not read block 64439 of relation 1663/16385/16658: Result too large"
    Does anyone know what's the problem and/or have any suggestions to solve my problem?! I can't archive anymore since the first appearance of this message.
    What happened before?
    -> I archived some assets via FCS and then transfered the original media to an offline storage media. That system worked fine for the last months and my normal server stays quit small in storage use. But now, after I added some more new productions and let FCS generate the assets, it doesn't work anymore...
    It's not about the file size - I tried even the smallest file I found in some productions.
    It's not a particular production - I tried some different productions.
    It's not about the storage - there's a lot of storage left on my server.
    So, if someone knows how get this server back on the road - let me know.
    THNX!
    Chris

    I would really appreciate some advice re: recent FCS search errors.
    We're having similar issues to C.P.CGN's 2 year old post, it's only developed for us in the last few weeks.
    Our FCS machine is running 10.6.8 mac os and 1.5.2 final cut server with the latest
    OS 10.6.x updates.
    FCS is still usable for 6 of 8 offliners, but on some machines, searching assets presents "ERROR: could not read block 74012 of relation1663/16385/16576: Input/output error."
    Assuming the OS and/or data drives on the FCS machine were failing, I cloned the database drive today and will clone the OS drive tomorrow night, but after searching the forums and seeing similar error messages I'm not so sure.
    FCS has been running fine for last 4 years, minus the recent Java security issues.
    Thanks in advance, any ideas appreciated!
    cheers,
    Aaron Mooney,
    Post Production Supervisor.
    Electric Playground Daily, Reviews On The Run Daily, Greedy Docs.
    epn.tv

  • ORA-00204: error in reading (block string, # blocks string) of controlfile

    dear all
    when i start db
    with command  sqlplus "/as sysdba" 
    at the end it generate an error
    C:\Documents and Settings\idsadm>sqlplus "/as sysdba"
    SQL*Plus: Release 10.2.0.1.0 - Production on Mon Oct 20 12:47:37 2008
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to an idle instance.
    SQL> startup
    ORACLE instance started.
    Total System Global Area  557842432 bytes
    Fixed Size                  1250140 bytes
    Variable Size             289410212 bytes
    Database Buffers          264241152 bytes
    Redo Buffers                2940928 bytes
    ORA-00204: error in reading (block 3, # blocks 50) of control file
    ORA-00202: control file: 'F:\ORACLE\IDS\SAPDATA1\CNTRL\CNTRLIDS.DBF'
    ORA-27091: unable to queue I/O
    ORA-27070: async read/write failed
    OSD-04006: ReadFile() failure, unable to read from file
    O/S-Error: (OS 23) Data error (cyclic redundancy check).

    dear karan & all
    i have copied "control file" from another location but now it generate an error
    SQL> startup
    ORACLE instance started.
    Total System Global Area  557842432 bytes
    Fixed Size                  1250140 bytes
    Variable Size             289410212 bytes
    Database Buffers          264241152 bytes
    Redo Buffers                2940928 bytes
    ORA-00211: control file does not match previous control files
    ORA-00202: control file: 'F:\ORACLE\IDS\SAPDATA1\CNTRL\CNTRLIDS.DBF'
    SQL>
    now tell me what can i do
    regard

  • Sapscript: How to combine two elements into a block when display ?

    /E  ITEM_CONDITIONS
    /:   PROTECT
    ZC &KOMVD-VTEXT&,,&KOMVD-KWERT&
    /:   ENDPROTECT
    /E  TOTAL_AMOUNT_ITEMS
    /:   PROTECT
    ZC &KOMK-SUPOS&
    /:   ENDPROTECT
    Hi, all. May i know how to combine the two elements into a same block when displaying?
    That's mean this two element content will not be split into two part between two pages when there is insufficient space in the front page.
    Thanks.
    Edited by: Jiansi Lim on Oct 8, 2008 12:24 AM

    You can evoke the PROTECT..ENDPROTECT in the print program before the call of the text elements.
          CALL FUNCTION 'CONTROL_FORM'
            EXPORTING
              command = 'PROTECT'.
          CALL FUNCTION 'CONTROL_FORM'
            EXPORTING
              command = 'ENDPROTECT'.

  • PDF forms won't open. Says Adobe Reader blocked for this site

    In last few days, when I click on link to a PDF document, I get a new tab, but a black message saying Adobe Reader blocked for the site. I've installed, and agreed end user; but nothing changes.

    This page should help: Safari 7 and 6.1 block PDFs | Acrobat, Reader
    -Shashi

  • Adobe Reader Blocked in Safari

    It's been a while, but ever since I upadated to Safari 7.0.1 (or maybe even the version earlier), I've been unable to open any PDF documents inside of Safari. When I click on a link on Google linked to a PDF document, a grey page shows up with the message "Adobe Reader blocked for this website" I tried clicking the message and a panel dropped down asking me whether I trust the website or not. But even after I clicked Trust and the page reloaded it self the PDF still doesn't show up.
    Anyoen know how to get around this? I know Apple got rid of native support for many web applications because of security threat but there should be a way to put it back in right?
    Thanks,

    Select
    Safari ▹ Preferences... ▹ Security
    from the Safari menu bar and check the box marked
    Allow (or Enable) plug-ins
    Then click the button marked
    Manage Website Settings...

  • Firefox have some promlems and it block when is opeining hotmail, in my laptop always have that problem, so i need check my email using another programs...that problem is in my laptop or it´s a problem of navigator??

    Firefox have some problems and it block when is opening hotmail, in my laptop always have that problem, so i need check my email using another programs...that problem is in my laptop or it´s a problem of navigator??

    I know you can't help with my Yahoo problem, however, apparently at some time in the past I have went to the Sync and tried to figure it out on both my laptop and my desktop, because I have the long snyc key information. However, when I go to try to sync both computers I never get the box to enter that key on either one. That is my problem. So should I try and get a new sync key and see if that works.

  • BufferedReader - reading text files in chunks

    Currently I am using the following to read in a file, 1 line at a time
    BufferedReader reader = new BufferedReader(new FileReader(inFile));          
    String line = null;                   
    // While there are lines to read from the file
    while ((line=reader.readLine()) != null)
         System.out.println(line);
    reader.close();Is it possible to extend this so insteadof reading a line at a time, I can read a chunk, for example 1Kb at a time, or would I need to use a different approach.
    Thanks

    You need to provide the buffer it has to use, but you use null. If you want to read 1024 characters, you need to pass it a character array of length 1024.
    And the offset is not an offset into the file, but into the buffer. Usually you want to pass 0 here.
    so your call would look like this:
    readRetVal = reader.read(chrArr, 0, 1024);And if you pass the value of chrArr.length as the last parameter you could just as well call this one:
    readRetVal = reader.read(chrArr);as it has the same effect. But you have to be carefull when constructing the string, as you might not have the entire size of the array filled with valid data (check readRetVal).

  • Export with Table Splitting : ORA-01115: IO error reading block from file

    Hello,
    We are in perfroming the last dryrun of our CU&UC conversion.
    The are now in the process of exporting the ECC6 system (Oracle 10.2.0.4.0, HPUX ia64) using sapinst features, "table splitting preparation"
    When doing so, we are facing critical errors :
    Creating file /export_uni/sapinst_splitting/ora_query3_tmp3_1.sql.
    ERROR 2010-08-11 10:27:28.881
    CJS-00084  SQL statement or script failed. DIAGNOSIS: Error message: ORA-12801: error signaled in parallel query server P002
    ORA-01115: IO error reading block from file 90 (block # 16640)
    ORA-27072: File I/O error
    HPUX-ia64 Error: 22: Invalid argument
    Additional information: 4
    Additional information: 16640
    Additional information: -1
    ORA-01115: IO error reading block from file 90 (block # 16640)
    ORA-27072: File I/O error
    HPUX-ia64 Error: 22: Invalid argument
    ORA-06512: at "SAPR3.TABLE_SPLITTER", line 775
    ORA-06512: at line 1
    I have therefore perfmed a dbverify ; no corruption has been recorded.
    When trying to perfrom the EXPORT, without table splitting ; it works fine ...but the processing time is extremely long, as you can imagine. Any help would be highly appreciated.Regards.
    Raoul

    Thank you Stefan,
    Our HPUX Release seems to be indeed 11v3,
    [root@:/root]# uname -a
    HP-UX B.11.31 U ia64 2566039091 unlimited-user license
    I'll check the installation of the  patch and keep you informed
    Thank you
    Raoul
    Edited by: Raoul Shiro on Aug 11, 2010 11:57 AM

  • When I attach a JPG file in my email and send it to a Windows friend they get the message "The file type being saved or retrieved has been blocked when they try to open it." Anyone know why and how to fix this problem?

    When I attach a JPG file in my email message and send it to a Windows friend they get the message "The file type being saved or retrieved has been blocked when they try to open it so that they can save it." Anyone know why and how to fix this problem?

    Your Windows friend should ask in a Windows forum why his email client won't open attached jpg files. We have no idea what email client he is using or how his Windows security is configured.

Maybe you are looking for

  • Goods Mvt based on SLED

    Hi there,               I got the requirement in which if the SLED is within one month then that batch cannot be used/sent to other countries but it can be used for the plant in the same country... Is there any stardard way that SAP supports...... Re

  • 10.5.8 updated killed Write/Update permissions on my Boot camp partition.

    I can't figure this one out. I regularly "reach over" to my boot camp partition to move files from XP to my mac, and have automator scripts that also do that. Since the update, it no longer works either manually or via automator. I can read and copy

  • ERROR: executing command  /usr/openv/netbackup/bin/bpbackup

    Hi, Online backup in one of our integration systems is failing with the followin reasons                                                                                Status = 58 : can't connect to client Status = 54 : timed out connecting to client

  • Payroll: Impact of Infotype Delimits.

    Hi Gurus, Currently i am working on assignment (From Employee Resignation to Full & Final settlement). I have a query: Is that possible to run the payroll when i delimit the IT. Say: I want to issue the full & Final Settlement. If i delimit the infot

  • Ringtones on iTunes 7.4

    Ok, so apple brought out iTunes 7.4 and it includes the "Ringtone" tabs for those who have iPhones. However, I don't seem to be able to purchase ringtones. Is it because it's not availble? Or is it my computer/itunes? I don't see any ringtone symbol