Class BufferUtil


  • public final class BufferUtil
    extends Object
    Buffer related utility methods.
    Author:
    Pascal Essiembre
    • Field Detail

      • MAX_CONTENT_FROM_END_TO_CUT

        public static final int MAX_CONTENT_FROM_END_TO_CUT
        See Also:
        Constant Field Values
    • Method Detail

      • flushBuffer

        public static void flushBuffer​(StringBuilder buffer,
                                       Writer out,
                                       boolean cutWisely)
                                throws IOException
        Flushes the buffer to output stream. If the buffer is considered partial (e.g. containing a partial set of a huge document), you can tell the method to be wise about only flushing the content up to the last line break it finds, dot, or space, when found before MAX_CONTENT_FROM_END_TO_CUT. The remaining content after the cut location will remain in the buffer for further use. If the output writer is null, it will simply truncate the buffer content without writing it anywhere.
        Parameters:
        buffer - the buffer to flush
        out - where to write the buffer content
        cutWisely - whether to "cut" wisely the buffer content
        Throws:
        IOException - when there is a problem flushing the buffer