• Post Reply Bookmark Topic Watch Topic
  • New Topic

unable to read file header  RSS feed

 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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 ,
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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 ....
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
yes i am reusing ...
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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 ...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!