com.liviutudor.rmi.io.gzip
Class GzipSocket

java.lang.Object
  extended by java.net.Socket
      extended by com.liviutudor.rmi.io.gzip.GzipSocket

 class GzipSocket
extends Socket

Socket which uses gzip to compress the data sent over the wire.

Author:
Liviu Tudor http://about.me/liviutudor

Field Summary
private  GZIPInputStream inputStream
          Wrapper for the socket input stream.
private  GZIPOutputStream outputStream
          Wrapper for the socket output stream.
 
Constructor Summary
GzipSocket(String host, int port)
          Creates a socket which connects to the given host on the given port.
 
Method Summary
 void close()
           
 InputStream getInputStream()
          Overrides the base class method for returning the input stream for this socket and returns instead the gzip-based wrapper.
 OutputStream getOutputStream()
          Overrides the base class method for returning the output stream for this socket and returns instead the gzip-based wrapper.
 void shutdownInput()
           
 void shutdownOutput()
           
 
Methods inherited from class java.net.Socket
bind, connect, connect, getChannel, getInetAddress, getKeepAlive, getLocalAddress, getLocalPort, getLocalSocketAddress, getOOBInline, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getSoTimeout, getTcpNoDelay, getTrafficClass, isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown, sendUrgentData, setKeepAlive, setOOBInline, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setSoLinger, setSoTimeout, setTcpNoDelay, setTrafficClass, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inputStream

private GZIPInputStream inputStream
Wrapper for the socket input stream.


outputStream

private GZIPOutputStream outputStream
Wrapper for the socket output stream.

Constructor Detail

GzipSocket

public GzipSocket(String host,
                  int port)
           throws UnknownHostException,
                  IOException
Creates a socket which connects to the given host on the given port.

Parameters:
host - Host to connect to
port - Port to connect to
Throws:
UnknownHostException - if host name or IP is wrong
IOException - if I/O errors occur when connecting
Method Detail

close

public void close()
           throws IOException
Overrides:
close in class Socket
Throws:
IOException

getInputStream

public InputStream getInputStream()
                           throws IOException
Overrides the base class method for returning the input stream for this socket and returns instead the gzip-based wrapper. Note that this is a lazy evaluation function. NOTE: The GzipInputStream blocks on creation to read the header so this function actually blocks until data is available over the wire!

Overrides:
getInputStream in class Socket
Returns:
wrapper for the base class input stream
Throws:
IOException - if I/O errors occur
See Also:
inputStream

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Overrides the base class method for returning the output stream for this socket and returns instead the gzip-based wrapper.

Overrides:
getOutputStream in class Socket
Returns:
wrapper for the base class output stream
Throws:
IOException - if I/O errors occur
See Also:
outputStream

shutdownInput

public void shutdownInput()
                   throws IOException
Overrides:
shutdownInput in class Socket
Throws:
IOException

shutdownOutput

public void shutdownOutput()
                    throws IOException
Overrides:
shutdownOutput in class Socket
Throws:
IOException


Liv