java.lang.Object
io.sf.carte.util.BufferSimpleWriter
- All Implemented Interfaces:
SimpleWriter
An implementation of
SimpleWriter
backed by a StringBuilder
.-
Constructor Summary
ConstructorDescriptionInitializes aBufferSimpleWriter
with an initial buffer capacity of 128 characters.BufferSimpleWriter
(int initialCapacity) Initializes aBufferSimpleWriter
with an initial buffer capacity ofinitialCapacity
characters. -
Method Summary
Modifier and TypeMethodDescriptionint
length()
Get the count of the characters in this object.void
newLine()
Write a newline according to the characteristics of the target platform.toString()
Return the contents of this buffer as aString
.void
unwrite()
Remove the last character found in this buffer, if any.void
unwrite
(int numChars) Remove the lastnumChars
characters found in this buffer.void
write
(char c) Write a character.void
write
(char[] cbuf, int offset, int len) Write a sequence of characters from an array.void
write
(int num) Write an integer.void
Write a character sequence.
-
Constructor Details
-
BufferSimpleWriter
public BufferSimpleWriter()Initializes aBufferSimpleWriter
with an initial buffer capacity of 128 characters. -
BufferSimpleWriter
public BufferSimpleWriter(int initialCapacity) Initializes aBufferSimpleWriter
with an initial buffer capacity ofinitialCapacity
characters.- Parameters:
initialCapacity
- the buffer initial capacity.
-
-
Method Details
-
length
public int length()Get the count of the characters in this object.- Returns:
- the count of the characters.
-
newLine
Description copied from interface:SimpleWriter
Write a newline according to the characteristics of the target platform.- Specified by:
newLine
in interfaceSimpleWriter
- Throws:
IOException
- if an error happens when writing.
-
toString
Return the contents of this buffer as aString
. -
unwrite
public void unwrite()Remove the last character found in this buffer, if any. -
unwrite
public void unwrite(int numChars) Remove the lastnumChars
characters found in this buffer.If
numChars
is larger than the length of this buffer, removes all its contents.- Parameters:
numChars
- the number of characters to remove.
-
write
Description copied from interface:SimpleWriter
Write a character sequence.- Specified by:
write
in interfaceSimpleWriter
- Parameters:
s
- the CharSequence.- Throws:
IOException
- if an error happens when writing.
-
write
Description copied from interface:SimpleWriter
Write a sequence of characters from an array.- Specified by:
write
in interfaceSimpleWriter
- Parameters:
cbuf
- the character array.offset
- the offset to start writing.len
- the number of characters to write from the array.- Throws:
IOException
- if an error happens when writing.
-
write
Description copied from interface:SimpleWriter
Write a character.- Specified by:
write
in interfaceSimpleWriter
- Parameters:
c
- the character.- Throws:
IOException
- if an error happens when writing.
-
write
Description copied from interface:SimpleWriter
Write an integer.- Specified by:
write
in interfaceSimpleWriter
- Parameters:
num
- the integer number.- Throws:
IOException
- if an error happens when writing.
-