org.indy.io
Class AbstractIOHandler

java.lang.Object
  |
  +--org.indy.io.AbstractIOHandler
All Implemented Interfaces:
IOHandler
Direct Known Subclasses:
IOHandlerSocket

public abstract class AbstractIOHandler
extends java.lang.Object
implements IOHandler

A skeleton implementation of IOHandler. This provides no-ops for the non base IO methods of IOHandler, property accessors and mutators and listener management for concrete subclasses.

Author:
Owen Green

Field Summary
protected  javax.swing.event.EventListenerList listenerList
          Holds a list of interested listeners
protected  int maximumLineLength
          The maximum line length to be used for read line operations Initially set to the Indy default value
protected  int readTimeOut
          The timeout to be used for read operations on this IOHandler.
 
Constructor Summary
AbstractIOHandler()
           
 
Method Summary
 void addIOHandlerListener(IOHandlerListener l)
          Add a IOHandlerListener to receive events from this IOHandler
 void afterAccept()
          Provides a no-op implementation of AfterAccept()
 void close()
          Provides a a no-op implementation of close()
 void connectClient(java.util.Map parameters, int timeout)
          A no-op implementation of IOHandler.connectClient(Map,int).
protected  void doOnConnect()
          Fires an onConnect event to all registered listeners
protected  void doOnDisconnect()
          Fires an onDisconnect event to all registered listeners
protected  void doStatus(Status s, java.lang.Object[] args)
          Fires an OnStatus event to all registered listeners
 int getMaximumLineLength()
          Gets the maximum line length to be used for read line operations
 int getReadTimeOut()
          Returns the current timeout for read operations on this IOHandler
 void open()
          Provides a no-op imlpementaion of open()
 int read(byte[] b)
          Reads a sequence of bytes from the socket, using the readTimeOut property, if set, or the Indy default timeout otherwise.
 int read(byte[] b, int len)
          Reads a sequence of bytes from the socket, using the readTimeOut property, if set, or the Indy default timeout otherwise.
 int read(byte[] b, int off, int len)
          Reads a sequence of bytes from the socket, using the readTimeOut property, if set, or the Indy default timeout otherwise.
 java.lang.String readLine()
          Reads a line of text from the socket using the maximumLineLength and readTimeOut properties.
 java.lang.String readLine(int timeout, int maxLineLength)
          Reads a line of data from the socket
 void removeIOHandlerListener(IOHandlerListener l)
          Remove a IOHandlerListener from the listener list.
 void setMaximumLineLength(int newMaximumLineLength)
          Sets the maximum line length to be acceped by this IOHandler
 void setReadTimeOut(int newTimeout)
          Set the timeout for read operations on this IOHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.indy.io.IOHandler
available, clearBuffer, currentReadBuffer, flush, isConnected, read, read, read, readLine, write, write, write
 

Field Detail

readTimeOut

protected int readTimeOut
The timeout to be used for read operations on this IOHandler. Initially set to the Indy default value
See Also:
IndyUtilities.getDefaultTimeout()

maximumLineLength

protected int maximumLineLength
The maximum line length to be used for read line operations Initially set to the Indy default value
See Also:
IndyUtilities.getDefaultMaxLineLength()

listenerList

protected javax.swing.event.EventListenerList listenerList
Holds a list of interested listeners
Constructor Detail

AbstractIOHandler

public AbstractIOHandler()
Method Detail

afterAccept

public void afterAccept()
Provides a no-op implementation of AfterAccept()
Specified by:
afterAccept in interface IOHandler
See Also:
IOHandler.afterAccept()

close

public void close()
Provides a a no-op implementation of close()
Specified by:
close in interface IOHandler
See Also:
IOHandler.close()

connectClient

public void connectClient(java.util.Map parameters,
                          int timeout)
                   throws IndyIOException
A no-op implementation of IOHandler.connectClient(Map,int).
Specified by:
connectClient in interface IOHandler
Parameters:
parameters - The parameters to use for connection
timeout - The timeout to use for connection
Throws:
IndyIOException - If an IO error ocurrs
See Also:
IOHandler.connectClient(Map,int)

open

public void open()
Provides a no-op imlpementaion of open()
Specified by:
open in interface IOHandler
See Also:
IOHandler.open()

read

public int read(byte[] b)
         throws IndyIOException
Reads a sequence of bytes from the socket, using the readTimeOut property, if set, or the Indy default timeout otherwise.
Specified by:
read in interface IOHandler
Parameters:
b - An array of bytes to read the data into
Returns:
The number of bytes actually read
Throws:
IndyIOException - If an IO error occurs.
PeerDisconnectedException - if the remote machine has disconnected
ReadTimedOutException - if the read opertaion timed out
NotConnectedException - if the socket is not connected
See Also:
IOHandler.read(byte[],int,int,int)

read

public int read(byte[] b,
                int len)
         throws IndyIOException,
                ReadTimedOutException
Reads a sequence of bytes from the socket, using the readTimeOut property, if set, or the Indy default timeout otherwise.
Specified by:
read in interface IOHandler
Parameters:
b - An array of bytes to read the data into
len - The amount of data to read
Returns:
The number of bytes actually read
Throws:
IndyIOException - If an IO error occurs.
PeerDisconnectedException - if the remote machine has disconnected
ReadTimedOutException - if the read opertaion timed out
NotConnectedException - if the socket is not connected
See Also:
IOHandler.read(byte[],int,int,int)

read

public int read(byte[] b,
                int off,
                int len)
         throws IndyIOException,
                ReadTimedOutException
Reads a sequence of bytes from the socket, using the readTimeOut property, if set, or the Indy default timeout otherwise.
Specified by:
read in interface IOHandler
Parameters:
b - An array of bytes to read the data into
off - The offset at which to start writing to b
len - The amount of data to read
Returns:
The number of bytes actually read
Throws:
IndyIOException - If an IO error occurs.
PeerDisconnectedException - if the remote machine has disconnected
ReadTimedOutException - if the read opertaion timed out
NotConnectedException - if the socket is not connected
See Also:
IOHandler.read(byte[],int,int,int)

readLine

public java.lang.String readLine()
                          throws IndyIOException
Reads a line of text from the socket using the maximumLineLength and readTimeOut properties.
Specified by:
readLine in interface IOHandler
Returns:
A line of data from the socket
Throws:
IndyIOException - if an IO error occurs
PeerDisconnectedException - if the remote machine disconnects normally
ReadTimedOutException - if the operation times out
MaxLineLengthExceededException - if the maximum line length is exceeded before a line break is found
See Also:
getReadTimeOut(), setReadTimeOut(int,int), getMaximumLineLength(), setMaximumLineLength(int)

readLine

public java.lang.String readLine(int timeout,
                                 int maxLineLength)
                          throws IndyIOException,
                                 PeerDisconnectedException,
                                 ReadTimedOutException,
                                 MaxLineLengthExceededException
Reads a line of data from the socket
Specified by:
readLine in interface IOHandler
Parameters:
timeout - The timeout to use for this operation
maxLineLength - The maxiumum line length to accept
Returns:
A line of data from the socket
Throws:
IndyIOException - if an IO error occurs
PeerDisconnectedException - if the remote machine disconnects normally
ReadTimedOutException - if the operation times out
MaxLineLengthExceededException - if the maximum line length is exceeded before a line break is found
See Also:
IOHandler.readLine(int,int,String)

getReadTimeOut

public int getReadTimeOut()
                   throws IndyIOException
Returns the current timeout for read operations on this IOHandler
Specified by:
getReadTimeOut in interface IOHandler
Returns:
The read timeout for this

setReadTimeOut

public void setReadTimeOut(int newTimeout)
                    throws IndyIOException
Set the timeout for read operations on this IOHandler
Specified by:
setReadTimeOut in interface IOHandler
Parameters:
newTimeout - The new timeout value to use
Throws:
java.lang.IllegalArgumentException - If the newTimeout is < 0

getMaximumLineLength

public int getMaximumLineLength()
Gets the maximum line length to be used for read line operations
Specified by:
getMaximumLineLength in interface IOHandler
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
Specified by:
setMaximumLineLength in interface 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
Specified by:
addIOHandlerListener in interface IOHandler
Parameters:
l - The IOHandlerListener
See Also:
removeIOHandlerListener(IOHandlerListener)

removeIOHandlerListener

public void removeIOHandlerListener(IOHandlerListener l)
Remove a IOHandlerListener from the listener list.
Specified by:
removeIOHandlerListener in interface IOHandler
Parameters:
l - The IOHandlerListener
See Also:
addIOHandlerListener(IOHandlerListener)

doOnDisconnect

protected void doOnDisconnect()
Fires an onDisconnect event to all registered listeners

doOnConnect

protected void doOnConnect()
Fires an onConnect event to all registered listeners

doStatus

protected void doStatus(Status s,
                        java.lang.Object[] args)
Fires an OnStatus event to all registered listeners


Copyright © 2002-2002 IndyJ. All Rights Reserved.