Class _Private_Utils

java.lang.Object
com.amazon.ion.impl._Private_Utils

public final class _Private_Utils extends Object
NOT FOR APPLICATION USE!
  • Field Details

    • READER_HASNEXT_REMOVED

      public static final boolean READER_HASNEXT_REMOVED
      Marker for code points relevant to removal of IonReader.hasNext().
      See Also:
    • 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 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:
    • ASCII_CHARSET_NAME

      public static final String ASCII_CHARSET_NAME
      See Also:
    • ASCII_CHARSET

      public static final Charset ASCII_CHARSET
    • UTF8_CHARSET_NAME

      public static final String UTF8_CHARSET_NAME
      The string "UTF-8".
      See Also:
    • UTF8_CHARSET

      public static final Charset UTF8_CHARSET
    • UTC

      public static final TimeZone UTC
      The UTC TimeZone. TODO determine if this is well-defined.
    • EMPTY_ITERATOR

      public static final ListIterator<?> EMPTY_ITERATOR
  • Constructor Details

    • _Private_Utils

      public _Private_Utils()
  • Method Details

    • emptyIterator

      public static final <T> ListIterator<T> emptyIterator()
    • safeEquals

      public static boolean safeEquals(Object a, Object b)
    • copyOf

      public static byte[] copyOf(byte[] original, int newLength)
      Replacement for Java6 Arrays.copyOf(byte[], int).
    • copyOf

      public static String[] copyOf(String[] original, int newLength)
    • addAll

      public static <T> void addAll(Collection<T> dest, Iterator<T> src)
    • addAllNonNull

      public static <T> void addAllNonNull(Collection<T> dest, Iterator<T> src)
    • newSymbolToken

      public static com.amazon.ion.impl.SymbolTokenImpl newSymbolToken(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, 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, 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 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(String s, 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 String decode(byte[] bytes, 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(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 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(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(InputStream in, byte[] buf) throws 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:
      IOException
      See Also:
    • readFully

      public static int readFully(InputStream in, byte[] buf, int offset, int length) throws 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:
      IOException
      See Also:
    • loadFileBytes

      public static byte[] loadFileBytes(File file) throws IOException
      Throws:
      IOException
    • utf8FileToString

      public static String utf8FileToString(File file) throws IonException, IOException
      Throws:
      IonException
      IOException
    • loadStreamBytes

      public static byte[] loadStreamBytes(InputStream in) throws IOException
      Throws:
      IOException
    • loadReader

      public static String loadReader(Reader in) throws IOException
      Throws:
      IOException
    • streamIsIonBinary

      public static boolean streamIsIonBinary(PushbackInputStream pushback) throws IonException, IOException
      Throws:
      IonException
      IOException
    • iterate

      public static 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(String name, int version, SymbolTable priorSymtab, Iterator<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:
      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.
    • symtabTree

      public static IonStruct symtabTree(SymbolTable symtab, ValueFactory valueFactory)
    • 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(String text)
      Returns the symbol ID matching a system symbol text of a local or shared symtab field.
    • stringIterator

      public static final Iterator<String> stringIterator(String... values)
    • stringIterator

      public static final Iterator<String> stringIterator(String[] values, int len)
    • intIterator

      public static final Iterator<Integer> intIterator(int... values)
    • intIterator

      public static final Iterator<Integer> intIterator(int[] values, int len)
    • writeAsBase64

      public static void writeAsBase64(InputStream byteStream, Appendable out) throws IOException
      Throws:
      IOException
    • newSubstituteSymtab

      public static SymbolTable newSubstituteSymtab(SymbolTable original, int version, int maxId)