Package ej.basictool

Class StreamUtils


  • public class StreamUtils
    extends Object
    Provides utility methods to manipulate streams.
    • Method Detail

      • readFully

        public static void readFully​(InputStream inputStream,
                                     byte[] array,
                                     int offset,
                                     int size)
                              throws IOException
        Reads an exact number of bytes from the given input stream.
        Parameters:
        inputStream - the input stream to read from.
        array - the array that will contain the data read.
        offset - the offset in the array of the first byte read.
        size - the number of bytes to read.
        Throws:
        EOFException - if the end of stream is reached before reading the given number of bytes.
        IOException - if an error occurred when reading from the input stream.
      • skipFully

        public static void skipFully​(InputStream inputStream,
                                     long size)
                              throws IOException
        Skips an exact number of bytes from the given input stream.
        Parameters:
        inputStream - the input stream to skip from.
        size - the number of bytes to skip.
        Throws:
        EOFException - if the end of stream is reached before skipping the given number of bytes.
        IOException - if an error occurred when reading from the input stream.