Package com.amazon.ion.util
Class IonTextUtils
- java.lang.Object
-
- com.amazon.ion.util.IonTextUtils
-
public class IonTextUtils extends java.lang.ObjectUtility methods for working with Ion's text-oriented data types.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIonTextUtils.SymbolVariant
-
Constructor Summary
Constructors Constructor Description IonTextUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisAllWhitespace(java.lang.CharSequence charSequence)Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return.static booleanisDigit(int codePoint, int radix)static booleanisIdentifierPart(int codePoint)static booleanisIdentifierStart(int codePoint)static booleanisNumericStop(int codePoint)Determines whether a given code point is one of the valid Ion numeric terminators.static booleanisOperatorPart(int codePoint)static booleanisWhitespace(int codePoint)Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return.static java.lang.StringprintBlob(byte[] value)static voidprintBlob(java.lang.Appendable out, byte[] value)static java.lang.StringprintClob(byte[] value)static voidprintClob(java.lang.Appendable out, byte[] value)static java.lang.StringprintCodePointAsString(int codePoint)Builds a String denoting an ASCII-encoded Ion string, with double-quotes surrounding a single Unicode code point.static voidprintDecimal(java.lang.Appendable out, java.math.BigDecimal decimal)static java.lang.StringprintDecimal(java.math.BigDecimal decimal)static java.lang.StringprintFloat(double value)static voidprintFloat(java.lang.Appendable out, double value)static voidprintFloat(java.lang.Appendable out, java.lang.Double value)static java.lang.StringprintFloat(java.lang.Double value)static voidprintJsonCodePoint(java.lang.Appendable out, int codePoint)Prints a single Unicode code point for use in an ASCII-safe JSON string.static voidprintJsonString(java.lang.Appendable out, java.lang.CharSequence text)Prints characters as an ASCII-encoded JSON string, including surrounding double-quotes.static voidprintLongString(java.lang.Appendable out, java.lang.CharSequence text)Prints characters as an ASCII-encoded Ion "long string", including surrounding triple-quotes.static java.lang.StringprintLongString(java.lang.CharSequence text)Builds a String denoting an ASCII-encoded Ion "long string", including surrounding triple-quotes.static voidprintQuotedSymbol(java.lang.Appendable out, java.lang.CharSequence text)Prints text as a single-quoted Ion symbol.static java.lang.StringprintQuotedSymbol(java.lang.CharSequence text)Builds a String containing a single-quoted Ion symbol.static voidprintString(java.lang.Appendable out, java.lang.CharSequence text)Prints characters as an ASCII-encoded Ion string, including surrounding double-quotes.static java.lang.StringprintString(java.lang.CharSequence text)Builds a String denoting an ASCII-encoded Ion string, including surrounding double-quotes.static voidprintStringCodePoint(java.lang.Appendable out, int codePoint)Prints a single Unicode code point for use in an ASCII-safe Ion string.static java.lang.StringprintSymbol(SymbolToken token)static voidprintSymbol(java.lang.Appendable out, java.lang.CharSequence text)Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary.static java.lang.StringprintSymbol(java.lang.CharSequence text)Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary.static voidprintSymbolCodePoint(java.lang.Appendable out, int codePoint)Prints a single Unicode code point for use in an ASCII-safe Ion symbol.static IonTextUtils.SymbolVariantsymbolVariant(java.lang.CharSequence symbol)Determines whether the text of a symbol represents an identifier, an operator, or a symbol that always requires (single) quotes.
-
-
-
Method Detail
-
isWhitespace
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- the character to test.- Returns:
trueifcis one of the four legal Ion whitespace characters.- See Also:
- RFC 4627
-
isAllWhitespace
public static boolean isAllWhitespace(java.lang.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- the CharSequence to test.- Returns:
trueifcharSequenceconsists entirely of the four legal Ion whitespace characters.- See Also:
isWhitespace(int), RFC 4627
-
isNumericStop
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 returnsfalsefor the slash.- Parameters:
codePoint- the Unicode scalar to test.- Returns:
- true when the scalar can legally follow an Ion number.
Returns false for the slash character
'/'.
-
isDigit
public static boolean isDigit(int codePoint, int radix)
-
isIdentifierStart
public static boolean isIdentifierStart(int codePoint)
-
isIdentifierPart
public static boolean isIdentifierPart(int codePoint)
-
isOperatorPart
public static boolean isOperatorPart(int codePoint)
-
symbolVariant
public static IonTextUtils.SymbolVariant symbolVariant(java.lang.CharSequence symbol)
Determines whether the text of a symbol represents an identifier, an operator, or a symbol that always requires (single) quotes.- Parameters:
symbol- must be a non-empty string.- Returns:
- the variant of the symbol.
- Throws:
java.lang.NullPointerException- ifsymbolisnull.
-
printStringCodePoint
public static void printStringCodePoint(java.lang.Appendable out, int codePoint) throws java.io.IOExceptionPrints a single Unicode code point for use in an ASCII-safe Ion string.- Parameters:
out- the stream to receive the data.codePoint- a Unicode code point.- Throws:
java.io.IOException
-
printSymbolCodePoint
public static void printSymbolCodePoint(java.lang.Appendable out, int codePoint) throws java.io.IOExceptionPrints a single Unicode code point for use in an ASCII-safe Ion symbol.- Parameters:
out- the stream to receive the data.codePoint- a Unicode code point.- Throws:
java.io.IOException
-
printJsonCodePoint
public static void printJsonCodePoint(java.lang.Appendable out, int codePoint) throws java.io.IOExceptionPrints a single Unicode code point for use in an ASCII-safe JSON string.- Parameters:
out- the stream to receive the data.codePoint- a Unicode code point.- Throws:
java.io.IOException
-
printString
public static void printString(java.lang.Appendable out, java.lang.CharSequence text) throws java.io.IOExceptionPrints characters as an ASCII-encoded Ion string, including surrounding double-quotes. If thetextis null, this printsnull.string.- Parameters:
out- the stream to receive the data.text- the text to print; may benull.- Throws:
java.io.IOException- if theAppendablethrows an exception.java.lang.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printJsonString
public static void printJsonString(java.lang.Appendable out, java.lang.CharSequence text) throws java.io.IOExceptionPrints characters as an ASCII-encoded JSON string, including surrounding double-quotes. If thetextis null, this printsnull.- Parameters:
out- the stream to receive the JSON data.text- the text to print; may benull.- Throws:
java.io.IOException- if theAppendablethrows an exception.java.lang.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printString
public static java.lang.String printString(java.lang.CharSequence text)
Builds a String denoting an ASCII-encoded Ion string, including surrounding double-quotes. If thetextis null, this returns"null.string".- Parameters:
text- the text to print; may benull.- Throws:
java.lang.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printLongString
public static java.lang.String printLongString(java.lang.CharSequence text)
Builds a String denoting an ASCII-encoded Ion "long string", including surrounding triple-quotes. If thetextis null, this returns"null.string".- Parameters:
text- the text to print; may benull.- Throws:
java.lang.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printLongString
public static void printLongString(java.lang.Appendable out, java.lang.CharSequence text) throws java.io.IOExceptionPrints characters as an ASCII-encoded Ion "long string", including surrounding triple-quotes. If thetextis null, this printsnull.string.- Parameters:
out- the stream to receive the data.text- the text to print; may benull.- Throws:
java.io.IOException- if theAppendablethrows an exception.java.lang.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printCodePointAsString
public static java.lang.String printCodePointAsString(int codePoint)
Builds a String denoting an ASCII-encoded Ion string, with double-quotes surrounding a single Unicode code point.- Parameters:
codePoint- a Unicode code point.
-
printSymbol
public static void printSymbol(java.lang.Appendable out, java.lang.CharSequence text) throws java.io.IOExceptionPrints the text as an Ion symbol, including surrounding single-quotes if they are necessary. Operator symbols such as'+'are quoted. If thetextis null, this printsnull.symbol.- Parameters:
out- the stream to receive the Ion data.text- the symbol text; may benull.- Throws:
java.io.IOException- if theAppendablethrows an exception.- See Also:
printSymbol(CharSequence)
-
printSymbol
public static java.lang.String printSymbol(java.lang.CharSequence text)
Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary. Operator symbols such as'+'are quoted. If thetextis null, this returns"null.symbol".- Parameters:
text- the symbol text; may benull.- Returns:
- a string containing the resulting Ion data.
- See Also:
printSymbol(Appendable, CharSequence)
-
printSymbol
public static java.lang.String printSymbol(SymbolToken token)
- Parameters:
token- the symbolToken to be printed.- Returns:
- a string representing the symboltoken.
-
printQuotedSymbol
public static void printQuotedSymbol(java.lang.Appendable out, java.lang.CharSequence text) throws java.io.IOExceptionPrints text as a single-quoted Ion symbol. If thetextis null, this printsnull.symbol.- Parameters:
out- the stream to receive the data.text- the symbol text; may benull.- Throws:
java.io.IOException- if theAppendablethrows an exception.java.lang.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printQuotedSymbol
public static java.lang.String printQuotedSymbol(java.lang.CharSequence text)
Builds a String containing a single-quoted Ion symbol. If thetextis null, this returns"null.symbol".- Parameters:
text- the symbol text; may benull.- Throws:
java.lang.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printDecimal
public static void printDecimal(java.lang.Appendable out, java.math.BigDecimal decimal) throws java.io.IOException- Throws:
java.io.IOException
-
printDecimal
public static java.lang.String printDecimal(java.math.BigDecimal decimal)
-
printFloat
public static void printFloat(java.lang.Appendable out, double value) throws java.io.IOException- Throws:
java.io.IOException
-
printFloat
public static java.lang.String printFloat(double value)
-
printFloat
public static void printFloat(java.lang.Appendable out, java.lang.Double value) throws java.io.IOException- Throws:
java.io.IOException
-
printFloat
public static java.lang.String printFloat(java.lang.Double value)
-
printBlob
public static void printBlob(java.lang.Appendable out, byte[] value) throws java.io.IOException- Throws:
java.io.IOException
-
printBlob
public static java.lang.String printBlob(byte[] value)
-
printClob
public static void printClob(java.lang.Appendable out, byte[] value) throws java.io.IOException- Throws:
java.io.IOException
-
printClob
public static java.lang.String printClob(byte[] value)
-
-