Package: org.apache.groovy.json.internal

## [Java] Class CharBuf

- org.apache.groovy.json.internal.CharBuf

- All Implemented Interfaces and Traits:
    CharSequence

      public class CharBuf
      extends Writer
      implements CharSequence

  Growable character buffer used by the JSON internals.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected char[]` | `buffer` | Backing storage for buffered characters.
    `protected int` | `capacity` | Current backing-array capacity.
    `protected int` | `location` | Next write position in buffer.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `CharBuf(char[] buffer)` Wraps an existing character buffer.
    `CharBuf(byte[] bytes)` Decodes UTF-8 bytes into the backing character buffer.
    `protected CharBuf(int capacity)` Creates a growable buffer with the supplied initial capacity.
    `protected CharBuf()` Creates a growable buffer with the default capacity.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `_len(int location)` Sets the current logical buffer length.
    `` | `public final CharBuf` | `add(String str)` Appends a string.
    `` | `public final CharBuf` | `add(int i)` Appends an int value.
    `` | `public final CharBuf` | `add(boolean b)` Appends a boolean value using cached JSON literals.
    `` | `public final CharBuf` | `add(byte i)` Appends a byte value.
    `` | `public final CharBuf` | `add(short i)` Appends a short value.
    `` | `public final CharBuf` | `add(long l)` Appends a long value.
    `` | `public final CharBuf` | `add(double d)` Appends a double value.
    `` | `public final CharBuf` | `add(float d)` Appends a float value.
    `` | `public CharBuf` | `add(char[] chars)` Appends a character array.
    `` | `public CharBuf` | `add(char[] chars, int length)` Appends a fixed-length prefix of a character array.
    `` | `public CharBuf` | `add(byte[] chars)` Appends a byte array as characters.
    `` | `public CharBuf` | `add(byte[] bytes, int start, int end)` Appends a byte subrange as characters.
    `` | `public final CharBuf` | `add(char ch)` Appends a single character.
    `` | `public CharBuf` | `addBigDecimal(BigDecimal key)` Appends a BigDecimal using cached character data.
    `` | `public CharBuf` | `addBigInteger(BigInteger key)` Appends a BigInteger using cached character data.
    `` | `public final CharBuf` | `addBoolean(boolean b)` Appends a boolean value.
    `` | `public final CharBuf` | `addByte(byte i)` Appends a byte value as a character digit sequence.
    `` | `public final CharBuf` | `addChar(byte i)` Appends a byte as a single character.
    `` | `public final CharBuf` | `addChar(int i)` Appends an int as a single character.
    `` | `public final CharBuf` | `addChar(short i)` Appends a short as a single character.
    `` | `public final CharBuf` | `addChar(char ch)` Appends a character.
    `` | `public final CharBuf` | `addChars(char[] chars)` Appends a character array using System.arraycopy.
    `` | `public final CharBuf` | `addDouble(double d)` Appends a double value using cached character data when available.
    `` | `public final CharBuf` | `addDouble(Double key)` Appends a Double using cached character data.
    `` | `public final CharBuf` | `addFloat(float d)` Appends a float value using cached character data when available.
    `` | `public final CharBuf` | `addFloat(Float key)` Appends a Float using cached character data.
    `` | `public final CharBuf` | `addInt(int i)` Appends an int value using cached character data when available.
    `` | `public final CharBuf` | `addInt(Integer key)` Appends an Integer using cached character data.
    `` | `public final CharBuf` | `addJsonEscapedString(String jsonString)` Appends a quoted JSON string with escaping enabled.
    `` | `public final CharBuf` | `addJsonEscapedString(String jsonString, boolean disableUnicodeEscaping)` Appends a quoted JSON string.
    `` | `public final CharBuf` | `addJsonEscapedString(char[] charArray)` Appends a quoted JSON string with escaping enabled.
    `` | `public final CharBuf` | `addJsonEscapedString(char[] charArray, boolean disableUnicodeEscaping)` Appends a quoted JSON string from a character array.
    `` | `public final CharBuf` | `addJsonFieldName(String str)` Appends a quoted JSON field name followed by a colon.
    `` | `public final CharBuf` | `addJsonFieldName(String str, boolean disableUnicodeEscaping)` Appends a quoted JSON field name followed by a colon.
    `` | `public final CharBuf` | `addJsonFieldName(char[] chars)` Appends a quoted JSON field name followed by a colon.
    `` | `public final CharBuf` | `addJsonFieldName(char[] chars, boolean disableUnicodeEscaping)` Appends a quoted JSON field name followed by a colon.
    `` | `public CharBuf` | `addLine(String str)` Appends a line followed by a newline character.
    `` | `public CharBuf` | `addLine(CharSequence str)` Appends a character sequence followed by a newline character.
    `` | `public final CharBuf` | `addLong(long l)` Appends a long value using cached character data when available.
    `` | `public final CharBuf` | `addLong(Long key)` Appends a Long using cached character data.
    `` | `public final void` | `addNull()` Appends the JSON literal `null`.
    `` | `public final CharBuf` | `addQuoted(char[] chars)` Appends a quoted character array without escaping.
    `` | `public final CharBuf` | `addQuoted(String str)` Appends a quoted string without escaping.
    `` | `public final CharBuf` | `addShort(short i)` Appends a short value as a character digit sequence.
    `` | `public final CharBuf` | `addString(String str)` Appends a string.
    `` | `public byte` | `byteValue()` Parses the buffered characters as a `byte`.
    `` | `public char` | `charAt(int index)` {@inheritDoc}
    `` | `public void` | `close()` No-op for this in-memory buffer.
    `` | `public static CharBuf` | `create(int capacity)` Creates a growable buffer with the supplied capacity.
    `` | `public static CharBuf` | `create(char[] buffer)` Wraps the supplied character buffer.
    `` | `public static CharBuf` | `createExact(int capacity)` Creates a buffer sized exactly for the requested capacity.
    `` | `public final CharBuf` | `decodeJsonString(char[] chars)` Decodes a JSON string fragment into this buffer.
    `` | `public final CharBuf` | `decodeJsonString(char[] chars, int start, int to)` Decodes a JSON string subrange into this buffer.
    `` | `public double` | `doubleValue()` Parses the buffered characters as a `double`.
    `` | `public float` | `floatValue()` Parses the buffered characters as a `float`.
    `` | `public void` | `flush()` No-op for this in-memory buffer.
    `` | `public void` | `init()` Allocates the backing array from the current capacity.
    `` | `public int` | `intValue()` Parses the buffered characters as an `int`.
    `` | `public int` | `len()` Returns the current buffer length.
    `` | `public int` | `length()` {@inheritDoc}
    `` | `public long` | `longValue()` Parses the buffered characters as a `long`.
    `` | `public char[]` | `readForRecycle()` Returns the backing array and resets the write position.
    `` | `public void` | `recycle()` Resets the write position without clearing the backing array.
    `` | `public void` | `removeLastChar()` Removes the last character when the buffer is not empty.
    `` | `public void` | `removeLastChar(char expect)` Removes the last character when it matches the expected value.
    `` | `public short` | `shortValue()` Parses the buffered characters as a `short`.
    `` | `public CharSequence` | `subSequence(int start, int end)` {@inheritDoc}
    `` | `public char[]` | `toCharArray()` Returns the backing character array.
    `` | `public String` | `toDebugString()` Returns a debug view of the current buffer state.
    `` | `public Number` | `toIntegerWrapper()` Parses the buffered characters as either an `Integer` or `Long`.
    `` | `public String` | `toString()` Returns the buffered characters as a string.
    `` | `public String` | `toStringAndRecycle()` Returns the buffered text and resets the write position.
    `` | `public void` | `write(char[] cbuf, int off, int len)` {@inheritDoc}

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Writer` | `append, append, append, append, append, append, close, equals, flush, getClass, hashCode, notify, notifyAll, nullWriter, toString, wait, wait, wait, write, write, write, write, write`

- - ### Field Detail

    - #### protected char[] buffer

      Backing storage for buffered characters.

    - #### protected int capacity

      Current backing-array capacity.

    - #### protected int location

      Next write position in buffer.

  - ### Constructor Detail

    - #### public CharBuf(char[] buffer)

      Wraps an existing character buffer.

    - #### public CharBuf(byte[] bytes)

      Decodes UTF-8 bytes into the backing character buffer.

    - #### protected CharBuf(int capacity)

      Creates a growable buffer with the supplied initial capacity.

    - #### protected CharBuf()

      Creates a growable buffer with the default capacity.

  - ### Method Detail

    - #### public void _len(int location)

      Sets the current logical buffer length.

    - #### public final CharBuf add(String str)

      Appends a string.

    - #### public final CharBuf add(int i)

      Appends an int value.

    - #### public final CharBuf add(boolean b)

      Appends a boolean value using cached JSON literals.

    - #### public final CharBuf add(byte i)

      Appends a byte value.

    - #### public final CharBuf add(short i)

      Appends a short value.

    - #### public final CharBuf add(long l)

      Appends a long value.

    - #### public final CharBuf add(double d)

      Appends a double value.

    - #### public final CharBuf add(float d)

      Appends a float value.

    - #### public CharBuf add(char[] chars)

      Appends a character array.

    - #### public CharBuf add(char[] chars, int length)

      Appends a fixed-length prefix of a character array.

    - #### public CharBuf add(byte[] chars)

      Appends a byte array as characters.

    - #### public CharBuf add(byte[] bytes, int start, int end)

      Appends a byte subrange as characters.

    - #### public final CharBuf add(char ch)

      Appends a single character.

    - #### public CharBuf addBigDecimal(BigDecimal key)

      Appends a BigDecimal using cached character data.

    - #### public CharBuf addBigInteger(BigInteger key)

      Appends a BigInteger using cached character data.

    - #### public final CharBuf addBoolean(boolean b)

      Appends a boolean value.

    - #### public final CharBuf addByte(byte i)

      Appends a byte value as a character digit sequence.

    - #### public final CharBuf addChar(byte i)

      Appends a byte as a single character.

    - #### public final CharBuf addChar(int i)

      Appends an int as a single character.

    - #### public final CharBuf addChar(short i)

      Appends a short as a single character.

    - #### public final CharBuf addChar(char ch)

      Appends a character.

    - #### public final CharBuf addChars(char[] chars)

      Appends a character array using System.arraycopy.

    - #### public final CharBuf addDouble(double d)

      Appends a double value using cached character data when available.

    - #### public final CharBuf addDouble(Double key)

      Appends a Double using cached character data.

    - #### public final CharBuf addFloat(float d)

      Appends a float value using cached character data when available.

    - #### public final CharBuf addFloat(Float key)

      Appends a Float using cached character data.

    - #### public final CharBuf addInt(int i)

      Appends an int value using cached character data when available.

    - #### public final CharBuf addInt(Integer key)

      Appends an Integer using cached character data.

    - #### public final CharBuf addJsonEscapedString(String jsonString)

      Appends a quoted JSON string with escaping enabled.

    - #### public final CharBuf addJsonEscapedString(String jsonString, boolean disableUnicodeEscaping)

      Appends a quoted JSON string.

    - #### public final CharBuf addJsonEscapedString(char[] charArray)

      Appends a quoted JSON string with escaping enabled.

    - #### public final CharBuf addJsonEscapedString(char[] charArray, boolean disableUnicodeEscaping)

      Appends a quoted JSON string from a character array.

    - #### public final CharBuf addJsonFieldName(String str)

      Appends a quoted JSON field name followed by a colon.

    - #### public final CharBuf addJsonFieldName(String str, boolean disableUnicodeEscaping)

      Appends a quoted JSON field name followed by a colon.

    - #### public final CharBuf addJsonFieldName(char[] chars)

      Appends a quoted JSON field name followed by a colon.

    - #### public final CharBuf addJsonFieldName(char[] chars, boolean disableUnicodeEscaping)

      Appends a quoted JSON field name followed by a colon.

    - #### public CharBuf addLine(String str)

      Appends a line followed by a newline character.

    - #### public CharBuf addLine(CharSequence str)

      Appends a character sequence followed by a newline character.

    - #### public final CharBuf addLong(long l)

      Appends a long value using cached character data when available.

    - #### public final CharBuf addLong(Long key)

      Appends a Long using cached character data.

    - #### public final void addNull()

      Appends the JSON literal `null`.

    - #### public final CharBuf addQuoted(char[] chars)

      Appends a quoted character array without escaping.

    - #### public final CharBuf addQuoted(String str)

      Appends a quoted string without escaping.

    - #### public final CharBuf addShort(short i)

      Appends a short value as a character digit sequence.

    - #### public final CharBuf addString(String str)

      Appends a string.

    - #### public byte byteValue()

      Parses the buffered characters as a `byte`.

    - #### public char charAt(int index)

      {@inheritDoc}

    - #### public void close()

      No-op for this in-memory buffer.

    - #### public static CharBuf create(int capacity)

      Creates a growable buffer with the supplied capacity.

    - #### public static CharBuf create(char[] buffer)

      Wraps the supplied character buffer.

    - #### public static CharBuf createExact(int capacity)

      Creates a buffer sized exactly for the requested capacity.

    - #### public final CharBuf decodeJsonString(char[] chars)

      Decodes a JSON string fragment into this buffer.

    - #### public final CharBuf decodeJsonString(char[] chars, int start, int to)

      Decodes a JSON string subrange into this buffer.

    - #### public double doubleValue()

      Parses the buffered characters as a `double`.

    - #### public float floatValue()

      Parses the buffered characters as a `float`.

    - #### public void flush()

      No-op for this in-memory buffer.

    - #### public void init()

      Allocates the backing array from the current capacity.

    - #### public int intValue()

      Parses the buffered characters as an `int`.

    - #### public int len()

      Returns the current buffer length.

    - #### public int length()

      {@inheritDoc}

    - #### public long longValue()

      Parses the buffered characters as a `long`.

    - #### public char[] readForRecycle()

      Returns the backing array and resets the write position.

    - #### public void recycle()

      Resets the write position without clearing the backing array.

    - #### public void removeLastChar()

      Removes the last character when the buffer is not empty.

    - #### public void removeLastChar(char expect)

      Removes the last character when it matches the expected value.

    - #### public short shortValue()

      Parses the buffered characters as a `short`.

    - #### public CharSequence subSequence(int start, int end)

      {@inheritDoc}

    - #### public char[] toCharArray()

      Returns the backing character array.

    - #### public String toDebugString()

      Returns a debug view of the current buffer state.

    - #### public Number toIntegerWrapper()

      Parses the buffered characters as either an `Integer` or `Long`.

    - #### public String toString()

      Returns the buffered characters as a string.

    - #### public String toStringAndRecycle()

      Returns the buffered text and resets the write position.

    - #### public void write(char[] cbuf, int off, int len)

      {@inheritDoc}