SK.gnome.dwarf.mail.utils
Class LoggedReader

java.lang.Object
  extended bySK.gnome.dwarf.mail.utils.LoggedReader

public class LoggedReader
extends java.lang.Object

Provides line reader with a built-in logging capability.

This class may be used to read lines from the underlying input stream while automatically logging them for debugging purposes. It is suitable for handling text-based network protocols, such as SMTP or POP3, for example.


Constructor Summary
LoggedReader(SK.gnome.dwarf.log.Logger logger, java.lang.String facility, java.lang.String prefix, java.io.InputStream stream, int limit)
          Creates a new LoggedReader.
 
Method Summary
 java.io.InputStream getStream()
          Returns the underlying input stream.
 int read()
          Reads a single character.
 java.lang.String readLine()
          Reads a single line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggedReader

public LoggedReader(SK.gnome.dwarf.log.Logger logger,
                    java.lang.String facility,
                    java.lang.String prefix,
                    java.io.InputStream stream,
                    int limit)
             throws java.io.UnsupportedEncodingException
Creates a new LoggedReader.

The reader will read from stream and log each read line via the logger. The log messages have the LOG_TRACE logging level and the logging facility associated with them. Each logged line is prepended with the prefix string. The reader will refuse to read lines larger than the limit argument.

The log messages will be generated only if it is enabled for the given facility via the SK.gnome.dwar.log.Log.setTrace(String) method.

This reader converts the input stream octets using the ISO 8859-1 character encoding.

Parameters:
logger - the logging service
facility - the logging facility
prefix - the prefix identifying the log messages
stream - the input stream to read from
limit - the maximum line length limit
Throws:
java.io.UnsupportedEncodingException - if the required encoding is not known
Method Detail

read

public int read()
         throws java.io.IOException
Reads a single character.

Returns:
the character read
Throws:
java.io.IOException - if an error occurs

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads a single line.

Returns:
the line read
Throws:
java.io.IOException - if an error occurs

getStream

public java.io.InputStream getStream()
Returns the underlying input stream.

The stream may be used to directly read byte octets when line-oriented input or logging function is not desired.

Returns:
the input stream


Copyright (c) 2004-2005, Gnome Ltd. All rights reserved.