net.sourceforge.jtds.jdbc

Class RequestStream


public class RequestStream
extends java.lang.Object

Class to implement an output stream for the server request.

Implementation note:

  1. This class contains methods to write different types of data to the server request stream in TDS format.
  2. 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

private byte[]
buffer
The output packet buffer.
private int
bufferPtr
The offset of the next byte to write.
private int
bufferSize
The current output buffer size
private boolean
isClosed
True if stream is closed.
private int
maxPrecision
The maximum decimal precision.
private byte
pktType
The request packet type.
private SharedSocket
socket
The shared network socket.
private int
streamId
The unique stream id.

Constructor Summary

RequestStream(SharedSocket socket, int streamId, int bufferSize, int maxPrecision)
Construct a RequestStream object.

Method Summary

(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
getBufferSize()
Retrieve the current output packet size.
(package private) byte
getMaxDecimalBytes()
Returns the maximum number of bytes required to output a decimal given the current maxPrecision.
(package private) int
getMaxPrecision()
Retrive the maximum decimal precision.
(package private) int
getServerType()
Retrieve the Server type.
(package private) int
getStreamId()
Retrieve the unique stream id.
(package private) int
getTdsVersion()
Retrieve the TDS version number.
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(BigDecimal value)
Write a BigDecimal value to the output stream.
(package private) void
write(String s)
Write a String object to the output stream.
(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(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(s[] , int off, int len)
Write a char array object to the output stream.
(package private) void
write(short s)
Write a short 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

buffer

private byte[] buffer
The output packet buffer.

bufferPtr

private int bufferPtr
The offset of the next byte to write.

bufferSize

private int bufferSize
The current output buffer size

isClosed

private boolean isClosed
True if stream is closed.

maxPrecision

private int maxPrecision
The maximum decimal precision.

pktType

private byte pktType
The request packet type.

socket

private final SharedSocket socket
The shared network socket.

streamId

private final int streamId
The unique stream id.

Constructor Details

RequestStream

(package private)  RequestStream(SharedSocket socket,
                                 int streamId,
                                 int bufferSize,
                                 int maxPrecision)
Construct a RequestStream object.
Parameters:
socket - the shared socket object to write to
streamId - the unique id for this stream
bufferSize - the initial buffer size to use (the current network packet size)
maxPrecision - the maximum precision for numeric/decimal types

Method Details

close

(package private)  void close()
Close the output stream.

flush

(package private)  void flush()
            throws IOException
Flush the packet to the output stream setting the last packet flag.

getBufferSize

(package private)  int getBufferSize()
Retrieve the current output packet size.
Returns:
the packet size as an int.

getMaxDecimalBytes

(package private)  byte getMaxDecimalBytes()
Returns:
the maximum number of bytes required to output a decimal.

getMaxPrecision

(package private)  int getMaxPrecision()
Retrive the maximum decimal precision.
Returns:
The precision as an int.

getServerType

(package private)  int getServerType()
Retrieve the Server type.
Returns:
The Server type as an int.

getStreamId

(package private)  int getStreamId()
Retrieve the unique stream id.
Returns:
the unique stream id as an int.

getTdsVersion

(package private)  int getTdsVersion()
Retrieve the TDS version number.
Returns:
The TDS version as an int.

putPacket

private void putPacket(int last)
            throws IOException
Write the TDS packet to the network.
Parameters:
last - Set to 1 if this is the last packet else 0.

setBufferSize

(package private)  void setBufferSize(int size)
Set the output buffer size

setPacketType

(package private)  void setPacketType(byte pktType)
Set the current output packet type.
Parameters:
pktType - The packet type eg TdsCore.QUERY_PKT.

write

(package private)  void write(BigDecimal value)
            throws IOException
Write a BigDecimal value to the output stream.
Parameters:
value - The BigDecimal value to write.

write

(package private)  void write(String s)
            throws IOException
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.

write

(package private)  void write(byte b)
            throws IOException
Write a byte to the output stream.
Parameters:
b - The byte value to write.

write

(package private)  void write(byte[] b)
            throws IOException
Write an array of bytes to the output stream.
Parameters:
b - The byte array to write.

write

(package private)  void write(byte[] b,
                              int off,
                              int len)
            throws IOException
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.

write

(package private)  void write(double f)
            throws IOException
Write a double value to the output stream.
Parameters:
f - The double value to write.

write

(package private)  void write(float f)
            throws IOException
Write a float value to the output stream.
Parameters:
f - The float value to write.

write

(package private)  void write(int i)
            throws IOException
Write an int value to the output stream.
Parameters:
i - The int value to write.

write

(package private)  void write(long l)
            throws IOException
Write a long value to the output stream.
Parameters:
l - The long value to write.

write

(package private)  void write(s[] ,
                              int off,
                              int len)
            throws IOException
Write a char array object to the output stream.
Parameters:

write

(package private)  void write(short s)
            throws IOException
Write a short value to the output stream.
Parameters:
s - The short value to write.

writeAscii

(package private)  void writeAscii(String s)
            throws IOException
Write a String to the output stream as translated bytes.
Parameters:
s - The String to write.

writeReaderBytes

(package private)  void writeReaderBytes(Reader in,
                                         int length)
            throws IOException
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.

writeReaderChars

(package private)  void writeReaderChars(Reader in,
                                         int length)
            throws IOException
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.

writeStreamBytes

(package private)  void writeStreamBytes(InputStream in,
                                         int length)
            throws IOException
Copy the contents of an InputStream to the server.
Parameters:
in - The InputStream to read.
length - The length of the stream.

Generated on June 12 2008