Class InputStreamUtil
java.lang.Object
org.apache.derby.iapi.services.io.InputStreamUtil
Utility methods for InputStream that are stand-ins for
a small subset of DataInput methods. This avoids pushing
a DataInputStream just to get this functionality.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
readFully
(InputStream in, byte[] b, int offset, int len) Read a number of bytes into an array.static int
readLoop
(InputStream in, byte[] b, int offset, int len) Read a number of bytes into an array.static int
Read an unsigned byte from an InputStream, throwing an EOFException if the end of the input is reached.static void
skipFully
(InputStream is, long skippedBytes) Skips requested number of bytes, throws EOFException if there is too few bytes in the stream.static final long
skipPersistent
(InputStream in, long bytesToSkip) Tries harder to skip the requested number of bytes.static long
Skips until EOF, returns number of bytes skipped.
-
Field Details
-
SKIP_FRAGMENT_SIZE
private static final int SKIP_FRAGMENT_SIZE- See Also:
-
-
Constructor Details
-
InputStreamUtil
public InputStreamUtil()
-
-
Method Details
-
readUnsignedByte
Read an unsigned byte from an InputStream, throwing an EOFException if the end of the input is reached.- Throws:
IOException
- if an I/O error occurs.EOFException
- if the end of the stream is reached- See Also:
-
readFully
Read a number of bytes into an array.- Throws:
IOException
- if an I/O error occurs.EOFException
- if the end of the stream is reached- See Also:
-
readLoop
Read a number of bytes into an array. Keep reading in a loop until len bytes are read or EOF is reached or an exception is thrown. Return the number of bytes read. (InputStream.read(byte[],int,int) does not guarantee to read len bytes even if it can do so without reaching EOF or raising an exception.)- Throws:
IOException
- if an I/O error occurs.
-
skipUntilEOF
Skips until EOF, returns number of bytes skipped.- Parameters:
is
- InputStream to be skipped.- Returns:
- number of bytes skipped in fact.
- Throws:
IOException
- if IOException occurs. It doesn't contain EOFException.NullPointerException
- if the param 'is' equals null.
-
skipFully
Skips requested number of bytes, throws EOFException if there is too few bytes in the stream.- Parameters:
is
- InputStream to be skipped.skippedBytes
- number of bytes to skip. if skippedBytes ≷= zero, do nothing.- Throws:
EOFException
- if EOF meets before requested number of bytes are skipped.IOException
- if IOException occurs. It doesn't contain EOFException.NullPointerException
- if the param 'is' equals null.
-
skipPersistent
Tries harder to skip the requested number of bytes.Note that even if the method fails to skip the requested number of bytes, it will not throw an exception. If this happens, the caller can be sure that end-of-stream has been reached.
- Parameters:
in
- byte streambytesToSkip
- the number of bytes to skip- Returns:
- The number of bytes skipped.
- Throws:
IOException
- if reading from the stream fails
-