Class InputStreamUtils


  • public class InputStreamUtils
    extends Object
    Convenience methods to read from InputStream.
    • Constructor Detail

      • InputStreamUtils

        public InputStreamUtils()
    • Method Detail

      • readFully

        public static byte[] readFully​(InputStream input)
        Read the InputStream until the end into a new byte array.
        Parameters:
        input - the input stream to read
        Returns:
        a new byte array containing data from the input stream
      • readFully

        public static byte[] readFully​(InputStream inputStream,
                                       int length)
        Read the specified number of bytes from the InputStream into a new byte array. The length of the array is less or equal to length.
        Parameters:
        inputStream - the input stream to read from
        length - the number of bytes to read
        Returns:
        a new byte array containing data from the input stream
        Throws:
        RuntimeEOFException - if there is less than length bytes in the stream
      • readFully

        public static void readFully​(InputStream inputStream,
                                     byte[] b,
                                     int off,
                                     int length)
        Read the specified number of bytes from the InputStream into the byte array starting from the specified position. The length of the array is less or equal to length.
        Parameters:
        inputStream - the input stream to read from
        b - the byte array to read into
        off - offset in the byte array
        length - the number of bytes to read
        Throws:
        RuntimeEOFException - if there is less than length bytes in the stream
      • skipFully

        public static void skipFully​(InputStream in,
                                     long length)
        Skip the specified number of bytes from the InputStream.
        Parameters:
        in - the input stream to skip bytes from
        length - the number of bytes to skip
        Throws:
        RuntimeEOFException - if there is less than length bytes in the stream