Class LimitInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.derby.iapi.services.io.LimitInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, Limit
Direct Known Subclasses:
RawToBinaryFormatStream

public class LimitInputStream extends FilterInputStream implements Limit
An abstract InputStream that provides abstract methods to limit the range that can be read from the stream.
  • Field Details

    • remainingBytes

      protected int remainingBytes
    • limitInPlace

      protected boolean limitInPlace
  • Constructor Details

    • LimitInputStream

      public LimitInputStream(InputStream in)
      Construct a LimitInputStream and call the clearLimit() method.
  • Method Details

    • read

      public int read() throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • skip

      public long skip(long count) throws IOException
      Overrides:
      skip in class FilterInputStream
      Throws:
      IOException
    • available

      public int available() throws IOException
      Overrides:
      available in class FilterInputStream
      Throws:
      IOException
    • setLimit

      public void setLimit(int length)
      Set the limit of the stream that can be read. After this call up to and including length bytes can be read from or skipped in the stream. Any attempt to read more than length bytes will result in an EOFException
      Specified by:
      setLimit in interface Limit
    • clearLimit

      public int clearLimit()
      Clear any limit set by setLimit. After this call no limit checking will be made on any read until a setLimit()) call is made.
      Specified by:
      clearLimit in interface Limit
      Returns:
      the number of bytes within the limit that have not been read. -1 if no limit was set.
    • setInput

      public void setInput(InputStream in)
    • markSupported

      public boolean markSupported()
      This stream doesn't support mark/reset, independent of whether the underlying stream does so or not.

      The reason for not supporting mark/reset, is that it is hard to combine with the limit functionality without always keeping track of the number of bytes read.

      Overrides:
      markSupported in class FilterInputStream
      Returns:
      false