org.objectweb.cjdbc.common.stream
Class CJDBCOutputStream

java.lang.Object
  extended byorg.objectweb.cjdbc.common.stream.CJDBCOutputStream

public class CJDBCOutputStream
extends java.lang.Object

DataOutputStream wrapper used between the controller and the driver.

Author:
Nicolas Modrzyk , Emmanuel Cecchet , CJDBCStream

Field Summary
private  long dateCreated
           
private  java.io.DataOutputStream output
           
private  java.net.Socket socket
           
 
Constructor Summary
CJDBCOutputStream(java.io.OutputStream out)
          Creates a new CJDBCOutputStream from the given input stream.
CJDBCOutputStream(java.net.Socket socket)
          Creates a new CJDBCOutputStream object for statistics on sockets
 
Method Summary
 void close()
           
 void flush()
           
 long getDateCreated()
           
 java.net.Socket getSocket()
           
 void write(byte[] b)
           
 void write(byte[] b, int offset, int length)
           
 void writeBoolean(boolean value)
           
 void writeDouble(double value)
           
 void writeFloat(float value)
           
 void writeInt(int value)
           
 void writeLong(long value)
           
 void writeUTF(java.lang.String string)
          We split the String into 21K-long chunks and encode+send them one after the other.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

output

private java.io.DataOutputStream output

socket

private java.net.Socket socket

dateCreated

private long dateCreated
Constructor Detail

CJDBCOutputStream

public CJDBCOutputStream(java.net.Socket socket)
                  throws java.io.IOException
Creates a new CJDBCOutputStream object for statistics on sockets

Parameters:
socket - socket to monitor
Throws:
java.io.IOException - if an IO error occurs

CJDBCOutputStream

public CJDBCOutputStream(java.io.OutputStream out)
Creates a new CJDBCOutputStream from the given input stream.

Parameters:
out - outputstream to wrap
Method Detail

flush

public void flush()
           throws java.io.IOException
Throws:
java.io.IOException - if an error occurs
See Also:
DataOutputStream.flush()

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException - if an error occurs
See Also:
FilterOutputStream.close()

writeUTF

public void writeUTF(java.lang.String string)
              throws java.io.IOException
We split the String into 21K-long chunks and encode+send them one after the other. This is because Java's writeUTF() fails when UTFlen is < 64K. UTFlen max is: 2 + 3 * string.length()

Java's writeUTF() is fully specified in DataOutput.writeUTF(java.lang.String) and stable since JDK1.0. Implementation is located in DataOutputStream.writeUTF(java.lang.String, java.io.DataOutput)

At first this looks like a kludge but: (1) On one hand it's almost required anyway to split into chunks (whatever technique we choose) since strings can be infinitely long and we don't want to allocate tons of memory. (2) On the other hand it is hard to find out a String serialization which is both efficient and based upon a standard encoding. Let's briefly look at the alternatives:

Parameters:
string - a String to write in UTF form to the stream
Throws:
java.io.IOException - if an error occurs
See Also:
DataOutputStream.writeUTF(java.lang.String)

writeInt

public void writeInt(int value)
              throws java.io.IOException
Parameters:
value - an int value to write to the stream
Throws:
java.io.IOException - if an error occurs
See Also:
DataOutputStream.writeInt(int)

writeLong

public void writeLong(long value)
               throws java.io.IOException
Parameters:
value - a long value to write to the stream
Throws:
java.io.IOException - if an error occurs
See Also:
DataOutputStream.writeLong(long)

writeFloat

public void writeFloat(float value)
                throws java.io.IOException
Parameters:
value - a float value to write to the stream
Throws:
java.io.IOException - if an error occurs
See Also:
DataOutputStream.writeFloat(float)

writeDouble

public void writeDouble(double value)
                 throws java.io.IOException
Parameters:
value - a double value to write to the stream
Throws:
java.io.IOException - if an error occurs
See Also:
DataOutputStream.writeDouble(double)

write

public void write(byte[] b)
           throws java.io.IOException
Parameters:
b - an array of bytes to write to the stream
Throws:
java.io.IOException - if an error occurs
See Also:
FilterOutputStream.write(byte[])

write

public void write(byte[] b,
                  int offset,
                  int length)
           throws java.io.IOException
Throws:
java.io.IOException
See Also:
DataOutputStream.write(byte[], int, int)

writeBoolean

public void writeBoolean(boolean value)
                  throws java.io.IOException
Parameters:
value - a boolean value to write to the stream
Throws:
java.io.IOException - if an error occurs
See Also:
DataOutputStream.writeBoolean(boolean)

getSocket

public java.net.Socket getSocket()
Returns:
Returns the socket.

getDateCreated

public long getDateCreated()
Returns:
Returns the dateCreated.


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.