net.sf.mmm.util.io.impl
Class LookaheadByteArrayBufferBuffer

java.lang.Object
  extended by net.sf.mmm.util.io.impl.AbstractByteArrayBufferBuffer
      extended by net.sf.mmm.util.io.impl.LookaheadByteArrayBufferBuffer
All Implemented Interfaces:
ByteBuffer, ByteIterator, ByteProcessable, ByteProvider, ComposedByteBuffer, ProcessableByteArrayBuffer

public class LookaheadByteArrayBufferBuffer
extends AbstractByteArrayBufferBuffer

This class is a byte-Buffer that represents the concatenation of multiple ByteArrayBufferImpls. The resulting LookaheadByteArrayBufferBuffer has its own state and does NOT modify a contained ByteArrayBufferImpl.
ATTENTION:
This class is NOT intended to be exposed. It should only be used internally by some class or component.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  AbstractByteArrayBufferBuffer master
          The master buffer adapted by this buffer.
 
Constructor Summary
LookaheadByteArrayBufferBuffer(AbstractByteArrayBufferBuffer master)
          The constructor.
 
Method Summary
protected  boolean fill(InputStream inputStream)
          This method fills this buffer using the given inputStream.
 boolean hasNext()
          This method determines if there is a next byte available.
 byte next()
          This method gets the current byte in the iteration.
 long process(ByteProcessor processor, long byteCount)
          This method processes the number of bytes given by length (as far as available) using the given processor.
 long skip(long byteCount)
          This method skips the number of bytes given by byteCount.
 
Methods inherited from class net.sf.mmm.util.io.impl.AbstractByteArrayBufferBuffer
fill, getByteArray, getByteArrayCount, getBytesAvailable, getCurrentBuffer, getCurrentBufferIndex, nextBuffer, peek, sync
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

master

private final AbstractByteArrayBufferBuffer master
The master buffer adapted by this buffer.

Constructor Detail

LookaheadByteArrayBufferBuffer

public LookaheadByteArrayBufferBuffer(AbstractByteArrayBufferBuffer master)
The constructor.

Parameters:
master - is the master-buffer to copy for lookahead reads.
Method Detail

next

public byte next()
          throws NoSuchElementException
This method gets the current byte in the iteration. After the call of this method this ByteIterator points to the next byte in the iteration or to the end if there is no such byte available.
ATTENTION:
You should only call this method if ByteIterator.hasNext() returns true.

Specified by:
next in interface ByteIterator
Overrides:
next in class AbstractByteArrayBufferBuffer
Returns:
the current byte in the iteration.
Throws:
NoSuchElementException - if there is no such byte available.
See Also:
Iterator.next()

hasNext

public boolean hasNext()
This method determines if there is a next byte available.

Specified by:
hasNext in interface ByteIterator
Overrides:
hasNext in class AbstractByteArrayBufferBuffer
Returns:
true if there is a next byte available, false otherwise (if the end of this buffer has been reached).

skip

public long skip(long byteCount)
This method skips the number of bytes given by byteCount.

Specified by:
skip in interface ByteIterator
Overrides:
skip in class AbstractByteArrayBufferBuffer
Parameters:
byteCount - is the expected number of bytes to skip.
Returns:
the number of bytes that have actually been skipped. This will typically be equal to byteCount. However the value may be less if the end of this iterator has been reached before the according number of bytes have been skipped. The value will always be greater or equal to 0.
See Also:
InputStream.skip(long)

process

public long process(ByteProcessor processor,
                    long byteCount)
This method processes the number of bytes given by length (as far as available) using the given processor.

Specified by:
process in interface ByteProcessable
Overrides:
process in class AbstractByteArrayBufferBuffer
Parameters:
processor - is the ByteProcessor called to process the bytes. It may be called multiple types if the data is sliced into multiple byte-arrays.
byteCount - is the desired number of bytes to process. The value has to be greater or equal to 0. A value of 0 will have no effect. If you want to process all available data to the end of stream or buffer you may use Long.MAX_VALUE.
Returns:
the number of bytes that have actually been processed. For a sufficient length this will typically be equal to length. However if the end of the data has been reached, a smaller value is returned. The value will always be greater or equal to 0.

fill

protected boolean fill(InputStream inputStream)
                throws IOException
This method fills this buffer using the given inputStream. If the buffer is already filled, this method will have no effect and return false.

Overrides:
fill in class AbstractByteArrayBufferBuffer
Parameters:
inputStream - is the InputStream providing the data to fill this buffer with.
Returns:
true if the end of the stream was encountered while (re)filling this buffer, false otherwise.
Throws:
IOException - if caused by the inputStream whilst reading.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.