public final class ClobStreamHeaderGenerator extends java.lang.Object implements 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.
Modifier and Type | Field and Description |
---|---|
private StringDataValue |
callbackDVD
Reference to "owning" DVD, used to update it with information about
which header format should be used.
|
private static CharStreamHeaderGenerator |
CHARHDRGEN
Header generator for the pre 10.5 header format.
|
private java.lang.Boolean |
isPreDerbyTenFive
true if the database version is prior to 10.5, false if
the version is 10.5 or newer. |
private static byte |
MAGIC_BYTE
Magic byte for the 10.5 stream header format.
|
private static byte[] |
UNKNOWN_LENGTH
Bytes for a 10.5 unknown length header.
|
Constructor and Description |
---|
ClobStreamHeaderGenerator(boolean isPreDerbyTenFive)
Creates a new generator using the specified header format.
|
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.
|
Modifier and Type | Method and Description |
---|---|
private void |
determineHeaderFormat()
Determines which header format to use.
|
boolean |
expectsCharCount()
Tells if the header encodes a character or byte count.
|
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.
|
int |
generateInto(java.io.ObjectOutput out,
long valueLength)
Generates the header for the specified length.
|
private static Context |
getContext(java.lang.String contextID)
Privileged lookup of a Context.
|
int |
getMaxHeaderLength()
Returns the maximum header length.
|
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.
|
int |
writeEOF(java.io.ObjectOutput out,
long valueLength)
Writes a Derby-specific end-of-stream marker to the destination stream
for the specified character length, if required.
|
private static final byte MAGIC_BYTE
private static final byte[] UNKNOWN_LENGTH
private static final CharStreamHeaderGenerator CHARHDRGEN
private final StringDataValue callbackDVD
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.
private java.lang.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.public ClobStreamHeaderGenerator(StringDataValue dvd)
dvd
- the owning data value descriptorpublic ClobStreamHeaderGenerator(boolean isPreDerbyTenFive)
isPreDerbyTenFive
- true
if the database version is prior
to 10.5, false
if the version is 10.5 or newerpublic boolean expectsCharCount()
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.
expectsCharCount
in interface StreamHeaderGenerator
false
if a byte count is expected (prior to 10.5),
true
if a character count is expected (10.5 and newer).public int generateInto(byte[] buf, int offset, long valueLength)
generateInto
in interface StreamHeaderGenerator
buf
- the buffer to write intooffset
- starting offset in the buffervalueLength
- the length to encode in the headerpublic int generateInto(java.io.ObjectOutput out, long valueLength) throws java.io.IOException
generateInto
in interface StreamHeaderGenerator
out
- the destination streamvalueLength
- the length to encode in the headerjava.io.IOException
- if writing to the destination stream failspublic int writeEOF(byte[] buffer, int offset, long valueLength)
writeEOF
in interface StreamHeaderGenerator
buffer
- the buffer to write intooffset
- starting offset in the buffervalueLength
- the length of the streampublic int writeEOF(java.io.ObjectOutput out, long valueLength) throws java.io.IOException
writeEOF
in interface StreamHeaderGenerator
out
- the destination streamvalueLength
- the length of the streamjava.io.IOException
- if writing to the destination stream failspublic int getMaxHeaderLength()
getMaxHeaderLength
in interface StreamHeaderGenerator
private void determineHeaderFormat()
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.
java.lang.IllegalStateException
- if there is no contextprivate static Context getContext(java.lang.String contextID)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.