• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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 ]
 
Wanderer
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.)
 
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
    Bookmark Topic Watch Topic
  • New Topic