Class LimitingInputStream

java.lang.Object
java.io.InputStream
org.apache.nifi.stream.io.LimitingInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class LimitingInputStream extends InputStream
  • Field Details

    • in

      private final InputStream in
    • limit

      private final long limit
    • bytesRead

      private long bytesRead
    • limitReached

      private volatile boolean limitReached
    • markOffset

      private long markOffset
  • Constructor Details

    • LimitingInputStream

      public LimitingInputStream(InputStream in, long limit)
      Constructs a limited input stream whereby if the limit is reached all subsequent calls to read will return a -1 and hasLimitReached() will indicate true. The limit is inclusive so if all 100 bytes of a 100 byte stream are read it will be true, otherwise false.
      Parameters:
      in - the underlying input stream
      limit - maximum length of bytes to read from underlying input stream
  • Method Details