Package io.sf.carte.util
Class BufferSimpleWriter
java.lang.Object
io.sf.carte.util.BufferSimpleWriter
- All Implemented Interfaces:
SimpleWriter
An implementation of
SimpleWriter backed by a StringBuilder.-
Constructor Summary
ConstructorsConstructorDescriptionInitializes aBufferSimpleWriterwith an initial buffer capacity of 128 characters.BufferSimpleWriter(int initialCapacity) Initializes aBufferSimpleWriterwith an initial buffer capacity ofinitialCapacitycharacters.BufferSimpleWriter(StringBuilder buffer) Initializes aBufferSimpleWriterwith the given buffer. -
Method Summary
Modifier and TypeMethodDescriptionGet theStringBuilderbuffer.intlength()Get the count of the characters in this object.voidnewLine()Write a newline according to the characteristics of the target platform.toString()Return the contents of this buffer as aString.voidunwrite()Remove the last character found in this buffer, if any.voidunwrite(int numChars) Remove the lastnumCharscharacters found in this buffer.voidwrite(char c) Write a character.voidwrite(char[] cbuf, int offset, int len) Write a sequence of characters from an array.voidwrite(int num) Write an integer.voidWrite a character sequence.
-
Constructor Details
-
BufferSimpleWriter
public BufferSimpleWriter()Initializes aBufferSimpleWriterwith an initial buffer capacity of 128 characters. -
BufferSimpleWriter
public BufferSimpleWriter(int initialCapacity) Initializes aBufferSimpleWriterwith an initial buffer capacity ofinitialCapacitycharacters.- Parameters:
initialCapacity- the buffer initial capacity.
-
BufferSimpleWriter
Initializes aBufferSimpleWriterwith the given buffer.- Parameters:
buffer- theStringBuilderbuffer.
-
-
Method Details
-
getBuffer
Get theStringBuilderbuffer.- Returns:
- the buffer.
-
length
public int length()Get the count of the characters in this object.- Returns:
- the count of the characters.
-
newLine
public void newLine()Description copied from interface:SimpleWriterWrite a newline according to the characteristics of the target platform.- Specified by:
newLinein interfaceSimpleWriter
-
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 lastnumCharscharacters found in this buffer.If
numCharsis larger than the length of this buffer, removes all its contents.- Parameters:
numChars- the number of characters to remove.
-
write
Description copied from interface:SimpleWriterWrite a character sequence.- Specified by:
writein interfaceSimpleWriter- Parameters:
s- the CharSequence.
-
write
public void write(char[] cbuf, int offset, int len) Description copied from interface:SimpleWriterWrite a sequence of characters from an array.- Specified by:
writein interfaceSimpleWriter- Parameters:
cbuf- the character array.offset- the offset to start writing.len- the number of characters to write from the array.
-
write
public void write(char c) Description copied from interface:SimpleWriterWrite a character.- Specified by:
writein interfaceSimpleWriter- Parameters:
c- the character.
-
write
public void write(int num) Description copied from interface:SimpleWriterWrite an integer.- Specified by:
writein interfaceSimpleWriter- Parameters:
num- the integer number.
-