You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Sawant, Ramdas (IT)" <Ra...@morganstanley.com> on 2006/03/30 16:37:56 UTC

InputStream and POIFSFileSystem...

Hi all,

             I have one question. Can I pass/use the same InputStream to
POIFSFileSystem. Because, when I passed the same InputStream to two
different functions I am getting the following error --

java.io.IOException: Unable to read entire header; -1 bytes read;
expected 512 bytes
        at
org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.
java:115)
        at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.j
ava:120)

Please put some light on this..

Regards,

Ramdas Sawant

........................................................................

Associate Consultant, Kanbay

Manikchand Ikon, South Wing 18 Dhole Patil Road
Pune  411001
INDIA

........................................................................
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender.  Sender does not waive confidentiality or privilege, and use is prohibited.

Re: InputStream and POIFSFileSystem...

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 30 Mar 2006, Sawant, Ramdas (IT) wrote:
> I have one question. Can I pass/use the same InputStream to 
> POIFSFileSystem. Because, when I passed the same InputStream to two 
> different functions I am getting the following error --

No, and nor can you do it with pretty much anything else that uses an 
input stream.

Just create one POIFSFileSystem, and make repeated calls to that.

If you really do need to give it to two different POIFSFileSystems, 
you'll have to read all the inputstream into a byte array, and create 
ByteArrayInputStreams from that. See your favourite Java book for details 
and other options

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/


RE: InputStream and POIFSFileSystem...

Posted by Tahir Akhtar <ta...@spectrum-tech.com>.
Hi Ramdas

This is nothing special to POIFS input stream. It is generally how input
stream works. Each stream present you a linear view of data like a queue
(hence the name stream). When you read, say a byte, from the stream it will
advance its pointer to next byte of data. Next time you read a byte from
that stream it will be the second byte that will be returned by the read
method. Different type of streams let you read different amount of data in
one go. For example data input stream will let you read an char that is two
bytes long.

So in summary when you have completely read the data from an input stream,
attempting to read further data will return nothing. If your application is
expecting certain amount of data (like a header in poifs) than it's going to
crash with an exception.

Hope that helps.

Regards,
Tahir Akhtar
-----Original Message-----
From: Sawant, Ramdas (IT) [mailto:Ramdas.Sawant@morganstanley.com] 
Sent: Thursday, March 30, 2006 7:38 PM
To: poi-user@jakarta.apache.org
Subject: InputStream and POIFSFileSystem...

Hi all,

             I have one question. Can I pass/use the same InputStream to
POIFSFileSystem. Because, when I passed the same InputStream to two
different functions I am getting the following error --

java.io.IOException: Unable to read entire header; -1 bytes read;
expected 512 bytes
        at
org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.
java:115)
        at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.j
ava:120)

Please put some light on this..

Regards,

Ramdas Sawant

........................................................................

Associate Consultant, Kanbay

Manikchand Ikon, South Wing 18 Dhole Patil Road
Pune  411001
INDIA

........................................................................
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender.  Sender does
not waive confidentiality or privilege, and use is prohibited.

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.3.3/296 - Release Date: 3/29/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.3.3/296 - Release Date: 3/29/2006
 


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/