Class ClobStreamHeaderGenerator
- All Implemented Interfaces:
StreamHeaderGenerator
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
FieldsModifier and TypeFieldDescriptionprivate final StringDataValueReference to "owning" DVD, used to update it with information about which header format should be used.private static final CharStreamHeaderGeneratorHeader generator for the pre 10.5 header format.private Booleantrueif the database version is prior to 10.5,falseif the version is 10.5 or newer.private static final byteMagic byte for the 10.5 stream header format.private static final byte[]Bytes for a 10.5 unknown length header. -
Constructor Summary
ConstructorsConstructorDescriptionClobStreamHeaderGenerator(boolean isPreDerbyTenFive) Creates a new generator using the specified header format.Creates a new generator that will use the context manager to determine which header format to use based on the database version. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidDetermines which header format to use.booleanTells if the header encodes a character or byte count.intgenerateInto(byte[] buf, int offset, long valueLength) Generates the header for the specified length and writes it into the provided buffer, starting at the specified offset.intgenerateInto(ObjectOutput out, long valueLength) Generates the header for the specified length.private static ContextgetContext(String contextID) Privileged lookup of a Context.intReturns the maximum header length.intwriteEOF(byte[] buffer, int offset, long valueLength) Writes a Derby-specific end-of-stream marker to the buffer for a stream of the specified character length, if required.intwriteEOF(ObjectOutput out, long valueLength) Writes a Derby-specific end-of-stream marker to the destination stream for the specified character length, if required.
-
Field Details
-
MAGIC_BYTE
private static final byte MAGIC_BYTEMagic byte for the 10.5 stream header format.- See Also:
-
UNKNOWN_LENGTH
private static final byte[] UNKNOWN_LENGTHBytes for a 10.5 unknown length header. -
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. -
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.
-
isPreDerbyTenFive
trueif the database version is prior to 10.5,falseif the version is 10.5 or newer. Ifnull, the version will be determined by obtaining the database context through the context service.
-
-
Constructor Details
-
ClobStreamHeaderGenerator
Creates a new generator that will use the context manager to determine which header format to use based on the database version.- Parameters:
dvd- the owning data value descriptor
-
ClobStreamHeaderGenerator
public ClobStreamHeaderGenerator(boolean isPreDerbyTenFive) Creates a new generator using the specified header format.- Parameters:
isPreDerbyTenFive-trueif the database version is prior to 10.5,falseif the version is 10.5 or newer
-
-
Method Details
-
expectsCharCount
public boolean 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.
- Specified by:
expectsCharCountin interfaceStreamHeaderGenerator- Returns:
falseif a byte count is expected (prior to 10.5),trueif a character count is expected (10.5 and newer).
-
generateInto
public int generateInto(byte[] buf, int offset, long valueLength) Generates the header for the specified length and writes it into the provided buffer, starting at the specified offset.- Specified by:
generateIntoin interfaceStreamHeaderGenerator- Parameters:
buf- the buffer to write intooffset- starting offset in the buffervalueLength- the length to encode in the header- Returns:
- The number of bytes written into the buffer.
-
generateInto
Generates the header for the specified length.- Specified by:
generateIntoin interfaceStreamHeaderGenerator- Parameters:
out- the destination streamvalueLength- the length to encode in the header- Returns:
- The number of bytes written to the destination stream.
- Throws:
IOException- if writing to the destination stream fails
-
writeEOF
public int writeEOF(byte[] buffer, int offset, long valueLength) Writes a Derby-specific end-of-stream marker to the buffer for a stream of the specified character length, if required.- Specified by:
writeEOFin interfaceStreamHeaderGenerator- Parameters:
buffer- the buffer to write intooffset- starting offset in the buffervalueLength- the length of the stream- Returns:
- Number of bytes written (zero or more).
-
writeEOF
Writes a Derby-specific end-of-stream marker to the destination stream for the specified character length, if required.- Specified by:
writeEOFin interfaceStreamHeaderGenerator- Parameters:
out- the destination streamvalueLength- the length of the stream- Returns:
- Number of bytes written (zero or more).
- Throws:
IOException- if writing to the destination stream fails
-
getMaxHeaderLength
public int getMaxHeaderLength()Returns the maximum header length.- Specified by:
getMaxHeaderLengthin interfaceStreamHeaderGenerator- Returns:
- Maximum header length in bytes.
-
determineHeaderFormat
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.
- Throws:
IllegalStateException- if there is no context
-
getContext
-