Package net.sourceforge.jtds.jdbc
Class RequestStream
- java.lang.Object
-
- net.sourceforge.jtds.jdbc.RequestStream
-
public class RequestStream extends java.lang.ObjectClass 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
Fields Modifier and Type Field Description private SharedSocket.VirtualSocket_VirtualSocketThe unique stream id.private byte[]bufferThe output packet buffer.private intbufferPtrThe offset of the next byte to write.private intbufferSizeThe current output buffer sizeprivate booleanisClosedTrue if stream is closed.private intmaxPrecisionThe maximum decimal precision.private bytepktTypeThe request packet type.private SharedSocketsocketThe shared network socket.
-
Constructor Summary
Constructors Constructor Description RequestStream(SharedSocket socket, SharedSocket.VirtualSocket vsock, int bufferSize, int maxPrecision)Construct a RequestStream object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidclose()Close the output stream.(package private) voidflush()Flush the packet to the output stream setting the last packet flag.(package private) intgetBufferSize()Retrieve the current output packet size.(package private) bytegetMaxDecimalBytes()Returns the maximum number of bytes required to output a decimal given the currentmaxPrecision.(package private) intgetMaxPrecision()Retrive the maximum decimal precision.(package private) intgetServerType()Retrieve the Server type.(package private) intgetTdsVersion()Retrieve the TDS version number.(package private) SharedSocket.VirtualSocketgetVirtualSocket()Retrieve theSharedSocket.VirtualSocketused by this stream.private voidputPacket(int last)Write the TDS packet to the network.(package private) voidsetBufferSize(int size)Set the output buffer size(package private) voidsetPacketType(byte pktType)Set the current output packet type.(package private) voidwrite(byte b)Write a byte to the output stream.(package private) voidwrite(byte[] b)Write an array of bytes to the output stream.(package private) voidwrite(byte[] b, int off, int len)Write a partial byte buffer to the output stream.(package private) voidwrite(char[] s, int off, int len)Write a char array object to the output stream.(package private) voidwrite(double f)Write a double value to the output stream.(package private) voidwrite(float f)Write a float value to the output stream.(package private) voidwrite(int i)Write an int value to the output stream.(package private) voidwrite(long l)Write a long value to the output stream.(package private) voidwrite(short s)Write a short value to the output stream.(package private) voidwrite(java.lang.String s)Write a String object to the output stream.(package private) voidwrite(java.math.BigDecimal value)Write a BigDecimal value to the output stream.(package private) voidwriteAscii(java.lang.String s)Write a String to the output stream as translated bytes.(package private) voidwriteReaderBytes(java.io.Reader in, int length)Copy the contents of a Reader stream to the server as bytes.(package private) voidwriteReaderChars(java.io.Reader in, int length)Copy the contents of a Reader stream to the server.(package private) voidwriteStreamBytes(java.io.InputStream in, int length)Copy the contents of an InputStream to the server.
-
-
-
Field Detail
-
socket
private final SharedSocket socket
The shared network socket.
-
buffer
private byte[] buffer
The output packet buffer.
-
bufferPtr
private int bufferPtr
The offset of the next byte to write.
-
pktType
private byte pktType
The request packet type.
-
_VirtualSocket
private final SharedSocket.VirtualSocket _VirtualSocket
The unique stream id.
-
isClosed
private boolean isClosed
True if stream is closed.
-
bufferSize
private final int bufferSize
The current output buffer size
-
maxPrecision
private final int maxPrecision
The maximum decimal precision.
-
-
Constructor Detail
-
RequestStream
RequestStream(SharedSocket socket, SharedSocket.VirtualSocket vsock, int bufferSize, int maxPrecision)
Construct a RequestStream object.- Parameters:
socket- the shared socket object to write tovsock- theSharedSocket.VirtualSocketused by this streambufferSize- the initial buffer size to use (the current network packet size)maxPrecision- the maximum precision for numeric/decimal types
-
-
Method Detail
-
setBufferSize
void setBufferSize(int size)
Set the output buffer size- Parameters:
size- The new buffer size (>=TdsCore.MIN_PKT_SIZE<=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.VirtualSocketused 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
void write(byte b) throws java.io.IOExceptionWrite a byte to the output stream.- Parameters:
b- The byte value to write.- Throws:
java.io.IOException
-
write
void write(byte[] b) throws java.io.IOExceptionWrite an array of bytes to the output stream.- Parameters:
b- The byte array to write.- Throws:
java.io.IOException
-
write
void write(byte[] b, int off, int len) throws java.io.IOExceptionWrite 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:
java.io.IOException
-
write
void write(int i) throws java.io.IOExceptionWrite an int value to the output stream.- Parameters:
i- The int value to write.- Throws:
java.io.IOException
-
write
void write(short s) throws java.io.IOExceptionWrite a short value to the output stream.- Parameters:
s- The short value to write.- Throws:
java.io.IOException
-
write
void write(long l) throws java.io.IOExceptionWrite a long value to the output stream.- Parameters:
l- The long value to write.- Throws:
java.io.IOException
-
write
void write(double f) throws java.io.IOExceptionWrite a double value to the output stream.- Parameters:
f- The double value to write.- Throws:
java.io.IOException
-
write
void write(float f) throws java.io.IOExceptionWrite a float value to the output stream.- Parameters:
f- The float value to write.- Throws:
java.io.IOException
-
write
void write(java.lang.String s) throws java.io.IOExceptionWrite 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:
java.io.IOException
-
write
void write(char[] s, int off, int len) throws java.io.IOExceptionWrite a char array object to the output stream.- Parameters:
s- The char[] to write.- Throws:
java.io.IOException
-
writeAscii
void writeAscii(java.lang.String s) throws java.io.IOExceptionWrite a String to the output stream as translated bytes.- Parameters:
s- The String to write.- Throws:
java.io.IOException
-
writeStreamBytes
void writeStreamBytes(java.io.InputStream in, int length) throws java.io.IOExceptionCopy the contents of an InputStream to the server.- Parameters:
in- The InputStream to read.length- The length of the stream.- Throws:
java.io.IOException
-
writeReaderChars
void writeReaderChars(java.io.Reader in, int length) throws java.io.IOExceptionCopy 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:
java.io.IOException
-
writeReaderBytes
void writeReaderBytes(java.io.Reader in, int length) throws java.io.IOExceptionCopy 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:
java.io.IOException
-
write
void write(java.math.BigDecimal value) throws java.io.IOExceptionWrite a BigDecimal value to the output stream.- Parameters:
value- The BigDecimal value to write.- Throws:
java.io.IOException
-
flush
void flush() throws java.io.IOExceptionFlush the packet to the output stream setting the last packet flag.- Throws:
java.io.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
private void putPacket(int last) throws java.io.IOExceptionWrite the TDS packet to the network.- Parameters:
last- Set to 1 if this is the last packet else 0.- Throws:
java.io.IOException
-
-