Class IonStreamUtils

java.lang.Object
com.amazon.ion.util.IonStreamUtils

public class IonStreamUtils extends Object
Utility methods for working with the Ion streaming interfaces, IonReader and IonWriter.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isGzip(byte[] buffer, int offset, int length)
    Determines whether a buffer contains GZIPped data.
    static boolean
    isIonBinary(byte[] buffer)
    Determines whether a buffer contains Ion binary data by looking for the presence of the Ion Version Marker at its start.
    static boolean
    isIonBinary(byte[] buffer, int offset, int length)
    Determines whether a buffer contains Ion binary data by looking for the presence of the Ion Version Marker at a given offset.
    static void
    Wraps the given Exception with IonException and throws.
    Returns a stream that decompresses a stream if it contains GZIPped data, otherwise has no effect on the stream (but may wrap it).
    static void
    writeBoolList(IonWriter writer, boolean[] values)
    writes an IonList with a series of IonBool values.
    static void
    writeFloatList(IonWriter writer, double[] values)
    writes an IonList with a series of IonFloat values.
    static void
    writeFloatList(IonWriter writer, float[] values)
    writes an IonList with a series of IonFloat values.
    static void
    writeIntList(IonWriter writer, byte[] values)
    writes an IonList with a series of IonInt values.
    static void
    writeIntList(IonWriter writer, int[] values)
    writes an IonList with a series of IonInt values.
    static void
    writeIntList(IonWriter writer, long[] values)
    writes an IonList with a series of IonInt values.
    static void
    writeIntList(IonWriter writer, short[] values)
    writes an IonList with a series of IonInt values.
    static void
    writeStringList(IonWriter writer, String[] values)
    writes an IonList with a series of IonString values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IonStreamUtils

      public IonStreamUtils()
  • Method Details

    • isIonBinary

      public static boolean isIonBinary(byte[] buffer)
      Determines whether a buffer contains Ion binary data by looking for the presence of the Ion Version Marker at its start. A false result does not imply that the buffer has Ion text, just that it's not Ion binary.
      Parameters:
      buffer - the data to check.
      Returns:
      true if the buffer contains Ion binary (starting from offset zero); false if the buffer is null or too short.
      See Also:
    • isIonBinary

      public static boolean isIonBinary(byte[] buffer, int offset, int length)
      Determines whether a buffer contains Ion binary data by looking for the presence of the Ion Version Marker at a given offset. A false result does not imply that the buffer has Ion text, just that it's not Ion binary.
      Parameters:
      buffer - the data to check.
      offset - the position in the buffer at which to start reading.
      length - the number of bytes in the buffer that are valid, starting from offset.
      Returns:
      true if the buffer contains Ion binary (starting from offset); false if the buffer is null or if the length is too short.
      See Also:
    • isGzip

      public static boolean isGzip(byte[] buffer, int offset, int length)
      Determines whether a buffer contains GZIPped data.
      Parameters:
      buffer - the data to check.
      offset - the position in the buffer at which to start reading.
      length - the number of bytes in the buffer that are valid, starting from offset.
      Returns:
      true if the buffer contains GZIPped data; false if the buffer is null or if the length is too short.
    • unGzip

      public static InputStream unGzip(InputStream in) throws IOException
      Returns a stream that decompresses a stream if it contains GZIPped data, otherwise has no effect on the stream (but may wrap it).
      Throws:
      IOException
    • throwAsIonException

      public static void throwAsIonException(Exception e)
      Wraps the given Exception with IonException and throws.
      Parameters:
      e - the exception to wrap.
    • writeBoolList

      public static void writeBoolList(IonWriter writer, boolean[] values) throws IOException
      writes an IonList with a series of IonBool values. This starts a List, writes the values (without any annoations) and closes the list. For text and tree writers this is just a convienience, but for the binary writer it can be optimized internally.
      Parameters:
      values - boolean values to populate the list with
      Throws:
      IOException
    • writeFloatList

      public static void writeFloatList(IonWriter writer, float[] values) throws IOException
      writes an IonList with a series of IonFloat values. This starts a List, writes the values (without any annoations) and closes the list. For text and tree writers this is just a convienience, but for the binary writer it can be optimized internally. Note that since, currently, IonFloat is a 64 bit float this is a helper that simply casts the passed in floats to double before writing them.
      Parameters:
      values - 32 bit float values to populate the lists IonFloat's with
      Throws:
      IOException
    • writeFloatList

      public static void writeFloatList(IonWriter writer, double[] values) throws IOException
      writes an IonList with a series of IonFloat values. This starts a List, writes the values (without any annoations) and closes the list. For text and tree writers this is just a convienience, but for the binary writer it can be optimized internally.
      Parameters:
      values - 64 bit float values to populate the lists IonFloat's with
      Throws:
      IOException
    • writeIntList

      public static void writeIntList(IonWriter writer, byte[] values) throws IOException
      writes an IonList with a series of IonInt values. This starts a List, writes the values (without any annoations) and closes the list. For text and tree writers this is just a convienience, but for the binary writer it can be optimized internally.
      Parameters:
      values - signed byte values to populate the lists int's with
      Throws:
      IOException
    • writeIntList

      public static void writeIntList(IonWriter writer, short[] values) throws IOException
      writes an IonList with a series of IonInt values. This starts a List, writes the values (without any annoations) and closes the list. For text and tree writers this is just a convienience, but for the binary writer it can be optimized internally.
      Parameters:
      values - signed short values to populate the lists int's with
      Throws:
      IOException
    • writeIntList

      public static void writeIntList(IonWriter writer, int[] values) throws IOException
      writes an IonList with a series of IonInt values. This starts a List, writes the values (without any annoations) and closes the list. For text and tree writers this is just a convienience, but for the binary writer it can be optimized internally.
      Parameters:
      values - signed int values to populate the lists int's with
      Throws:
      IOException
    • writeIntList

      public static void writeIntList(IonWriter writer, long[] values) throws IOException
      writes an IonList with a series of IonInt values. This starts a List, writes the values (without any annoations) and closes the list. For text and tree writers this is just a convienience, but for the binary writer it can be optimized internally.
      Parameters:
      values - signed long values to populate the lists int's with
      Throws:
      IOException
    • writeStringList

      public static void writeStringList(IonWriter writer, String[] values) throws IOException
      writes an IonList with a series of IonString values. This starts a List, writes the values (without any annoations) and closes the list. For text and tree writers this is just a convienience, but for the binary writer it can be optimized internally.
      Parameters:
      values - Java String to populate the lists IonString's from
      Throws:
      IOException