Class StreamUtil

java.lang.Object
com.aquima.interactions.foundation.utility.StreamUtil

public final class StreamUtil extends Object
Utility class for handling streams.
Since:
9.0
Author:
Arjan Pragt
  • Field Details

    • MAX_SKIP_BUFFER_SIZE

      public static final int MAX_SKIP_BUFFER_SIZE
      MAX_SKIP_BUFFER_SIZE is used to determine the maximum buffer size to use when skipping.
      See Also:
  • Method Details

    • getBytes

      public static byte[] getBytes(InputStream stream) throws IOException
      Throws:
      IOException
    • skip

      public static void skip(InputStream is, long number) throws IOException
      Skips over and discards number bytes of data from the input stream. The InputStream implementation provides a method to skip over bytes in the stream, but its contract explicitly defines the absence of a success guarantee. The implementation provided here does provide such a guarantee. This implementation first uses the provided skip() implementation as provided by the stream. If that fails to successfully skip the desired amount of bytes, this implementation reverts to reading (and discarding) data from the stream, iteratively until the desired amount of bytes are skipped. This method may skip more bytes than are remaining in the backing file. This produces no exception and the number of bytes skipped may include some number of bytes that were beyond the EOF of the backing file. Attempting to read from the stream after skipping past the end will result in -1 indicating the end of the file.
      Parameters:
      is - The input stream in which to skip over bytes (cannot be null).
      number - The number of bytes to skip (cannot be negative);
      Throws:
      IOException - IO errors
      Since:
      9.3