Class _Private_Utils
- java.lang.Object
-
- com.amazon.ion.impl._Private_Utils
-
public final class _Private_Utils extends java.lang.ObjectNOT FOR APPLICATION USE!
-
-
Field Summary
Fields Modifier and Type Field Description static java.nio.charset.CharsetASCII_CHARSETstatic java.lang.StringASCII_CHARSET_NAMEstatic byte[]EMPTY_BYTE_ARRAYJust a zero-length byte array, used to avoid allocation.static int[]EMPTY_INT_ARRAYJust a zero-length int array, used to avoid allocation.static java.util.ListIterator<?>EMPTY_ITERATORstatic java.lang.String[]EMPTY_STRING_ARRAYJust a zero-length String array, used to avoid allocation.static intMAX_LOOKAHEAD_UTF16(null.timestamp) requires 11 ASCII chars to distinguish from (null.timestamps) aka (null '.' 'timestamps')static booleanREADER_HASNEXT_REMOVEDMarker for code points relevant to removal of IonReader.hasNext().static java.util.TimeZoneUTCThe UTCTimeZone.static java.nio.charset.CharsetUTF8_CHARSETstatic java.lang.StringUTF8_CHARSET_NAMEThe string"UTF-8".
-
Constructor Summary
Constructors Constructor Description _Private_Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> voidaddAll(java.util.Collection<T> dest, java.util.Iterator<T> src)static <T> voidaddAllNonNull(java.util.Collection<T> dest, java.util.Iterator<T> src)static byte[]convertUtf16UnitsToUtf8(java.lang.String text)This differs fromutf8(String)by using our custem encoder.static SymbolTablecopyLocalSymbolTable(SymbolTable symtab)Creates a mutable copy of this local symbol table.static byte[]copyOf(byte[] original, int newLength)Replacement for Java6Arrays.copyOf(byte[], int).static java.lang.String[]copyOf(java.lang.String[] original, int newLength)static java.lang.Stringdecode(byte[] bytes, java.nio.charset.Charset charset)Decodes a byte sequence into a string, given aCharset.static <T> java.util.ListIterator<T>emptyIterator()static byte[]encode(java.lang.String s, java.nio.charset.Charset charset)Encodes a String into bytes of a given encoding.static intgetSidForSymbolTableField(java.lang.String text)Returns the symbol ID matching a system symbol text of a local or shared symtab field.static SymbolTableinitialSymtab(_Private_LocalSymbolTableFactory lstFactory, SymbolTable defaultSystemSymtab, SymbolTable... imports)Returns a minimal symtab that, either system or local depending on the given values, that supports representation as an IonStruct.static java.util.Iterator<java.lang.Integer>intIterator(int... values)static java.util.Iterator<java.lang.Integer>intIterator(int[] values, int len)static booleanisNonSymbolScalar(IonType type)Determines whether the passed-in data type is a scalar and not a symbol.static booleanisTrivialTable(SymbolTable table)Is the table null, system, or local without imported symbols?static java.util.Iterator<IonValue>iterate(ValueFactory valueFactory, IonReader input)Create a value iterator from a reader.static byte[]loadFileBytes(java.io.File file)static java.lang.StringloadReader(java.io.Reader in)static byte[]loadStreamBytes(java.io.InputStream in)static SymbolTokenlocalize(SymbolTable symtab, SymbolToken sym)static voidlocalize(SymbolTable symtab, SymbolToken[] syms)static voidlocalize(SymbolTable symtab, SymbolToken[] syms, int count)static _Private_LocalSymbolTableFactorynewLocalSymbolTableAsStructFactory(ValueFactory imageFactory)Deprecated.due to DOM entanglement.static SymbolTablenewSharedSymtab(IonReader reader, boolean alreadyInStruct)static SymbolTablenewSharedSymtab(IonStruct ionRep)static SymbolTablenewSharedSymtab(java.lang.String name, int version, SymbolTable priorSymtab, java.util.Iterator<java.lang.String> symbols)As perIonSystem.newSharedSymbolTable(String, int, Iterator, SymbolTable...), any duplicate or null symbol texts are skipped.static SymbolTablenewSubstituteSymtab(SymbolTable original, int version, int maxId)static com.amazon.ion.impl.SymbolTokenImplnewSymbolToken(int sid)static SymbolTokennewSymbolToken(SymbolTable symtab, int sid)static SymbolTokennewSymbolToken(SymbolTable symtab, java.lang.String text)Checks symbol content.static com.amazon.ion.impl.SymbolTokenImplnewSymbolToken(java.lang.String text, int sid)static SymbolToken[]newSymbolTokens(SymbolTable symtab, int... syms)static SymbolToken[]newSymbolTokens(SymbolTable symtab, java.lang.String... text)Validates each text element.static intreadFully(java.io.InputStream in, byte[] buf)CallsInputStream.read(byte[], int, int)until the buffer is filled or EOF is encountered.static intreadFully(java.io.InputStream in, byte[] buf, int offset, int length)CallsInputStream.read(byte[], int, int)until the requested length is read or EOF is encountered.static booleansafeEquals(java.lang.Object a, java.lang.Object b)static booleanstreamIsIonBinary(java.io.PushbackInputStream pushback)static java.util.Iterator<java.lang.String>stringIterator(java.lang.String... values)static java.util.Iterator<java.lang.String>stringIterator(java.lang.String[] values, int len)static booleansymtabExtends(SymbolTable superset, SymbolTable subset)Determines whether the passed-insupersetsymtab is an extension ofsubset.static booleansymtabIsLocalAndNonTrivial(SymbolTable symtab)static booleansymtabIsSharedNotSystem(SymbolTable symtab)Indicates whether a table is shared but not a system table.static IonStructsymtabTree(SymbolTable symtab, ValueFactory valueFactory)static SymbolTablesystemSymtab(int version)static int[]toSids(SymbolToken[] symbols, int count)static java.lang.String[]toStrings(SymbolToken[] symbols, int count)Extracts the non-null text from a list of symbol tokens.static java.lang.Stringutf8(byte[] bytes)Decodes a UTF-8 byte sequence to a String.static byte[]utf8(java.lang.String s)Encodes a String into UTF-8 bytes.static java.lang.Stringutf8FileToString(java.io.File file)static booleanvalueIsLocalSymbolTable(_Private_IonValue v)Checks the passed in value and returns whether or not the value could be a local symbol table.static voidwriteAsBase64(java.io.InputStream byteStream, java.lang.Appendable out)
-
-
-
Field Detail
-
READER_HASNEXT_REMOVED
public static final boolean READER_HASNEXT_REMOVED
Marker for code points relevant to removal of IonReader.hasNext().- See Also:
- Constant Field Values
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
Just a zero-length byte array, used to avoid allocation.
-
EMPTY_STRING_ARRAY
public static final java.lang.String[] EMPTY_STRING_ARRAY
Just a zero-length String array, used to avoid allocation.
-
EMPTY_INT_ARRAY
public static final int[] EMPTY_INT_ARRAY
Just a zero-length int array, used to avoid allocation.
-
MAX_LOOKAHEAD_UTF16
public static final int MAX_LOOKAHEAD_UTF16
(null.timestamp) requires 11 ASCII chars to distinguish from (null.timestamps) aka (null '.' 'timestamps')- See Also:
IonCharacterReader.DEFAULT_BUFFER_SIZE,IonCharacterReader.BUFFER_PADDING, Constant Field Values
-
ASCII_CHARSET_NAME
public static final java.lang.String ASCII_CHARSET_NAME
- See Also:
- Constant Field Values
-
ASCII_CHARSET
public static final java.nio.charset.Charset ASCII_CHARSET
-
UTF8_CHARSET_NAME
public static final java.lang.String UTF8_CHARSET_NAME
The string"UTF-8".- See Also:
- Constant Field Values
-
UTF8_CHARSET
public static final java.nio.charset.Charset UTF8_CHARSET
-
UTC
public static final java.util.TimeZone UTC
The UTCTimeZone. TODO determine if this is well-defined.
-
EMPTY_ITERATOR
public static final java.util.ListIterator<?> EMPTY_ITERATOR
-
-
Method Detail
-
emptyIterator
public static final <T> java.util.ListIterator<T> emptyIterator()
-
safeEquals
public static boolean safeEquals(java.lang.Object a, java.lang.Object b)
-
copyOf
public static byte[] copyOf(byte[] original, int newLength)Replacement for Java6Arrays.copyOf(byte[], int).
-
copyOf
public static java.lang.String[] copyOf(java.lang.String[] original, int newLength)
-
addAll
public static <T> void addAll(java.util.Collection<T> dest, java.util.Iterator<T> src)
-
addAllNonNull
public static <T> void addAllNonNull(java.util.Collection<T> dest, java.util.Iterator<T> src)
-
newSymbolToken
public static com.amazon.ion.impl.SymbolTokenImpl newSymbolToken(java.lang.String text, int sid)- Returns:
- not null
-
newSymbolToken
public static com.amazon.ion.impl.SymbolTokenImpl newSymbolToken(int sid)
- Returns:
- not null
-
newSymbolToken
public static SymbolToken newSymbolToken(SymbolTable symtab, java.lang.String text)
Checks symbol content.- Returns:
- not null
-
newSymbolToken
public static SymbolToken newSymbolToken(SymbolTable symtab, int sid)
- Returns:
- not null
-
newSymbolTokens
public static SymbolToken[] newSymbolTokens(SymbolTable symtab, java.lang.String... text)
Validates each text element.- Parameters:
text- may be null or empty.- Returns:
- not null.
-
newSymbolTokens
public static SymbolToken[] newSymbolTokens(SymbolTable symtab, int... syms)
- Parameters:
syms- may be null or empty.- Returns:
- not null.
-
localize
public static SymbolToken localize(SymbolTable symtab, SymbolToken sym)
-
localize
public static void localize(SymbolTable symtab, SymbolToken[] syms, int count)
- Parameters:
syms- may be mutated, replacing entries with localized updates!
-
localize
public static void localize(SymbolTable symtab, SymbolToken[] syms)
- Parameters:
syms- may be mutated, replacing entries with localized updates!
-
toStrings
public static java.lang.String[] toStrings(SymbolToken[] symbols, int count)
Extracts the non-null text from a list of symbol tokens.- Returns:
- not null.
- Throws:
UnknownSymbolException- if any token is missing text.
-
toSids
public static int[] toSids(SymbolToken[] symbols, int count)
-
encode
public static byte[] encode(java.lang.String s, java.nio.charset.Charset charset)Encodes a String into bytes of a given encoding.This method is preferred to
Charset.encode(String)andString.getBytes(String)(etc.) since those methods will replace or ignore bad input, and here we throw an exception.- Parameters:
s- the string to encode.- Returns:
- the encoded string, not null.
- Throws:
IonException- if there's aCharacterCodingException.
-
decode
public static java.lang.String decode(byte[] bytes, java.nio.charset.Charset charset)Decodes a byte sequence into a string, given aCharset.This method is preferred to
Charset.decode(ByteBuffer)andString(byte[], Charset)(etc.) since those methods will replace or ignore bad input, and here we throw an exception.- Parameters:
bytes- the data to decode.- Returns:
- the decoded string, not null.
- Throws:
IonException- if there's aCharacterCodingException.
-
utf8
public static byte[] utf8(java.lang.String s)
Encodes a String into UTF-8 bytes.This method is preferred to
Charset.encode(String)andString.getBytes(String)(etc.) since those methods will replace or ignore bad input, and here we throw an exception.- Parameters:
s- the string to encode.- Returns:
- the encoded UTF-8 bytes, not null.
- Throws:
IonException- if there's aCharacterCodingException.
-
utf8
public static java.lang.String utf8(byte[] bytes)
Decodes a UTF-8 byte sequence to a String.This method is preferred to
Charset.decode(ByteBuffer)andString(byte[], Charset)(etc.) since those methods will replace or ignore bad input, and here we throw an exception.- Parameters:
bytes- the data to decode.- Returns:
- the decoded string, not null.
- Throws:
IonException- if there's aCharacterCodingException.
-
convertUtf16UnitsToUtf8
public static byte[] convertUtf16UnitsToUtf8(java.lang.String text)
This differs fromutf8(String)by using our custem encoder. Not sure which is better. TODO benchmark the two approaches
-
readFully
public static int readFully(java.io.InputStream in, byte[] buf) throws java.io.IOExceptionCallsInputStream.read(byte[], int, int)until the buffer is filled or EOF is encountered. This method will block until the request is satisfied.- Parameters:
in- The stream to read from.buf- The buffer to read to.- Returns:
- the number of bytes read from the stream. May be less than
buf.lengthif EOF is encountered before reading that far. - Throws:
java.io.IOException- See Also:
readFully(InputStream, byte[], int, int)
-
readFully
public static int readFully(java.io.InputStream in, byte[] buf, int offset, int length) throws java.io.IOExceptionCallsInputStream.read(byte[], int, int)until the requested length is read or EOF is encountered. This method will block until the request is satisfied.- Parameters:
in- The stream to read from.buf- The buffer to read to.offset- The offset of the buffer to read from.length- The length of the data to read.- Returns:
- the number of bytes read from the stream. May be less than
lengthif EOF is encountered before reading that far. - Throws:
java.io.IOException- See Also:
readFully(InputStream, byte[])
-
loadFileBytes
public static byte[] loadFileBytes(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
utf8FileToString
public static java.lang.String utf8FileToString(java.io.File file) throws IonException, java.io.IOException- Throws:
IonExceptionjava.io.IOException
-
loadStreamBytes
public static byte[] loadStreamBytes(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
loadReader
public static java.lang.String loadReader(java.io.Reader in) throws java.io.IOException- Throws:
java.io.IOException
-
streamIsIonBinary
public static boolean streamIsIonBinary(java.io.PushbackInputStream pushback) throws IonException, java.io.IOException- Throws:
IonExceptionjava.io.IOException
-
iterate
public static java.util.Iterator<IonValue> iterate(ValueFactory valueFactory, IonReader input)
Create a value iterator from a reader. Primarily a trampoline for access permission.
-
valueIsLocalSymbolTable
public static boolean valueIsLocalSymbolTable(_Private_IonValue v)
Checks the passed in value and returns whether or not the value could be a local symbol table. It does this by checking the type and annotations.- Returns:
- boolean true if v can be a local symbol table otherwise false
-
symtabIsSharedNotSystem
public static final boolean symtabIsSharedNotSystem(SymbolTable symtab)
Indicates whether a table is shared but not a system table.
-
symtabIsLocalAndNonTrivial
public static boolean symtabIsLocalAndNonTrivial(SymbolTable symtab)
-
isTrivialTable
public static boolean isTrivialTable(SymbolTable table)
Is the table null, system, or local without imported symbols?
-
systemSymtab
public static SymbolTable systemSymtab(int version)
-
newSharedSymtab
public static SymbolTable newSharedSymtab(IonStruct ionRep)
-
newSharedSymtab
public static SymbolTable newSharedSymtab(IonReader reader, boolean alreadyInStruct)
-
newSharedSymtab
public static SymbolTable newSharedSymtab(java.lang.String name, int version, SymbolTable priorSymtab, java.util.Iterator<java.lang.String> symbols)
As perIonSystem.newSharedSymbolTable(String, int, Iterator, SymbolTable...), any duplicate or null symbol texts are skipped. Therefore, THIS METHOD IS NOT SUITABLE WHEN READING SERIALIZED SHARED SYMBOL TABLES since that scenario must preserve all sids.- Parameters:
priorSymtab- may be null.
-
copyLocalSymbolTable
public static SymbolTable copyLocalSymbolTable(SymbolTable symtab) throws SubstituteSymbolTableException
Creates a mutable copy of this local symbol table. The cloned table will be created in the context of the sameValueFactory.Note that the resulting symbol table holds a distinct, deep copy of the given table, adding symbols on either instances will not modify the other.
- Parameters:
symtab-- Returns:
- a new mutable
SymbolTableinstance; not null - Throws:
java.lang.IllegalArgumentException- if the given table is not a local symbol tableSubstituteSymbolTableException- if any imported table by the given local symbol table is a substituted table (whereby no exact match was found in its catalog)
-
newLocalSymbolTableAsStructFactory
@Deprecated public static _Private_LocalSymbolTableFactory newLocalSymbolTableAsStructFactory(ValueFactory imageFactory)
Deprecated.due to DOM entanglement. Streaming applications should use .Trampoline toFactory(ValueFactory)- Parameters:
imageFactory- the ValueFactory from which to construct the IonStruct representation of the LST- Returns:
- a new
LocalSymbolTableAsStruct.Factory
-
initialSymtab
public static SymbolTable initialSymtab(_Private_LocalSymbolTableFactory lstFactory, SymbolTable defaultSystemSymtab, SymbolTable... imports)
Returns a minimal symtab that, either system or local depending on the given values, that supports representation as an IonStruct. If the imports are empty, the default system symtab is returned.- Parameters:
lstFactory- the factory to use to build the local symbol table, never nulldefaultSystemSymtab- the default system symtab, which will be used if the first import inimportsisn't a system symtab, never nullimports- the set of shared symbol tables to import; may be null or empty. The first (and only the first) may be a system table, in which case thedefaultSystemSymtabis ignored.
-
symtabTree
public static IonStruct symtabTree(SymbolTable symtab, ValueFactory valueFactory)
-
symtabExtends
public static boolean symtabExtends(SymbolTable superset, SymbolTable subset)
Determines whether the passed-insupersetsymtab is an extension ofsubset.If both are LSTs, their imported tables and locally declared symbols are exhaustively checked, which can be expensive. Callers of this method should cache the results of these comparisons.
- Parameters:
superset- either a system or local symbol tablesubset- either a system or local symbol table- Returns:
- true if
supersetextendssubset, false if not
-
isNonSymbolScalar
public static boolean isNonSymbolScalar(IonType type)
Determines whether the passed-in data type is a scalar and not a symbol.
-
getSidForSymbolTableField
public static final int getSidForSymbolTableField(java.lang.String text)
Returns the symbol ID matching a system symbol text of a local or shared symtab field.
-
stringIterator
public static final java.util.Iterator<java.lang.String> stringIterator(java.lang.String... values)
-
stringIterator
public static final java.util.Iterator<java.lang.String> stringIterator(java.lang.String[] values, int len)
-
intIterator
public static final java.util.Iterator<java.lang.Integer> intIterator(int... values)
-
intIterator
public static final java.util.Iterator<java.lang.Integer> intIterator(int[] values, int len)
-
writeAsBase64
public static void writeAsBase64(java.io.InputStream byteStream, java.lang.Appendable out) throws java.io.IOException- Throws:
java.io.IOException
-
newSubstituteSymtab
public static SymbolTable newSubstituteSymtab(SymbolTable original, int version, int maxId)
-
-