Package net.sourceforge.jtds.jdbc
Class RequestStream
java.lang.Object
net.sourceforge.jtds.jdbc.RequestStream
Class to implement an output stream for the server request.
Implementation note:
- This class contains methods to write different types of data to the server request stream in TDS format.
- Character translation of String items is carried out.
- Version:
- $Id: RequestStream.java,v 1.18 2005-09-21 21:50:34 ddkilzer Exp $
- Author:
- Mike Hutchinson.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SharedSocket.VirtualSocket
The unique stream id.private byte[]
The output packet buffer.private int
The offset of the next byte to write.private final int
The current output buffer sizeprivate boolean
True if stream is closed.private final int
The maximum decimal precision.private byte
The request packet type.private final SharedSocket
The shared network socket. -
Constructor Summary
ConstructorsConstructorDescriptionRequestStream
(SharedSocket socket, SharedSocket.VirtualSocket vsock, int bufferSize, int maxPrecision) Construct a RequestStream object. -
Method Summary
Modifier and TypeMethodDescription(package private) void
close()
Close the output stream.(package private) void
flush()
Flush the packet to the output stream setting the last packet flag.(package private) int
Retrieve the current output packet size.(package private) byte
Returns the maximum number of bytes required to output a decimal given the currentmaxPrecision
.(package private) int
Retrive the maximum decimal precision.(package private) int
Retrieve the Server type.(package private) int
Retrieve the TDS version number.(package private) SharedSocket.VirtualSocket
Retrieve theSharedSocket.VirtualSocket
used by this stream.private void
putPacket
(int last) Write the TDS packet to the network.(package private) void
setBufferSize
(int size) Set the output buffer size(package private) void
setPacketType
(byte pktType) Set the current output packet type.(package private) void
write
(byte b) Write a byte to the output stream.(package private) void
write
(byte[] b) Write an array of bytes to the output stream.(package private) void
write
(byte[] b, int off, int len) Write a partial byte buffer to the output stream.(package private) void
write
(char[] s, int off, int len) Write a char array object to the output stream.(package private) void
write
(double f) Write a double value to the output stream.(package private) void
write
(float f) Write a float value to the output stream.(package private) void
write
(int i) Write an int value to the output stream.(package private) void
write
(long l) Write a long value to the output stream.(package private) void
write
(short s) Write a short value to the output stream.(package private) void
Write a String object to the output stream.(package private) void
write
(BigDecimal value) Write a BigDecimal value to the output stream.(package private) void
writeAscii
(String s) Write a String to the output stream as translated bytes.(package private) void
writeReaderBytes
(Reader in, int length) Copy the contents of a Reader stream to the server as bytes.(package private) void
writeReaderChars
(Reader in, int length) Copy the contents of a Reader stream to the server.(package private) void
writeStreamBytes
(InputStream in, int length) Copy the contents of an InputStream to the server.
-
Field Details
-
socket
The shared network socket. -
buffer
private byte[] bufferThe output packet buffer. -
bufferPtr
private int bufferPtrThe offset of the next byte to write. -
pktType
private byte pktTypeThe request packet type. -
_VirtualSocket
The unique stream id. -
isClosed
private boolean isClosedTrue if stream is closed. -
bufferSize
private final int bufferSizeThe current output buffer size -
maxPrecision
private final int maxPrecisionThe maximum decimal precision.
-
-
Constructor Details
-
Method Details
-
setBufferSize
void setBufferSize(int size) Set the output buffer size- Parameters:
size
- The new buffer size (>=TdsCore.MIN_PKT_SIZE
invalid input: '<'=TdsCore.MAX_PKT_SIZE
).
-
getBufferSize
int getBufferSize()Retrieve the current output packet size.- Returns:
- the packet size as an
int
.
-
getMaxPrecision
int getMaxPrecision()Retrive the maximum decimal precision.- Returns:
- The precision as an
int
.
-
getMaxDecimalBytes
byte getMaxDecimalBytes()Returns the maximum number of bytes required to output a decimal given the currentmaxPrecision
.- Returns:
- the maximum number of bytes required to output a decimal.
-
getVirtualSocket
SharedSocket.VirtualSocket getVirtualSocket()Retrieve theSharedSocket.VirtualSocket
used by this stream.- Returns:
- the unique stream id as an
int
.
-
setPacketType
void setPacketType(byte pktType) Set the current output packet type.- Parameters:
pktType
- The packet type eg TdsCore.QUERY_PKT.
-
write
Write a byte to the output stream.- Parameters:
b
- The byte value to write.- Throws:
IOException
-
write
Write an array of bytes to the output stream.- Parameters:
b
- The byte array to write.- Throws:
IOException
-
write
Write a partial byte buffer to the output stream.- Parameters:
b
- The byte array buffer.off
- The offset into the byte array.len
- The number of bytes to write.- Throws:
IOException
-
write
Write an int value to the output stream.- Parameters:
i
- The int value to write.- Throws:
IOException
-
write
Write a short value to the output stream.- Parameters:
s
- The short value to write.- Throws:
IOException
-
write
Write a long value to the output stream.- Parameters:
l
- The long value to write.- Throws:
IOException
-
write
Write a double value to the output stream.- Parameters:
f
- The double value to write.- Throws:
IOException
-
write
Write a float value to the output stream.- Parameters:
f
- The float value to write.- Throws:
IOException
-
write
Write a String object to the output stream. If the TDS version is >= 7.0 write a UNICODE string otherwise wrote a translated byte stream.- Parameters:
s
- The String to write.- Throws:
IOException
-
write
Write a char array object to the output stream.- Parameters:
s
- The char[] to write.- Throws:
IOException
-
writeAscii
Write a String to the output stream as translated bytes.- Parameters:
s
- The String to write.- Throws:
IOException
-
writeStreamBytes
Copy the contents of an InputStream to the server.- Parameters:
in
- The InputStream to read.length
- The length of the stream.- Throws:
IOException
-
writeReaderChars
Copy the contents of a Reader stream to the server.- Parameters:
in
- The Reader object with the data.length
- The length of the data in characters.- Throws:
IOException
-
writeReaderBytes
Copy the contents of a Reader stream to the server as bytes.NB. Only reliable where the charset is single byte.
- Parameters:
in
- The Reader object with the data.length
- The length of the data in bytes.- Throws:
IOException
-
write
Write a BigDecimal value to the output stream.- Parameters:
value
- The BigDecimal value to write.- Throws:
IOException
-
flush
Flush the packet to the output stream setting the last packet flag.- Throws:
IOException
-
close
void close()Close the output stream. -
getTdsVersion
int getTdsVersion()Retrieve the TDS version number.- Returns:
- The TDS version as an
int
.
-
getServerType
int getServerType()Retrieve the Server type.- Returns:
- The Server type as an
int
.
-
putPacket
Write the TDS packet to the network.- Parameters:
last
- Set to 1 if this is the last packet else 0.- Throws:
IOException
-