Class UStringWriter
java.lang.Object
java.io.Writer
cl.netswitch.lib.util.UStringWriter
- All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
A character stream that collects its output in an unsynchronized string
builder, which can then be used to construct a string.
Closing a UStringWriter has no effect. The methods in this class can
be called after the stream has been closed without generating an
IOException.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new string writer using the default initial string builder size.UStringWriter(int initialSize) Create a new string writer using the specified initial string builder size. -
Method Summary
Modifier and TypeMethodDescriptionappend(char ch) Appends the specified character to this writer.append(CharSequence csq) Appends the specified character sequence to this writer.append(CharSequence csq, int start, int end) Appends a subsequence of the specified character sequence to this writer.voidclose()Closes this writer.voidflush()Flushes the stream.Returns the buffer holding the current contents of this writer.toString()Returns the current contents of the buffer as a string.voidwrite(char[] chars, int offset, int length) Writes a portion of an array of characters.voidwrite(int ch) Writes a single character.voidWrites a string.voidWrites a portion of a string.Methods inherited from class Writer
nullWriter, write
-
Constructor Details
-
UStringWriter
public UStringWriter()Create a new string writer using the default initial string builder size. -
UStringWriter
public UStringWriter(int initialSize) Create a new string writer using the specified initial string builder size.- Parameters:
initialSize- the number ofcharvalues that will fit into the string builder before it is automatically expanded.- Throws:
IllegalArgumentException- ifinitialSizeis negative.
-
-
Method Details
-
write
-
write
public void write(char[] chars, int offset, int length) Writes a portion of an array of characters.- Specified by:
writein classWriter- Parameters:
chars- an array of characters.offset- the offset from which to start writing characters.length- the number of characters to write.- Throws:
IndexOutOfBoundsException- if arguments are out-of-bounds.
-
write
-
write
-
append
Appends the specified character sequence to this writer.An invocation of this method of the form
out.append(csq)behaves in exactly the same way as the invocation:out.write(csq.toString())
Depending on the specification oftoStringfor the character sequencecsqthe entire sequence may not be appended. For instance, invoking thetoStringmethod of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Parameters:
csq- the character sequence to append. Ifcsqisnullthen the four characters"null"are appended to this writer.- Returns:
- this writer.
-
append
Appends a subsequence of the specified character sequence to this writer.An invocation of this method of the form
out.append(csq, start, end)whencsqis notnull, behaves in exactly the same way as the invocation:out.write(csq.subSequence(start, end).toString())
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Parameters:
csq- the character sequence from which a subsequence will be appended. Ifcsqisnull, then characters will be appended as ifcsqcontained the four characters"null".start- the index of the first character in the subsequence.end- the index of the character following the last character in the subsequence.- Returns:
- this writer.
- Throws:
IndexOutOfBoundsException- ifstartorendare negative,startis greater thanend, orendis greater thancsq.length().
-
append
Appends the specified character to this writer.An invocation of this method of the form
out.append(c)behaves in exactly the same way as the invocation:out.write(c)
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Parameters:
ch- the character to append.- Returns:
- this writer.
-
toString
-
getBuffer
Returns the buffer holding the current contents of this writer.- Returns:
- the buffer holding the current contents of this writer.
-
flush
-
close
Closes this writer. Closing aUStringWriterhas no effect. The methods in this class can be called after the stream has been closed without generating anIOException.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- if an I/O error occurs.
-