# Class: com.pnfsoftware.jeb.util.collect.BytePipe

A dynamic byte array \(pipe\). Bytes are written/appended at the end; bytes are read from the beginning. Reading methods raise if the number of requested bytes is more than what is available in the array. 

 This class is **thread\-safe for a single producer thread, single consumer thread.** If there are multiple producers and/or multiple consumers, client code is responsible for making sure that writer threads coordinate among themselves, and that reader threads do the same as well. Ideally \(and most likely\), client code should have a single writer thread, and one reader thread \(same or different as the writer's\).

## Constructor: BytePipe

Description: Create an array whose initial capacity if 4,096 bytes.

## Constructor: BytePipe
- parameter: `initialCapacity`, type: `int`

Description: Create an array with the provided initial capacity.
parameter: initialCapacity: strictly positive number

## Method: append
- parameter: `data`, type: `byte[]`
- parameter: `offset`, type: `int`
- parameter: `length`, type: `int`

Description: Append bytes to this array.
parameter: data: source data
parameter: offset: source offset
parameter: length: number of bytes to append

## Method: append
- parameter: `data`, type: `byte[]`

Description: Append bytes to this array.
parameter: data: source data

## Method: append
- parameter: `b`, type: `byte`

Description: Append a single byte to this dynamic array.
parameter: b: byte value

## Method: append
- parameter: `b`, type: `int`

Description: Append a single byte to this dynamic array.
parameter: b: byte value

## Method: available
- return type: `int`

Description: Get the number of bytes available for reading.
return: the number of bytes available for reading

## Method: blockUntilAvailable
- parameter: `n`, type: `int`
- parameter: `timeout`, type: `long`
- return type: `int`

Description: Wait until enough data is available for reading.
parameter: n: size in bytes
parameter: timeout: in milliseconds \(0 means infinite\)
return: the amount of bytes in the pipe available for reading

## Method: capacity
- return type: `int`

Description: Get the current capacity of the array. Note: the capacity varies as bytes are written/read to the array.
return: the current capacity in bytes

## Method: get
- parameter: `data`, type: `byte[]`
- parameter: `offset`, type: `int`
- parameter: `size`, type: `int`

Description: Get a specified amount of bytes. Throws if not enough bytes are available.
parameter: data: destination data
parameter: offset: destination offset
parameter: size: number of bytes to read

## Method: get
- parameter: `data`, type: `byte[]`

Description: Get a specified amount of bytes. Throws if not enough bytes are available.
parameter: data: destination data

## Method: get
- return type: `int`

Description: Retrieve a single byte. Throws if there is nothing available.
return: unsigned byte value

## Method: getAll
- return type: `byte[]`

Description: Read all available bytes.
return: all available bytes

## Method: limit
- return type: `int`

Description: Get the number of bytes in the pipe.
return: write limit

## Method: peek
- parameter: `data`, type: `byte[]`
- parameter: `where`, type: `int`
- parameter: `size`, type: `int`

Description: Peek into this array for a specified amount of data. Throws if not enough bytes are available.
parameter: data: destination data
parameter: where: destination offset
parameter: size: number of bytes to peek

## Method: peek
- parameter: `data`, type: `byte[]`

Description: Peek into this array. Throws if not enough bytes are available.
parameter: data: destination data

## Method: peek
- return type: `byte`

Description: Peek a single byte within this array, at the current position. Throws if there a byte is not available.
return: next byte

## Method: peekLast
- return type: `byte`

Description: Peek the latest byte appended to this array. Throws if there a byte is not available.
return: last byte

## Method: position
- return type: `int`

Description: Get the current position in the pipe.
return: read position

## Method: readWait
- parameter: `timeout`, type: `long`
- return type: `int`

Description: Read a single byte of data. This method is blocking.
parameter: timeout: in milliseconds; 0 means infinite
return: \-1 on error \(timeout elapsed and no data is available\)

## Method: reset

Description: Reset this array: the number of bytes available for reading becomes 0.

## Method: skip
- parameter: `n`, type: `int`

Description: Skip bytes. Throws if not enough bytes are available.
parameter: n: number of bytes to skip

