org.indy.io
Interface IOHandler

All Known Implementing Classes:
AbstractIOHandler

public interface IOHandler

An IOHandler wraps an underlying communications mechanism and provides access to its IO facilities and some convinivence methods. It is assumed that concrete implementations will implement some sort of buffering mechanism, at least for read operations to incraese efficiency. Implementors may prefer instead to sub-class AbstractIOHandler which provides a number of convinience no-ops and skeletal method implementations.


Method Summary
 void addIOHandlerListener(IOHandlerListener l)
          Add a IOHandlerListener to receive events from this IOHandler
 void afterAccept()
          Invoked after a server-side accept() operation
 int available()
          Gets the number of bytes that can be read from this IOHandler without blocking
 void clearBuffer()
          Clears the input buffer of this IOHandler
 void close()
          Closes this IOHandler Should generate an IOHandlerListener.onDisconnect(IOHandler) event.
 void connectClient(java.util.Map parameters, int timeout)
          Connects this IOHandler to a remote implementation.
 byte[] currentReadBuffer()
          Retreives the contents of the IOHandler's input that can be read without blocking.
 void flush()
          Flushes the output of this IOHandler.
 int getMaximumLineLength()
          Gets the maximum line length to be used for read line operations
 int getReadTimeOut()
          Get the timeout to use for read operations on this IOHandler
 boolean isConnected()
          Determines whether or not this IOHandler is connected.
 void open()
          I'm not actually sure what this is here for.
 int read()
          Reads a single byte of data from this IOHandler's input
 int read(byte[] b)
          Reads some bytes from this IOHandler
 int read(byte[] b, int len)
          Reads up to len bytes from this IOHandler
 int read(byte[] b, int off, int len)
          Reads up to len bytes from this IOHandler into b starting at off
 int read(byte[] b, int off, int len, int timeout)
          Reads up to len bytes from this IOHandler into b starting at off waiting for up to timeout for data.
 int read(int timeout)
          Reads a single byte of data from this IOHandler's input
 java.lang.String readLine()
          Reads a line of text from the IOHandler's input using the properties for read timeout and maxiumum linelength
 java.lang.String readLine(int timeout, int maxLine)
          Reads a line of text from the IOHandler's input.
 java.lang.String readLine(int timeout, int maxLine, java.lang.String encoding)
          Reads a line of text from the IOHandler using If encoding is null the default character encoding for the platform will be used.
 void removeIOHandlerListener(IOHandlerListener l)
          Remove a IOHandlerListener from this IOHandler's listener listl
 void setMaximumLineLength(int newMaximumLineLength)
          Sets the maximum line length to be acceped by this IOHandler
 void setReadTimeOut(int newTimeout)
          Sets the timeout to use for read operations on this IOHandler
 void write(byte[] b)
          Writes some bytes to this IOHandler's output.
 void write(byte[] b, int off, int len)
          Writes some bytes to this IOHandler's output.
 void write(int b)
          Writes a single byte to this IOHandler's output
 

Method Detail

isConnected

public boolean isConnected()
Determines whether or not this IOHandler is connected.
Returns:
true if connected false otherwise

afterAccept

public void afterAccept()
Invoked after a server-side accept() operation

close

public void close()
Closes this IOHandler Should generate an IOHandlerListener.onDisconnect(IOHandler) event.

read

public int read()
         throws IndyIOException
Reads a single byte of data from this IOHandler's input
Returns:
A byte of data from this IOHandler
Throws:
IndyIOException - if an IOError occurs

read

public int read(int timeout)
         throws IndyIOException
Reads a single byte of data from this IOHandler's input
Parameters:
timeout - The timeout to use for this read operation
Returns:
A byte of data from this IOHandler
Throws:
IndyIOException - if an IOError occurs

clearBuffer

public void clearBuffer()
Clears the input buffer of this IOHandler

currentReadBuffer

public byte[] currentReadBuffer()
                         throws IndyIOException
Retreives the contents of the IOHandler's input that can be read without blocking.
Returns:
The data available without blocking
Throws:
IndyIOException - If an IOError occurs.

readLine

public java.lang.String readLine()
                          throws IndyIOException
Reads a line of text from the IOHandler's input using the properties for read timeout and maxiumum linelength
Returns:
A line of text from the IOHandler
Throws:
IndyIOException - if an IO error occurs
See Also:
getReadTimeOut(), setReadTimeOut(int,int), getMaximumLineLength(), setMaximumLineLength(int)

readLine

public java.lang.String readLine(int timeout,
                                 int maxLine)
                          throws IndyIOException
Reads a line of text from the IOHandler's input.
Parameters:
timeout - the timeout to use for this operation
maxLine - the maxium line length to accepy
Returns:
A line of text from the IOHandler
Throws:
IndyIOException - if an IO error occurs.

readLine

public java.lang.String readLine(int timeout,
                                 int maxLine,
                                 java.lang.String encoding)
                          throws IndyIOException
Reads a line of text from the IOHandler using If encoding is null the default character encoding for the platform will be used.
Parameters:
timeout - the timeout to use for this operation
maxLine - the maximum line length to accept
encoding - the character encoding to use.
Returns:
A line of text
Throws:
IndyIOException -  

connectClient

public void connectClient(java.util.Map parameters,
                          int timeout)
                   throws IndyIOException,
                          ConnectException,
                          ConnectTimedOutException
Connects this IOHandler to a remote implementation. The contents of map depend on the implementation in question, so a socket may have values for host, port etc. Concrete implementations may also find it useful to provide a connect method with implementation specific parameters. Concrete implementations should consider allowing map populations that are all Strings, so as to allow easy storage of connection parameters using java.util.Properties Successful connection should generate an IOHandlerListener.onConnect(IOHandler) event.
Parameters:
parameters - A java.util.Map containing implementation specific connection parameters.
timeout - The timeout to use for connecting
Throws:
IndyIOException - If an IO error occurs
ConnectException - If a connection error occurs
ConnectTimedOutException - If connection times out.

open

public void open()
I'm not actually sure what this is here for. More news as it comes, kids.

flush

public void flush()
           throws IndyIOException
Flushes the output of this IOHandler.
Throws:
IndyIOException - if an IO error occurs

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IndyIOException
Writes some bytes to this IOHandler's output.
Parameters:
b - The bytes to write
off - The offset at which to start writing
len - The number of bytes to write
Throws:
IndyIOException - if an IO error occurs.

write

public void write(byte[] b)
           throws IndyIOException
Writes some bytes to this IOHandler's output.
Parameters:
b - The bytes to write
Throws:
IndyIOException - if an IO error occurs.

write

public void write(int b)
           throws IndyIOException
Writes a single byte to this IOHandler's output
Parameters:
b - The byte to be written
Throws:
IndyIOException - if an IO error occurs.

read

public int read(byte[] b)
         throws IndyIOException
Reads some bytes from this IOHandler
Parameters:
b - A buffer to read the bytes into
Returns:
The number of bytes read
Throws:
IndyIOException - if an IO error occurs

read

public int read(byte[] b,
                int len)
         throws IndyIOException
Reads up to len bytes from this IOHandler
Parameters:
b - The buffer to read the bytes into
len - The number opf bytes to be read
Returns:
The actual number of bytes read
Throws:
IndyIOException - if an IO error occurs.

read

public int read(byte[] b,
                int off,
                int len)
         throws IndyIOException
Reads up to len bytes from this IOHandler into b starting at off
Parameters:
b - The buffer to read into
off - The buffer offset to start filling at
len - The number of bytes to read
Returns:
The actual number of bytes read
Throws:
IndyIOException - if an IO error occurs.

read

public int read(byte[] b,
                int off,
                int len,
                int timeout)
         throws IndyIOException
Reads up to len bytes from this IOHandler into b starting at off waiting for up to timeout for data.
Parameters:
b - The buffer to read into
off - The buffer offset to start filling at
len - The number of bytes to read
timeout - The timeout to use for this operation
Returns:
The actual number of bytes read
Throws:
IndyIOException - if an IO error occurs.

available

public int available()
              throws IndyIOException
Gets the number of bytes that can be read from this IOHandler without blocking
Returns:
the number of bytes that can be read without blocking
Throws:
IndyIOException - if an IO error occurs

getReadTimeOut

public int getReadTimeOut()
                   throws IndyIOException
Get the timeout to use for read operations on this IOHandler
Returns:
the time out to use for read operations by default
Throws:
IndyIOException - If the IOHandler is connected and an IOError occurs

setReadTimeOut

public void setReadTimeOut(int newTimeout)
                    throws IndyIOException
Sets the timeout to use for read operations on this IOHandler
Parameters:
newTimeout - The new timeout to use
Throws:
IndyIOException - If the IOHandler is connected and an IOError occurs

getMaximumLineLength

public int getMaximumLineLength()
Gets the maximum line length to be used for read line operations
Returns:
The maximum line length accepted by this IOHandler

setMaximumLineLength

public void setMaximumLineLength(int newMaximumLineLength)
Sets the maximum line length to be acceped by this IOHandler
Parameters:
newMaximumLineLength - The new maximum line length
Throws:
java.lang.IllegalArgumentException - if newMaximumLineLength is < 0

addIOHandlerListener

public void addIOHandlerListener(IOHandlerListener l)
Add a IOHandlerListener to receive events from this IOHandler
Parameters:
l - The IOHandlerListener

removeIOHandlerListener

public void removeIOHandlerListener(IOHandlerListener l)
Remove a IOHandlerListener from this IOHandler's listener listl
Parameters:
l - The IOHandlerListener


Copyright © 2002-2002 IndyJ. All Rights Reserved.