• Post Reply Bookmark Topic Watch Topic
  • New Topic

IO Exception: Unable to read entire block; 49 bytes read; expected 512 bytes

 
Pramod
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am uploading an MSExcel file to a servlet. The servlet reads this file thru ServletInputStream and when I try to pass this stream to
// reads Excel file
HSSFWorkbook wb = new HSSFWorkbook(inputStream);
It throws me exception:
java.io.IOException Unable to read entire block; 49 bytes read; expected 512 bytes
Can anybody help me in this ?
[ February 18, 2003: Message edited by: Pramod Deshmukh ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a bug in HSSFWorkbook - one of the POI developers evidently didn't fully understand how InputStreams work. The problem is explained here, along with a fix. if you don't want to patch their file, you can probably also work around this by doing something like this:

Unlike the general read(byte[]) method defined in InputStream, the ByteInputStream's read(byte[]) method is guaranteed to always return the maximum number of bytes possible. (Limited by either the size of the byte[] being read into, or the end of the input stream - nothing else.)
 
Glenn Murray
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I had this problem recently with POI 2.5.1 and 3.0 alpha3, so it doesn't
seem that they are going to fix it.

I'm happy to report that Java Excel API at http://www.andykhan.com/jexcelapi/ works for my needs, and does Excel 95, as well.

Cheers,
Glenn
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!