PIRL

PIRL.Utilities
Class ByteBuffer_InputStream

java.lang.Object
  extended by java.io.InputStream
      extended by PIRL.Utilities.ByteBuffer_InputStream
All Implemented Interfaces:
Closeable

public class ByteBuffer_InputStream
extends InputStream

A ByteBuffer_InputStream presents a ByteBuffer as an InputStream.

This class is thread safe: Methods that might modify the backing ByteBuffer are synchronized on the ByteBuffer.

Version:
1.4
Author:
Bradford Castalia, UA/PIRL
See Also:
ByteBuffer, InputStream

Field Summary
static String ID
          Class identification name with source code version and date.
 
Constructor Summary
ByteBuffer_InputStream(ByteBuffer source)
          Construct a ByteBuffer_InputStream on a ByteBuffer.
 
Method Summary
 int available()
          Get the number of bytes remaining in the source.
 void mark(int read_limit)
          Sets a mark at the current input position.
 boolean markSupported()
          Test if stream mark and reset are supported.
 int read()
          Get the next datum from the source.
 int read(byte[] byte_array)
          Get some number of bytes from the source and store them into a byte array.
 int read(byte[] byte_array, int offset, int length)
          Get some number of bytes from the source and store them into a byte array.
 void reset()
          Reset the source position to the most recent mark position.
 long skip(long amount)
          Skip over some number of input bytes.
 ByteBuffer Source()
          Get the ByteBuffer backing this ByteBuffer_InputStream.
 
Methods inherited from class java.io.InputStream
close
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
Class identification name with source code version and date.

See Also:
Constant Field Values
Constructor Detail

ByteBuffer_InputStream

public ByteBuffer_InputStream(ByteBuffer source)
Construct a ByteBuffer_InputStream on a ByteBuffer.

Parameters:
source - The ByteBuffer to be used as the source of input data.
Method Detail

Source

public ByteBuffer Source()
Get the ByteBuffer backing this ByteBuffer_InputStream.

Returns:
The ByteBuffer backing this ByteBuffer_InputStream.

available

public int available()
Get the number of bytes remaining in the source.

Overrides:
available in class InputStream
Returns:
The number of bytes remaining in the source. This is the difference between the buffer's current input position and the input limit. Note that the limit may be less than the buffer capacity.

mark

public void mark(int read_limit)
Sets a mark at the current input position.

The operation is synchronized on the source buffer.

Overrides:
mark in class InputStream
Parameters:
read_limit - Ignored: The read limit is always the source limit.

markSupported

public boolean markSupported()
Test if stream mark and reset are supported.

Overrides:
markSupported in class InputStream
Returns:
Always returns true.

read

public int read()
Get the next datum from the source.

The operation is synchronized on the source buffer.

Specified by:
read in class InputStream
Returns:
The value of the next source byte (0-255) at the current buffer position, or -1 if the source position is at its limit.

read

public int read(byte[] byte_array)
Get some number of bytes from the source and store them into a byte array.

This method simply returns read (byte_array, 0, byte_array.length).

Overrides:
read in class InputStream
Parameters:
byte_array - A byte[] array where the source data is to be stored.
Returns:
The number of bytes read into the array, or -1 if the source position is at its limit.
Throws:
NullPointerException - If the byte array is null.
See Also:
read(byte[], int, int)

read

public int read(byte[] byte_array,
                int offset,
                int length)
Get some number of bytes from the source and store them into a byte array.

If the length to read is less than or equal to zero, zero is returned. Otherwise the effective length is the lesser of the length and the amount of data remaining in the source buffer.

The operation is synchronized on the source buffer.

Overrides:
read in class InputStream
Parameters:
byte_array - A byte[] array where the source data is to be stored.
offset - The index of the array where the first byte will be stored.
length - The maximum number of bytes to transfer from the source to the array.
Returns:
The number of bytes read into the array, or -1 if the source position is at its limit.
Throws:
NullPointerException - If the byte array is null.
IndexOutOfBoundsException - If the offset is negative or the offset plus the effective length is greater than the remaining space in the array.

reset

public void reset()
           throws IOException
Reset the source position to the most recent mark position.

The operation is synchronized on the source buffer.

Overrides:
reset in class InputStream
Throws:
IOException - If no mark has been set.

skip

public long skip(long amount)
Skip over some number of input bytes.

The source input position is moved to its current position plus the lesser of the amount specified or the amount available data remaining in the buffer.

The operation is synchronized on the source buffer.

Overrides:
skip in class InputStream
Parameters:
amount - The amount of data to skip.
Returns:
The number of data bytes skipped.

PIRL

Copyright (C) \ 2003-2009 Bradford Castalia, University of Arizona