Class InputStreamUtil

java.lang.Object
org.apache.derby.iapi.services.io.InputStreamUtil

public final class InputStreamUtil extends Object
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 Details

  • Constructor Details

    • InputStreamUtil

      public InputStreamUtil()
  • Method Details

    • readUnsignedByte

      public static int readUnsignedByte(InputStream in) throws IOException
      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

      public static void readFully(InputStream in, byte[] b, int offset, int len) throws IOException
      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

      public static int readLoop(InputStream in, byte[] b, int offset, int len) throws IOException
      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

      public static long skipUntilEOF(InputStream is) throws IOException
      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

      public static void skipFully(InputStream is, long skippedBytes) throws IOException
      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

      public static final long skipPersistent(InputStream in, long bytesToSkip) throws IOException
      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 stream
      bytesToSkip - the number of bytes to skip
      Returns:
      The number of bytes skipped.
      Throws:
      IOException - if reading from the stream fails