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. -
Method Summary
Modifier and TypeMethodDescriptionintlength()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.
-
-
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:SimpleWriterWrite a newline according to the characteristics of the target platform.- Specified by:
newLinein 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 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.- Throws:
IOException- if an error happens when writing.
-
write
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.- Throws:
IOException- if an error happens when writing.
-
write
Description copied from interface:SimpleWriterWrite a character.- Specified by:
writein interfaceSimpleWriter- Parameters:
c- the character.- Throws:
IOException- if an error happens when writing.
-
write
Description copied from interface:SimpleWriterWrite an integer.- Specified by:
writein interfaceSimpleWriter- Parameters:
num- the integer number.- Throws:
IOException- if an error happens when writing.
-