Top Description Inners Constructors Methods
com.amazon.ion.util

public Class IonTextUtils

extends Object
Class Inheritance
Static Imports
com.amazon.ion.impl._Private_IonConstants.isHighSurrogate, ._Private_IonConstants.isLowSurrogate, ._Private_IonConstants.makeUnicodeScalar, ._Private_IonTextAppender.ZERO_PADDING, ._Private_IonTextAppender.isIdentifierKeyword, ._Private_IonTextAppender.symbolNeedsQuoting, ._Private_IonTextWriterBuilder.STANDARD

Utility methods for working with Ion's text-oriented data types.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
public static enum

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if charSequence consists entirely of the four legal Ion whitespace characters.
isAllWhitespace
(CharSequence
the CharSequence to test.
charSequence
)

Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return.

public static boolean
isDigit(int codePoint, int radix)

public static boolean
isIdentifierPart(int codePoint)

public static boolean
isIdentifierStart(int codePoint)

public static boolean

Returns:

true when the scalar can legally follow an Ion number. Returns false for the slash character '/'.
isNumericStop
(int
the Unicode scalar to test.
codePoint
)

Determines whether a given code point is one of the valid Ion numeric terminators.

public static boolean
isOperatorPart(int codePoint)

public static boolean

Returns:

true if c is one of the four legal Ion whitespace characters.
isWhitespace
(int
the character to test.
codePoint
)

Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return.

public static void
printBlob(Appendable out, byte[] value)

public static String
printBlob(byte[] value)

public static void
printClob(Appendable out, byte[] value)

public static String
printClob(byte[] value)

private static void
printCodePoint(Appendable out, int c, IonTextUtils.EscapeMode mode)

Prints a single code point, ASCII safe.

private static void
printCodePointAsEightHexDigits(Appendable out, int c)

Prints an eight-digit hex escape sequence, "\UHHHHHHHH", using lower-case for alphabetics.

private static void
printCodePointAsFourHexDigits(Appendable out, int c)

Generates a four-digit hex escape sequence, "\uHHHH", using lower-case for alphabetics.

public static String
printCodePointAsString(int
a Unicode code point.
codePoint
)

Builds a String denoting an ASCII-encoded Ion string, with double-quotes surrounding a single Unicode code point.

private static void
printCodePointAsSurrogatePairHexDigits(Appendable out, int c)

Generates a surrogate pair as two four-digit hex escape sequences, "\uHHHH\uHHHH", using lower-case for alphabetics.

private static void
printCodePointAsTwoHexDigits(Appendable out, int c)

Generates a two-digit hex escape sequence, "\xHH", using lower-case for alphabetics.

private static void
public static void
public static String
public static void
printFloat(Appendable out, double value)

public static String
printFloat(double value)

public static void
public static String
public static void
printJsonCodePoint(Appendable
the stream to receive the data.
out
,
int
a Unicode code point.
codePoint
)

Prints a single Unicode code point for use in an ASCII-safe JSON string.

public static void
printJsonString(Appendable
the stream to receive the JSON data.
out
,
CharSequence
the text to print; may be null.
text
)

Prints characters as an ASCII-encoded JSON string, including surrounding double-quotes.

public static String
printLongString(CharSequence
the text to print; may be null.
text
)

Builds a String denoting an ASCII-encoded Ion "long string", including surrounding triple-quotes.

public static void
printLongString(Appendable
the stream to receive the data.
out
,
CharSequence
the text to print; may be null.
text
)

Prints characters as an ASCII-encoded Ion "long string", including surrounding triple-quotes.

public static void
printQuotedSymbol(Appendable
the stream to receive the data.
out
,
CharSequence
the symbol text; may be null.
text
)

Prints text as a single-quoted Ion symbol.

public static String
printQuotedSymbol(CharSequence
the symbol text; may be null.
text
)

Builds a String containing a single-quoted Ion symbol.

public static void
printString(Appendable
the stream to receive the data.
out
,
CharSequence
the text to print; may be null.
text
)

Prints characters as an ASCII-encoded Ion string, including surrounding double-quotes.

public static String
printString(CharSequence
the text to print; may be null.
text
)

Builds a String denoting an ASCII-encoded Ion string, including surrounding double-quotes.

public static void
printStringCodePoint(Appendable
the stream to receive the data.
out
,
int
a Unicode code point.
codePoint
)

Prints a single Unicode code point for use in an ASCII-safe Ion string.

public static void
printSymbol(Appendable
the stream to receive the Ion data.
out
,
CharSequence
the symbol text; may be null.
text
)

Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary.

public static String

Returns:

a string containing the resulting Ion data.
printSymbol
(CharSequence
the symbol text; may be null.
text
)

Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary.

public static String

Returns:

a string representing the symboltoken.
printSymbol
(SymbolToken
the symbolToken to be printed.
token
)

public static void
printSymbolCodePoint(Appendable
the stream to receive the data.
out
,
int
a Unicode code point.
codePoint
)

Prints a single Unicode code point for use in an ASCII-safe Ion symbol.

public static IonTextUtils.SymbolVariant

Returns:

the variant of the symbol.
symbolVariant
(CharSequence
must be a non-empty string.
symbol
)

Determines whether the text of a symbol represents an identifier, an operator, or a symbol that always requires (single) quotes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

IonTextUtilsback to summary
public IonTextUtils()

Method Detail

isAllWhitespaceback to summary
public static boolean isAllWhitespace(CharSequence charSequence)

Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return. This matches the definition of whitespace used by JSON.

Parameters
charSequence:CharSequence

the CharSequence to test.

Returns:boolean

true if charSequence consists entirely of the four legal Ion whitespace characters.

See Also
isWhitespace(int), RFC 4627
isDigitback to summary
public static boolean isDigit(int codePoint, int radix)
isIdentifierPartback to summary
public static boolean isIdentifierPart(int codePoint)
isIdentifierStartback to summary
public static boolean isIdentifierStart(int codePoint)
isNumericStopback to summary
public static boolean isNumericStop(int codePoint)

Determines whether a given code point is one of the valid Ion numeric terminators.

The slash character '/' is not itself a valid terminator, but if the next character is '/' or '*' then the number is followed by a comment. Since this method cannot perform the look-ahead necessary to make that determination, it returns false for the slash.

Parameters
codePoint:int

the Unicode scalar to test.

Returns:boolean

true when the scalar can legally follow an Ion number. Returns false for the slash character '/'.

isOperatorPartback to summary
public static boolean isOperatorPart(int codePoint)
isWhitespaceback to summary
public static boolean isWhitespace(int codePoint)

Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return. This matches the definition of whitespace used by JSON.

Parameters
codePoint:int

the character to test.

Returns:boolean

true if c is one of the four legal Ion whitespace characters.

See Also
RFC 4627
printBlobback to summary
public static void printBlob(Appendable out, byte[] value) throws IOException
printBlobback to summary
public static String printBlob(byte[] value)
printClobback to summary
public static void printClob(Appendable out, byte[] value) throws IOException
printClobback to summary
public static String printClob(byte[] value)
printCodePointback to summary
private static void printCodePoint(Appendable out, int c, IonTextUtils.EscapeMode mode) throws IOException

Prints a single code point, ASCII safe.

printCodePointAsEightHexDigitsback to summary
private static void printCodePointAsEightHexDigits(Appendable out, int c) throws IOException

Prints an eight-digit hex escape sequence, "\UHHHHHHHH", using lower-case for alphabetics.

printCodePointAsFourHexDigitsback to summary
private static void printCodePointAsFourHexDigits(Appendable out, int c) throws IOException

Generates a four-digit hex escape sequence, "\uHHHH", using lower-case for alphabetics.

printCodePointAsStringback to summary
public static String printCodePointAsString(int codePoint)

Builds a String denoting an ASCII-encoded Ion string, with double-quotes surrounding a single Unicode code point.

Parameters
codePoint:int

a Unicode code point.

printCodePointAsSurrogatePairHexDigitsback to summary
private static void printCodePointAsSurrogatePairHexDigits(Appendable out, int c) throws IOException

Generates a surrogate pair as two four-digit hex escape sequences, "\uHHHH\uHHHH", using lower-case for alphabetics. This for necessary for JSON when the code point is outside the BMP.

printCodePointAsTwoHexDigitsback to summary
private static void printCodePointAsTwoHexDigits(Appendable out, int c) throws IOException

Generates a two-digit hex escape sequence, "\xHH", using lower-case for alphabetics.

printCodePointsback to summary
private static void printCodePoints(Appendable out, CharSequence text, IonTextUtils.EscapeMode mode) throws IOException
Exceptions
IllegalArgumentException:
if the text contains invalid UTF-16 surrogates.
printDecimalback to summary
public static void printDecimal(Appendable out, BigDecimal decimal) throws IOException
printDecimalback to summary
public static String printDecimal(BigDecimal decimal)
printFloatback to summary
public static void printFloat(Appendable out, double value) throws IOException
printFloatback to summary
public static String printFloat(double value)
printFloatback to summary
public static void printFloat(Appendable out, Double value) throws IOException
printFloatback to summary
public static String printFloat(Double value)
printJsonCodePointback to summary
public static void printJsonCodePoint(Appendable out, int codePoint) throws IOException

Prints a single Unicode code point for use in an ASCII-safe JSON string.

Parameters
out:Appendable

the stream to receive the data.

codePoint:int

a Unicode code point.

printJsonStringback to summary
public static void printJsonString(Appendable out, CharSequence text) throws IOException

Prints characters as an ASCII-encoded JSON string, including surrounding double-quotes. If the text is null, this prints null.

Parameters
out:Appendable

the stream to receive the JSON data.

text:CharSequence

the text to print; may be null.

Exceptions
IOException:
if the Appendable throws an exception.
IllegalArgumentException:
if the text contains invalid UTF-16 surrogates.
printLongStringback to summary
public static String printLongString(CharSequence text)

Builds a String denoting an ASCII-encoded Ion "long string", including surrounding triple-quotes. If the text is null, this returns "null.string".

Parameters
text:CharSequence

the text to print; may be null.

Exceptions
IllegalArgumentException:
if the text contains invalid UTF-16 surrogates.
printLongStringback to summary
public static void printLongString(Appendable out, CharSequence text) throws IOException

Prints characters as an ASCII-encoded Ion "long string", including surrounding triple-quotes. If the text is null, this prints null.string.

Parameters
out:Appendable

the stream to receive the data.

text:CharSequence

the text to print; may be null.

Exceptions
IOException:
if the Appendable throws an exception.
IllegalArgumentException:
if the text contains invalid UTF-16 surrogates.
printQuotedSymbolback to summary
public static void printQuotedSymbol(Appendable out, CharSequence text) throws IOException

Prints text as a single-quoted Ion symbol. If the text is null, this prints null.symbol.

Parameters
out:Appendable

the stream to receive the data.

text:CharSequence

the symbol text; may be null.

Exceptions
IOException:
if the Appendable throws an exception.
IllegalArgumentException:
if the text contains invalid UTF-16 surrogates.
printQuotedSymbolback to summary
public static String printQuotedSymbol(CharSequence text)

Builds a String containing a single-quoted Ion symbol. If the text is null, this returns "null.symbol".

Parameters
text:CharSequence

the symbol text; may be null.

Exceptions
IllegalArgumentException:
if the text contains invalid UTF-16 surrogates.
printStringback to summary
public static void printString(Appendable out, CharSequence text) throws IOException

Prints characters as an ASCII-encoded Ion string, including surrounding double-quotes. If the text is null, this prints null.string.

Parameters
out:Appendable

the stream to receive the data.

text:CharSequence

the text to print; may be null.

Exceptions
IOException:
if the Appendable throws an exception.
IllegalArgumentException:
if the text contains invalid UTF-16 surrogates.
printStringback to summary
public static String printString(CharSequence text)

Builds a String denoting an ASCII-encoded Ion string, including surrounding double-quotes. If the text is null, this returns "null.string".

Parameters
text:CharSequence

the text to print; may be null.

Exceptions
IllegalArgumentException:
if the text contains invalid UTF-16 surrogates.
printStringCodePointback to summary
public static void printStringCodePoint(Appendable out, int codePoint) throws IOException

Prints a single Unicode code point for use in an ASCII-safe Ion string.

Parameters
out:Appendable

the stream to receive the data.

codePoint:int

a Unicode code point.

printSymbolback to summary
public static void printSymbol(Appendable out, CharSequence text) throws IOException

Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary. Operator symbols such as '+' are quoted. If the text is null, this prints null.symbol.

Parameters
out:Appendable

the stream to receive the Ion data.

text:CharSequence

the symbol text; may be null.

Exceptions
IOException:
if the Appendable throws an exception.
See Also
printSymbol(CharSequence)
printSymbolback to summary
public static String printSymbol(CharSequence text)

Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary. Operator symbols such as '+' are quoted. If the text is null, this returns "null.symbol".

Parameters
text:CharSequence

the symbol text; may be null.

Returns:String

a string containing the resulting Ion data.

See Also
printSymbol(Appendable, CharSequence)
printSymbolback to summary
public static String printSymbol(SymbolToken token)
Parameters
token:SymbolToken

the symbolToken to be printed.

Returns:String

a string representing the symboltoken.

printSymbolCodePointback to summary
public static void printSymbolCodePoint(Appendable out, int codePoint) throws IOException

Prints a single Unicode code point for use in an ASCII-safe Ion symbol.

Parameters
out:Appendable

the stream to receive the data.

codePoint:int

a Unicode code point.

symbolVariantback to summary
public static IonTextUtils.SymbolVariant symbolVariant(CharSequence symbol)

Determines whether the text of a symbol represents an identifier, an operator, or a symbol that always requires (single) quotes.

Parameters
symbol:CharSequence

must be a non-empty string.

Returns:IonTextUtils.SymbolVariant

the variant of the symbol.

Exceptions
NullPointerException:
if symbol is null.
com.amazon.ion.util back to summary

private final Enum IonTextUtils.EscapeMode

extends Enum<IonTextUtils.EscapeMode>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final IonTextUtils.EscapeMode
public static final IonTextUtils.EscapeMode
public static final IonTextUtils.EscapeMode
public static final IonTextUtils.EscapeMode

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static IonTextUtils.EscapeMode
public static IonTextUtils.EscapeMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ION_LONG_STRINGback to summary
public static final IonTextUtils.EscapeMode ION_LONG_STRING
ION_STRINGback to summary
public static final IonTextUtils.EscapeMode ION_STRING
ION_SYMBOLback to summary
public static final IonTextUtils.EscapeMode ION_SYMBOL
JSONback to summary
public static final IonTextUtils.EscapeMode JSON

Constructor Detail

EscapeModeback to summary
private EscapeMode()

Method Detail

valueOfback to summary
public static IonTextUtils.EscapeMode valueOf(String name)
valuesback to summary
public static IonTextUtils.EscapeMode[] values()
com.amazon.ion.util back to summary

public final Enum IonTextUtils.SymbolVariant

extends Enum<IonTextUtils.SymbolVariant>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final IonTextUtils.SymbolVariant
public static final IonTextUtils.SymbolVariant
public static final IonTextUtils.SymbolVariant

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static IonTextUtils.SymbolVariant
public static IonTextUtils.SymbolVariant[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

IDENTIFIERback to summary
public static final IonTextUtils.SymbolVariant IDENTIFIER
OPERATORback to summary
public static final IonTextUtils.SymbolVariant OPERATOR
QUOTEDback to summary
public static final IonTextUtils.SymbolVariant QUOTED

Constructor Detail

SymbolVariantback to summary
private SymbolVariant()

Method Detail

valueOfback to summary
public static IonTextUtils.SymbolVariant valueOf(String name)
valuesback to summary
public static IonTextUtils.SymbolVariant[] values()