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

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

List of all members.

Public Member Functions

 CJDBCInputStream (InputStream in) throws IOException, StreamCorruptedException
 CJDBCInputStream (Socket socket) throws IOException, StreamCorruptedException
Object readObject () throws ClassNotFoundException, IOException, OptionalDataException
void close () throws IOException
boolean readBoolean () throws IOException
int readInt () throws IOException
long readLong () throws IOException
String readUTF () throws IOException
int available () throws IOException
long getBytesRead ()
Socket getSocket ()
boolean getUseCompression ()
long getDateCreated ()
long getSpeed ()

Detailed Description

This class is to provide an ObjectInputStream implementation, but we cannot override the readObject method, so we made as a wrapper. The CJDBCInputStream in pair with the CJDBCOutputStream offers a five times compression using the java Inflater and Deflater class. useCompression can be set to on or off anytime.

Author:
Nicolas Modrzyk

Emmanuel Cecchet

Definition at line 45 of file CJDBCInputStream.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.common.stream.CJDBCInputStream.CJDBCInputStream InputStream  in  )  throws IOException, StreamCorruptedException
 

Creates a new CJDBCInputStream from the given input stream.

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

Definition at line 62 of file CJDBCInputStream.java.

00064   {
00065     input = new ObjectInputStream(new BufferedInputStream(in));
00066     bytesRead = 0;
00067   }

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

Useful constructor for statistics on sockets ..

Parameters:
socket socket for this stream
Exceptions:
IOException if an error occurs
StreamCorruptedException if an error occurs

Definition at line 76 of file CJDBCInputStream.java.

00078   {
00079     this(socket.getInputStream());
00080     this.socket = socket;
00081     dateCreated = System.currentTimeMillis();
00082   }


Member Function Documentation

int org.objectweb.cjdbc.common.stream.CJDBCInputStream.available  )  throws IOException
 

See also:
java.io.ObjectInputStream#available()
Returns:
the number of available bytes.
Exceptions:
IOException if an error occurs

Definition at line 199 of file CJDBCInputStream.java.

00200   {
00201     return input.available();
00202   }

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

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

Definition at line 134 of file CJDBCInputStream.java.

00135   {
00136     input.close();
00137   }

long org.objectweb.cjdbc.common.stream.CJDBCInputStream.getBytesRead  ) 
 

Returns:
Returns the bytesRead.

Definition at line 207 of file CJDBCInputStream.java.

00208   {
00209     return bytesRead;
00210   }

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

Returns:
Returns the dateCreated.

Definition at line 231 of file CJDBCInputStream.java.

00232   {
00233     return dateCreated;
00234   }

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

Returns:
Returns the socket.

Definition at line 215 of file CJDBCInputStream.java.

00216   {
00217     return socket;
00218   }

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

Returns:
Returns the speed.

Definition at line 239 of file CJDBCInputStream.java.

00240   {
00241     return speed;
00242   }

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

Returns:
Returns the useCompression.

Definition at line 223 of file CJDBCInputStream.java.

00224   {
00225     return useCompression;
00226   }

boolean org.objectweb.cjdbc.common.stream.CJDBCInputStream.readBoolean  )  throws IOException
 

See also:
java.io.ObjectInputStream#readBoolean()
Returns:
a boolean value
Exceptions:
IOException if an error occurs

Definition at line 144 of file CJDBCInputStream.java.

00145   {
00146     bytesRead++;
00147     return input.readBoolean();
00148   }

int org.objectweb.cjdbc.common.stream.CJDBCInputStream.readInt  )  throws IOException
 

See also:
java.io.ObjectInputStream#readInt()
Returns:
an int value
Exceptions:
IOException if an error occurs

Definition at line 155 of file CJDBCInputStream.java.

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

00156   {
00157     bytesRead += 4;
00158     return input.readInt();
00159   }

long org.objectweb.cjdbc.common.stream.CJDBCInputStream.readLong  )  throws IOException
 

See also:
java.io.ObjectInputStream#readLong()
Returns:
a long value
Exceptions:
IOException if an error occurs

Definition at line 166 of file CJDBCInputStream.java.

00167   {
00168     bytesRead += 8;
00169     return input.readLong();
00170   }

Object org.objectweb.cjdbc.common.stream.CJDBCInputStream.readObject  )  throws ClassNotFoundException, IOException, OptionalDataException
 

Returns:
the Object read from the stream
Exceptions:
ClassNotFoundException if an error occurs
IOException if an error occurs
OptionalDataException if an error occurs
See also:
java.io.ObjectInputStream#readObject()

Definition at line 91 of file CJDBCInputStream.java.

Referenced by org.objectweb.cjdbc.driver.Driver.connect(), org.objectweb.cjdbc.driver.Connection.getControllerVersionNumber(), org.objectweb.cjdbc.driver.Connection.getPrimaryKeys(), org.objectweb.cjdbc.driver.Connection.getStaticMetadata(), and org.objectweb.cjdbc.driver.Connection.getTables().

00093   {
00094     if (useCompression)
00095     {
00096       int len = input.readInt();
00097       byte[] read = new byte[len];
00098       input.readFully(read);
00099 
00100       bytesRead += len + 4;
00101       // we read an integer in the pipe for the size of the array.
00102       return CJDBCStream.decompressObject(read);
00103     }
00104     else
00105     {
00106       int objectType = input.readInt();
00107       switch (objectType)
00108       {
00109         case CJDBCStream.OBJECT :
00110           // Use the unshared version to prevent the stream to keep references
00111           // on objects. This prevents objects sent through the channel from
00112           // being garbage collected and results in memory leaks.
00113           return input.readUnshared();
00114         case CJDBCStream.NULL :
00115           return null;
00116         case CJDBCStream.STRING_OBJECT :
00117           return input.readUTF();
00118         case CJDBCStream.INTEGER_OBJECT :
00119           return new Integer(input.readInt());
00120         case CJDBCStream.LONG_OBJECT :
00121           return new Long(input.readLong());
00122         case CJDBCStream.BOOLEAN_OBJECT :
00123           return input.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
00124         default :
00125           throw new RuntimeException("Unhandled type on stream: " + objectType);
00126       }
00127     }
00128   }

String org.objectweb.cjdbc.common.stream.CJDBCInputStream.readUTF  )  throws IOException
 

See also:
java.io.ObjectInputStream#readUTF()
Returns:
a String in UTF format
Exceptions:
IOException if an error occurs

Definition at line 177 of file CJDBCInputStream.java.

Referenced by org.objectweb.cjdbc.driver.Driver.connect(), and org.objectweb.cjdbc.controller.core.ControllerWorkerThread.run().

00178   {
00179     Object read;
00180     try
00181     {
00182       read = this.readObject();
00183     }
00184     catch (Exception e)
00185     {
00186       throw new IOException(e.getMessage());
00187     }
00188     if (read == null)
00189       return null;
00190     bytesRead += ((String) read).length();
00191     return (String) read;
00192   }


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