Package com.nomagic.magicreport.engine
Class MemoryWriter
java.lang.Object
java.io.Writer
com.nomagic.magicreport.engine.MemoryWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
A character stream that collects its output in a memory.
- Since:
- Apr 30, 2008
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new memory writer using the default initial string-buffer size.MemoryWriter(int initialSize) Create a new memory writer using the specified initial string-buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the stream.voidflush()Flush the stream.Return the string buffer itself.longsize()Return the size of current written data.toString()Return the buffer's current value as a string.voidwrite(char[] cbuf, int off, int len) Write a portion of an array of characters.voidwrite(int c) Write a single character.voidWrite a string.voidWrite a portion of a string.
-
Constructor Details
-
MemoryWriter
public MemoryWriter()Create a new memory writer using the default initial string-buffer size. -
MemoryWriter
public MemoryWriter(int initialSize) Create a new memory writer using the specified initial string-buffer size.- Parameters:
initialSize- The number ofcharvalues that will fit into this buffer before it is automatically expanded- Throws:
IllegalArgumentException- IfinitialSizeis negative
-
-
Method Details
-
write
Write a single character.- Overrides:
writein classWriter- Parameters:
c- character- Throws:
IOException- If an I/O error occurs
-
write
Write a portion of an array of characters.- Specified by:
writein classWriter- Parameters:
cbuf- Array of charactersoff- Offset from which to start writing characterslen- Number of characters to write- Throws:
IOException- If an I/O error occurs
-
write
Write a string. -
write
Write a portion of a string. -
toString
Return the buffer's current value as a string. -
flush
public void flush()Flush the stream. -
close
Close the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- If an I/O error occurs
-
getBuffer
Return the string buffer itself.- Returns:
- StringBuilder holding the current buffer value.
- Throws:
IOException- the stream has been closed
-
size
public long size()Return the size of current written data.- Returns:
- writer size
-