Package org.apache.nifi.stream.io
Class LimitingInputStream
java.lang.Object
java.io.InputStream
org.apache.nifi.stream.io.LimitingInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
private final InputStream
private final long
private boolean
private long
-
Constructor Summary
ConstructorsConstructorDescriptionLimitingInputStream
(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. -
Method Summary
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
in
-
limit
private final long limit -
bytesRead
private long bytesRead -
limitReached
private volatile boolean limitReached -
markOffset
private long markOffset
-
-
Constructor Details
-
LimitingInputStream
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 streamlimit
- maximum length of bytes to read from underlying input stream
-
-
Method Details
-
hasReachedLimit
- Throws:
IOException
-
markLimitReached
private int markLimitReached() -
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
getLimit
public long getLimit()
-