Class _Private_Utils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Charsetstatic final Stringstatic final byte[]Just a zero-length byte array, used to avoid allocation.static final int[]Just a zero-length int array, used to avoid allocation.static final ListIterator<?> static final String[]Just a zero-length String array, used to avoid allocation.static final int(null.timestamp) requires 11 ASCII chars to distinguish from (null.timestamps) aka (null '.' 'timestamps')static final booleanMarker for code points relevant to removal of IonReader.hasNext().static final TimeZoneThe UTCTimeZone.static final Charsetstatic final StringThe string"UTF-8". -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidaddAll(Collection<T> dest, Iterator<T> src) static <T> voidaddAllNonNull(Collection<T> dest, Iterator<T> src) static byte[]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 String[]static StringDecodes a byte sequence into a string, given aCharset.static final <T> ListIterator<T> static byte[]Encodes a String into bytes of a given encoding.static final intReturns 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.intIterator(int... values) 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?iterate(ValueFactory valueFactory, IonReader input) Create a value iterator from a reader.static byte[]loadFileBytes(File file) static StringloadReader(Reader in) static byte[]static SymbolTokenlocalize(SymbolTable symtab, SymbolToken sym) static voidlocalize(SymbolTable symtab, SymbolToken[] syms) static voidlocalize(SymbolTable symtab, SymbolToken[] syms, int count) newLocalSymbolTableAsStructFactory(ValueFactory imageFactory) Deprecated.due to DOM entanglement.static SymbolTablenewSharedSymtab(IonReader reader, boolean alreadyInStruct) static SymbolTablenewSharedSymtab(IonStruct ionRep) static SymbolTablenewSharedSymtab(String name, int version, SymbolTable priorSymtab, Iterator<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, String text) Checks symbol content.static com.amazon.ion.impl.SymbolTokenImplnewSymbolToken(String text, int sid) static SymbolToken[]newSymbolTokens(SymbolTable symtab, int... syms) static SymbolToken[]newSymbolTokens(SymbolTable symtab, String... text) Validates each text element.static intreadFully(InputStream in, byte[] buf) CallsInputStream.read(byte[], int, int)until the buffer is filled or EOF is encountered.static intreadFully(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(Object a, Object b) static booleanstreamIsIonBinary(PushbackInputStream pushback) stringIterator(String... values) stringIterator(String[] values, int len) static booleansymtabExtends(SymbolTable superset, SymbolTable subset) Determines whether the passed-insupersetsymtab is an extension ofsubset.static booleanstatic final 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 String[]toStrings(SymbolToken[] symbols, int count) Extracts the non-null text from a list of symbol tokens.static Stringutf8(byte[] bytes) Decodes a UTF-8 byte sequence to a String.static byte[]Encodes a String into UTF-8 bytes.static Stringutf8FileToString(File file) static booleanChecks the passed in value and returns whether or not the value could be a local symbol table.static voidwriteAsBase64(InputStream byteStream, Appendable out)
-
Field Details
-
READER_HASNEXT_REMOVED
public static final boolean READER_HASNEXT_REMOVEDMarker for code points relevant to removal of IonReader.hasNext().- See Also:
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAYJust a zero-length byte array, used to avoid allocation. -
EMPTY_STRING_ARRAY
Just a zero-length String array, used to avoid allocation. -
EMPTY_INT_ARRAY
public static final int[] EMPTY_INT_ARRAYJust 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:
-
ASCII_CHARSET_NAME
- See Also:
-
ASCII_CHARSET
-
UTF8_CHARSET_NAME
The string"UTF-8".- See Also:
-
UTF8_CHARSET
-
UTC
The UTCTimeZone. TODO determine if this is well-defined. -
EMPTY_ITERATOR
-
-
Constructor Details
-
_Private_Utils
public _Private_Utils()
-
-
Method Details
-
emptyIterator
-
safeEquals
-
copyOf
public static byte[] copyOf(byte[] original, int newLength) Replacement for Java6Arrays.copyOf(byte[], int). -
copyOf
-
addAll
-
addAllNonNull
-
newSymbolToken
- Returns:
- not null
-
newSymbolToken
public static com.amazon.ion.impl.SymbolTokenImpl newSymbolToken(int sid) - Returns:
- not null
-
newSymbolToken
Checks symbol content.- Returns:
- not null
-
newSymbolToken
- Returns:
- not null
-
newSymbolTokens
Validates each text element.- Parameters:
text- may be null or empty.- Returns:
- not null.
-
newSymbolTokens
- Parameters:
syms- may be null or empty.- Returns:
- not null.
-
localize
-
localize
- Parameters:
syms- may be mutated, replacing entries with localized updates!
-
localize
- Parameters:
syms- may be mutated, replacing entries with localized updates!
-
toStrings
Extracts the non-null text from a list of symbol tokens.- Returns:
- not null.
- Throws:
UnknownSymbolException- if any token is missing text.
-
toSids
-
encode
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
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
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
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
This differs fromutf8(String)by using our custem encoder. Not sure which is better. TODO benchmark the two approaches -
readFully
CallsInputStream.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:
IOException- See Also:
-
readFully
CallsInputStream.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:
IOException- See Also:
-
loadFileBytes
- Throws:
IOException
-
utf8FileToString
- Throws:
IonExceptionIOException
-
loadStreamBytes
- Throws:
IOException
-
loadReader
- Throws:
IOException
-
streamIsIonBinary
public static boolean streamIsIonBinary(PushbackInputStream pushback) throws IonException, IOException - Throws:
IonExceptionIOException
-
iterate
Create a value iterator from a reader. Primarily a trampoline for access permission. -
valueIsLocalSymbolTable
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
-
symtabIsLocalAndNonTrivial
-
isTrivialTable
Is the table null, system, or local without imported symbols? -
systemSymtab
-
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:
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
-
symtabExtends
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
Determines whether the passed-in data type is a scalar and not a symbol. -
getSidForSymbolTableField
Returns the symbol ID matching a system symbol text of a local or shared symtab field. -
stringIterator
-
stringIterator
-
intIterator
-
intIterator
-
writeAsBase64
- Throws:
IOException
-
newSubstituteSymtab
-