Top Description Fields Constructors Methods
org.apache.derby.iapi.types

public final Class RawToBinaryFormatStream

extends LimitInputStream
Class Inheritance
Imports
java.io.InputStream, .IOException, .EOFException, org.apache.derby.iapi.services.io.DerbyIOException, .LimitInputStream, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.shared.common.reference.SQLState

Stream that takes a raw input stream and converts it to the on-disk format of the binary types by prepending the length of the value.

If the length of the stream is known then it is encoded as the first bytes in the stream in the defined format.
If the length is unknown then the first four bytes will be zero, indicating unknown length.

Note

This stream cannot be re-used. Once end of file is reached, the next read call will throw an EOFException

See Also
SQLBinary

Field Summary

Modifier and TypeField and Description
private byte[]
encodedLength

Encoding of the length in bytes which will be seen as the first encodedLength.length bytes of this stream.

private int
encodedOffset

Number of bytes of length encoding.

private boolean
private final int
length

The length of the stream.

private final int
maximumLength

The maximum allowed length for the stream.

private final String
typeName

The type of the column the stream is inserted into.

Inherited from org.apache.derby.iapi.services.io.LimitInputStream:
limitInPlaceremainingBytes

Constructor Summary

AccessConstructor and Description
public
RawToBinaryFormatStream(InputStream
application's raw binary stream passed into JDBC layer
in
,
int
length of the stream
length
)

Create a binary on-disk stream from the given InputStream.

public
RawToBinaryFormatStream(InputStream
the application stream
in
,
int
maximum length of the column data is inserted into
maximumLength
,
String
type name for the column data is inserted into
typeName
)

Create a binary on-disk stream from the given InputStream of unknown length.

Method Summary

Modifier and TypeMethod and Description
private void
checkSufficientData()

JDBC 3.0 (from tutorial book) requires that an input stream has the correct number of bytes in the stream.

public int
read()

Overrides org.apache.derby.iapi.services.io.LimitInputStream.read.

Read from the wrapped stream prepending the intial bytes if needed.

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides org.apache.derby.iapi.services.io.LimitInputStream.read.

Read from the wrapped stream prepending the intial bytes if needed.

Inherited from org.apache.derby.iapi.services.io.LimitInputStream:
availableclearLimitmarkSupportedsetInputsetLimitskip

Field Detail

encodedLengthback to summary
private byte[] encodedLength

Encoding of the length in bytes which will be seen as the first encodedLength.length bytes of this stream.

encodedOffsetback to summary
private int encodedOffset

Number of bytes of length encoding.

eofback to summary
private boolean eof
lengthback to summary
private final int length

The length of the stream. Unknown if less than 0.

maximumLengthback to summary
private final int maximumLength

The maximum allowed length for the stream. No limit if less than 0.

typeNameback to summary
private final String typeName

The type of the column the stream is inserted into. Used for length less streams, null if not in use.

Constructor Detail

RawToBinaryFormatStreamback to summary
public RawToBinaryFormatStream(InputStream in, int length)

Create a binary on-disk stream from the given InputStream. The on-disk stream prepends a length encoding, and validates that the actual length of the stream matches the specified length (as according to JDBC 3.0).

Parameters
in:InputStream

application's raw binary stream passed into JDBC layer

length:int

length of the stream

Exceptions
IllegalArgumentException:
if length is negative. This exception should never be exposed to the user, and seeing it means a programming error exists in the code.
RawToBinaryFormatStreamback to summary
public RawToBinaryFormatStream(InputStream in, int maximumLength, String typeName)

Create a binary on-disk stream from the given InputStream of unknown length. A limit is placed on the maximum length of the stream.

Parameters
in:InputStream

the application stream

maximumLength:int

maximum length of the column data is inserted into

typeName:String

type name for the column data is inserted into

Exceptions
IllegalArgumentException:
if maximum length is negative, or type name is null. This exception should never be exposed to the user, and seeing it means a programming error exists in the code. Although a missing type name is not critical, an exception is is thrown to signal the intended use of this constructor.

Method Detail

checkSufficientDataback to summary
private void checkSufficientData() throws IOException

JDBC 3.0 (from tutorial book) requires that an input stream has the correct number of bytes in the stream.

readback to summary
public int read() throws IOException

Overrides org.apache.derby.iapi.services.io.LimitInputStream.read.

Read from the wrapped stream prepending the intial bytes if needed. If stream has been read, and eof reached, in that case any subsequent read will throw an EOFException

Returns:int

Doc from java.io.FilterInputStream.read.

the next byte of data, or -1 if the end of the stream is reached.

Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides org.apache.derby.iapi.services.io.LimitInputStream.read.

Read from the wrapped stream prepending the intial bytes if needed. If stream has been read, and eof reached, in that case any subsequent read will throw an EOFException

Parameters
b:byte[]

Doc from java.io.FilterInputStream.read.

the buffer into which the data is read.

off:int

Doc from java.io.FilterInputStream.read.

the start offset in array b at which the data is written.

len:int

Doc from java.io.FilterInputStream.read.

the maximum number of bytes to read.

Returns:int

Doc from java.io.FilterInputStream.read.

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.