Class OutputBuffer


  • class OutputBuffer
    extends java.lang.Object
    This is primarily used to replace the StringBuffer class, as a way for the Formatter to store the start tag for an XML element. This enables the start tag of the current element to be removed without disrupting any of the other nodes within the document. Once the contents of the output buffer have been filled its contents can be emitted to the writer object.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.StringBuilder text
      The characters that this buffer has accumulated.
    • Constructor Summary

      Constructors 
      Constructor Description
      OutputBuffer()
      Constructor for OutputBuffer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void append​(char ch)
      This will add a char to the end of the buffer.
      void append​(char[] value)
      This will add a char array to the buffer.
      void append​(char[] value, int off, int len)
      This will add a char array to the buffer.
      void append​(java.lang.String value)
      This will add a String to the end of the buffer.
      void append​(java.lang.String value, int off, int len)
      This will add a String to the end of the buffer.
      void clear()
      This will empty the OutputBuffer so that it does not contain any content.
      void write​(java.io.Writer out)
      This method is used to write the contents of the buffer to the specified Writer object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • text

        private java.lang.StringBuilder text
        The characters that this buffer has accumulated.
    • Constructor Detail

      • OutputBuffer

        public OutputBuffer()
        Constructor for OutputBuffer. The default OutputBuffer stores 16 characters before a resize is needed to append extra characters.
    • Method Detail

      • append

        public void append​(char ch)
        This will add a char to the end of the buffer. The buffer will not overflow with repeated uses of the append, it uses an ensureCapacity method which will allow the buffer to dynamically grow in size to accommodate more characters.
        Parameters:
        ch - the character to be appended to the buffer
      • append

        public void append​(java.lang.String value)
        This will add a String to the end of the buffer. The buffer will not overflow with repeated uses of the append, it uses an ensureCapacity method which will allow the buffer to dynamically grow in size to accommodate large string objects.
        Parameters:
        value - the string to be appended to this output buffer
      • append

        public void append​(char[] value)
        This will add a char array to the buffer. The buffer will not overflow with repeated uses of the append, it uses an ensureCapacity method which will allow the buffer to dynamically grow in size to accommodate large character arrays.
        Parameters:
        value - the character array to be appended to this
      • append

        public void append​(char[] value,
                           int off,
                           int len)
        This will add a char array to the buffer. The buffer will not overflow with repeated uses of the append, it uses an ensureCapacity method which will allow the buffer to dynamically grow in size to accommodate large character arrays.
        Parameters:
        value - the character array to be appended to this
        off - the read offset for the array to begin reading
        len - the number of characters to append to this
      • append

        public void append​(java.lang.String value,
                           int off,
                           int len)
        This will add a String to the end of the buffer. The buffer will not overflow with repeated uses of the append, it uses an ensureCapacity method which will allow the buffer to dynamically grow in size to accommodate large string objects.
        Parameters:
        value - the string to be appended to the output buffer
        off - the offset to begin reading from the string
        len - the number of characters to append to this
      • write

        public void write​(java.io.Writer out)
                   throws java.io.IOException
        This method is used to write the contents of the buffer to the specified Writer object. This is used when the XML element is to be committed to the resulting XML document.
        Parameters:
        out - this is the writer to write the buffered text to
        Throws:
        java.io.IOException - thrown if there is an I/O problem
      • clear

        public void clear()
        This will empty the OutputBuffer so that it does not contain any content. This is used to that when the buffer is written to a specified Writer object nothing is written out. This allows XML elements to be removed.