Top Description Fields Constructors Methods
org.apache.derby.client.am

public Class ByteArrayCombinerStream

extends InputStream
Class Inheritance
Imports
java.io.InputStream, .IOException, java.util.ArrayList

A stream whose source is a list of byte arrays. This class was created when first implementing the JDBC 4 length less overloads in the client driver. The reason was missing support for streaming data with unknown length from the client to the server. The purpose of the stream is to avoid having to repeatedly copy data to grow the byte buffer, or doing a single big copy to combine the byte arrays in the end. This is important for the temporary solution, since we must materialize the stream to find the length anyway. If there is less data available than the specified length, an exception is thrown. Available data is determined by the length of the byte arrays, not the contents of them. A byte array with all 0's is considered valid data. Besides from truncation, this stream does not change the underlying data in any way.

Field Summary

Modifier and TypeField and Description
private int
arrayIndex

Index of the array we are currently reading from.

private final ArrayList<byte[]>
arrays

A list of the arrays to combine.

private byte[]
curArray

The array we are currently reading from.

private long
gOffset

Global offset into the whole stream.

private int
off

The local offset into the current array.

private final long
specifiedLength

Length of the stream.

Constructor Summary

AccessConstructor and Description
public
ByteArrayCombinerStream(ArrayList<byte[]>
an ArrayList with references to the source byte arrays. The references are copied to a new ArrayList instance.
arraysIn
,
long
the length of the stream. Never published outside this object. Note that the length specified can be shorter than the actual number of bytes in the byte arrays.
length
)

Create a stream whose source is a list of byte arrays.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

number of available bytes
available
()

Overrides java.io.InputStream.available.

Return the number of available bytes.
private byte[]

Returns:

a byte[]-object, or null if there are no more arrays
nextArray
()

Fetch the next array to read data from.

public int

Returns:

a byte, or -1 if the end-of-stream is reached
read
()

Implements abstract java.io.InputStream.read.

Read a single byte.
public int

Returns:

the number of bytes read, or -1 if end-of-stream is reached
read
(byte[]
the array to copy bytes into
buf
,
int
offset into the array
offset
,
int
the maximum number of bytes to read
length
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.
Inherited from java.io.InputStream:
closemarkmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

arrayIndexback to summary
private int arrayIndex

Index of the array we are currently reading from.

arraysback to summary
private final ArrayList<byte[]> arrays

A list of the arrays to combine.

curArrayback to summary
private byte[] curArray

The array we are currently reading from.

gOffsetback to summary
private long gOffset

Global offset into the whole stream.

offback to summary
private int off

The local offset into the current array.

specifiedLengthback to summary
private final long specifiedLength

Length of the stream.

Constructor Detail

ByteArrayCombinerStreamback to summary
public ByteArrayCombinerStream(ArrayList<byte[]> arraysIn, long length)

Create a stream whose source is a list of byte arrays.

Parameters
arraysIn:ArrayList<byte[]>

an ArrayList with references to the source byte arrays. The references are copied to a new ArrayList instance.

length:long

the length of the stream. Never published outside this object. Note that the length specified can be shorter than the actual number of bytes in the byte arrays.

Exceptions
IllegalArgumentException:
if there is less data available than specified by length, or length is negative.

Method Detail

availableback to summary
public int available()

Overrides java.io.InputStream.available.

Return the number of available bytes. The method assumes the specified length of the stream is correct.

Returns:int

number of available bytes

nextArrayback to summary
private byte[] nextArray()

Fetch the next array to read data from. The reference in the ArrayList is cleared when the array is "taken out".

Returns:byte[]

a byte[]-object, or null if there are no more arrays

readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Read a single byte.

Returns:int

a byte, or -1 if the end-of-stream is reached

Exceptions
IOException:

Doc from java.io.InputStream.read.

if an I/O error occurs.

readback to summary
public int read(byte[] buf, int offset, int length) throws IOException

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

Parameters
buf:byte[]

the array to copy bytes into

offset:int

offset into the array

length:int

the maximum number of bytes to read

Returns:int

the number of bytes read, or -1 if end-of-stream is reached

Exceptions
IOException:

Doc from java.io.InputStream.read.

If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.