class DDMWriter
extends java.lang.Object
Modifier and Type | Field | Description |
---|---|---|
private DRDAConnThread |
agent |
|
private java.nio.ByteBuffer |
buffer |
Output buffer.
|
private CcsidManager |
ccsidManager |
|
private int |
correlationID |
|
private static int |
DEFAULT_BUFFER_SIZE |
|
private int |
dssLengthLocation |
|
private DssTrace |
dssTrace |
|
private EbcdicCcsidManager |
ebcdicCcsidManager |
|
private java.nio.charset.CharsetEncoder |
encoder |
Encoder which encodes strings with the server's default encoding.
|
private boolean |
isContinuationDss |
|
private boolean |
isDRDAProtocol |
|
private int |
lastDSSBeforeMark |
|
private int[] |
markStack |
|
private static int |
MAX_MARKS_NESTING |
|
(package private) static int |
MAX_VARCHAR_BYTE_LENGTH |
The maximum length in bytes for strings sent by
writeLDString() ,
which is the maximum unsigned integer value that fits in two bytes. |
private int |
nextCorrelationID |
|
private int |
prevHdrLocation |
|
private byte |
previousChainByte |
|
private int |
previousCorrId |
|
private int |
top |
|
(package private) long |
totalByteCount |
|
private Utf8CcsidManager |
utf8CcsidManager |
Constructor | Description |
---|---|
DDMWriter(DRDAConnThread agent,
DssTrace dssTrace) |
Modifier and Type | Method | Description |
---|---|---|
private void |
beginDss(boolean chainedToNextStructure,
int dssType) |
Begins a DSS stream (for writing LOB data).
|
private void |
beginDss(int dssType,
boolean ensureLen) |
Write DSS header
DSS Header format is
2 bytes - length
1 byte - 'D0' - indicates DDM data
1 byte - DSS format
|---|---------|----------|
| 0 | flags | type |
|---|---------|----------|
| 0 | 1 2 3 | 4 5 6 7 |
|---|---------|----------|
bit 0 - '0'
bit 1 - '0' - unchained, '1' - chained
bit 2 - '0' - do not continue on error, '1' - continue on error
bit 3 - '0' - next DSS has different correlator, '1' - next DSS has
same correlator
type - 1 - Request DSS
- 2 - Reply DSS
- 3 - Object DSS
- 4 - Communications DSS
- 5 - Request DSS where no reply is expected
|
private int |
calculateExtendedLengthByteCount(long ddmSize) |
Calculate extended length byte count which follows the DSS header
for extended DDM.
|
protected void |
clearBuffer() |
Clear the entire send buffer
|
protected void |
clearDdm() |
Erase all writes for the current ddm and reset the
top
|
protected void |
clearDSSesBackToMark(int mark) |
Does a logical "clear" of everything written to the buffer after
the received mark.
|
protected byte[] |
copyDSSDataToEnd(int start) |
Copy Data to End
Create a buffer and copy from the position given to the end of data
Note that the position given is treated as relative to the
current DSS, for there may be other DSS blocks (chained, presumably)
which are sitting unwritten in the buffer.
|
protected void |
createDssObject() |
Create DSS data object
|
protected void |
createDssReply() |
Create DSS reply object
|
protected void |
createDssRequest() |
Create DSS request object
NOTE: This is _ONLY_ used for testing the protocol
(via the ProtocolTestAdapter.java file in this package)!
|
protected boolean |
doesRequestContainData() |
|
protected void |
endDdm() |
End the current DDM
|
protected void |
endDdmAndDss() |
End final DDM and DSS header by writing the length in the length location
|
protected void |
endDss() |
End DSS header by writing the length in the length location
and setting the chain bit.
|
private void |
endDss(boolean finalizeLength) |
End DSS header by writing the length in the length location
and setting the chain bit.
|
protected void |
endDss(byte chainByte) |
End DSS header by writing the length in the length location
and setting the chain bit.
|
private void |
ensureLength(int length) |
Ensure that there is space in the buffer
|
protected void |
finalizeChain(byte currChainByte,
java.io.OutputStream socketOutputStream) |
Finalize the current DSS chain and send it if
needed.
|
private void |
finalizeDssLength() |
Finish a DSS Layer A object.
|
protected void |
flush() |
Flush buffer to outputstream
|
protected void |
flush(java.io.OutputStream socketOutputStream) |
Flush buffer to specified stream
|
private void |
flushScalarStreamSegment(boolean lastSegment,
java.io.OutputStream out) |
|
protected byte[] |
getBufferContents(int startPos) |
Get a copy of a subsequence of the output buffer, starting at the
specified position and ending at the current buffer position.
|
protected int |
getBufferPosition() |
Get the current position in the output buffer.
|
private int |
getCorrelationID() |
Looks at chaining info for previous DSS written, and use
that to figure out what the correlation id for the current
DSS should be.
|
protected CcsidManager |
getCurrentCcsidManager() |
|
protected int |
getDSSLength() |
Get the length of the current DSS block we're working on.
|
private static int |
getLayerBStreamingBufferSize() |
|
private static boolean |
isContinuationByte(byte b) |
Check if a byte value represents a continuation byte in a UTF-8 byte
sequence.
|
private void |
markDssAsContinued(boolean forLob) |
Mark the DSS that we're currently writing as
a continued DSS, which is done by setting
the high-order bit to "1", per DDM spec.
|
protected int |
markDSSClearPoint() |
Takes note of the location of the most recently completed
DSS in the buffer, and then returns the current offset.
|
private int |
maxEncodedLength(java.lang.String s) |
Find the maximum number of bytes needed to represent the string in the
default encoding.
|
private void |
overrideChainByte(int pos,
byte chainByte) |
Override the default chaining byte with the chaining byte that is passed
in.
|
protected void |
padBytes(byte val,
int length) |
Write pad bytes using spaceChar
|
private static int |
peekStream(java.io.InputStream in) |
|
private static java.io.OutputStream |
placeLayerBStreamingBuffer(java.io.OutputStream original) |
|
private int |
prepScalarStream(boolean chainedWithSameCorrelator,
int codePoint,
boolean writeNullByte) |
prepScalarStream does the following prep for writing stream data:
1.
|
protected void |
reset(DssTrace dssTrace) |
reset values for sending next message
|
protected void |
resetChainState() |
Reset any chaining state that needs to be reset
at time of the send
|
private void |
sendBytes(java.io.OutputStream socketOutputStream) |
|
private void |
sendBytes(java.io.OutputStream socketOutputStream,
boolean flashStream) |
|
protected void |
setBufferPosition(int position) |
Change the current position in the output buffer.
|
protected void |
setCMDProtocol() |
set protocol to CMD protocol
|
protected void |
setEbcdicCcsid() |
|
protected void |
setUtf8Ccsid() |
|
protected void |
startDdm(int codePoint) |
Mark the location of the length bytes for the collection so they
can be updated later
|
protected void |
truncateDSS(int value) |
Truncate the current DSS.
|
(package private) void |
writeBigDecimal(java.math.BigDecimal b,
int precision,
int scale) |
Write a Java
java.math.BigDecimal to packed decimal bytes. |
protected void |
writeBoolean(boolean v) |
Write platform boolean
|
protected void |
writeByte(int value) |
Write byte
|
protected void |
writeBytes(byte[] buf) |
Write byte array
|
protected void |
writeBytes(byte[] buf,
int length) |
Write byte array
|
protected void |
writeBytes(byte[] buf,
int start,
int length) |
Write byte array
|
(package private) void |
writeCodePoint4Bytes(int codePoint,
int value) |
Write code point and 4 bytes
|
protected void |
writeDouble(double v) |
Write platform double
|
protected void |
writeExtendedLength(long size) |
|
protected void |
writeFloat(float v) |
Write platform float
|
protected void |
writeInt(int v) |
Write platform int
|
protected void |
writeLDBytes(byte[] buf) |
|
protected void |
writeLDBytes(byte[] buf,
int index) |
|
protected void |
writeLDString(java.lang.String s) |
Write length delimited string
|
protected void |
writeLDString(java.lang.String s,
int index,
DRDAStatement stmt,
boolean isParameter) |
Write length delimited string
|
(package private) void |
writeLengthCodePoint(int length,
int codePoint) |
|
protected void |
writeLong(long v) |
Write platform long
|
protected void |
writeNetworkInt(int value) |
Write network int
|
protected void |
writeNetworkShort(int value) |
Write network short
|
(package private) void |
writeScalar1Byte(int codePoint,
int value) |
Write scalar 1 byte object includes length, codepoint and value
|
protected void |
writeScalar2Bytes(int value) |
|
protected void |
writeScalar2Bytes(int codePoint,
int value) |
Write scalar 2 byte object includes length, codepoint and value
|
protected void |
writeScalarBytes(int codePoint,
byte[] buf) |
Write scalar byte array object includes length, codepoint and value
|
protected void |
writeScalarHeader(int codePoint,
int dataLength) |
Write scalar object header includes length and codepoint
|
protected void |
writeScalarPaddedBytes(byte[] buf,
int paddedLength,
byte padByte) |
Write padded scalar byte array object value
|
protected void |
writeScalarPaddedBytes(int codePoint,
byte[] buf,
int paddedLength,
byte padByte) |
Write padded scalar byte array object includes length, codepoint and value
|
(package private) void |
writeScalarPaddedString(int codePoint,
java.lang.String string,
int paddedLength) |
Write padded scalar string object includes length, codepoint and value
the string is converted into the appropriate codeset (EBCDIC)
|
protected void |
writeScalarPaddedString(DRDAString drdaString,
int paddedLength) |
Write padded scalar
DRDAString object value. |
protected void |
writeScalarStream(boolean chainedWithSameCorrelator,
int codePoint,
EXTDTAInputStream in,
boolean writeNullByte) |
|
(package private) void |
writeScalarString(int codePoint,
java.lang.String string) |
Write scalar string object includes length, codepoint and value
the string is converted into the appropriate codeset (EBCDIC)
|
protected void |
writeShort(boolean b) |
Write boolean as short
|
protected void |
writeShort(int v) |
Write platform short
|
protected void |
writeString(java.lang.String s) |
Write string with default encoding
|
protected void |
writeUDT(java.lang.Object val,
int index) |
Write a value of a user defined type.
|
private static final int MAX_MARKS_NESTING
private static final int DEFAULT_BUFFER_SIZE
static final int MAX_VARCHAR_BYTE_LENGTH
writeLDString()
,
which is the maximum unsigned integer value that fits in two bytes.private java.nio.ByteBuffer buffer
private int[] markStack
private int top
private EbcdicCcsidManager ebcdicCcsidManager
private Utf8CcsidManager utf8CcsidManager
private CcsidManager ccsidManager
private DRDAConnThread agent
private int dssLengthLocation
private int correlationID
private int nextCorrelationID
private boolean isDRDAProtocol
private DssTrace dssTrace
private int prevHdrLocation
private int previousCorrId
private byte previousChainByte
private boolean isContinuationDss
private int lastDSSBeforeMark
private final java.nio.charset.CharsetEncoder encoder
volatile long totalByteCount
DDMWriter(DRDAConnThread agent, DssTrace dssTrace)
protected void setUtf8Ccsid()
protected void setEbcdicCcsid()
protected CcsidManager getCurrentCcsidManager()
protected void reset(DssTrace dssTrace)
protected int getBufferPosition()
protected void setBufferPosition(int position)
position
- new positionprotected byte[] getBufferContents(int startPos)
startPos
- the position of the first byte to copystartPos
up to the current positionprotected void setCMDProtocol()
protected void createDssReply()
protected void createDssRequest()
protected void createDssObject()
private void markDssAsContinued(boolean forLob)
protected void endDss(byte chainByte)
private void overrideChainByte(int pos, byte chainByte)
pos
- the position on which the chaining byte is locatedchainByte
- the chaining byte that overrides the defaultprotected void endDss()
private void endDss(boolean finalizeLength)
protected void endDdmAndDss()
protected byte[] copyDSSDataToEnd(int start)
start
- protected void startDdm(int codePoint)
protected void clearDdm()
protected void clearBuffer()
protected void endDdm()
protected int getDSSLength()
protected void truncateDSS(int value)
value
- DSS lengthprotected void writeByte(int value)
value
- byte to be writtenprotected void writeNetworkShort(int value)
value
- value to be writtenprotected void writeNetworkInt(int value)
value
- value to be writtenprotected void writeBytes(byte[] buf, int length)
buf
- byte array to be writtenlength
- - length to writeprotected void writeBytes(byte[] buf, int start, int length)
buf
- byte array to be writtenstart
- - starting positionlength
- - length to writeprotected void writeBytes(byte[] buf)
buf
- byte array to be writtenprotected void writeLDBytes(byte[] buf)
protected void writeLDBytes(byte[] buf, int index)
void writeCodePoint4Bytes(int codePoint, int value)
codePoint
- - code point to writevalue
- - value to write after code pointvoid writeScalar1Byte(int codePoint, int value)
codePoint
- - code point to writevalue
- - value to write after code pointprotected void writeScalar2Bytes(int codePoint, int value)
codePoint
- - code point to writevalue
- - value to write after code pointprotected void writeScalar2Bytes(int value)
protected void writeScalarStream(boolean chainedWithSameCorrelator, int codePoint, EXTDTAInputStream in, boolean writeNullByte) throws DRDAProtocolException
DRDAProtocolException
private void beginDss(boolean chainedToNextStructure, int dssType)
private int prepScalarStream(boolean chainedWithSameCorrelator, int codePoint, boolean writeNullByte) throws DRDAProtocolException
DRDAProtocolException
protected boolean doesRequestContainData()
private void flushScalarStreamSegment(boolean lastSegment, java.io.OutputStream out) throws DRDAProtocolException
DRDAProtocolException
void writeLengthCodePoint(int length, int codePoint)
protected void writeScalarHeader(int codePoint, int dataLength)
codePoint
- - code point to writedataLength
- - length of object datavoid writeScalarString(int codePoint, java.lang.String string)
codePoint
- - code point to writestring
- - string to be writtenvoid writeScalarPaddedString(int codePoint, java.lang.String string, int paddedLength)
codePoint
- - code point to writestring
- - string to be writtenpaddedLength
- - length to pad string toprotected void writeScalarPaddedString(DRDAString drdaString, int paddedLength)
DRDAString
object value. The
string is converted into the appropriate codeset.drdaString
- string to be writtenpaddedLength
- length to pad string toprotected void writeScalarPaddedBytes(int codePoint, byte[] buf, int paddedLength, byte padByte)
codePoint
- - code point to writebuf
- - byte array to be writtenpaddedLength
- - length to pad string topadByte
- - byte to be used for paddingprotected void writeScalarPaddedBytes(byte[] buf, int paddedLength, byte padByte)
buf
- - byte array to be writtenpaddedLength
- - length to pad string topadByte
- - byte to be used for paddingprotected void writeScalarBytes(int codePoint, byte[] buf)
codePoint
- - code point to writebuf
- - byte array to be writtenprotected void writeShort(int v)
v
- value to be writtenprotected void writeShort(boolean b)
b
- boolean value true = 1 false = 0protected void writeInt(int v)
v
- value to be writtenprotected void writeLong(long v)
v
- value to be writtenprotected void writeFloat(float v)
v
- value to be writtenprotected void writeDouble(double v)
v
- value to be writtenprotected void writeBoolean(boolean v)
v
- value to be writtenprotected void writeLDString(java.lang.String s) throws DRDAProtocolException
s
- value to be written with integerDRDAProtocolException
protected void writeUDT(java.lang.Object val, int index) throws DRDAProtocolException
val
- object to be writtenDRDAProtocolException
private int maxEncodedLength(java.lang.String s)
s
- the string to encodeprotected void writeLDString(java.lang.String s, int index, DRDAStatement stmt, boolean isParameter) throws DRDAProtocolException
s
- value to be written with integerindex
- column index to put in warningstmt
- the executing statement (null if not invoked as
part of statement execution)isParameter
- true if the value written is for an output
parameter in a procedure callDRDAProtocolException
private static boolean isContinuationByte(byte b)
10xxxxxx
.b
- the byte to checktrue
if b
is a continuation byte, or
false
if it is the first byte in a UTF-8 sequenceprotected void writeString(java.lang.String s) throws DRDAProtocolException
s
- value to be writtenDRDAProtocolException
protected void padBytes(byte val, int length)
val
- value to be writtenlength
- length to be writtenprotected void flush() throws java.io.IOException
java.io.IOException
protected void flush(java.io.OutputStream socketOutputStream) throws java.io.IOException
socketOutputStream
- java.io.IOException
private void beginDss(int dssType, boolean ensureLen)
private void finalizeDssLength()
protected void writeExtendedLength(long size)
private int calculateExtendedLengthByteCount(long ddmSize)
ddmSize
- - size of DDM commandprivate void ensureLength(int length)
length
- space requiredvoid writeBigDecimal(java.math.BigDecimal b, int precision, int scale) throws java.sql.SQLException
java.math.BigDecimal
to packed decimal bytes.b
- BigDecimal to writeprecision
- Precision of decimal or numeric typescale
- declared scalejava.sql.SQLException
- Thrown if # digits > 31private void sendBytes(java.io.OutputStream socketOutputStream) throws java.io.IOException
java.io.IOException
private void sendBytes(java.io.OutputStream socketOutputStream, boolean flashStream) throws java.io.IOException
java.io.IOException
protected void resetChainState()
private int getCorrelationID()
protected void finalizeChain(byte currChainByte, java.io.OutputStream socketOutputStream) throws DRDAProtocolException
socketOutputStream
- Output stream to which we're flushing.DRDAProtocolException
protected int markDSSClearPoint()
protected void clearDSSesBackToMark(int mark)
private static int peekStream(java.io.InputStream in) throws java.io.IOException
java.io.IOException
private static int getLayerBStreamingBufferSize()
private static java.io.OutputStream placeLayerBStreamingBuffer(java.io.OutputStream original)
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.