org.ssonet.io
Class IOFilterStream

java.lang.Object
  |
  +--org.ssonet.io.IOFilterStream
All Implemented Interfaces:
IOStream, java.lang.Runnable
Direct Known Subclasses:
NullFilterStream

public abstract class IOFilterStream
extends java.lang.Object
implements IOStream, java.lang.Runnable

Base for IOStreams wich need to exchange messages asynchronous.

Version:
$Id: IOFilterStream.java,v 1.4 2003/10/28 11:49:29 tk4 Exp $
Author:
Thomas Kriegelstein

Field Summary
static boolean debug
           
protected  org.ssonet.io.IOStream ios
           
protected  java.util.LinkedList list
           
protected  boolean protocolMode
           
protected  java.io.IOException readException
           
protected  java.lang.Thread runner
           
protected  java.io.IOException writeException
           
 
Constructor Summary
IOFilterStream()
           
 
Method Summary
 int available()
           
 void closeIn()
          Closes the Inputstream.
 void closeOut()
          Closes the outputStream.
protected abstract  void handleMessage(byte b, org.ssonet.io.IOStream ios)
          Subclasses implement this to handle their messages.
 int read(byte[] buffer)
          Reads from the IOStream.
 void run()
          Main loop.
 void setIOStream(org.ssonet.io.IOStream ios)
          Sets the IOStream and starts handling Messages.
 void write(byte[] buffer)
          Writes to the IOStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

runner

protected java.lang.Thread runner

ios

protected org.ssonet.io.IOStream ios

readException

protected java.io.IOException readException

writeException

protected java.io.IOException writeException

protocolMode

protected boolean protocolMode

list

protected java.util.LinkedList list

debug

public static boolean debug
Constructor Detail

IOFilterStream

public IOFilterStream()
Method Detail

handleMessage

protected abstract void handleMessage(byte b,
                                      org.ssonet.io.IOStream ios)
                               throws java.io.IOException
Subclasses implement this to handle their messages. b==0 means data and never reaches this method, only protocol messages are handled here. Subclasses have to take care of length encoding.

Parameters:
b - message code
ios - IOStream to read from and write to
java.io.IOException

setIOStream

public void setIOStream(org.ssonet.io.IOStream ios)
Sets the IOStream and starts handling Messages.


run

public void run()
Main loop.

Specified by:
run in interface java.lang.Runnable

read

public int read(byte[] buffer)
         throws java.io.IOException
Reads from the IOStream. May block.

Specified by:
read in interface IOStream
Parameters:
buffer - the buffer, which shall be filled with bytes read
Returns:
the number of bytes read, or -1 if the End Of Stream is reached.
Throws:
java.io.IOException - if an error occures while reading from the stream
See Also:
IOStream.read(byte[])

write

public void write(byte[] buffer)
           throws java.io.IOException
Writes to the IOStream. May block.

Specified by:
write in interface IOStream
Parameters:
buffer - the buffer holding the bytes to write to the stream
Throws:
java.io.IOException - if an error occures while writing to the stream
See Also:
IOStream.write(byte[])

closeIn

public void closeIn()
             throws java.io.IOException
Description copied from interface: IOStream
Closes the Inputstream.

Specified by:
closeIn in interface IOStream
java.io.IOException

closeOut

public void closeOut()
              throws java.io.IOException
Description copied from interface: IOStream
Closes the outputStream.

Specified by:
closeOut in interface IOStream
java.io.IOException

available

public int available()
              throws java.io.IOException
Specified by:
available in interface IOStream
Returns:
the number of bytes currently available from the inputstream without blocking.
java.io.IOException


Copyright © 2003 DRIM Team. All Rights Reserved.