Package com.helger.commons.io.stream
Class NonBlockingStringWriter
java.lang.Object
java.io.Writer
com.helger.commons.io.stream.NonBlockingStringWriter
- All Implemented Interfaces:
IHasSize,Closeable,Flushable,Appendable,AutoCloseable
A non-synchronized copy of the class
It uses
StringWriter.It uses
StringBuilder instead of StringBuffer and therefore
does not need synchronized access!- Author:
- Philip Helger
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new string writer using the default initial string-buffer size.NonBlockingStringWriter(int nInitialSize) Create a new string writer using the specified initial string-buffer size. -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) Appends the specified character to this writer.append(CharSequence aCS) Appends the specified character sequence to this writer.append(CharSequence aCS, int nStart, int nEnd) Appends a subsequence of the specified character sequence to this writer.voidclose()Closing aStringWriterhas no effect.voidflush()Flush the stream.char[]booleanisEmpty()voidreset()Remove all content of the buffer.intsize()toString()Deprecated.Don't call this; use getAsString insteadvoidwrite(char[] aBuf, int nOfs, int nLen) Write a portion of an array of characters.voidwrite(int c) Write a single character.voidWrite a string.voidWrite a portion of a string.Methods inherited from class java.io.Writer
nullWriter, writeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.commons.lang.IHasSize
isNotEmpty
-
Constructor Details
-
NonBlockingStringWriter
public NonBlockingStringWriter()Create a new string writer using the default initial string-buffer size. -
NonBlockingStringWriter
Create a new string writer using the specified initial string-buffer size.- Parameters:
nInitialSize- The number ofcharvalues that will fit into this buffer before it is automatically expanded- Throws:
IllegalArgumentException- IfinitialSizeis negative
-
-
Method Details
-
write
public void write(int c) Write a single character. -
write
Write a portion of an array of characters. -
write
Write a string. -
write
Write a portion of a string. -
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 invocationout.write (csq.toString ())
Depending on the specification of
toStringfor the character sequencecsq, the 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:
aCS- The character sequence to append. Ifcsqisnull, then 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 invocationout.write (csq.subSequence (start, end).toString ())
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Parameters:
aCS- The character sequence from which a subsequence will be appended. Ifcsqisnull, then characters will be appended as ifcsqcontained the four characters"null".nStart- The index of the first character in the subsequencenEnd- 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 invocationout.write (c)
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Parameters:
c- The 16-bit character to append- Returns:
- This writer
-
flush
public void flush()Flush the stream. -
close
public void close()Closing aStringWriterhas no effect. The methods in this class can be called after the stream has been closed without generating anIOException. -
directGetStringBuilder
- Returns:
- The contained StringBuilder. Never
null. Handle with care!
-
getAsCharArray
- Returns:
- Return the buffer's current value as a string.
-
getAsString
- Returns:
- the buffer's current value as a string.
-
reset
public void reset()Remove all content of the buffer. -
size
-
isEmpty
public boolean isEmpty() -
toString
Deprecated.Don't call this; use getAsString instead
-