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 longprivate final InputStreamprivate final longprivate booleanprivate 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:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
getLimit
public long getLimit()
-