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
@NotThreadSafe public class NonBlockingStringWriter extends Writer implements IHasSize
A non-synchronized copy of the classStringWriter.
It usesStringBuilderinstead ofStringBufferand therefore does not need synchronized access!- Author:
- Philip Helger
- See Also:
StringWriter
-
-
Constructor Summary
Constructors Constructor Description NonBlockingStringWriter()Create 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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description NonBlockingStringWriterappend(char c)Appends the specified character to this writer.NonBlockingStringWriterappend(CharSequence aCS)Appends the specified character sequence to this writer.NonBlockingStringWriterappend(CharSequence aCS, int nStart, int nEnd)Appends a subsequence of the specified character sequence to this writer.voidclose()Closing aStringWriterhas no effect.StringBuilderdirectGetStringBuilder()voidflush()Flush the stream.char[]getAsCharArray()StringgetAsString()booleanisEmpty()voidreset()Remove all content of the buffer.intsize()StringtoString()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(String sStr)Write a string.voidwrite(String sStr, int nOfs, int nLen)Write a portion of a string.-
Methods inherited from class java.io.Writer
nullWriter, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.lang.IHasSize
isNotEmpty
-
-
-
-
Constructor Detail
-
NonBlockingStringWriter
public NonBlockingStringWriter()
Create a new string writer using the default initial string-buffer size.
-
NonBlockingStringWriter
public NonBlockingStringWriter(@Nonnegative int nInitialSize)
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 Detail
-
write
public void write(@Nonnull char[] aBuf, @Nonnegative int nOfs, @Nonnegative int nLen)
Write a portion of an array of characters.
-
append
public NonBlockingStringWriter append(CharSequence aCS)
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
public NonBlockingStringWriter append(CharSequence aCS, int nStart, int nEnd)
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
public NonBlockingStringWriter append(char c)
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
@Nonnull @ReturnsMutableObject("design") public StringBuilder directGetStringBuilder()
- Returns:
- The contained StringBuilder. Never
null. Handle with care!
-
getAsCharArray
@Nonnull @ReturnsMutableCopy public char[] getAsCharArray()
- Returns:
- Return the buffer's current value as a string.
-
reset
public void reset()
Remove all content of the buffer.
-
size
@Nonnegative public int size()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceIHasSize- Returns:
trueif no items are present,falseif at least a single item is present.- See Also:
IHasSize.size(),IHasSize.isNotEmpty()
-
toString
@Deprecated public String toString()
Deprecated.Don't call this; use getAsString instead
-
-