Class IonStreamUtils


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

      Constructors 
      Constructor Description
      IonStreamUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      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 java.io.InputStream unGzip​(java.io.InputStream in)
      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, java.lang.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 Detail

      • IonStreamUtils

        public IonStreamUtils()
    • Method Detail

      • 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(byte[], int, int)
      • 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:
        isIonBinary(byte[])
      • 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 java.io.InputStream unGzip​(java.io.InputStream in)
                                          throws java.io.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:
        java.io.IOException
      • writeBoolList

        public static void writeBoolList​(IonWriter writer,
                                         boolean[] values)
                                  throws java.io.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:
        java.io.IOException
      • writeFloatList

        public static void writeFloatList​(IonWriter writer,
                                          float[] values)
                                   throws java.io.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:
        java.io.IOException
      • writeFloatList

        public static void writeFloatList​(IonWriter writer,
                                          double[] values)
                                   throws java.io.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:
        java.io.IOException
      • writeIntList

        public static void writeIntList​(IonWriter writer,
                                        byte[] values)
                                 throws java.io.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:
        java.io.IOException
      • writeIntList

        public static void writeIntList​(IonWriter writer,
                                        short[] values)
                                 throws java.io.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:
        java.io.IOException
      • writeIntList

        public static void writeIntList​(IonWriter writer,
                                        int[] values)
                                 throws java.io.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:
        java.io.IOException
      • writeIntList

        public static void writeIntList​(IonWriter writer,
                                        long[] values)
                                 throws java.io.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:
        java.io.IOException
      • writeStringList

        public static void writeStringList​(IonWriter writer,
                                           java.lang.String[] values)
                                    throws java.io.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:
        java.io.IOException