jpl.mipl.mdms.connection
Class SocketStream

java.lang.Object
  extended by jpl.mipl.mdms.connection.SocketStream

public class SocketStream
extends Object

This is a wrapper class to the java socket class. It addes additional useful methods to simplify sending and receiving of data stream.

Version:
$Id: SocketStream.java,v 1.5 2003/09/09 22:55:01 rap Exp $
Author:
T. Huang

Constructor Summary
SocketStream()
          Default constructor to initialize the socket stream object.
SocketStream(Socket s)
          Constructor to initialize the socket stream object with a Socket object.
 
Method Summary
 void close()
          Closes the socket connection, if it exists.
protected  void finalize()
          Cleanup method execute by the garbage collector.
 DataInputStream getDataInputStream()
          Access method to the internal data input stream object.
 DataOutputStream getDataOutputStream()
          Access method to the internal output data stream object.
 Socket getSocket()
          To return the internal socket object.
 int recv()
          Reads an int from a socket
 int recv(StringBuffer sb)
          Receives a string buffer from the socket.
 int recvNBytes(byte[] b, int offset, int n)
          Receives an array of bytes.
 int send(int val)
          Sends an int through the socket.
 int send(String s)
          Sends a string through the socket.
 int send(StringBuffer sb)
          Sends a String Buffer through the socket.
 int sendNBytes(byte[] b, int offset, int length)
          Sends an array of bytes through the socket.
 void setDataInputStream(InputStream is)
          Sets the internal input data stream object.
 void setDataOutputStream(OutputStream os)
          Sets the internal data output stream.
 void setSocket(Socket s)
          Sets the socket object and initializes the internal I/O stream objects.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketStream

public SocketStream()
Default constructor to initialize the socket stream object.


SocketStream

public SocketStream(Socket s)
             throws IOException
Constructor to initialize the socket stream object with a Socket object.

Parameters:
s - The socket object.
Throws:
IOException - when I/O failure
Method Detail

setSocket

public void setSocket(Socket s)
               throws IOException
Sets the socket object and initializes the internal I/O stream objects.

Parameters:
s - The socket object.
Throws:
IOException - when I/O failure

getSocket

public Socket getSocket()
To return the internal socket object.

Returns:
The internal socket object.

close

public void close()
           throws IOException
Closes the socket connection, if it exists.

Throws:
IOException - when I/O failure

send

public int send(StringBuffer sb)
         throws IOException
Sends a String Buffer through the socket.

Parameters:
sb - The input string buffer.
Returns:
The number of bytes sent.
Throws:
IOException - when I/O failure

send

public int send(String s)
         throws IOException
Sends a string through the socket.

Parameters:
s - The input string to be sent.
Returns:
The number of bytes sent.
Throws:
IOException - when I/O failure

send

public int send(int val)
         throws IOException
Sends an int through the socket.

Parameters:
val - the integer value
Returns:
The value sent
Throws:
IOException - when I/O failure

sendNBytes

public int sendNBytes(byte[] b,
                      int offset,
                      int length)
               throws IOException
Sends an array of bytes through the socket.

Parameters:
b - The input byte array.
offset - The input offset.
length - The length of the byte array.
Returns:
The number of bytes sent.
Throws:
IOException - when I/O failure

recv

public int recv(StringBuffer sb)
         throws IOException
Receives a string buffer from the socket.

Parameters:
sb - The output string buffer.
Returns:
The number of bytes received.
Throws:
IOException - when I/O failure

recv

public int recv()
         throws IOException
Reads an int from a socket

Returns:
the int value
Throws:
IOException - when I/O failure

recvNBytes

public int recvNBytes(byte[] b,
                      int offset,
                      int n)
               throws IOException
Receives an array of bytes.

Parameters:
b - The received byte array.
offset - The returned offset value.
n - The number of bytes received.
Returns:
The number of bytes received.
Throws:
IOException - when I/O failure

setDataOutputStream

public void setDataOutputStream(OutputStream os)
Sets the internal data output stream.

Parameters:
os - The input output stream object.

getDataOutputStream

public DataOutputStream getDataOutputStream()
Access method to the internal output data stream object.

Returns:
The output data stream object.

setDataInputStream

public void setDataInputStream(InputStream is)
Sets the internal input data stream object.

Parameters:
is - The input stream object.

getDataInputStream

public DataInputStream getDataInputStream()
Access method to the internal data input stream object.

Returns:
The data input stream object.

finalize

protected void finalize()
                 throws Throwable
Cleanup method execute by the garbage collector.

Overrides:
finalize in class Object
Throws:
Throwable - when finalizing