|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.mmm.util.io.impl.DetectorStreamBufferImpl
public class DetectorStreamBufferImpl
This is the implementation of the DetectorStreamBuffer interface.
It is based on the idea that each DetectorStreamProcessor in the
chain has its own DetectorStreamBuffer instance. Therefore it holds
the according DetectorStreamProcessor building a pair of
buffer+processor. Further it holds an instance of the predecessor and thereby
represents the chain itself.
| Nested Class Summary | |
|---|---|
protected class |
DetectorStreamBufferImpl.CurrentByteArray
This inner class is a view on the current ByteArray. |
protected static class |
DetectorStreamBufferImpl.SeekMode
Enum with available modes for a seek. |
| Field Summary | |
|---|---|
private LinkedList<ByteArray> |
arrayQueue
The Queue of available DetectorStreamBufferImpl.CurrentByteArrays that have NOT
yet been processed. |
private ByteArrayPool |
byteArrayPool
The ByteArrayPool. |
private DetectorStreamBufferImpl |
chainSuccessor
The successor in the chain or null if this is the last. |
private byte[] |
currentArray
The current DetectorStreamBufferImpl.CurrentByteArray to work on. |
private int |
currentArrayIndex
The index in currentArray. |
private int |
currentArrayMax
The maximum index in
currentArray. |
private int |
currentArrayMin
The start-index in currentArray. |
private ByteArray |
currentArrayView
|
private ByteArray |
currentByteArray
|
private DetectorStreamProcessor |
processor
The actual processor served by this buffer. |
private long |
seekCount
|
private DetectorStreamBufferImpl.SeekMode |
seekMode
|
private long |
streamPosition
|
| Constructor Summary | |
|---|---|
DetectorStreamBufferImpl(DetectorStreamProcessor processor,
DetectorStreamBufferImpl successor,
ByteArrayPool byteArrayPool)
The constructor. |
|
| Method Summary | |
|---|---|
protected void |
append(ByteArray nextArray)
This method queues the given DetectorStreamBufferImpl.CurrentByteArray at the end of this buffer. |
int |
fill(byte[] buffer,
int offset,
int length)
This method fills the given buffer starting at
offset with the next bytes from this
ComposedByteBuffer. |
ByteArray |
getByteArray(int index)
This method gets the ByteArray at the given index. |
int |
getByteArrayCount()
This method gets the number of ByteArrays currently available via
ComposedByteBuffer.getByteArray(int). |
int |
getBytesAvailable()
This method gets the number of bytes available. |
long |
getStreamPosition()
This method gets the absolute position of the current pointer in the logical stream (the data provided by this interface that origins from the previous member of the chain). |
boolean |
hasNext()
This method determines if there is a next byte available. |
void |
insert(byte... data)
This method inserts the given bytes at the current position into the stream. |
void |
insert(ByteArray data)
This method inserts the given data at the current position
into the stream. |
byte |
next()
This method gets the current byte in the iteration. |
private boolean |
nextArray()
This method switches over to the next internal byte-array. |
byte |
peek()
This method gets the current byte in the iteration. |
void |
process(Map<String,Object> metadata,
boolean eos)
|
protected void |
release(ByteArray byteArray)
This method is called when a DetectorStreamBufferImpl.CurrentByteArray is wiped out of the chain. |
void |
remove(long byteCount)
This method removes the number of bytes given by byteCount
from the stream starting at the current position. |
protected void |
seek(long byteCount,
DetectorStreamBufferImpl.SeekMode mode)
This method removes or skips the
given number of bytes. |
long |
skip()
This method skips all bytes available in this
buffer. |
long |
skip(long byteCount)
This method skips the number of bytes given by byteCount in
the stream starting at the current position. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private DetectorStreamProcessor processor
private DetectorStreamBufferImpl chainSuccessor
null if this is the last.
private long streamPosition
getStreamPosition()private long seekCount
seek(long, SeekMode)private DetectorStreamBufferImpl.SeekMode seekMode
seek(long, SeekMode)private ByteArray currentByteArray
getByteArray(int)private byte[] currentArray
DetectorStreamBufferImpl.CurrentByteArray to work on.
private int currentArrayMin
currentArray.
private int currentArrayIndex
index in currentArray.
private int currentArrayMax
maximum index in
currentArray.
private final LinkedList<ByteArray> arrayQueue
Queue of available DetectorStreamBufferImpl.CurrentByteArrays that have NOT
yet been processed.
private final ByteArray currentArrayView
getByteArray(int)private ByteArrayPool byteArrayPool
ByteArrayPool.
| Constructor Detail |
|---|
public DetectorStreamBufferImpl(DetectorStreamProcessor processor,
DetectorStreamBufferImpl successor,
ByteArrayPool byteArrayPool)
processor - is the DetectorStreamProcessor served by this
buffer.successor - is the successor in the chain or null if this
is the last buffer/processor pair in the chain.byteArrayPool - is the ByteArrayPool to use.| Method Detail |
|---|
public long skip(long byteCount)
byteCount in
the stream starting at the current position. The given number of bytes will
be untouched in stream (queued for the next processor in the chain).
skip in interface ByteIteratorskip in interface DetectorStreamBufferbyteCount - is the number of bytes to ignore. This value can be
greater than the currently available
bytes. You may supply Long.MAX_VALUE to ignore to the end
of the stream.
byteCount.InputStream.skip(long)public long skip()
available in this
buffer. This is logically the same as
skip(ByteProvider.getBytesAvailable()) but
more efficient.
skip in interface DetectorStreamBufferpublic ByteArray getByteArray(int index)
ByteArray at the given index. The
DetectorStreamBuffer is composed out of
ByteArrays. This method allows efficient processing of bytes from
byte[] rather then calling ByteIterator.hasNext() and
ByteIterator.next() and repetitive. Additionally this way allows full lookahead
up to the end of the buffer without consuming the data.ByteIterator.next() or ByteIterator.skip(long) will
invalidate the returned ByteArray. Please do NOT call these methods
while working with ByteArrays.
getByteArray in interface ComposedByteBufferindex - is the index of the requested ByteArray. It has to be
in the range from 0 to
ComposedByteBuffer.getByteArrayCount() - 1. A value of 0
indicates the current ByteArray this buffer is currently
pointing to. For that current buffer
ByteArray.getBytes()[ByteArray.getCurrentIndex()]
will have the same result as ByteIterator.peek().
ByteArray.ComposedByteBuffer.getByteArrayCount()public int getByteArrayCount()
ByteArrays currently available via
ComposedByteBuffer.getByteArray(int).ByteIterator.next() or ByteIterator.skip(long) will
invalidate the returned ByteArray. Please do NOT call these methods
while working with ByteArrays.
getByteArrayCount in interface ComposedByteBufferByteArrays.public int getBytesAvailable()
getBytesAvailable in interface ByteProviderpublic boolean hasNext()
next byte available.
hasNext in interface ByteIteratortrue if there is a next byte
available, false otherwise (if the end of this buffer
has been reached).protected void release(ByteArray byteArray)
DetectorStreamBufferImpl.CurrentByteArray is wiped out of the chain.
byteArray - is the array to release.private boolean nextArray()
byte-array.
true if a new buffer is available, false
if the buffer queue is empty.
public byte next()
throws NoSuchElementException
ByteIterator points to the next byte in the iteration
or to the end if there is no such byte available.ByteIterator.hasNext() returns
true.
next in interface ByteIteratorNoSuchElementException - if there is no such byte available.Iterator.next()
public byte peek()
throws NoSuchElementException
ByteIterator.next()
this method does NOT modify the state of this ByteIterator.
Therefore the peeked byte does NOT get consumed and repetitive calls will
return the same value.ByteIterator.hasNext() returns
true.
peek in interface ByteIteratorNoSuchElementException - if there is no such byte available.ByteIterator.next()public void insert(byte... data)
DetectorStreamBuffer.insert(ByteArray).
insert in interface DetectorStreamBufferdata - is a ByteArray with the data to insert.public void insert(ByteArray data)
data at the current position
into the stream.
insert in interface DetectorStreamBufferdata - is a ByteArray with the data to insert.
protected void seek(long byteCount,
DetectorStreamBufferImpl.SeekMode mode)
removes or skips the
given number of bytes.
byteCount - is the number of bytes to seek.mode - is the DetectorStreamBufferImpl.SeekMode.public void remove(long byteCount)
byteCount
from the stream starting at the current position.
remove in interface DetectorStreamBufferbyteCount - is the number of bytes to remove. This value can be
greater than the currently available
bytes. You may supply Long.MAX_VALUE to remove the rest of
the stream.DetectorStreamBuffer.skip(long)public long getStreamPosition()
inserted.
getStreamPosition in interface DetectorStreamBufferprotected void append(ByteArray nextArray)
DetectorStreamBufferImpl.CurrentByteArray at the end of this buffer.
nextArray - is the DetectorStreamBufferImpl.CurrentByteArray to append.
public void process(Map<String,Object> metadata,
boolean eos)
throws IOException
metadata - is the Map with the meta-data.eos - - true if the end of the stream has been reached
and the given buffer has to be
IOException - in case of an Input/Output error. Should only be used
internally.DetectorStreamProcessor.process(DetectorStreamBuffer, Map, boolean)
public int fill(byte[] buffer,
int offset,
int length)
buffer starting at
offset with the next bytes from this
ComposedByteBuffer. The bytes that are filled into the given
buffer will therefore be consumed. This method can be used to
write data from this buffer to an OutputStream or supply it
to the consumer of an InputStream.
fill in interface ComposedByteBufferbuffer - is the buffer to fill.offset - is the index in the given buffer where to fill
in the first byte. See ByteArray.getCurrentIndex().length - is the expected number of bytes to fill into
buffer. Has to be positive and less or equal to
buffer.length - offset. However at most the number of
available bytes can be filled even if
length is greater.
buffer. Will be positive and less or equal to the
given length. Should be only less than
maxLength if NOT enough bytes are available.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||