Class LimitedInputStream
java.lang.Object
java.io.InputStream
org.greenrobot.essentials.io.LimitedInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
Wraps around an InputStream and limits the amount of bytes that can be read from it. Use it if you operate on an
InputStream that consists of chunks of a know size, each to be processed using a buffered input stream (e.g.
GZIPInputStream). Normal buffered input streams would read beyond the limit. The LimitedInputStream never closes the
inside InputStream(close does nothing).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()static GZIPInputStreamcreateGZIPInputStream(InputStream in, int maxBytes) intintread()intread(byte[] buffer) intread(byte[] buffer, int offset, int count) longskip(long byteCount) Methods inherited from class InputStream
mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skipNBytes, transferTo
-
Field Details
-
bytesLeft
private int bytesLeft -
in
-
-
Constructor Details
-
LimitedInputStream
-
-
Method Details
-
createGZIPInputStream
public static GZIPInputStream createGZIPInputStream(InputStream in, int maxBytes) throws IOException - Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
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
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
getBytesLeft
public int getBytesLeft()
-