Top Description Fields Constructors Methods
org.apache.poi.poifs.filesystem

public final Class DocumentInputStream

extends InputStream
implements LittleEndianInput
Class Inheritance
All Implemented Interfaces
org.apache.poi.util.LittleEndianInput
Static Imports
org.apache.poi.util.LittleEndianConsts.INT_SIZE, .LittleEndianConsts.LONG_SIZE, .LittleEndianConsts.SHORT_SIZE

This class provides methods to read a DocumentEntry managed by a POIFSFileSystem instance.

Field Summary

Modifier and TypeField and Description
private ByteBuffer
private boolean
_closed

have we been closed?

private int
_current_block_count

current block count

private int
_current_offset

current offset into the Document

private Iterator<ByteBuffer>
private final POIFSDocument
_document

the actual Document

private final int
_document_size

the Document's size

private int
_marked_offset

current marked offset into the Document (used by mark and reset)

private int
_marked_offset_count

and the block count for it

private static final int
EOF

returned by read operations if we're at end of document

Constructor Summary

AccessConstructor and Description
public
DocumentInputStream(DocumentEntry
the DocumentEntry to be read
document
)

Create an InputStream from the specified DocumentEntry

public
DocumentInputStream(POIFSDocument
the Document to be read
document
)

Create an InputStream from the specified Document

Method Summary

Modifier and TypeMethod and Description
private boolean
public int
available()

Overrides java.io.InputStream.available.

Implements org.apache.poi.util.LittleEndianInput.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

private void
checkAvaliable(int requestedSize)

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

private void
public synchronized void
mark(int
the maximum limit of bytes that can be read before the mark position becomes invalid.
ignoredReadlimit
)

Overrides java.io.InputStream.mark.

Marks the current position in this input stream.

public boolean

Returns:

true always
markSupported
()

Overrides java.io.InputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
b
)

Overrides java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b.

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public byte
public double
public void
public void
readFully(byte[] buf, int off, int len)

Implements org.apache.poi.util.LittleEndianInput.readFully.

public int
public long
public void
readPlain(byte[]
the byte array to receive the bytes
buf
,
int
the start offset into the byte array
off
,
int
the amount of bytes to fill
len
)

Implements org.apache.poi.util.LittleEndianInput.readPlain.

Usually acts the same as readFully(byte[], int, int), but for an encrypted stream the raw (unencrypted) data is filled

public short
public int
public long
public int
private int

Returns:

the bytes remaining until the end of the stream
remainingBytes
()

Helper methods for forbidden api calls

public synchronized void
reset()

Overrides java.io.InputStream.reset.

Repositions this stream to the position at the time the mark() method was last called on this input stream.

public long
skip(long
the number of bytes to be skipped.
n
)

Overrides java.io.InputStream.skip.

Skips over and discards n bytes of data from this input stream.

Inherited from java.io.InputStream:
nullInputStreamreadAllBytesreadNBytesreadNBytesskipNBytestransferTo

Field Detail

_bufferback to summary
private ByteBuffer _buffer
_closedback to summary
private boolean _closed

have we been closed?

_current_block_countback to summary
private int _current_block_count

current block count

_current_offsetback to summary
private int _current_offset

current offset into the Document

_databack to summary
private Iterator<ByteBuffer> _data
_documentback to summary
private final POIFSDocument _document

the actual Document

_document_sizeback to summary
private final int _document_size

the Document's size

_marked_offsetback to summary
private int _marked_offset

current marked offset into the Document (used by mark and reset)

_marked_offset_countback to summary
private int _marked_offset_count

and the block count for it

EOFback to summary
private static final int EOF

returned by read operations if we're at end of document

Constructor Detail

DocumentInputStreamback to summary
public DocumentInputStream(DocumentEntry document) throws IOException

Create an InputStream from the specified DocumentEntry

Parameters
document:DocumentEntry

the DocumentEntry to be read

Exceptions
IOException:
if the DocumentEntry cannot be opened (like, maybe it has been deleted?)
DocumentInputStreamback to summary
public DocumentInputStream(POIFSDocument document)

Create an InputStream from the specified Document

Parameters
document:POIFSDocument

the Document to be read

Method Detail

atEODback to summary
private boolean atEOD()
availableback to summary
public int available()

Overrides java.io.InputStream.available.

Implements org.apache.poi.util.LittleEndianInput.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.

Annotations
@Override
checkAvaliableback to summary
private void checkAvaliable(int requestedSize)
closeback to summary
public void close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
dieIfClosedback to summary
private void dieIfClosed() throws IOException
markback to summary
public synchronized void mark(int ignoredReadlimit)

Overrides java.io.InputStream.mark.

Doc from java.io.InputStream.mark.

Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

The general contract of mark is that, if the method markSupported returns true, the stream somehow remembers all the bytes read after the call to mark and stands ready to supply those same bytes again if and whenever the method reset is called. However, the stream is not required to remember any data at all if more than readlimit bytes are read from the stream before reset is called.

Marking a closed stream should not have any effect on the stream.

Parameters
ignoredReadlimit:int

the maximum limit of bytes that can be read before the mark position becomes invalid.

Annotations
@Override
markSupportedback to summary
public boolean markSupported()

Overrides java.io.InputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

Returns:boolean

true always

Annotations
@Override
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[0], the next one into b[1], and so on. The number of bytes read is, at most, equal to the length of b. Let k be the number of bytes actually read; these bytes will be stored in elements b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
readByteback to summary
public byte readByte()

Implements org.apache.poi.util.LittleEndianInput.readByte.

Annotations
@Override
readDoubleback to summary
public double readDouble()

Implements org.apache.poi.util.LittleEndianInput.readDouble.

Annotations
@Override
readFullyback to summary
public void readFully(byte[] buf)

Implements org.apache.poi.util.LittleEndianInput.readFully.

Annotations
@Override
readFullyback to summary
public void readFully(byte[] buf, int off, int len)

Implements org.apache.poi.util.LittleEndianInput.readFully.

Annotations
@Override
readIntback to summary
public int readInt()

Implements org.apache.poi.util.LittleEndianInput.readInt.

Annotations
@Override
readLongback to summary
public long readLong()

Implements org.apache.poi.util.LittleEndianInput.readLong.

Annotations
@Override
readPlainback to summary
public void readPlain(byte[] buf, int off, int len)

Implements org.apache.poi.util.LittleEndianInput.readPlain.

Doc from org.apache.poi.util.LittleEndianInput.readPlain.

Usually acts the same as readFully(byte[], int, int), but for an encrypted stream the raw (unencrypted) data is filled

Parameters
buf:byte[]

the byte array to receive the bytes

off:int

the start offset into the byte array

len:int

the amount of bytes to fill

Annotations
@Override
readShortback to summary
public short readShort()

Implements org.apache.poi.util.LittleEndianInput.readShort.

Annotations
@Override
readUByteback to summary
public int readUByte()

Implements org.apache.poi.util.LittleEndianInput.readUByte.

Annotations
@Override
readUIntback to summary
public long readUInt()
readUShortback to summary
public int readUShort()

Implements org.apache.poi.util.LittleEndianInput.readUShort.

Annotations
@Override
remainingBytesback to summary
private int remainingBytes()

Helper methods for forbidden api calls

Returns:int

the bytes remaining until the end of the stream

resetback to summary
public synchronized void reset()

Overrides java.io.InputStream.reset.

Repositions this stream to the position at the time the mark() method was last called on this input stream. If mark() has not been called this method repositions the stream to its beginning.

Annotations
@Override
skipback to summary
public long skip(long n) throws IOException

Overrides java.io.InputStream.skip.

Doc from java.io.InputStream.skip.

Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, the skip method for class InputStream always returns 0, and no bytes are skipped. Subclasses may handle the negative value differently.

Parameters
n:long

the number of bytes to be skipped.

Returns:long

the actual number of bytes skipped which might be zero.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.