Package com.helger.base.io.nonblocking
Class NonBlockingStringWriter
java.lang.Object
java.io.Writer
com.helger.base.io.nonblocking.NonBlockingStringWriter
- All Implemented Interfaces:
IHasSize,IWriteToWriter,Closeable,Flushable,Appendable,AutoCloseable
@NotThreadSafe
public class NonBlockingStringWriter
extends Writer
implements IHasSize, IWriteToWriter
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.@NonNull StringBuildervoidflush()Flush the stream.char @NonNull []@NonNull StringbooleanisEmpty()voidreset()Remove all content of the buffer.intsize()toString()Deprecated.Don't call this; use getAsString insteadvoidwrite(char @NonNull [] aBuf, int nOfs, int nLen) Write a portion of an array of characters.voidwrite(int c) Write a single character.voidWrite a portion of a string.voidWrite a string.voidWrites the contents of the buffer to another character stream.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.base.iface.IHasSize
isNotEmptyMethods inherited from interface com.helger.base.io.iface.IWriteToWriter
writeToAndClose
-
Constructor Details
-
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 Details
-
write
public void write(int c) Write a single character. -
write
public void write(char @NonNull [] aBuf, @Nonnegative int nOfs, @Nonnegative int nLen) Write a portion of an array of characters. -
write
Write a string. -
write
Write a portion of a string. -
writeTo
Writes the contents of the buffer to another character stream.- Specified by:
writeToin interfaceIWriteToWriter- Parameters:
aWriter- the writer to write to- Throws:
IOException- If an I/O error occurs.
-
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
@ReturnsMutableCopy public char @NonNull [] 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
@Nonnegative public int size() -
isEmpty
public boolean isEmpty() -
toString
Deprecated.Don't call this; use getAsString instead
-