Class StreamUtil
java.lang.Object
com.aquima.interactions.foundation.utility.StreamUtil
Utility class for handling streams.
- Since:
- 9.0
- Author:
- Arjan Pragt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
MAX_SKIP_BUFFER_SIZE is used to determine the maximum buffer size to use when skipping. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
getBytes
(InputStream stream) static void
skip
(InputStream is, long number) Skips over and discardsnumber
bytes of data from the input stream.
-
Field Details
-
MAX_SKIP_BUFFER_SIZE
public static final int MAX_SKIP_BUFFER_SIZEMAX_SKIP_BUFFER_SIZE is used to determine the maximum buffer size to use when skipping.- See Also:
-
-
Method Details
-
getBytes
- Throws:
IOException
-
skip
Skips over and discardsnumber
bytes of data from the input stream. TheInputStream
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 benull
).number
- The number of bytes to skip (cannot be negative);- Throws:
IOException
- Since:
- 9.3
-