Package com.aoindustries.io.buffer
Class LoggingWriter
- java.lang.Object
-
- java.io.Writer
-
- com.aoindustries.io.buffer.BufferWriter
-
- com.aoindustries.io.buffer.LoggingWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class LoggingWriter extends BufferWriter
Logs all write calls in a way that can be put into Java source code. This is used to capture real-world scenarios for unit testing. This class is not thread safe.- Author:
- AO Industries, Inc.
-
-
Constructor Summary
Constructors Constructor Description LoggingWriter(BufferWriter wrapped, Writer log)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LoggingWriterappend(char c)LoggingWriterappend(CharSequence csq)LoggingWriterappend(CharSequence csq, int start, int end)voidclose()voidflush()longgetId()longgetLength()Gets the number of characters in this buffer.LoggingResultgetResult()Gets the result from this buffer.StringtoString()Gets a short message (like type and length).voidwrite(char[] cbuf)voidwrite(char[] cbuf, int off, int len)voidwrite(int c)voidwrite(String str)voidwrite(String str, int off, int len)
-
-
-
Constructor Detail
-
LoggingWriter
public LoggingWriter(BufferWriter wrapped, Writer log) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getId
public long getId()
-
write
public void write(int c) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(char[] cbuf) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(char[] cbuf, int off, int len) throws IOException- Specified by:
writein classWriter- Throws:
IOException
-
write
public void write(String str) throws IOException
- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(String str, int off, int len) throws IOException
- Overrides:
writein classWriter- Throws:
IOException
-
append
public LoggingWriter append(CharSequence csq) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
append
public LoggingWriter append(CharSequence csq, int start, int end) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
append
public LoggingWriter append(char c) throws IOException
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
getLength
public long getLength() throws IOExceptionDescription copied from class:BufferWriterGets the number of characters in this buffer. Once closed, this length will not be modified.- Specified by:
getLengthin classBufferWriter- Throws:
IOException
-
toString
public String toString()
Description copied from class:BufferWriterGets a short message (like type and length).- Specified by:
toStringin classBufferWriter- See Also:
To get access to the buffered content.
-
getResult
public LoggingResult getResult() throws IllegalStateException, IOException
Description copied from class:BufferWriterGets the result from this buffer. The buffer must be closed.- Specified by:
getResultin classBufferWriter- Throws:
IllegalStateException- if not closedIOException
-
-