• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic