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

public Class POIFSStream

extends Object
implements Iterable<ByteBuffer>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Imports
java.io.IOException, .OutputStream, java.nio.ByteBuffer, java.util.Iterator, .NoSuchElementException, org.apache.poi.poifs.common.POIFSConstants, org.apache.poi.poifs.filesystem.BlockStore.ChainLoopDetector, org.apache.poi.poifs.property.Property, org.apache.poi.poifs.storage.HeaderBlock

This handles reading and writing a stream within a POIFSFileSystem. It can supply an iterator to read blocks, and way to write out to existing and new blocks. Most users will want a higher level version of this, which deals with properties to track which stream this is. This only works on big block streams, it doesn't handle small block ones. This uses the new NIO code TODO Implement a streaming write method, and append

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
private class
POIFSStream.StreamBlockByteBufferIterator

Class that handles a streaming read of one stream

private class
POIFSStream.StreamBlockOffsetIterator

Class that handles a streaming read of one stream

Field Summary

Modifier and TypeField and Description
private final BlockStore
private OutputStream
private int

Constructor Summary

AccessConstructor and Description
public
POIFSStream(BlockStore blockStore, int startBlock)

Constructor for an existing stream.

public
POIFSStream(BlockStore blockStore)

Constructor for a new stream.

Method Summary

Modifier and TypeMethod and Description
public void
free()

Frees all blocks in the stream

private void
pack-priv Iterator<ByteBuffer>
pack-priv Iterator<Integer>
public OutputStream
public int
getStartBlock()

What block does this stream start at?

public Iterator<ByteBuffer>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator that'll supply one ByteBuffer per block in the stream.

pack-priv void
updateContents(byte[] contents)

Updates the contents of the stream to the new set of bytes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockStoreback to summary
private final BlockStore blockStore
outStreamback to summary
private OutputStream outStream
startBlockback to summary
private int startBlock

Constructor Detail

POIFSStreamback to summary
public POIFSStream(BlockStore blockStore, int startBlock)

Constructor for an existing stream. It's up to you to know how to get the start block (eg from a HeaderBlock or a Property)

POIFSStreamback to summary
public POIFSStream(BlockStore blockStore)

Constructor for a new stream. A start block won't be allocated until you begin writing to it.

Method Detail

freeback to summary
public void free() throws IOException

Frees all blocks in the stream

freeback to summary
private void free(BlockStore.ChainLoopDetector loopDetector)
getBlockIteratorback to summary
pack-priv Iterator<ByteBuffer> getBlockIterator()
getBlockOffsetIteratorback to summary
pack-priv Iterator<Integer> getBlockOffsetIterator()
getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException
getStartBlockback to summary
public int getStartBlock()

What block does this stream start at? Will be POIFSConstants#END_OF_CHAIN for a new stream that hasn't been written to yet.

iteratorback to summary
public Iterator<ByteBuffer> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator that'll supply one ByteBuffer per block in the stream.

Returns:Iterator<ByteBuffer>

Doc from java.lang.Iterable.iterator.

an Iterator.

updateContentsback to summary
pack-priv void updateContents(byte[] contents) throws IOException

Updates the contents of the stream to the new set of bytes. Note - if this is property based, you'll still need to update the size in the property yourself

org.apache.poi.poifs.filesystem back to summary

protected Class POIFSStream.StreamBlockByteBuffer

extends OutputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv ByteBuffer
pack-priv BlockStore.ChainLoopDetector
pack-priv int
pack-priv byte[]
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

pack-priv void
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from java.io.OutputStream:
flushnullOutputStreamwrite

Field Detail

bufferback to summary
pack-priv ByteBuffer buffer
loopDetectorback to summary
pack-priv BlockStore.ChainLoopDetector loopDetector
nextBlockback to summary
pack-priv int nextBlock
oneByteback to summary
pack-priv byte[] oneByte
prevBlockback to summary
pack-priv int prevBlock

Constructor Detail

StreamBlockByteBufferback to summary
pack-priv StreamBlockByteBuffer() throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Exceptions
IOException:
if an I/O error occurs.
createBlockIfNeededback to summary
pack-priv void createBlockIfNeeded() throws IOException
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
org.apache.poi.poifs.filesystem back to summary

private Class POIFSStream.StreamBlockByteBufferIterator

extends Object
implements Iterator<ByteBuffer>
Class Inheritance
  • java.lang.Object
  • org.apache.poi.poifs.filesystem.POIFSStream.StreamBlockByteBufferIterator
All Implemented Interfaces
java.util.Iterator

Class that handles a streaming read of one stream

Field Summary

Modifier and TypeField and Description
private final BlockStore.ChainLoopDetector
private int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public ByteBuffer
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loopDetectorback to summary
private final BlockStore.ChainLoopDetector loopDetector
nextBlockback to summary
private int nextBlock

Constructor Detail

StreamBlockByteBufferIteratorback to summary
pack-priv StreamBlockByteBufferIterator(int firstBlock)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public ByteBuffer next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:ByteBuffer

the next element in the iteration

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

org.apache.poi.poifs.filesystem back to summary

private Class POIFSStream.StreamBlockOffsetIterator

extends Object
implements Iterator<Integer>
Class Inheritance
  • java.lang.Object
  • org.apache.poi.poifs.filesystem.POIFSStream.StreamBlockOffsetIterator
All Implemented Interfaces
java.util.Iterator

Class that handles a streaming read of one stream

Field Summary

Modifier and TypeField and Description
private final BlockStore.ChainLoopDetector
private int

Constructor Summary

AccessConstructor and Description
pack-priv
StreamBlockOffsetIterator(int firstBlock)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Integer
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loopDetectorback to summary
private final BlockStore.ChainLoopDetector loopDetector
nextBlockback to summary
private int nextBlock

Constructor Detail

StreamBlockOffsetIteratorback to summary
pack-priv StreamBlockOffsetIterator(int firstBlock)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public Integer next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Integer

the next element in the iteration

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.