• 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
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

unable to read file header

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all ,
my problem is related with file Header
in my jsp application i am uploading excel sheet using "apache.poi"
for validation when i m open & chek file it work fine , but next time when i read same file again ..... then following exception occur .....

-------------------------------------------------------------------------------------
Unable to read entire header; 0 bytes read; expected 512 bytes
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:83)
-------------------------------------------------------------------------------------
is this problem related with file header ...??
thanks in advance ,
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you try to open the file the second time, is it still there? Or have you accidentally truncated it by opening it for writing (i.e., with a FileWriter?)
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Ernest !
yes , file is there no any other operation with that .
but second time when i assign this fileStream to
.----------------------------------------------
fileSystem = new POIFSFileSystem(fileStream );
----------------------------------------------
now i m getting that error ....
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean you are reusing the same stream, the one you have already read from?
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i am reusing ...
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ! ,
i just want to add some lines ....
i receive input stream as follow
-------------------------------------------------
InputStream f1 = (InputStream) request.getAttribute("fileStream");
-------------------------------------------------
this one is one excel file ...
now pass this 'f1'

method1(f1);// here i m takiing 'f1' as InputStream or FileInputStream (by typecasting 'f1')

in method1 i am able to read input stream using apache api
suppose i pass this inputStream again to 'method1()' it gives error ...
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cant reuse the same file stream - it is positioned at the end-of-file. Just open a new one.

Bill
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there no any other way except reopen the file ,
as i explain last post
i store that requist in two different InputStream , but it gives same error

i have also copied that inputstream in another inputstream , but it not work
[ May 12, 2008: Message edited by: Sanjay Chougule ]
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you get the Excel data from the client, save it to a temporary file on the server; then you can open it as many times as you need to.
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest !!!
I have also tried same thing , i.e. copy client data at server & reuse it but reusing second time it gives same error �.
This inputstream also not support mark() & reset() methods .
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the content of the stream into a byte array, and then pass a ByteArrayInputStream into those methods. Use a new ByteArrayInputStream for each method call, and reuse the byte array.
 
reply
    Bookmark Topic Watch Topic
  • New Topic