Package org.apache.groovy.json.internal
Class CharBuf
java.lang.Object
java.io.Writer
org.apache.groovy.json.internal.CharBuf
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable,CharSequence
Growable character buffer used by the JSON internals.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected char[]Backing storage for buffered characters.protected intCurrent backing-array capacity.protected intNext write position inbuffer. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCharBuf()Creates a growable buffer with the default capacity.CharBuf(byte[] bytes) Decodes UTF-8 bytes into the backing character buffer.CharBuf(char[] buffer) Wraps an existing character buffer.protectedCharBuf(int capacity) Creates a growable buffer with the supplied initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoid_len(int location) Sets the current logical buffer length.final CharBufadd(boolean b) Appends a boolean value using cached JSON literals.final CharBufadd(byte i) Appends a byte value.add(byte[] chars) Appends a byte array as characters.add(byte[] bytes, int start, int end) Appends a byte subrange as characters.final CharBufadd(char ch) Appends a single character.add(char[] chars) Appends a character array.add(char[] chars, int length) Appends a fixed-length prefix of a character array.final CharBufadd(double d) Appends a double value.final CharBufadd(float d) Appends a float value.final CharBufadd(int i) Appends an int value.final CharBufadd(long l) Appends a long value.final CharBufadd(short i) Appends a short value.final CharBufAppends a string.addBigDecimal(BigDecimal key) Appends aBigDecimalusing cached character data.addBigInteger(BigInteger key) Appends aBigIntegerusing cached character data.final CharBufaddBoolean(boolean b) Appends a boolean value.final CharBufaddByte(byte i) Appends a byte value as a character digit sequence.final CharBufaddChar(byte i) Appends a byte as a single character.final CharBufaddChar(char ch) Appends a character.final CharBufaddChar(int i) Appends an int as a single character.final CharBufaddChar(short i) Appends a short as a single character.final CharBufaddChars(char[] chars) Appends a character array usingSystem.arraycopy(Object, int, Object, int, int).final CharBufaddDouble(double d) Appends a double value using cached character data when available.final CharBufAppends aDoubleusing cached character data.final CharBufaddFloat(float d) Appends a float value using cached character data when available.final CharBufAppends aFloatusing cached character data.final CharBufaddInt(int i) Appends an int value using cached character data when available.final CharBufAppends anIntegerusing cached character data.final CharBufaddJsonEscapedString(char[] charArray) Appends a quoted JSON string with escaping enabled.final CharBufaddJsonEscapedString(char[] charArray, boolean disableUnicodeEscaping) Appends a quoted JSON string from a character array.final CharBufaddJsonEscapedString(String jsonString) Appends a quoted JSON string with escaping enabled.final CharBufaddJsonEscapedString(String jsonString, boolean disableUnicodeEscaping) Appends a quoted JSON string.final CharBufaddJsonFieldName(char[] chars) Appends a quoted JSON field name followed by a colon.final CharBufaddJsonFieldName(char[] chars, boolean disableUnicodeEscaping) Appends a quoted JSON field name followed by a colon.final CharBufaddJsonFieldName(String str) Appends a quoted JSON field name followed by a colon.final CharBufaddJsonFieldName(String str, boolean disableUnicodeEscaping) Appends a quoted JSON field name followed by a colon.addLine(CharSequence str) Appends a character sequence followed by a newline character.Appends a line followed by a newline character.final CharBufaddLong(long l) Appends a long value using cached character data when available.final CharBufAppends aLongusing cached character data.final voidaddNull()Appends the JSON literalnull.final CharBufaddQuoted(char[] chars) Appends a quoted character array without escaping.final CharBufAppends a quoted string without escaping.final CharBufaddShort(short i) Appends a short value as a character digit sequence.final CharBufAppends a string.byteParses the buffered characters as abyte.charcharAt(int index) voidclose()No-op for this in-memory buffer.static CharBufcreate(char[] buffer) Wraps the supplied character buffer.static CharBufcreate(int capacity) Creates a growable buffer with the supplied capacity.static CharBufcreateExact(int capacity) Creates a buffer sized exactly for the requested capacity.final CharBufdecodeJsonString(char[] chars) Decodes a JSON string fragment into this buffer.final CharBufdecodeJsonString(char[] chars, int start, int to) Decodes a JSON string subrange into this buffer.doubleParses the buffered characters as adouble.floatParses the buffered characters as afloat.voidflush()No-op for this in-memory buffer.voidinit()Allocates the backing array from the current capacity.intintValue()Parses the buffered characters as anint.intlen()Returns the current buffer length.intlength()longParses the buffered characters as along.char[]Returns the backing array and resets the write position.voidrecycle()Resets the write position without clearing the backing array.voidRemoves the last character when the buffer is not empty.voidremoveLastChar(char expect) Removes the last character when it matches the expected value.shortParses the buffered characters as ashort.subSequence(int start, int end) char[]Returns the backing character array.Returns a debug view of the current buffer state.Parses the buffered characters as either anIntegerorLong.toString()Returns the buffered characters as a string.Returns the buffered text and resets the write position.voidwrite(char[] cbuf, int off, int len) Methods inherited from class java.io.Writer
append, append, append, nullWriter, write, write, write, writeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
capacity
protected int capacityCurrent backing-array capacity. -
location
protected int locationNext write position inbuffer. -
buffer
protected char[] bufferBacking 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
Creates a buffer sized exactly for the requested capacity. -
create
Creates a growable buffer with the supplied capacity. -
create
Wraps the supplied character buffer. -
write
public void write(char[] cbuf, int off, int len) -
flush
No-op for this in-memory buffer.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
No-op for this in-memory buffer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
init
public void init()Allocates the backing array from the current capacity. -
add
Appends a string. -
addString
Appends a string. -
add
Appends an int value. -
addInt
Appends an int value using cached character data when available. -
addInt
Appends anIntegerusing cached character data. -
add
Appends a boolean value using cached JSON literals. -
addBoolean
Appends a boolean value. -
add
Appends a byte value. -
addByte
Appends a byte value as a character digit sequence. -
add
Appends a short value. -
addShort
Appends a short value as a character digit sequence. -
add
Appends a long value. -
add
Appends a double value. -
addDouble
Appends a double value using cached character data when available. -
addDouble
Appends aDoubleusing cached character data. -
add
Appends a float value. -
addFloat
Appends a float value using cached character data when available. -
addFloat
Appends aFloatusing cached character data. -
addChar
Appends a byte as a single character. -
addChar
Appends an int as a single character. -
addChar
Appends a short as a single character. -
addChar
Appends a character. -
addLine
Appends a line followed by a newline character. -
addLine
Appends a character sequence followed by a newline character. -
add
Appends a character array. -
addChars
Appends a character array usingSystem.arraycopy(Object, int, Object, int, int). -
addQuoted
Appends a quoted character array without escaping. -
addJsonEscapedString
Appends a quoted JSON string with escaping enabled. -
addJsonEscapedString
Appends a quoted JSON string. -
addJsonEscapedString
Appends a quoted JSON string with escaping enabled. -
addJsonEscapedString
Appends a quoted JSON string from a character array. -
addJsonFieldName
Appends a quoted JSON field name followed by a colon. -
addJsonFieldName
Appends a quoted JSON field name followed by a colon. -
addJsonFieldName
Appends a quoted JSON field name followed by a colon. -
addJsonFieldName
Appends a quoted JSON field name followed by a colon. -
addQuoted
Appends a quoted string without escaping. -
add
Appends a fixed-length prefix of a character array. -
add
Appends a byte array as characters. -
add
Appends a byte subrange as characters. -
add
Appends a single character. -
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
toString
Returns the buffered characters as a string.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
toDebugString
Returns a debug view of the current buffer state. -
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 adouble. -
floatValue
public float floatValue()Parses the buffered characters as afloat. -
intValue
public int intValue()Parses the buffered characters as anint. -
longValue
public long longValue()Parses the buffered characters as along. -
byteValue
public byte byteValue()Parses the buffered characters as abyte. -
shortValue
public short shortValue()Parses the buffered characters as ashort. -
toIntegerWrapper
Parses the buffered characters as either anIntegerorLong. -
addNull
public final void addNull()Appends the JSON literalnull. -
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
Appends aBigDecimalusing cached character data. -
addBigInteger
Appends aBigIntegerusing cached character data. -
addLong
Appends a long value using cached character data when available. -
addLong
Appends aLongusing cached character data. -
decodeJsonString
Decodes a JSON string fragment into this buffer. -
decodeJsonString
Decodes a JSON string subrange into this buffer.
-