Package com.fasterxml.jackson.core.io
Class SerializedString
java.lang.Object
com.fasterxml.jackson.core.io.SerializedString
- All Implemented Interfaces:
SerializableString
,Serializable
String token that can lazily serialize String contained and then reuse that
serialization later on. This is similar to JDBC prepared statements, for example,
in that instances should only be created when they are used more than use;
prime candidates are various serializers.
Class is final for performance reasons and since this is not designed to be extensible or customizable (customizations would occur in calling code)
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
appendQuoted
(char[] buffer, int offset) Method that will append quoted characters of this String into given buffer.int
appendQuotedUTF8
(byte[] buffer, int offset) Method that will append quoted UTF-8 bytes of this String into given buffer, if there is enough room; if not, returns -1.int
appendUnquoted
(char[] buffer, int offset) Method that will append unquoted characters of this String into given buffer.int
appendUnquotedUTF8
(byte[] buffer, int offset) Method that will append unquoted ('raw') UTF-8 bytes of this String into given buffer.final char[]
Accessor for accessing value that has been quoted (escaped) using JSON quoting rules (using backslash-prefixed codes) into a char array.final byte[]
Accessor for accessing value that has been quoted (escaped) using JSON quoting rules (using backslash-prefixed codes), and encoded using UTF-8 encoding into a byte array.final byte[]
Accessor for accessing value as is (without JSON quoting (ecaping)) encoded as UTF-8 byte array.final int
Returns length of the String as charactersfinal boolean
final String
getValue()
Returns unquoted String that this object represents (and offers serialized forms for)final int
hashCode()
int
putQuotedUTF8
(ByteBuffer buffer) Method for appending JSON-escaped UTF-8 encoded String value into givenByteBuffer
, if it fits.int
putUnquotedUTF8
(ByteBuffer buffer) Method for appending unquoted ('raw') UTF-8 encoded String value into givenByteBuffer
, if it fits.protected Object
final String
toString()
int
Method for writing JSON-escaped UTF-8 encoded String value using givenOutputStream
.int
Method for writing unescaped UTF-8 encoded String value using givenOutputStream
.
-
Field Details
-
_value
-
_quotedUTF8Ref
protected byte[] _quotedUTF8Ref -
_unquotedUTF8Ref
protected byte[] _unquotedUTF8Ref -
_quotedChars
protected char[] _quotedChars -
_jdkSerializeValue
Ugly hack, to work through the requirement that _value is indeed final, and that JDK serialization won't call ctor(s).- Since:
- 2.1
-
-
Constructor Details
-
SerializedString
-
-
Method Details
-
readResolve
-
getValue
Description copied from interface:SerializableString
Returns unquoted String that this object represents (and offers serialized forms for)- Specified by:
getValue
in interfaceSerializableString
- Returns:
- Unquoted String
-
charLength
public final int charLength()Returns length of the String as characters- Specified by:
charLength
in interfaceSerializableString
- Returns:
- Length of the String in characters
-
asQuotedChars
public final char[] asQuotedChars()Accessor for accessing value that has been quoted (escaped) using JSON quoting rules (using backslash-prefixed codes) into a char array.- Specified by:
asQuotedChars
in interfaceSerializableString
- Returns:
- JSON quoted form of the String as
char[]
-
asQuotedUTF8
public final byte[] asQuotedUTF8()Accessor for accessing value that has been quoted (escaped) using JSON quoting rules (using backslash-prefixed codes), and encoded using UTF-8 encoding into a byte array.- Specified by:
asQuotedUTF8
in interfaceSerializableString
- Returns:
- UTF-8 encoded version of JSON-escaped String
-
asUnquotedUTF8
public final byte[] asUnquotedUTF8()Accessor for accessing value as is (without JSON quoting (ecaping)) encoded as UTF-8 byte array.- Specified by:
asUnquotedUTF8
in interfaceSerializableString
- Returns:
- UTF-8 encoded version of String, without any escaping
-
appendQuoted
public int appendQuoted(char[] buffer, int offset) Description copied from interface:SerializableString
Method that will append quoted characters of this String into given buffer. Functionally equivalent to:char[] ch = str.asQuotedChars(); System.arraycopy(ch, 0, buffer, offset, ch.length); return ch.length;
- Specified by:
appendQuoted
in interfaceSerializableString
- Parameters:
buffer
- Buffer to append JSON-escaped String intooffset
- Offset inbuffer
to append String at- Returns:
- Number of characters appended, if successful, otherwise -1
-
appendQuotedUTF8
public int appendQuotedUTF8(byte[] buffer, int offset) Description copied from interface:SerializableString
Method that will append quoted UTF-8 bytes of this String into given buffer, if there is enough room; if not, returns -1. Functionally equivalent to:byte[] bytes = str.asQuotedUTF8(); System.arraycopy(bytes, 0, buffer, offset, bytes.length); return bytes.length;
- Specified by:
appendQuotedUTF8
in interfaceSerializableString
- Parameters:
buffer
- Buffer to append JSON-escaped String intooffset
- Offset inbuffer
to append String at- Returns:
- Number of bytes appended, if successful, otherwise -1
-
appendUnquoted
public int appendUnquoted(char[] buffer, int offset) Description copied from interface:SerializableString
Method that will append unquoted characters of this String into given buffer. Functionally equivalent to:char[] ch = str.getValue().toCharArray(); System.arraycopy(bytes, 0, buffer, offset, ch.length); return ch.length;
- Specified by:
appendUnquoted
in interfaceSerializableString
- Parameters:
buffer
- Buffer to append literal (unescaped) String intooffset
- Offset inbuffer
to append String at- Returns:
- Number of characters appended, if successful, otherwise -1
-
appendUnquotedUTF8
public int appendUnquotedUTF8(byte[] buffer, int offset) Description copied from interface:SerializableString
Method that will append unquoted ('raw') UTF-8 bytes of this String into given buffer. Functionally equivalent to:byte[] bytes = str.asUnquotedUTF8(); System.arraycopy(bytes, 0, buffer, offset, bytes.length); return bytes.length;
- Specified by:
appendUnquotedUTF8
in interfaceSerializableString
- Parameters:
buffer
- Buffer to append literal (unescaped) String intooffset
- Offset inbuffer
to append String at- Returns:
- Number of bytes appended, if successful, otherwise -1
-
writeQuotedUTF8
Description copied from interface:SerializableString
Method for writing JSON-escaped UTF-8 encoded String value using givenOutputStream
.- Specified by:
writeQuotedUTF8
in interfaceSerializableString
- Parameters:
out
-OutputStream
to write String into- Returns:
- Number of bytes written
- Throws:
IOException
- if underlying stream write fails
-
writeUnquotedUTF8
Description copied from interface:SerializableString
Method for writing unescaped UTF-8 encoded String value using givenOutputStream
.- Specified by:
writeUnquotedUTF8
in interfaceSerializableString
- Parameters:
out
-OutputStream
to write String into- Returns:
- Number of bytes written
- Throws:
IOException
- if underlying stream write fails
-
putQuotedUTF8
Description copied from interface:SerializableString
Method for appending JSON-escaped UTF-8 encoded String value into givenByteBuffer
, if it fits.- Specified by:
putQuotedUTF8
in interfaceSerializableString
- Parameters:
buffer
-ByteBuffer
to append String into- Returns:
- Number of bytes put, if contents fit, otherwise -1
-
putUnquotedUTF8
Description copied from interface:SerializableString
Method for appending unquoted ('raw') UTF-8 encoded String value into givenByteBuffer
, if it fits.- Specified by:
putUnquotedUTF8
in interfaceSerializableString
- Parameters:
buffer
-ByteBuffer
to append String into- Returns:
- Number of bytes put, if contents fit, otherwise -1
-
toString
-
hashCode
public final int hashCode() -
equals
-