Class LimitReader

java.lang.Object
java.io.Reader
org.apache.derby.iapi.services.io.LimitReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable, Limit

public final class LimitReader extends Reader implements Limit
A Reader that provides methods to limit the range that can be read from the reader.
  • Field Details

    • remainingCharacters

      private int remainingCharacters
    • limitInPlace

      private boolean limitInPlace
    • reader

      private Reader reader
  • Constructor Details

    • LimitReader

      public LimitReader(Reader reader)
      Construct a LimitReader and call the clearLimit() method.
  • Method Details

    • read

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

      public int read(char[] c, int off, int len) throws IOException
      Specified by:
      read in class Reader
      Throws:
      IOException
    • skip

      public long skip(long count) throws IOException
      Overrides:
      skip in class Reader
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Reader
      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 characters can be read from or skipped in the stream. Any attempt to read more than length characters will result in an EOFException
      Specified by:
      setLimit in interface Limit
    • getLimit

      public final int getLimit()
      return limit of the stream that can be read without throwing EOFException
      Returns:
      the remaining characters left to be read from the stream
    • 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 not limit was set.