|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Writer
java.io.FilterWriter
com.gc.iotools.stream.writer.inspection.WriterDumper<T>
public class WriterDumper<T extends Writer>
This class act as a filter, simply forwarding the calls to the
Writer passed in the constructor. Doing so it also keeps track
of the data written to the underlying stream. This is useful for logging
purposes.
WARNING: data written to this Writer are kept in
memory, so this class should be used when the maximum size of the character
data is known in advance, and it is "small" compared to memory size. In
case this is not possible this class should be instantiated limiting the
data that can be dumped #WriterDumper(sink, maxDumpSize).
Usage:
Reader source=... //some data to be read.
Writer destination1= new StringWriter();
WriterDumper dumper = new WriterDumper(destination1);
org.apache.commons.io.IOUtils.copy(source, dumper);
dumper.close();
String data= dumper.getData();
//at this point "data" and destination1.toString() contains the same string.
| Field Summary | |
|---|---|
static long |
INDEFINITE_SIZE
Constant INDEFINITE_SIZE=-1L |
| Fields inherited from class java.io.FilterWriter |
|---|
out |
| Fields inherited from class java.io.Writer |
|---|
lock |
| Constructor Summary | |
|---|---|
WriterDumper(T sink)
Constructor for WriterDumper. |
|
WriterDumper(T sink,
long maxDumpSize)
Constructor for WriterDumper. |
|
| Method Summary | |
|---|---|
void |
close()
|
void |
enableDump(boolean enable)
Allow to switch off the copy to the internal character buffer. |
String |
getData()
Returns the data that was written until now to the internal character buffer. |
T |
getWrappedStream()
Returns the wrapped (original) Writer passed in the
constructor. |
void |
write(char[] b,
int off,
int len)
|
void |
write(int b)
|
| Methods inherited from class java.io.FilterWriter |
|---|
flush, write |
| Methods inherited from class java.io.Writer |
|---|
append, append, append, write, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long INDEFINITE_SIZE
INDEFINITE_SIZE=-1L
| Constructor Detail |
|---|
public WriterDumper(T sink)
Constructor for WriterDumper. Completely record the stream for an indefinite size into memory.
sink - the underlying stream that must be dumped.
public WriterDumper(T sink,
long maxDumpSize)
Constructor for WriterDumper.
sink - the underlying stream that must be dumped.maxDumpSize - the maximum size of the dump.| Method Detail |
|---|
public void close()
throws IOException
close in interface Closeableclose in class FilterWriterIOExceptionpublic void enableDump(boolean enable)
Allow to switch off the copy to the internal character buffer. The copy is enabled by default.
enable - a boolean.public final String getData()
Returns the data that was written until now to the internal character
buffer. This corresponds to the data written to the internal
Writer passed in the constructor if
maxDumpSize was not reach and data dump was not disabled
(calling enableDump(false)).
public final T getWrappedStream()
Returns the wrapped (original) Writer passed in the
constructor.
Writer passed in the constructor
public void write(char[] b,
int off,
int len)
throws IOException
write in class FilterWriterIOException
public void write(int b)
throws IOException
write in class FilterWriterIOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||