Class CharBuf

java.lang.Object
java.io.Writer
org.apache.groovy.json.internal.CharBuf
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable, CharSequence

public class CharBuf extends Writer implements CharSequence
Growable character buffer used by the JSON internals.
  • Field Details

    • capacity

      protected int capacity
      Current backing-array capacity.
    • location

      protected int location
      Next write position in buffer.
    • buffer

      protected char[] buffer
      Backing storage for buffered characters.
  • Constructor Details

    • CharBuf

      public CharBuf(char[] buffer)
      Wraps an existing character buffer.
    • CharBuf

      public CharBuf(byte[] bytes)
      Decodes UTF-8 bytes into the backing character buffer.
    • CharBuf

      protected CharBuf(int capacity)
      Creates a growable buffer with the supplied initial capacity.
    • CharBuf

      protected CharBuf()
      Creates a growable buffer with the default capacity.
  • Method Details

    • createExact

      public static CharBuf createExact(int capacity)
      Creates a buffer sized exactly for the requested capacity.
    • create

      public static CharBuf create(int capacity)
      Creates a growable buffer with the supplied capacity.
    • create

      public static CharBuf create(char[] buffer)
      Wraps the supplied character buffer.
    • write

      public void write(char[] cbuf, int off, int len)
      Specified by:
      write in class Writer
    • flush

      public void flush() throws IOException
      No-op for this in-memory buffer.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
      Throws:
      IOException
    • close

      public void close() throws IOException
      No-op for this in-memory buffer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException
    • init

      public void init()
      Allocates the backing array from the current capacity.
    • add

      public final CharBuf add(String str)
      Appends a string.
    • addString

      public final CharBuf addString(String str)
      Appends a string.
    • add

      public final CharBuf add(int i)
      Appends an int value.
    • addInt

      public final CharBuf addInt(int i)
      Appends an int value using cached character data when available.
    • addInt

      public final CharBuf addInt(Integer key)
      Appends an Integer using cached character data.
    • add

      public final CharBuf add(boolean b)
      Appends a boolean value using cached JSON literals.
    • addBoolean

      public final CharBuf addBoolean(boolean b)
      Appends a boolean value.
    • add

      public final CharBuf add(byte i)
      Appends a byte value.
    • addByte

      public final CharBuf addByte(byte i)
      Appends a byte value as a character digit sequence.
    • add

      public final CharBuf add(short i)
      Appends a short value.
    • addShort

      public final CharBuf addShort(short i)
      Appends a short value as a character digit sequence.
    • add

      public final CharBuf add(long l)
      Appends a long value.
    • add

      public final CharBuf add(double d)
      Appends a double value.
    • addDouble

      public final CharBuf addDouble(double d)
      Appends a double value using cached character data when available.
    • addDouble

      public final CharBuf addDouble(Double key)
      Appends a Double using cached character data.
    • add

      public final CharBuf add(float d)
      Appends a float value.
    • addFloat

      public final CharBuf addFloat(float d)
      Appends a float value using cached character data when available.
    • addFloat

      public final CharBuf addFloat(Float key)
      Appends a Float using cached character data.
    • addChar

      public final CharBuf addChar(byte i)
      Appends a byte as a single character.
    • addChar

      public final CharBuf addChar(int i)
      Appends an int as a single character.
    • addChar

      public final CharBuf addChar(short i)
      Appends a short as a single character.
    • addChar

      public final CharBuf addChar(char ch)
      Appends a character.
    • addLine

      public CharBuf addLine(String str)
      Appends a line followed by a newline character.
    • addLine

      public CharBuf addLine(CharSequence str)
      Appends a character sequence followed by a newline character.
    • add

      public CharBuf add(char[] chars)
      Appends a character array.
    • addChars

      public final CharBuf addChars(char[] chars)
      Appends a character array using System.arraycopy(Object, int, Object, int, int).
    • addQuoted

      public final CharBuf addQuoted(char[] chars)
      Appends a quoted character array without escaping.
    • addJsonEscapedString

      public final CharBuf addJsonEscapedString(String jsonString)
      Appends a quoted JSON string with escaping enabled.
    • addJsonEscapedString

      public final CharBuf addJsonEscapedString(String jsonString, boolean disableUnicodeEscaping)
      Appends a quoted JSON string.
    • addJsonEscapedString

      public final CharBuf addJsonEscapedString(char[] charArray)
      Appends a quoted JSON string with escaping enabled.
    • addJsonEscapedString

      public final CharBuf addJsonEscapedString(char[] charArray, boolean disableUnicodeEscaping)
      Appends a quoted JSON string from a character array.
    • addJsonFieldName

      public final CharBuf addJsonFieldName(String str)
      Appends a quoted JSON field name followed by a colon.
    • addJsonFieldName

      public final CharBuf addJsonFieldName(String str, boolean disableUnicodeEscaping)
      Appends a quoted JSON field name followed by a colon.
    • addJsonFieldName

      public final CharBuf addJsonFieldName(char[] chars)
      Appends a quoted JSON field name followed by a colon.
    • addJsonFieldName

      public final CharBuf addJsonFieldName(char[] chars, boolean disableUnicodeEscaping)
      Appends a quoted JSON field name followed by a colon.
    • addQuoted

      public final CharBuf addQuoted(String str)
      Appends a quoted string without escaping.
    • add

      public CharBuf add(char[] chars, int length)
      Appends a fixed-length prefix of a character array.
    • add

      public CharBuf add(byte[] chars)
      Appends a byte array as characters.
    • add

      public CharBuf add(byte[] bytes, int start, int end)
      Appends a byte subrange as characters.
    • add

      public final CharBuf add(char ch)
      Appends a single character.
    • length

      public int length()
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int index)
      Specified by:
      charAt in interface CharSequence
    • subSequence

      public CharSequence subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • toString

      public String toString()
      Returns the buffered characters as a string.
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • toDebugString

      public String toDebugString()
      Returns a debug view of the current buffer state.
    • toStringAndRecycle

      public String toStringAndRecycle()
      Returns the buffered text and resets the write position.
    • len

      public int len()
      Returns the current buffer length.
    • toCharArray

      public char[] toCharArray()
      Returns the backing character array.
    • _len

      public void _len(int location)
      Sets the current logical buffer length.
    • readForRecycle

      public char[] readForRecycle()
      Returns the backing array and resets the write position.
    • recycle

      public void recycle()
      Resets the write position without clearing the backing array.
    • doubleValue

      public double doubleValue()
      Parses the buffered characters as a double.
    • floatValue

      public float floatValue()
      Parses the buffered characters as a float.
    • intValue

      public int intValue()
      Parses the buffered characters as an int.
    • longValue

      public long longValue()
      Parses the buffered characters as a long.
    • byteValue

      public byte byteValue()
      Parses the buffered characters as a byte.
    • shortValue

      public short shortValue()
      Parses the buffered characters as a short.
    • toIntegerWrapper

      public Number toIntegerWrapper()
      Parses the buffered characters as either an Integer or Long.
    • addNull

      public final void addNull()
      Appends the JSON literal null.
    • removeLastChar

      public void removeLastChar()
      Removes the last character when the buffer is not empty.
    • removeLastChar

      public void removeLastChar(char expect)
      Removes the last character when it matches the expected value.
    • addBigDecimal

      public CharBuf addBigDecimal(BigDecimal key)
      Appends a BigDecimal using cached character data.
    • addBigInteger

      public CharBuf addBigInteger(BigInteger key)
      Appends a BigInteger using cached character data.
    • addLong

      public final CharBuf addLong(long l)
      Appends a long value using cached character data when available.
    • addLong

      public final CharBuf addLong(Long key)
      Appends a Long using cached character data.
    • decodeJsonString

      public final CharBuf decodeJsonString(char[] chars)
      Decodes a JSON string fragment into this buffer.
    • decodeJsonString

      public final CharBuf decodeJsonString(char[] chars, int start, int to)
      Decodes a JSON string subrange into this buffer.