You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Tony Chao <tc...@cymfony.com> on 2003/03/17 20:57:41 UTC
poi.poifs.storage.RawDataBlock read block size bug?
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;
}
}
Re: poi.poifs.storage.RawDataBlock read block size bug?
Posted by "Andrew C. Oliver" <ac...@apache.org>.
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: poi-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: poi-dev-help@jakarta.apache.org
>
>
>
>