Class _Private_Utils


  • public final class _Private_Utils
    extends java.lang.Object
    NOT FOR APPLICATION USE!
    • 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 UTC TimeZone. TODO determine if this is well-defined.
      • EMPTY_ITERATOR

        public static final java.util.ListIterator<?> EMPTY_ITERATOR
    • Constructor Detail

      • _Private_Utils

        public _Private_Utils()
    • 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 Java6 Arrays.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 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) and String.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 a CharacterCodingException.
      • decode

        public static java.lang.String decode​(byte[] bytes,
                                              java.nio.charset.Charset charset)
        Decodes a byte sequence into a string, given a Charset.

        This method is preferred to Charset.decode(ByteBuffer) and String(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 a CharacterCodingException.
      • utf8

        public static byte[] utf8​(java.lang.String s)
        Encodes a String into UTF-8 bytes.

        This method is preferred to Charset.encode(String) and String.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 a CharacterCodingException.
      • 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) and String(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 a CharacterCodingException.
      • convertUtf16UnitsToUtf8

        public static byte[] convertUtf16UnitsToUtf8​(java.lang.String text)
        This differs from utf8(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.IOException
        Calls InputStream.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.length if 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.IOException
        Calls InputStream.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 length if 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:
        IonException
        java.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:
        IonException
        java.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​(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 per IonSystem.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 same ValueFactory.

        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 SymbolTable instance; not null
        Throws:
        java.lang.IllegalArgumentException - if the given table is not a local symbol table
        SubstituteSymbolTableException - 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 to Factory(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 null
        defaultSystemSymtab - the default system symtab, which will be used if the first import in imports isn't a system symtab, never null
        imports - 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 the defaultSystemSymtab is ignored.
      • symtabExtends

        public static boolean symtabExtends​(SymbolTable superset,
                                            SymbolTable subset)
        Determines whether the passed-in superset symtab is an extension of subset.

        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 table
        subset - either a system or local symbol table
        Returns:
        true if superset extends subset, 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)