Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.common.stream.CJDBCOutputStream Class Reference

List of all members.

Public Member Functions

 CJDBCOutputStream (Socket socket) throws IOException, StreamCorruptedException
 CJDBCOutputStream (OutputStream out) throws IOException, StreamCorruptedException
void flush () throws IOException
void close () throws IOException
void writeObject (Object obj) throws IOException
void writeUTF (String string) throws IOException
void writeInt (int value) throws IOException
void writeLong (long value) throws IOException
void writeBoolean (boolean value) throws IOException
long getBytesWritten ()
Socket getSocket ()
long getDateCreated ()
boolean getUseCompression ()
long getSpeed ()

Detailed Description

ObjectOutputStream to use between the controller and the driver.

See also:
org.objectweb.cjdbc.common.stream.CJDBCStream
Author:
Nicolas Modrzyk

Emmanuel Cecchet

Definition at line 42 of file CJDBCOutputStream.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.common.stream.CJDBCOutputStream.CJDBCOutputStream Socket  socket  )  throws IOException, StreamCorruptedException
 

Creates a new CJDBCOutputStream object for statistics on sockets

Parameters:
socket socket to monitor
Exceptions:
IOException if an IO error occurs
StreamCorruptedException if an error occurs

Definition at line 71 of file CJDBCOutputStream.java.

00073   {
00074     this(socket.getOutputStream());
00075     this.socket = socket;
00076   }

org.objectweb.cjdbc.common.stream.CJDBCOutputStream.CJDBCOutputStream OutputStream  out  )  throws IOException, StreamCorruptedException
 

Creates a new CJDBCOutputStream from the given input stream.

Parameters:
out outputstream to wrap
Exceptions:
IOException if new ObjectInputStream() throws anException
StreamCorruptedException same as above

Definition at line 86 of file CJDBCOutputStream.java.

00088   {
00089     output = new ObjectOutputStream(new BufferedOutputStream(out));
00090     dateCreated = System.currentTimeMillis();
00091     bytesWritten = 0;
00092   }


Member Function Documentation

void org.objectweb.cjdbc.common.stream.CJDBCOutputStream.close  )  throws IOException
 

See also:
java.io.ObjectOutputStream#close()
Exceptions:
IOException if an error occurs

Definition at line 107 of file CJDBCOutputStream.java.

Referenced by org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread.shutdown().

00108   {
00109     output.close();
00110   }

void org.objectweb.cjdbc.common.stream.CJDBCOutputStream.flush  )  throws IOException
 

See also:
java.io.ObjectOutputStream#flush()
Exceptions:
IOException if an error occurs

Definition at line 98 of file CJDBCOutputStream.java.

Referenced by org.objectweb.cjdbc.driver.Driver.connect(), org.objectweb.cjdbc.driver.Connection.execReadStoredProcedure(), org.objectweb.cjdbc.driver.Connection.execWriteRequestWithKeys(), org.objectweb.cjdbc.driver.Connection.execWriteStoredProcedure(), org.objectweb.cjdbc.controller.core.ControllerWorkerThread.run(), and org.objectweb.cjdbc.controller.core.ControllerServerThread.run().

00099   {
00100     output.flush();
00101   }

long org.objectweb.cjdbc.common.stream.CJDBCOutputStream.getBytesWritten  ) 
 

Returns:
Returns the bytesWritten.

Definition at line 234 of file CJDBCOutputStream.java.

Referenced by org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread.getBytesWritten().

00235   {
00236     return bytesWritten;
00237   }

long org.objectweb.cjdbc.common.stream.CJDBCOutputStream.getDateCreated  ) 
 

Returns:
Returns the dateCreated.

Definition at line 250 of file CJDBCOutputStream.java.

00251   {
00252     return dateCreated;
00253   }

Socket org.objectweb.cjdbc.common.stream.CJDBCOutputStream.getSocket  ) 
 

Returns:
Returns the socket.

Definition at line 242 of file CJDBCOutputStream.java.

Referenced by org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread.retrieveClientData().

00243   {
00244     return socket;
00245   }

long org.objectweb.cjdbc.common.stream.CJDBCOutputStream.getSpeed  ) 
 

Returns:
Returns the speed.

Definition at line 266 of file CJDBCOutputStream.java.

Referenced by org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread.getReadingSpeed(), and org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread.getWritingSpeed().

00267   {
00268     return speed;
00269   }

boolean org.objectweb.cjdbc.common.stream.CJDBCOutputStream.getUseCompression  ) 
 

Returns:
Returns the useCompression.

Definition at line 258 of file CJDBCOutputStream.java.

00259   {
00260     return useCompression;
00261   }

void org.objectweb.cjdbc.common.stream.CJDBCOutputStream.writeBoolean boolean  value  )  throws IOException
 

See also:
java.io.ObjectOutputStream#writeBoolean(boolean)
Parameters:
value a boolean value to write to the stream
Exceptions:
IOException if an error occurs

Definition at line 225 of file CJDBCOutputStream.java.

00226   {
00227     bytesWritten += 1;
00228     output.writeBoolean(value);
00229   }

void org.objectweb.cjdbc.common.stream.CJDBCOutputStream.writeInt int  value  )  throws IOException
 

See also:
java.io.ObjectOutputStream#writeInt(int)
Parameters:
value an int value to write to the stream
Exceptions:
IOException if an error occurs

Definition at line 203 of file CJDBCOutputStream.java.

Referenced by org.objectweb.cjdbc.driver.Driver.connect(), org.objectweb.cjdbc.driver.Connection.execReadStoredProcedure(), org.objectweb.cjdbc.driver.Connection.execWriteRequestWithKeys(), and org.objectweb.cjdbc.driver.Connection.execWriteStoredProcedure().

00204   {
00205     bytesWritten += 4;
00206     output.writeInt(value);
00207   }

void org.objectweb.cjdbc.common.stream.CJDBCOutputStream.writeLong long  value  )  throws IOException
 

See also:
java.io.ObjectOutputStream#writeLong(long)
Parameters:
value a long value to write to the stream
Exceptions:
IOException if an error occurs

Definition at line 214 of file CJDBCOutputStream.java.

00215   {
00216     bytesWritten += 8;
00217     output.writeLong(value);
00218   }

void org.objectweb.cjdbc.common.stream.CJDBCOutputStream.writeObject Object  obj  )  throws IOException
 

See also:
java.io.ObjectOutputStream#writeObject(java.lang.Object)
Parameters:
obj an Object to write to the stream
Exceptions:
IOException if an error occurs

Definition at line 117 of file CJDBCOutputStream.java.

Referenced by org.objectweb.cjdbc.controller.core.ControllerWorkerThread.run(), and org.objectweb.cjdbc.controller.core.ControllerServerThread.run().

00118   {
00119     if (useCompression)
00120     {
00121       byte[] bytes = CJDBCStream.compressObject(obj);
00122       bytesWritten += bytes.length + 4;
00123       // we are sending an integer on the pipe.
00124 
00125       output.writeInt(bytes.length);
00126       output.write(bytes);
00127     }
00128     else
00129     {
00130       if (obj == null)
00131       {
00132         output.writeInt(CJDBCStream.NULL);
00133         return;
00134       }
00135       else if (obj instanceof String)
00136       {
00137         String str = (String) obj;
00138         if (str.length() < MAXIMUM_STRING_LENGTH_IN_WRITEUTF)
00139         { // If the String can fit for a writeUTF call then use it else defaults
00140           // to writeUnshared (below) that will call the appropriate method to
00141           // send longer strings (not publicly available in the API).
00142           output.writeInt(CJDBCStream.STRING_OBJECT);
00143           output.writeUTF(str);
00144           return;
00145         }
00146       }
00147       else if (obj instanceof Integer)
00148       {
00149         output.writeInt(CJDBCStream.INTEGER_OBJECT);
00150         output.writeInt(((Integer) obj).intValue());
00151         return;
00152       }
00153       else if (obj instanceof Long)
00154       {
00155         output.writeInt(CJDBCStream.LONG_OBJECT);
00156         output.writeLong(((Long) obj).longValue());
00157         return;
00158       }
00159       else if (obj instanceof Boolean)
00160       {
00161         output.writeInt(CJDBCStream.BOOLEAN_OBJECT);
00162         output.writeBoolean(((Boolean) obj).booleanValue());
00163         return;
00164       }
00165 
00166       // Here we have an object for which we don't have special optimization and
00167       // that we will send as an object
00168       output.writeInt(CJDBCStream.OBJECT);
00169 
00170       // Use the unshared version to prevent the stream to keep references on
00171       // objects. This prevents objects sent through the channel from being
00172       // garbage collected and results in memory leaks.
00173       output.writeUnshared(obj);
00174 
00175       if (obj instanceof ArrayList)
00176       { // Reset the stream for shallow copies since unshared does not handle
00177         // them.
00178         output.flush();
00179         output.reset();
00180       }
00181     }
00182 
00183   }

void org.objectweb.cjdbc.common.stream.CJDBCOutputStream.writeUTF String  string  )  throws IOException
 

See also:
java.io.ObjectOutputStream#writeUTF(java.lang.String)
Parameters:
string a String to write in UTF form to the stream
Exceptions:
IOException if an error occurs

Definition at line 190 of file CJDBCOutputStream.java.

Referenced by org.objectweb.cjdbc.driver.Driver.connect().

00191   {
00192     // Let writeObject handle this in case string is null
00193     this.writeObject(string);
00194     if (string != null)
00195       bytesWritten += string.length();
00196   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:13 2005 for C-JDBC by  doxygen 1.3.9.1