PIRL.Utilities

## Class ByteBuffer_OutputStream

- java.lang.Object
- - java.io.OutputStream
  - - PIRL.Utilities.ByteBuffer_OutputStream

All Implemented Interfaces:
  Closeable, Flushable, AutoCloseable

    public class ByteBuffer_OutputStream
    extends OutputStream

A ByteBuffer_OutputStream presents a ByteBuffer as an OutputStream.

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

See Also:
  `ByteBuffer`, `OutputStream`

### Field Summary

Fields
`static String` `ID` Class identification name with source code version and date.

### Constructor Summary

Constructors
Constructor and Description
`ByteBuffer_OutputStream(ByteBuffer destination)` Construct a ByteBuffer_OutputStream on a ByteBuffer.

### Method Summary

Methods
`int` `available()` Get the amount of storage space remaining in the destination.
`ByteBuffer` `Destination()` Get the ByteBuffer backing this ByteBuffer_OutputStream.
`void` `write(byte[] byte_array)` Put the contents of a byte array into the destination.
`void` `write(byte[] byte_array, int offset, int amount)` Put some number of bytes from a byte array into the destination.
`void` `write(int datum)` Put the datum at the next position in the destination.

### Methods inherited from class java.io.OutputStream

`close, flush`

### 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_OutputStream

    public ByteBuffer_OutputStream(ByteBuffer destination)

Construct a ByteBuffer_OutputStream on a ByteBuffer.

Parameters:
  `destination` - The ByteBuffer to be used as the destination of output data.
Throws:
  `NullPointerException` - If the destination is null.

### Method Detail

#### Destination

    public ByteBuffer Destination()

Get the ByteBuffer backing this ByteBuffer_OutputStream.

Returns:
  The ByteBuffer backing this ByteBuffer_OutputStream.

#### available

    public int available()

Get the amount of storage space remaining in the destination.

Returns:
  The number of bytes remaining in the `destination`. This is the difference between the buffer's current output `position` and the output `limit`. Note that the limit may be less than the buffer `capacity`.

#### write

    public void write(int datum)
               throws EOFException

Put the datum at the next position in the destination.

The operation is synchronized on the destination buffer.

Specified by:
  `write` in class `OutputStream`
Throws:
  `EOFExcetption` - If the destination is full; i.e. the output position is at its limit.
  `EOFException`
See Also:
  `available()`

#### write

    public void write(byte[] byte_array)
               throws EOFException

Put the contents of a byte array into the destination.

This method simply uses `write (byte_array, 0, byte_array.length)`.

Overrides:
  `write` in class `OutputStream`
Parameters:
  `byte_array` - A byte[] array containing the data to be stored in the destination buffer.
Throws:
  `NullPointerException` - If the byte array is null.
  `EOFExcetption` - If the destination is full; i.e. the output position is at its limit.
  `EOFException`
See Also:
  `write(byte[], int, int)`, `available()`

#### write

    public void write(byte[] byte_array,
             int offset,
             int amount)
               throws EOFException

Put some number of bytes from a byte array into the destination.

If the amount to write is less than or equal to zero nothing is done. The amount specified to write must be no greater than the number of bytes in the array after the offset nor the space remaining in the destination buffer.

The operation is synchronized on the destination buffer.

Overrides:
  `write` in class `OutputStream`
Parameters:
  `byte_array` - A byte[] array containing data to be transferred.
  `offset` - The index of the array containing the first byte to be transferred.
  `amount` - The maximum number of bytes to transfer from the array to the `destination`.
Throws:
  `NullPointerException` - If the byte array is null.
  `IndexOutOfBoundsException` - If the offset is negative or the offset plus the amount is greater than the remaining bytes in the array.
  `EOFExcetption` - If the space `available` in the destination is less than the amount of data specified to transfer.
  `EOFException`