Package com.helger.commons.io.stream
Class NonBlockingCharArrayWriter
- java.lang.Object
-
- java.io.Writer
-
- com.helger.commons.io.stream.NonBlockingCharArrayWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class NonBlockingCharArrayWriter extends Writer
A non-synchronized copy of the classCharArrayWriter.
It does not use the internal lock object.- Since:
- 8.6.4
- Author:
- Philip Helger
- See Also:
CharArrayWriter
-
-
Constructor Summary
Constructors Constructor Description NonBlockingCharArrayWriter()Creates a new NonBlockingCharArrayWriter.NonBlockingCharArrayWriter(int nInitialSize)Creates a new NonBlockingCharArrayWriter with the specified initial size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NonBlockingCharArrayWriterappend(char c)Appends the specified character to this writer.NonBlockingCharArrayWriterappend(CharSequence csq)Appends the specified character sequence to this writer.NonBlockingCharArrayWriterappend(CharSequence csq, int start, int end)Appends a subsequence of the specified character sequence to this writer.voidclose()Close the stream.char[]directGetBuffer()voidflush()Flush the stream.StringgetAsString()Converts input data to a string.StringgetAsString(int nLength)Converts input data to a string.StringgetAsString(int nOfs, int nLength)Converts input data to a string.intgetBufferSize()intgetSize()Returns the current size of the buffer.booleanisEmpty()booleanisNotEmpty()voidreset()Resets the buffer so that you can use it again without throwing away the already allocated buffer.booleanstartsWith(char[] aChars)booleanstartsWith(char[] aChars, int nOfs, int nLen)byte[]toByteArray(Charset aCharset)Returns a copy of the input data as bytes in the correct charset.char[]toCharArray()Returns a copy of the input data.voidwrite(char[] aBuf)Writes an array of characters.voidwrite(char[] aBuf, int nOfs, int nLen)Writes characters to the buffer.voidwrite(int c)Writes a character to the buffer.voidwrite(String sStr)Writes a string.voidwrite(String sStr, int nOfs, int nLen)Write a portion of a string to the buffer.voidwriteTo(Writer out)Writes the contents of the buffer to another character stream.-
Methods inherited from class java.io.Writer
nullWriter
-
-
-
-
Constructor Detail
-
NonBlockingCharArrayWriter
public NonBlockingCharArrayWriter()
Creates a new NonBlockingCharArrayWriter.
-
NonBlockingCharArrayWriter
public NonBlockingCharArrayWriter(@Nonnegative int nInitialSize)
Creates a new NonBlockingCharArrayWriter with the specified initial size.- Parameters:
nInitialSize- an int specifying the initial buffer size.- Throws:
IllegalArgumentException- if initialSize is negative
-
-
Method Detail
-
write
public void write(@Nonnull char[] aBuf)
Writes an array of characters.
-
write
public void write(@Nonnull char[] aBuf, @Nonnegative int nOfs, @Nonnegative int nLen)
Writes characters to the buffer.
-
write
public void write(@Nonnull String sStr, @Nonnegative int nOfs, @Nonnegative int nLen)
Write a portion of a string to the buffer.
-
writeTo
public void writeTo(@Nonnull Writer out) throws IOException
Writes the contents of the buffer to another character stream.- Parameters:
out- the output stream to write to- Throws:
IOException- If an I/O error occurs.
-
append
public NonBlockingCharArrayWriter append(@Nullable CharSequence csq)
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:
csq- The character sequence to append. Ifcsqisnull, then the four characters"null"are appended to this writer.- Returns:
- This writer
-
append
public NonBlockingCharArrayWriter append(@Nullable CharSequence csq, int start, int end)
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:
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 subsequenceend- 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 NonBlockingCharArrayWriter 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
-
reset
public void reset()
Resets the buffer so that you can use it again without throwing away the already allocated buffer.
-
toCharArray
@Nonnull @ReturnsMutableCopy public char[] toCharArray()
Returns a copy of the input data.- Returns:
- an array of chars copied from the input data.
-
directGetBuffer
@Nonnull @ReturnsMutableObject public char[] directGetBuffer()
- Returns:
- The internally used char array. Never
null. Handle with care!
-
toByteArray
@Nonnull @ReturnsMutableCopy public byte[] toByteArray(@Nonnull Charset aCharset)
Returns a copy of the input data as bytes in the correct charset.- Parameters:
aCharset- The charset to be used. May not benull.- Returns:
- an array of bytes. Never
null.
-
getSize
@Nonnegative public int getSize()
Returns the current size of the buffer.- Returns:
- an int representing the current size of the buffer.
-
getBufferSize
@Nonnegative public int getBufferSize()
- Returns:
- The number of pre-allocated chars. Always ≥ 0.
-
isEmpty
public boolean isEmpty()
-
isNotEmpty
public boolean isNotEmpty()
-
startsWith
public boolean startsWith(@Nonnull char[] aChars)
-
startsWith
public boolean startsWith(@Nonnull char[] aChars, @Nonnegative int nOfs, @Nonnegative int nLen)
-
getAsString
@Nonnull @ReturnsMutableCopy public String getAsString()
Converts input data to a string.- Returns:
- the string.
-
getAsString
@Nonnull public String getAsString(@Nonnegative int nLength)
Converts input data to a string.- Parameters:
nLength- The number of characters to convert. Must be ≤ thangetSize().- Returns:
- the string.
-
getAsString
@Nonnull public String getAsString(@Nonnegative int nOfs, @Nonnegative int nLength)
Converts input data to a string.- Parameters:
nOfs- The offset to start at. Must be ≥ 0.nLength- The number of characters to convert. Must be ≤ thangetSize().- Returns:
- the string.
-
flush
public void flush()
Flush the stream.
-
close
public void close()
Close the stream. This method does not release the buffer, since its contents might still be required. Note: Invoking this method in this class will have no effect.
-
-