|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Reader
org.rakeshv.io.LoggingReader
public class LoggingReader
A decorator class that logs all the data it reads from the underlying
Reader to a specified Writer.
The following code shows a way of using this class.
import org.rakeshv.io.LoggingReader;
import java.io.BufferedReader;
import java.io.FileReader;
public class test
{
public static void main( String[] args )
{
try
{
String logFile = "/tmp/log.txt";
BufferedReader reader = new BufferedReader(
new LoggingReader( new FileReader( "/tmp/test.java" ),
logFile ) );
String line = "";
while ( ( line = reader.readLine() ) != null )
{
}
reader.close();
}
catch ( Throwable t )
{
t.printStackTrace();
}
}
}
© Copyright 2005, Rakesh Vidyadharan
| Field Summary | |
|---|---|
private boolean |
flush
A flag used to indicate that the writer must be
flushed prior to closing this reader. |
private java.io.Reader |
reader
The Reader from which the data that is to be
logged will be read. |
private java.io.Writer |
writer
The writer to which the contents read from the reader are to be logged. |
| Fields inherited from class java.io.Reader |
|---|
lock |
| Constructor Summary | |
|---|---|
LoggingReader(java.io.Reader reader,
java.io.File file)
Create a new instance of the class that decorates the specified Reader, and the specified file |
|
LoggingReader(java.io.Reader reader,
java.lang.String fileName)
Create a new instance of the class that decorates the specified Reader, and the specified fileName
|
|
LoggingReader(java.io.Reader reader,
java.io.Writer writer)
Create a new instance of the class that decorates the specified Reader, and the specified Writer
|
|
| Method Summary | |
|---|---|
void |
close()
Close the stream. |
void |
flush()
Flushes the writer. |
boolean |
getFlush()
Returns flush. |
java.io.Reader |
getReader()
Returns reader. |
java.io.Writer |
getWriter()
Returns writer. |
void |
mark(int readlimit)
Mark the present position in the stream. |
boolean |
markSupported()
Tell whether this stream supports the mark(int) operation. |
int |
read()
Read a single character. |
int |
read(char[] buffer)
Read characters into an array. |
int |
read(char[] buffer,
int offset,
int length)
Read characters into a portion of an array. |
boolean |
ready()
Tell whether this stream is ready to be read. |
void |
reset()
Reset the stream. |
protected void |
setFlush(boolean flush)
Set flush. |
protected void |
setReader(java.io.Reader reader)
Set reader. |
protected void |
setWriter(java.io.Writer writer)
Set writer. |
long |
skip(long number)
Skip characters. |
| Methods inherited from class java.io.Reader |
|---|
read |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.io.Reader reader
Reader from which the data that is to be
logged will be read.
private java.io.Writer writer
private boolean flush
writer must be
flushed prior to closing this reader.
| Constructor Detail |
|---|
public LoggingReader(java.io.Reader reader,
java.io.Writer writer)
Reader, and the specified Writer
reader - The reader from which data will be read. This
is the reader that will be decorated.writer - The writer to which the data read is to be
logged.
public LoggingReader(java.io.Reader reader,
java.lang.String fileName)
throws java.io.IOException
Reader, and the specified fileName
reader - The reader from which data will be read. This
is the reader that will be decorated.fileName - The fully qualified name of the file to which the
data is to be logged.
java.io.IOException - If the file exists but is a directory rather
than a regular file, does not exist but cannot be created, or
cannot be opened for any other reasonFileUtilities.mkdirs(java.io.File)
public LoggingReader(java.io.Reader reader,
java.io.File file)
throws java.io.IOException
Reader, and the specified file
reader - The reader from which data will be read. This
is the reader that will be decorated.file - The file to which the data is to be logged.
java.io.IOException - If the file exists but is a directory rather
than a regular file, does not exist but cannot be created, or
cannot be opened for any other reasonFileUtilities.mkdirs(java.io.File)| Method Detail |
|---|
public int read()
throws java.io.IOException
read in class java.io.Reader0 to 65535 (0x00-0xffff), or
-1 if the end of the stream has been reached
java.io.IOException - If errors are encountered while reading the
byte of data.
public int read(char[] buffer)
throws java.io.IOException
read in class java.io.Readerbuffer - The buffer into which the characters will be read.
-1
if the end of the stream has been reached
java.io.IOException - If errors are encountered while reading the
data.read( char[], int, int )
public int read(char[] buffer,
int offset,
int length)
throws java.io.IOException
read in class java.io.Readerbuffer - The buffer into which the characters will be read.offset - The start offset in array buffer at
which the characters are written.length - The maximum number of characters to read.
-1
if the end of the stream has been reached
java.io.IOException - If errors are encountered while reading the
data.
public long skip(long number)
throws java.lang.IllegalArgumentException,
java.io.IOException
skip in class java.io.Readernumber - The number of characters to be skipped.
java.lang.IllegalArgumentException - If number is
negative.
java.io.IOException - If errors are encountered while skipping.
public boolean ready()
throws java.io.IOException
ready in class java.io.Readertrue if the next read() is
guaranteed not to block for input, false otherwise.
Note that returning false does not guarantee that
the next read will block.
java.io.IOException - If errors are encountered while interacting
with the input stream.public boolean markSupported()
mark(int) operation.
markSupported in class java.io.Readertrue if and only if this
stream supports the mark operation.
public void mark(int readlimit)
throws java.io.IOException
reset() will attempt to reposition the stream to this
point. Not all character-input streams support the mark(int)
operation.
Note: Logging will remain true to the read sequence.
In other words, marking and resetting the reader will
cause duplicate characters to be written to the writer.
mark in class java.io.Readerreadlimit - Limit on the number of characters that may be
read while still preserving the mark. After reading this many
characters, attempting to reset the stream may fail.
java.io.IOException - If the stream does not support mark()
, or if some other I/O error occurs
public void reset()
throws java.io.IOException
reset()
operation, and some support reset() without
supporting mark().
reset in class java.io.Readerjava.io.IOException - If the stream has not been marked, or if the
mark has been invalidated, or if the stream does not support
reset(), or if some other I/O error occursmark(int)
public void close()
throws java.io.IOException
read(), ready(), mark(int), or reset()
invocations will throw an IOException. Closing a
previously-closed stream, however, has no effect.
Closes the reader that this stream decorates. Also
closes the writer to which the data is logged. If the
flush is true, then the writer is
flushed prior to closing.
close in interface java.io.Closeableclose in class java.io.Readerjava.io.IOException - If errors are encountered while interacting
with the input stream.
public void flush()
throws java.io.IOException
writer. Invoke this method if the
Writer you used to initialise this stream
requires to be flushed prior to a close invocation.
You must invoke this method prior to invoking the
close() method if the Writer needs to
be flushed.
java.io.IOExceptionpublic final java.io.Reader getReader()
reader.
protected final void setReader(java.io.Reader reader)
reader.
reader - The value to set.public final java.io.Writer getWriter()
writer.
protected final void setWriter(java.io.Writer writer)
writer.
writer - The value to set.public final boolean getFlush()
flush.
protected final void setFlush(boolean flush)
flush.
flush - The value to set.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||