Package org.greenrobot.essentials.io
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 TypeMethodDescriptionint
void
close()
static GZIPInputStream
createGZIPInputStream
(InputStream in, int maxBytes) int
int
read()
int
read
(byte[] buffer) int
read
(byte[] buffer, int offset, int count) long
skip
(long byteCount) Methods inherited from class java.io.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:
available
in classInputStream
- Throws:
IOException
-
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
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
getBytesLeft
public int getBytesLeft()
-