## org.exist.util
Class FastStringBuffer

    java.lang.Object
      org.exist.util.FastStringBuffer

All Implemented Interfaces:
  java.lang.CharSequence, java.io.Serializable

public final class FastStringBuffer
extends java.lang.Object
implements java.lang.CharSequence, java.io.Serializable

A simple implementation of a class similar to StringBuffer. Unlike StringBuffer it is not synchronized. It also offers the capability to remove unused space. (This class could possibly be replaced by StringBuilder in JDK 1.5, but using our own class gives more control.)

See Also:
  Serialized Form

Field Summary
`static int` `SUPPRESS_BOTH` Manefest constant: Suppress both leading and trailing whitespace.
`static int` `SUPPRESS_LEADING_WS` Manefest constant: Suppress leading whitespace.
`static int` `SUPPRESS_TRAILING_WS` Manefest constant: Suppress trailing whitespace.

Constructor Summary
`FastStringBuffer(int initialSize)`

Method Summary
`void` `append(char ch)` Append a character to the buffer
`void` `append(char[] srcArray)` Append the entire contents of a character array to the buffer
`void` `append(char[] srcArray, int start, int length)` Append the contents of a character array to the buffer
`void` `append(java.lang.CharSequence s)` Append the contents of a general CharSequence to the buffer
`void` `append(CharSlice s)` Append the contents of a CharSlice to the buffer
`void` `append(FastStringBuffer s)` Append the contents of a FastStringBuffer to the buffer
`void` `append(java.lang.String s)` Append the contents of a String to the buffer
`void` `append(java.lang.StringBuffer s)` Append the contents of a StringBuffer to the buffer
`void` `appendWideChar(int ch)` Append a wide character to the buffer (as a surrogate pair if necessary)
`char` `charAt(int index)` Returns the `char` value at the specified index.
`java.lang.CharSequence` `condense()` Remove surplus space from the array.
`static java.lang.String` `diagnosticPrint(java.lang.CharSequence in)` Diagnostic print of the contents of a CharSequence
`void` `ensureCapacity(int extra)` Expand the character array if necessary to ensure capacity for appended data
`void` `getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)` Copies characters from this FastStringBuffer into the destination character array.
`java.lang.String` `getNormalizedString(int mode)` Gets the normalizedString attribute of the FastStringBuffer object
`java.lang.StringBuffer` `getNormalizedString(java.lang.StringBuffer sb, int mode)` Gets the normalizedString attribute of the FastStringBuffer object
`int` `indexOf(char ch)` Get the index of the first character equal to a given value
`void` `insertCharAt(int index, char ch)` Insert a character at a particular offset
`int` `length()` Returns the length of this character sequence.
`void` `prependWideChar(int ch)` Prepend a wide character to the buffer (as a surrogate pair if necessary)
`void` `removeCharAt(int index)` Remove a character at a particular offset
`void` `setCharAt(int index, char ch)` Set the character at a particular offset
`void` `setLength(int length)` Set the length.
`java.lang.CharSequence` `subSequence(int start, int end)` Returns a new `CharSequence` that is a subsequence of this sequence.
`java.lang.String` `toString()` Convert contents of the FastStringBuffer to a string
`void` `write(java.io.Writer writer)` Write the value to a writer

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### SUPPRESS_LEADING_WS

    public static final int SUPPRESS_LEADING_WS

  Manefest constant: Suppress leading whitespace. This should be used when normalize-to-SAX is called for the first chunk of a multi-chunk output, or one following unsuppressed whitespace in a previous chunk. see #sendNormalizedSAXcharacters(char[],int,int,org.xml.sax.ContentHandler,int)

  See Also:
    Constant Field Values

### SUPPRESS_TRAILING_WS

    public static final int SUPPRESS_TRAILING_WS

  Manefest constant: Suppress trailing whitespace. This should be used when normalize-to-SAX is called for the last chunk of a multi-chunk output; it may have to be or'ed with SUPPRESS_LEADING_WS.

  See Also:
    Constant Field Values

### SUPPRESS_BOTH

    public static final int SUPPRESS_BOTH

  Manefest constant: Suppress both leading and trailing whitespace. This should be used when normalize-to-SAX is called for a complete string. (I'm not wild about the name of this one. Ideas welcome.) see sendNormalizedSAXcharacters(char[],int,int,org.xml.sax.ContentHandler,int)

  See Also:
    Constant Field Values

Constructor Detail

### FastStringBuffer

    public FastStringBuffer(int initialSize)

Method Detail

### append

    public void append(java.lang.String s)

  Append the contents of a String to the buffer

  Parameters:
    `s` - the String to be appended

### append

    public void append(CharSlice s)

  Append the contents of a CharSlice to the buffer

  Parameters:
    `s` - the String to be appended

### append

    public void append(FastStringBuffer s)

  Append the contents of a FastStringBuffer to the buffer

  Parameters:
    `s` - the FastStringBuffer to be appended

### append

    public void append(java.lang.StringBuffer s)

  Append the contents of a StringBuffer to the buffer

  Parameters:
    `s` - the StringBuffer to be appended

### append

    public void append(java.lang.CharSequence s)

  Append the contents of a general CharSequence to the buffer

  Parameters:
    `s` - the CharSequence to be appended

### append

    public void append(char[] srcArray,
                       int start,
                       int length)

  Append the contents of a character array to the buffer

  Parameters:
    `srcArray` - the array whose contents are to be added
    `start` - the offset of the first character in the array to be copied
    `length` - the number of characters to be copied

### append

    public void append(char[] srcArray)

  Append the entire contents of a character array to the buffer

  Parameters:
    `srcArray` - the array whose contents are to be added

### append

    public void append(char ch)

  Append a character to the buffer

  Parameters:
    `ch` - the character to be added

### appendWideChar

    public void appendWideChar(int ch)

  Append a wide character to the buffer (as a surrogate pair if necessary)

### prependWideChar

    public void prependWideChar(int ch)

  Prepend a wide character to the buffer (as a surrogate pair if necessary)

### length

    public int length()

  Returns the length of this character sequence. The length is the number of 16-bit `char`s in the sequence.

  Specified by:
    `length` in interface `java.lang.CharSequence`
  Returns:
    the number of `char`s in this sequence

### charAt

    public char charAt(int index)

  Returns the `char` value at the specified index. An index ranges from zero to `length() - 1`. The first `char` value of the sequence is at index zero, the next at index one, and so on, as for array indexing.

  If the `char` value specified by the index is a surrogate, the surrogate value is returned.

  Specified by:
    `charAt` in interface `java.lang.CharSequence`
  Parameters:
    `index` - the index of the `char` value to be returned
  Returns:
    the specified `char` value
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the `index` argument is negative or not less than `length()`

### subSequence

    public java.lang.CharSequence subSequence(int start,
                                              int end)

  Returns a new `CharSequence` that is a subsequence of this sequence. The subsequence starts with the `char` value at the specified index and ends with the `char` value at index `end - 1`. The length (in `char`s) of the returned sequence is `end - start`, so if `start == end` then an empty sequence is returned.

  Specified by:
    `subSequence` in interface `java.lang.CharSequence`
  Parameters:
    `start` - the start index, inclusive
    `end` - the end index, exclusive
  Returns:
    the specified subsequence
  Throws:
    `java.lang.IndexOutOfBoundsException` - if `start` or `end` are negative, if `end` is greater than `length()`, or if `start` is greater than `end`

### getChars

    public void getChars(int srcBegin,
                         int srcEnd,
                         char[] dst,
                         int dstBegin)

  Copies characters from this FastStringBuffer into the destination character array.

  The first character to be copied is at index `srcBegin`; the last character to be copied is at index `srcEnd-1` (thus the total number of characters to be copied is `srcEnd-srcBegin`). The characters are copied into the subarray of `dst` starting at index `dstBegin` and ending at index:

  >          dstbegin + (srcEnd-srcBegin) - 1

  Parameters:
    `srcBegin` - index of the first character in the string to copy.
    `srcEnd` - index after the last character in the string to copy.
    `dst` - the destination array.
    `dstBegin` - the start offset in the destination array.
  Throws:
    `java.lang.IndexOutOfBoundsException` - If any of the following is true:
    - `srcBegin` is negative.
    - `srcBegin` is greater than `srcEnd`
    - `srcEnd` is greater than the length of this string
    - `dstBegin` is negative
    - `dstBegin+(srcEnd-srcBegin)` is larger than `dst.length`

### indexOf

    public int indexOf(char ch)

  Get the index of the first character equal to a given value

  Parameters:
    `ch` - the character to search for
  Returns:
    the position of the first occurrence, or -1 if not found

### toString

    public java.lang.String toString()

  Convert contents of the FastStringBuffer to a string

  Specified by:
    `toString` in interface `java.lang.CharSequence`

### setCharAt

    public void setCharAt(int index,
                          char ch)

  Set the character at a particular offset

  Parameters:
    `index` - the index of the character to be set
    `ch` - the new character to overwrite the existing character at that location
  Throws:
    `java.lang.IndexOutOfBoundsException` - if int<0 or int>=length()

### insertCharAt

    public void insertCharAt(int index,
                             char ch)

  Insert a character at a particular offset

  Parameters:
    `index` - the index of the character to be set
    `ch` - the new character to insert at that location
  Throws:
    `java.lang.IndexOutOfBoundsException` - if int<0 or int>=length()

### removeCharAt

    public void removeCharAt(int index)

  Remove a character at a particular offset

  Parameters:
    `index` - the index of the character to be set
  Throws:
    `java.lang.IndexOutOfBoundsException` - if int<0 or int>=length()

### setLength

    public void setLength(int length)

  Set the length. If this exceeds the current length, this method is a no-op. If this is less than the current length, characters beyond the specified point are deleted.

  Parameters:
    `length` - the new length

### ensureCapacity

    public void ensureCapacity(int extra)

  Expand the character array if necessary to ensure capacity for appended data

### condense

    public java.lang.CharSequence condense()

  Remove surplus space from the array. This doesn't reduce the array to the minimum possible size; it only reclaims space if it seems worth doing. Specifically, it contracts the array if the amount of wasted space is more than 256 characters, or more than half the allocated size.

### write

    public void write(java.io.Writer writer)
               throws java.io.IOException

  Write the value to a writer

  Throws:
    `java.io.IOException`

### diagnosticPrint

    public static java.lang.String diagnosticPrint(java.lang.CharSequence in)

  Diagnostic print of the contents of a CharSequence

### getNormalizedString

    public java.lang.String getNormalizedString(int mode)

  Gets the normalizedString attribute of the FastStringBuffer object

  Parameters:
    `mode` - Description of the Parameter
  Returns:
    The normalizedString value

### getNormalizedString

    public java.lang.StringBuffer getNormalizedString(java.lang.StringBuffer sb,
                                                      int mode)

  Gets the normalizedString attribute of the FastStringBuffer object

  Parameters:
    `sb` - Description of the Parameter
    `mode` - Description of the Parameter
  Returns:
    The normalizedString value

Copyright (C) Wolfgang Meier. All rights reserved.