Class Template

java.lang.Object
org.simpleframework.xml.core.Template

class Template extends Object
This is primarily used to replace the StringBuffer class, as a way for the TemplateEngine to store the data for a specific region within the parse data that constitutes a desired value. The methods are not synchronized so it enables the characters to be taken quicker than the string buffer class.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected char[]
    The characters that this buffer has accumulated.
    protected String
    This is used to quicken toString.
    protected int
    This is the number of characters this has stored.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for Template.
    Template(int size)
    This creates a Template with a specific default size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(char c)
    This will add a char to the end of the buffer.
    void
    append(char[] c, int off, int len)
    This will add a char to the end of the buffer.
    void
    This will add a String to the end of the buffer.
    void
    append(String str, int off, int len)
    This will add a String to the end of the buffer.
    void
    This will add a Template to the end of this.
    void
    append(Template text, int off, int len)
    This will add a Template to the end of this.
    void
    This will empty the Template so that the toString paramater will return null.
    protected void
    ensureCapacity(int min)
    This ensure that there is enough space in the buffer to allow for more characters to be added.
    int
    This will return the number of bytes that have been appended to the Template.
    This will return the characters that have been appended to the Template as a String object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • cache

      protected String cache
      This is used to quicken toString.
    • buf

      protected char[] buf
      The characters that this buffer has accumulated.
    • count

      protected int count
      This is the number of characters this has stored.
  • Constructor Details

    • Template

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

      public Template(int size)
      This creates a Template with a specific default size. The buffer will be created the with the length specified. The Template can grow to accomodate a collection of characters larger the the size spacified.
      Parameters:
      size - initial size of this Template
  • Method Details

    • append

      public void append(char c)
      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 accomodate more characters.
      Parameters:
      c - the char to be appended
    • append

      public void append(String str)
      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 accomodate large String objects.
      Parameters:
      str - the String to be appended to this
    • append

      public void append(Template text)
      This will add a Template to the end of this. 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 accomodate large Template objects.
      Parameters:
      text - the Template to be appended
    • append

      public void append(char[] c, int off, int len)
      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 accomodate large char arrays.
      Parameters:
      c - the char array to be appended to this
      off - the read offset for the array
      len - the number of characters to append to this
    • append

      public void append(String str, 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 accomodate large String objects.
      Parameters:
      str - the String to be appended to this
      off - the read offset for the String
      len - the number of characters to append to this
    • append

      public void append(Template text, int off, int len)
      This will add a Template to the end of this. 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 accomodate large Template objects.
      Parameters:
      text - the Template to be appended
      off - the read offset for the Template
      len - the number of characters to append to this
    • ensureCapacity

      protected void ensureCapacity(int min)
      This ensure that there is enough space in the buffer to allow for more characters to be added. If the buffer is already larger than min then the buffer will not be expanded at all.
      Parameters:
      min - the minimum size needed for this buffer
    • clear

      public void clear()
      This will empty the Template so that the toString paramater will return null. This is used so that the same Template can be recycled for different tokens.
    • length

      public int length()
      This will return the number of bytes that have been appended to the Template. This will return zero after the clear method has been invoked.
      Returns:
      the number of characters within this buffer object
    • toString

      public String toString()
      This will return the characters that have been appended to the Template as a String object. If the String object has been created before then a cached String object will be returned. This method will return null after clear is invoked.
      Overrides:
      toString in class Object
      Returns:
      the characters appended as a String