Package org.apache.derby.iapi.types
Class RawToBinaryFormatStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.derby.iapi.services.io.LimitInputStream
org.apache.derby.iapi.types.RawToBinaryFormatStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Limit
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
Encoding of the length in bytes which will be seen as the first encodedLength.length bytes of this stream.private int
Number of bytes of length encoding.private boolean
private final int
The length of the stream.private final int
The maximum allowed length for the stream.private final String
The type of the column the stream is inserted into.Fields inherited from class org.apache.derby.iapi.services.io.LimitInputStream
limitInPlace, remainingBytes
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionRawToBinaryFormatStream
(InputStream in, int length) Create a binary on-disk stream from the givenInputStream
.RawToBinaryFormatStream
(InputStream in, int maximumLength, String typeName) Create a binary on-disk stream from the givenInputStream
of unknown length. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
JDBC 3.0 (from tutorial book) requires that an input stream has the correct number of bytes in the stream.int
read()
Read from the wrapped stream prepending the intial bytes if needed.int
read
(byte[] b, int off, int len) Read from the wrapped stream prepending the intial bytes if needed.Methods inherited from class org.apache.derby.iapi.services.io.LimitInputStream
available, clearLimit, markSupported, setInput, setLimit, skip
Methods inherited from class java.io.FilterInputStream
close, mark, read, reset
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
encodedOffset
private int encodedOffsetNumber of bytes of length encoding. -
encodedLength
private byte[] encodedLengthEncoding of the length in bytes which will be seen as the first encodedLength.length bytes of this stream. -
eof
private boolean eof -
length
private final int lengthThe length of the stream. Unknown if less than 0. -
maximumLength
private final int maximumLengthThe maximum allowed length for the stream. No limit if less than 0. -
typeName
The type of the column the stream is inserted into. Used for length less streams,null
if not in use.
-
-
Constructor Details
-
RawToBinaryFormatStream
Create a binary on-disk stream from the givenInputStream
. 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
- application's raw binary stream passed into JDBC layerlength
- length of the stream- Throws:
IllegalArgumentException
- iflength
is negative. This exception should never be exposed to the user, and seeing it means a programming error exists in the code.
-
RawToBinaryFormatStream
Create a binary on-disk stream from the givenInputStream
of unknown length. A limit is placed on the maximum length of the stream.- Parameters:
in
- the application streammaximumLength
- maximum length of the column data is inserted intotypeName
- type name for the column data is inserted into- Throws:
IllegalArgumentException
- if maximum length is negative, or type name isnull
. 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 Details
-
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- Overrides:
read
in classLimitInputStream
- Throws:
IOException
-
checkSufficientData
JDBC 3.0 (from tutorial book) requires that an input stream has the correct number of bytes in the stream.- Throws:
IOException
-
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- Overrides:
read
in classLimitInputStream
- Throws:
IOException
-