Patches and unit tests please (or relevant ones passing):
http://jakarta.apache.org/poi/getinvolved/index.html

Thanks,

Andy

Tony Chao wrote:

While trying to open an input stream with new HSSFWorkbook(input);
I got an erro indicating RawDataBlock was unable to read the entire block.

java.io.IOException: Unable to read entire block; 47 bytes read; expected
512 bytes
        at org.apache.poi.poifs.storage.RawDataBlock.(RawDataBlock.java:98)
        at org.apache.poi.poifs.storage.RawDataBlockList.(RawDataBlockList.java:88)
        at
org.apache.poi.poifs.filesystem.POIFSFileSystem.(POIFSFileSystem.java:123)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:238)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:219)

I examined the source code and found that RawDataBlock expects to be able to
read
0x0200 bytes from the input stream with 1 read call. (code segment attached
at the end)

Is there a reason RawDataBlock has to read 0x0200 blocks at a time?
If RawDataBlock requires data in 0x0200 chunks, shouldn't the read loop
until 0x0200 is available?

I suspect the problem is b/c most ppl use FileInputStream for their
HSSFWorkbook,
I tried to use a ServletInputStream and a ByteArrayInputStream. Both gave
exceptions
because they return data in chunks smaller than 0x0200.

I would propose the method loop until POIFSConstants.BIG_BLOCK_SIZE bytes
are
collected, or at least try a few times before giving up. (e.g. if read 0
bytes for 3
consecutive reads, give up)

If this is an acceptable suggestion, I can reply with the suggested code
changes.

Thanks
-Tony




Code Segment: public RawDataBlock(final InputStream stream) throws IOException { _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ]; int count = stream.read(_data);

       if (count == -1)
       {
           _eof = true;
       }
       else if (count != POIFSConstants.BIG_BLOCK_SIZE)
       {
           String type = " byte" + ((count == 1) ? ("")
                                                 : ("s"));

           throw new IOException("Unable to read entire block; " + count
                                 + type + " read; expected "
                                 + POIFSConstants.BIG_BLOCK_SIZE + "
bytes");
       }
       else
       {
           _eof = false;
       }
   }


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]








---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to