com.marringtons.io
Class RecordingBufferedReader

java.lang.Object
  extended byjava.io.Reader
      extended byjava.io.BufferedReader
          extended bycom.marringtons.io.RecordingBufferedReader

public class RecordingBufferedReader
extends BufferedReader

Use this class instead of BufferedReader to record traffic through the reader. It is a programmatic equivalent of the Unix tee command. It only records once asked to do so. When on, the reader behaves as normal passing information as expected, but all the information passed is also sent to an independant Writer object.

Author:
Paul Marrington

Constructor Summary
RecordingBufferedReader(Reader in)
          Create a buffered reader that can also record the traffic on demand.
 
Method Summary
 int read()
          Overridden read method to record if recording turned on.
 int read(char[] buffer, int offset, int length)
          Overridden read method to record if recording turned on.
 String readLine()
          Overridden read method to record if recording turned on.
 void record(Writer writer)
          Turn recording on.
 void stop()
          Close and turn off recording.
 
Methods inherited from class java.io.BufferedReader
close, mark, markSupported, ready, reset, skip
 
Methods inherited from class java.io.Reader
read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecordingBufferedReader

public RecordingBufferedReader(Reader in)
Create a buffered reader that can also record the traffic on demand.

Parameters:
in - reader we want to record as it performs
Method Detail

record

public void record(Writer writer)
Turn recording on.

Parameters:
writer - where to write recording as it occurs.

stop

public void stop()
          throws IOException
Close and turn off recording.

Throws:
IOException

read

public int read()
         throws IOException
Overridden read method to record if recording turned on.

Returns:
character read (-1 for EOF)
Throws:
IOException
See Also:
Reader.read()

read

public int read(char[] buffer,
                int offset,
                int length)
         throws IOException
Overridden read method to record if recording turned on.

Parameters:
buffer - to read into.
offset - to read into buffer.
length - characters to read.
Returns:
number of characters read (-1 on eof).
Throws:
IOException
See Also:
Reader.read(char[], int, int)

readLine

public String readLine()
                throws IOException
Overridden read method to record if recording turned on.

Returns:
Line read or null if EOF.
Throws:
IOException
See Also:
BufferedReader.readLine()


Copyright © 2005 Paul Marrington http://library.marringtons.com