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
A non-synchronized copy of the class
It does not use the internal lock object.
CharArrayWriter.It does not use the internal lock object.
- Since:
- 8.6.4
- Author:
- Philip Helger
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected char[]The buffer where data is stored.protected intThe number of chars in the buffer. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new NonBlockingCharArrayWriter.NonBlockingCharArrayWriter(int nInitialSize) Creates a new NonBlockingCharArrayWriter with the specified initial size. -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) 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()Close the stream.char[]voidflush()Flush the stream.Converts input data to a string.getAsString(int nLength) Converts input data to a string.getAsString(int nOfs, int nLength) Converts input data to a string.intintgetSize()Returns the current size of the buffer.booleanisEmpty()booleanvoidreset()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[]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.voidWrites a string.voidWrite a portion of a string to the buffer.voidWrites the contents of the buffer to another character stream.Methods inherited from class java.io.Writer
nullWriter
-
Field Details
-
m_aBuf
protected char[] m_aBufThe buffer where data is stored. -
m_nCount
protected int m_nCountThe number of chars in the buffer.
-
-
Constructor Details
-
NonBlockingCharArrayWriter
public NonBlockingCharArrayWriter()Creates a new NonBlockingCharArrayWriter. -
NonBlockingCharArrayWriter
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 Details
-
write
public void write(int c) Writes a character to the buffer. -
write
Writes an array of characters. -
write
Writes characters to the buffer. -
write
Writes a string. -
write
Write a portion of a string to the buffer. -
writeTo
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
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
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
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
Returns a copy of the input data.- Returns:
- an array of chars copied from the input data.
-
directGetBuffer
- Returns:
- The internally used char array. Never
null. Handle with care!
-
toByteArray
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
Returns the current size of the buffer.- Returns:
- an int representing the current size of the buffer.
-
getBufferSize
- Returns:
- The number of pre-allocated chars. Always ≥ 0.
-
isEmpty
public boolean isEmpty() -
isNotEmpty
public boolean isNotEmpty() -
startsWith
-
startsWith
-
getAsString
Converts input data to a string.- Returns:
- the string.
-
getAsString
Converts input data to a string.- Parameters:
nLength- The number of characters to convert. Must be ≤ thangetSize().- Returns:
- the string.
-
getAsString
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.
-