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

public final Class ClobStreamHeaderGenerator

extends Object
implements StreamHeaderGenerator
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.types.StreamHeaderGenerator
Imports
java.io.IOException, .ObjectOutput, org.apache.derby.iapi.db.DatabaseContext, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.context.Context, .ContextService, org.apache.derby.iapi.sql.dictionary.DataDictionary

Generates stream headers for Clob data values.

THREAD SAFETY NOTE: This class is considered thread safe, even though it strictly speaking isn't. However, with the assumption that an instance of this class cannot be shared across databases with different versions, the only bad thing that can happen is that the mode is obtained several times.

Field Summary

Modifier and TypeField and Description
private final StringDataValue
callbackDVD

Reference to "owning" DVD, used to update it with information about which header format should be used.

private static final CharStreamHeaderGenerator
CHARHDRGEN

Header generator for the pre 10.5 header format.

private Boolean
isPreDerbyTenFive

true if the database version is prior to 10.5, false if the version is 10.5 or newer.

private static final byte
MAGIC_BYTE

Magic byte for the 10.5 stream header format.

private static final byte[]
UNKNOWN_LENGTH

Bytes for a 10.5 unknown length header.

Constructor Summary

AccessConstructor and Description
public
ClobStreamHeaderGenerator(StringDataValue
the owning data value descriptor
dvd
)

Creates a new generator that will use the context manager to determine which header format to use based on the database version.

public
ClobStreamHeaderGenerator(boolean
true if the database version is prior to 10.5, false if the version is 10.5 or newer
isPreDerbyTenFive
)

Creates a new generator using the specified header format.

Method Summary

Modifier and TypeMethod and Description
private void
determineHeaderFormat()

Determines which header format to use.

public boolean

Returns:

false if a byte count is expected (prior to 10.5), true if a character count is expected (10.5 and newer).
expectsCharCount
()

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.expectsCharCount.

Tells if the header encodes a character or byte count.

public int

Returns:

The number of bytes written into the buffer.
generateInto
(byte[]
the buffer to write into
buf
,
int
starting offset in the buffer
offset
,
long
the length to encode in the header
valueLength
)

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.generateInto.

Generates the header for the specified length and writes it into the provided buffer, starting at the specified offset.

public int

Returns:

The number of bytes written to the destination stream.
generateInto
(ObjectOutput
the destination stream
out
,
long
the length to encode in the header
valueLength
)

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.generateInto.

Generates the header for the specified length.

private static Context
getContext(final String contextID)

Must be private so that user code can't call this entry point.

public int

Returns:

Maximum header length in bytes.
getMaxHeaderLength
()

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.getMaxHeaderLength.

Returns the maximum header length.

public int

Returns:

Number of bytes written (zero or more).
writeEOF
(byte[]
the buffer to write into
buffer
,
int
starting offset in the buffer
offset
,
long
the length of the stream
valueLength
)

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.writeEOF.

Writes a Derby-specific end-of-stream marker to the buffer for a stream of the specified character length, if required.

public int

Returns:

Number of bytes written (zero or more).
writeEOF
(ObjectOutput
the destination stream
out
,
long
the length of the stream
valueLength
)

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.writeEOF.

Writes a Derby-specific end-of-stream marker to the destination stream for the specified character length, if required.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callbackDVDback to summary
private final StringDataValue callbackDVD

Reference to "owning" DVD, used to update it with information about which header format should be used. This is currently only determined by consulting the data dictionary about the version.

This is an optimization to avoid having to consult the data dictionary on every request to generate a header when a data value descriptor is reused.

CHARHDRGENback to summary
private static final CharStreamHeaderGenerator CHARHDRGEN

Header generator for the pre 10.5 header format. This format is used for Clobs as well if the database version is pre 10.5.

isPreDerbyTenFiveback to summary
private Boolean isPreDerbyTenFive

true if the database version is prior to 10.5, false if the version is 10.5 or newer. If null, the version will be determined by obtaining the database context through the context service.

MAGIC_BYTEback to summary
private static final byte MAGIC_BYTE

Magic byte for the 10.5 stream header format.

UNKNOWN_LENGTHback to summary
private static final byte[] UNKNOWN_LENGTH

Bytes for a 10.5 unknown length header.

Constructor Detail

ClobStreamHeaderGeneratorback to summary
public ClobStreamHeaderGenerator(StringDataValue dvd)

Creates a new generator that will use the context manager to determine which header format to use based on the database version.

Parameters
dvd:StringDataValue

the owning data value descriptor

ClobStreamHeaderGeneratorback to summary
public ClobStreamHeaderGenerator(boolean isPreDerbyTenFive)

Creates a new generator using the specified header format.

Parameters
isPreDerbyTenFive:boolean

true if the database version is prior to 10.5, false if the version is 10.5 or newer

Method Detail

determineHeaderFormatback to summary
private void determineHeaderFormat()

Determines which header format to use.

Implementation Note

The header format is determined by consulting the data dictionary throught the context service. If there is no context, the operation will fail.

Exceptions
IllegalStateException:
if there is no context
expectsCharCountback to summary
public boolean expectsCharCount()

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.expectsCharCount.

Tells if the header encodes a character or byte count.

Currently the header expects a character count if the header format is 10.5 (or newer), and a byte count if we are accessing a database created by a version prior to 10.5.

Returns:boolean

false if a byte count is expected (prior to 10.5), true if a character count is expected (10.5 and newer).

generateIntoback to summary
public int generateInto(byte[] buf, int offset, long valueLength)

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.generateInto.

Generates the header for the specified length and writes it into the provided buffer, starting at the specified offset.

Parameters
buf:byte[]

the buffer to write into

offset:int

starting offset in the buffer

valueLength:long

the length to encode in the header

Returns:int

The number of bytes written into the buffer.

generateIntoback to summary
public int generateInto(ObjectOutput out, long valueLength) throws IOException

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.generateInto.

Generates the header for the specified length.

Parameters
out:ObjectOutput

the destination stream

valueLength:long

the length to encode in the header

Returns:int

The number of bytes written to the destination stream.

Exceptions
IOException:
if writing to the destination stream fails
getContextback to summary
private static Context getContext(final String contextID)

Must be private so that user code can't call this entry point.

getMaxHeaderLengthback to summary
public int getMaxHeaderLength()

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.getMaxHeaderLength.

Returns the maximum header length.

Returns:int

Maximum header length in bytes.

writeEOFback to summary
public int writeEOF(byte[] buffer, int offset, long valueLength)

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.writeEOF.

Writes a Derby-specific end-of-stream marker to the buffer for a stream of the specified character length, if required.

Parameters
buffer:byte[]

the buffer to write into

offset:int

starting offset in the buffer

valueLength:long

the length of the stream

Returns:int

Number of bytes written (zero or more).

writeEOFback to summary
public int writeEOF(ObjectOutput out, long valueLength) throws IOException

Implements org.apache.derby.iapi.types.StreamHeaderGenerator.writeEOF.

Writes a Derby-specific end-of-stream marker to the destination stream for the specified character length, if required.

Parameters
out:ObjectOutput

the destination stream

valueLength:long

the length of the stream

Returns:int

Number of bytes written (zero or more).

Exceptions
IOException:

Doc from org.apache.derby.iapi.types.StreamHeaderGenerator.writeEOF.

if writing to the destination stream fails