org.simpleframework.util.parse

## Class ParseBuffer

- java.lang.Object
- - org.simpleframework.util.parse.ParseBuffer

    public class ParseBuffer
    extends java.lang.Object

This is primarily used to replace the `StringBuffer` class, as a way for the `Parser` to store the char's for a specific region within the parse data that constitutes a desired value. The methods are not synchronized so it enables the `char`'s to be taken quicker than the `StringBuffer` class.

Author:
  Niall Gallagher

### Field Summary

Fields
`protected char[]` `buf` The `char`'s this buffer accumulated.
`protected java.lang.String` `cache` This is used to quicken `toString`.
`protected int` `count` This is the number of `char`'s stored.

### Constructor Summary

Constructors
Constructor and Description
`ParseBuffer()` Constructor for `ParseBuffer`.
`ParseBuffer(int size)` This creates a `ParseBuffer` with a specific default size.

### Method Summary

Methods
`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` `append(ParseBuffer text)` This will add a `ParseBuffer` to the end of this.
`void` `append(ParseBuffer text, int off, int len)` This will add a `ParseBuffer` to the end of this.
`void` `append(java.lang.String text)` This will add a `String` to the end of the buffer.
`void` `append(java.lang.String str, int off, int len)` This will add a `String` to the end of the buffer.
`void` `clear()` This will empty the `ParseBuffer` so that the `toString` parameter will return `null`.
`protected void` `ensureCapacity(int min)` This ensure that there is enough space in the buffer to allow for more `char`'s to be added.
`int` `length()` This will return the number of bytes that have been appended to the `ParseBuffer`.
`void` `reset(ParseBuffer text)` This will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended.
`void` `reset(java.lang.String text)` This will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended.
`java.lang.String` `toString()` This will return the characters that have been appended to the `ParseBuffer` as a `String` object.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### cache

    protected java.lang.String cache

This is used to quicken `toString`.

#### buf

    protected char[] buf

The `char`'s this buffer accumulated.

#### count

    protected int count

This is the number of `char`'s stored.

### Constructor Detail

#### ParseBuffer

    public ParseBuffer()

Constructor for `ParseBuffer`. The default `ParseBuffer` stores 16 `char`'s before a `resize` is needed to accommodate extra characters.

#### ParseBuffer

    public ParseBuffer(int size)

This creates a `ParseBuffer` with a specific default size. The buffer will be created the with the length specified. The `ParseBuffer` can grow to accommodate a collection of `char`'s larger the the size specified.

Parameters:
  `size` - initial size of this `ParseBuffer`

### Method Detail

#### 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 accommodate more `char`'s.

Parameters:
  `c` - the `char` to be appended

#### append

    public void append(java.lang.String text)

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:
  `text` - the `String` to be appended to this

#### reset

    public void reset(java.lang.String text)

This will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended. This is used when a value is to be set into the buffer value. See the `append(String)` method for reference.

Parameters:
  `text` - this is the text that is to be appended to this

#### append

    public void append(ParseBuffer text)

This will add a `ParseBuffer` 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 accommodate large `ParseBuffer` objects.

Parameters:
  `text` - the `ParseBuffer` to be appended

#### reset

    public void reset(ParseBuffer text)

This will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended. This is used when a value is to be set into the buffer value. See the `append(ParseBuffer)` method for reference.

Parameters:
  `text` - this is the text that is to be appended to this

#### 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 accommodate large `char` arrays.

Parameters:
  `c` - the `char` array to be appended to this
  `off` - the read offset for the array
  `len` - the number of `char`'s to add

#### append

    public void append(java.lang.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 accommodate large `String` objects.

Parameters:
  `str` - the `String` to be appended to this
  `off` - the read offset for the `String`
  `len` - the number of `char`'s to add

#### append

    public void append(ParseBuffer text,
              int off,
              int len)

This will add a `ParseBuffer` 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 accommodate large `ParseBuffer` objects.

Parameters:
  `text` - the `ParseBuffer` to be appended
  `off` - the read offset for the `ParseBuffer`
  `len` - the number of `char`'s to add

#### ensureCapacity

    protected void ensureCapacity(int min)

This ensure that there is enough space in the buffer to allow for more `char`'s 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

#### clear

    public void clear()

This will empty the `ParseBuffer` so that the `toString` parameter will return `null`. This is used so that the same `ParseBuffer` can be recycled for different tokens.

#### length

    public int length()

This will return the number of bytes that have been appended to the `ParseBuffer`. This will return zero after the clear method has been invoked.

Returns:
  the number of `char`'s within the buffer

#### toString

    public java.lang.String toString()

This will return the characters that have been appended to the `ParseBuffer` 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 `java.lang.Object`
Returns:
  the `char`'s appended as a `String`