org.jibx.runtime.impl
Class InByteBuffer

java.lang.Object
  extended by org.jibx.runtime.impl.InByteBuffer
All Implemented Interfaces:
IByteBuffer, IInByteBuffer

public class InByteBuffer
extends java.lang.Object
implements IInByteBuffer

Byte buffer wrapping an input stream. Clients need to obey the interface access rules.

Author:
Dennis M. Sosnoski

Field Summary
static int DEFAULT_BUFFER_SIZE
          Default input buffer size.
 
Constructor Summary
InByteBuffer()
          Constructor using default buffer size.
InByteBuffer(int size)
          Constructor with size specified.
 
Method Summary
 void finish()
          Complete usage of the current stream.
 byte[] getBuffer()
          Get the byte array buffer.
 int getLimit()
          Get offset past the end of data in buffer.
 int getOffset()
          Get the index of the next byte to be read.
 boolean require(int size)
          Require some number of bytes of data.
 void reset()
          Reset to initial state for reuse.
 void setInput(java.io.InputStream is)
          Set the actual input stream to be used for this buffer.
 void setOffset(int offset)
          Set the current offset.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
Default input buffer size.

See Also:
Constant Field Values
Constructor Detail

InByteBuffer

public InByteBuffer(int size)
Constructor with size specified.

Parameters:
size - initial buffer size in bytes

InByteBuffer

public InByteBuffer()
Constructor using default buffer size.

Method Detail

reset

public void reset()
Reset to initial state for reuse.


setInput

public void setInput(java.io.InputStream is)
Set the actual input stream to be used for this buffer. If an input stream is currently open when this is called the existing stream is closed and any buffered data discarded, with any errors ignored.

Parameters:
is - stream

getBuffer

public byte[] getBuffer()
Get the byte array buffer.

Specified by:
getBuffer in interface IByteBuffer
Returns:
array

getOffset

public int getOffset()
Get the index of the next byte to be read. After reading data, the setOffset(int) method must be used to update the current offset before any other operations are performed on the buffer.

Specified by:
getOffset in interface IByteBuffer
Returns:
offset

setOffset

public void setOffset(int offset)
Set the current offset. This must be used to update the stored buffer state after reading any data.

Specified by:
setOffset in interface IByteBuffer
Parameters:
offset -

getLimit

public int getLimit()
Get offset past the end of data in buffer.

Specified by:
getLimit in interface IInByteBuffer
Returns:
offset past end of data

require

public boolean require(int size)
                throws java.io.IOException
Require some number of bytes of data. When this call is made the buffer can discard all data up to the current offset, and will copy retained data down to the start of the buffer array and read more data from the input stream if necessary to make the requested number of bytes available. This call may cause the byte array buffer to be replaced, so getBuffer(), getLimit(), and getOffset() must all be called again before any further use of the buffer.

Specified by:
require in interface IInByteBuffer
Parameters:
size - desired number of bytes
Returns:
true if request satisfied, false if not
Throws:
java.io.IOException

finish

public void finish()
            throws java.io.IOException
Complete usage of the current stream. This method should be called whenever the application is done reading from the buffered stream. Once this method is called, a call to setInput(InputStream) is required before the buffer can again be used.

Specified by:
finish in interface IByteBuffer
Throws:
java.io.IOException


Project Web Site