Class NonBlockingBufferedWriter

    • Constructor Detail

      • NonBlockingBufferedWriter

        public NonBlockingBufferedWriter​(@Nonnull
                                         Writer aWriter)
        Creates a buffered character-output stream that uses a default-sized output buffer.
        Parameters:
        aWriter - A Writer
      • NonBlockingBufferedWriter

        public NonBlockingBufferedWriter​(@Nonnull
                                         Writer aWriter,
                                         @Nonnegative
                                         int nBufSize)
        Creates a new buffered character-output stream that uses an output buffer of the given size.
        Parameters:
        aWriter - A Writer
        nBufSize - Output-buffer size, a positive integer
        Throws:
        IllegalArgumentException - If size is ≤ 0
    • Method Detail

      • flushBuffer

        protected void flushBuffer()
                            throws IOException
        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

        public void write​(char[] cbuf,
                          int nOfs,
                          int nLen)
                   throws IOException
        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:
        write in class Writer
        Parameters:
        cbuf - A character array
        nOfs - Offset from which to start reading characters
        nLen - Number of characters to write
        Throws:
        IOException - If an I/O error occurs
      • write

        public void write​(String s,
                          int off,
                          int len)
                   throws IOException
        Writes a portion of a String.

        If the value of the len parameter is negative then no characters are written. This is contrary to the specification of this method in the superclass, which requires that an IndexOutOfBoundsException be thrown.

        Overrides:
        write in class Writer
        Parameters:
        s - String to be written
        off - Offset from which to start reading characters
        len - Number of characters to be written
        Throws:
        IOException - If an I/O error occurs
      • reset

        public void reset()
        Remove all content of the buffer.
      • isEmpty

        public boolean isEmpty()
      • getAsString

        @Nonnull
        public String getAsString​(@Nonnegative
                                  int nLength)
        Converts input data to a string.
        Parameters:
        nLength - The number of characters to convert. Must be ≤ than getSize().
        Returns:
        the string.
      • newLine

        public void newLine()
                     throws IOException
        Writes a line separator. The line separator string is defined by the system property line.separator, and is not necessarily a single newline ('\n') character.
        Throws:
        IOException - If an I/O error occurs