Package com.helger.commons.io.stream
Class NonBlockingBufferedWriter
java.lang.Object
java.io.Writer
com.helger.commons.io.stream.NonBlockingBufferedWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
This is a non-blocking version of
BufferedWriter. It is 1:1
rip without the synchronized statements.- Author:
- Philip Helger
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionNonBlockingBufferedWriter(Writer aWriter) Creates a buffered character-output stream that uses a default-sized output buffer.NonBlockingBufferedWriter(Writer aWriter, int nBufSize) Creates a new buffered character-output stream that uses an output buffer of the given size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()Flushes the stream.protected voidFlushes the output buffer to the underlying character stream, without flushing the stream itself.Converts input data to a string.getAsString(int nLength) Converts input data to a string.intintgetSize()booleanisEmpty()voidnewLine()Writes a line separator.voidreset()Remove all content of the buffer.voidwrite(char[] cbuf, int nOfs, int nLen) Writes a portion of an array of characters.voidwrite(int c) Writes a single character.voidWrites a portion of a String.
-
Constructor Details
-
NonBlockingBufferedWriter
Creates a buffered character-output stream that uses a default-sized output buffer.- Parameters:
aWriter- A Writer
-
NonBlockingBufferedWriter
Creates a new buffered character-output stream that uses an output buffer of the given size.- Parameters:
aWriter- A WriternBufSize- Output-buffer size, a positive integer- Throws:
IllegalArgumentException- If size is ≤ 0
-
-
Method Details
-
flushBuffer
Flushes the output buffer to the underlying character stream, without flushing the stream itself. This method is non-private only so that it may be invoked by PrintStream.- Throws:
IOException- of the writer is not open
-
write
Writes a single character.- Overrides:
writein classWriter- Throws:
IOException- If an I/O error occurs
-
write
Writes a portion of an array of characters.Ordinarily this method stores characters from the given array into this stream's buffer, flushing the buffer to the underlying stream as needed. If the requested length is at least as large as the buffer, however, then this method will flush the buffer and write the characters directly to the underlying stream. Thus redundant
BufferedWriters will not copy data unnecessarily.- Specified by:
writein classWriter- Parameters:
cbuf- A character arraynOfs- Offset from which to start reading charactersnLen- Number of characters to write- Throws:
IOException- If an I/O error occurs
-
write
Writes a portion of a String.If the value of the
lenparameter is negative then no characters are written. This is contrary to the specification of this method in the superclass, which requires that anIndexOutOfBoundsExceptionbe thrown.- Overrides:
writein classWriter- Parameters:
s- String to be writtenoff- Offset from which to start reading characterslen- Number of characters to be written- Throws:
IOException- If an I/O error occurs
-
reset
public void reset()Remove all content of the buffer. -
getSize
-
getBufferSize
-
isEmpty
public boolean isEmpty() -
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.
-
newLine
Writes a line separator. The line separator string is defined by the system propertyline.separator, and is not necessarily a single newline ('\n') character.- Throws:
IOException- If an I/O error occurs
-
flush
Flushes the stream.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException- If an I/O error occurs
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-