java.lang.Object
io.sf.carte.util.BufferSimpleWriter
- All Implemented Interfaces:
SimpleWriter,Appendable
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 TypeMethodDescriptionappend(CharSequence csq, int start, int end) Get theStringBuilderbuffer.charGet the last character processed.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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.sf.carte.util.SimpleWriter
append, append
-
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.- Specified by:
unwritein interfaceSimpleWriter
-
getLastChar
Get the last character processed.- Specified by:
getLastCharin interfaceSimpleWriter- Returns:
- the last character processed.
- Throws:
IllegalStateException- if no character was processed yet.
-
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.- Specified by:
unwritein interfaceSimpleWriter- 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.
-
append
- Specified by:
appendin interfaceAppendable- Specified by:
appendin interfaceSimpleWriter- Throws:
IOException
-
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.
-