Class ProtonStreamUtils


  • public abstract class ProtonStreamUtils
    extends java.lang.Object
    Set of Utility methods useful when dealing with byte arrays and other primitive types.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte readByte​(java.io.InputStream stream)
      Reads a single byte from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
      static byte[] readBytes​(java.io.InputStream stream, int length)
      Reads the given number of bytes from the provided InputStream into an array and return that to the caller.
      static double readDouble​(java.io.InputStream stream)
      Reads a double value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
      static byte readEncodingCode​(java.io.InputStream stream)
      Reads a single byte from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
      static float readFloat​(java.io.InputStream stream)
      Reads a float value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
      static int readInt​(java.io.InputStream stream)
      Reads a integer value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
      static long readLong​(java.io.InputStream stream)
      Reads a long value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
      static short readShort​(java.io.InputStream stream)
      Reads a short value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
      static java.io.InputStream reset​(java.io.InputStream stream)
      Attempts to reset the provided InputStream to a previously marked point.
      static java.io.InputStream skipBytes​(java.io.InputStream stream, long amount)
      Attempts to skip the given number of bytes from the provided InputStream instance and throws a DecodeException if an error occurs during the skip.
      static java.io.OutputStream writeByte​(byte value, java.io.OutputStream stream)
      Write the given Byte to the target OutputStream.
      static java.io.OutputStream writeInt​(int value, java.io.OutputStream stream)
      Write the given Integer to the target OutputStream.
      static java.io.OutputStream writeLong​(long value, java.io.OutputStream stream)
      Write the given Long to the target OutputStream.
      static java.io.OutputStream writeShort​(short value, java.io.OutputStream stream)
      Write the given Short to the target OutputStream.
      • Methods inherited from class java.lang.Object

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

      • ProtonStreamUtils

        public ProtonStreamUtils()
    • Method Detail

      • writeByte

        public static java.io.OutputStream writeByte​(byte value,
                                                     java.io.OutputStream stream)
                                              throws EncodeException
        Write the given Byte to the target OutputStream.
        Parameters:
        value - the value to write to the OutputStream.
        stream - the OutputStream where the target value is to be written.
        Returns:
        the given OutputStream instance.
        Throws:
        EncodeException - if an error occurs while writing to the target OutputStream.
      • writeShort

        public static java.io.OutputStream writeShort​(short value,
                                                      java.io.OutputStream stream)
                                               throws EncodeException
        Write the given Short to the target OutputStream.
        Parameters:
        value - the value to write to the OutputStream.
        stream - the OutputStream where the target value is to be written.
        Returns:
        the given OutputStream instance.
        Throws:
        EncodeException - if an error occurs while writing to the target OutputStream.
      • writeInt

        public static java.io.OutputStream writeInt​(int value,
                                                    java.io.OutputStream stream)
                                             throws EncodeException
        Write the given Integer to the target OutputStream.
        Parameters:
        value - the value to write to the OutputStream.
        stream - the OutputStream where the target value is to be written.
        Returns:
        the given OutputStream instance.
        Throws:
        EncodeException - if an error occurs while writing to the target OutputStream.
      • writeLong

        public static java.io.OutputStream writeLong​(long value,
                                                     java.io.OutputStream stream)
                                              throws EncodeException
        Write the given Long to the target OutputStream.
        Parameters:
        value - the value to write to the OutputStream.
        stream - the OutputStream where the target value is to be written.
        Returns:
        the given OutputStream instance.
        Throws:
        EncodeException - if an error occurs while writing to the target OutputStream.
      • readBytes

        public static byte[] readBytes​(java.io.InputStream stream,
                                       int length)
                                throws DecodeException
        Reads the given number of bytes from the provided InputStream into an array and return that to the caller. If the requested number of bytes cannot be read from the stream an DecodeException is thrown to indicate an underflow.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        length - The number of bytes to read from the given input stream.
        Returns:
        a byte array containing the requested number of bytes read from the given InputStream
        Throws:
        DecodeException - if an error occurs reading from the stream or insufficient bytes are available.
      • readEncodingCode

        public static byte readEncodingCode​(java.io.InputStream stream)
                                     throws DecodeException
        Reads a single byte from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        Returns:
        the given byte that was read from the stream.
        Throws:
        DecodeException - if an error occurs during the read or EOF is reached.
      • readByte

        public static byte readByte​(java.io.InputStream stream)
                             throws DecodeException
        Reads a single byte from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        Returns:
        the given byte that was read from the stream.
        Throws:
        DecodeException - if an error occurs during the read or EOF is reached.
      • readShort

        public static short readShort​(java.io.InputStream stream)
        Reads a short value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        Returns:
        the given byte that was read from the stream.
        Throws:
        DecodeException - if an error occurs during the read or EOF is reached.
      • readInt

        public static int readInt​(java.io.InputStream stream)
        Reads a integer value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        Returns:
        the given byte that was read from the stream.
        Throws:
        DecodeException - if an error occurs during the read or EOF is reached.
      • readLong

        public static long readLong​(java.io.InputStream stream)
        Reads a long value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        Returns:
        the given byte that was read from the stream.
        Throws:
        DecodeException - if an error occurs during the read or EOF is reached.
      • readFloat

        public static float readFloat​(java.io.InputStream stream)
        Reads a float value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        Returns:
        the given byte that was read from the stream.
        Throws:
        DecodeException - if an error occurs during the read or EOF is reached.
      • readDouble

        public static double readDouble​(java.io.InputStream stream)
        Reads a double value from the given InputStream and thrown a DecodeException if the InputStream indicates an EOF condition was encountered.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        Returns:
        the given byte that was read from the stream.
        Throws:
        DecodeException - if an error occurs during the read or EOF is reached.
      • skipBytes

        public static java.io.InputStream skipBytes​(java.io.InputStream stream,
                                                    long amount)
        Attempts to skip the given number of bytes from the provided InputStream instance and throws a DecodeException if an error occurs during the skip.
        Parameters:
        stream - The InputStream where the bytes should be read from.
        amount - The number of bytes that should be skipped.
        Returns:
        the InputStream instance that was passed.
        Throws:
        DecodeException - if an error occurs during the read or EOF is reached.
      • reset

        public static java.io.InputStream reset​(java.io.InputStream stream)
                                         throws DecodeException
        Attempts to reset the provided InputStream to a previously marked point. If an error occurs this method throws an DecodeException to describe the error.
        Parameters:
        stream - The InputStream that is to be reset.
        Returns:
        the InputStream instance that was passed.
        Throws:
        DecodeException - if an error occurs during the reset.