java.lang.Object
java.io.InputStream
org.refcodes.io.BoundedInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
A
BoundedInputStream
decorates an InputStream
and restricts
reading bytes from the InputStream
decoratee up to a given total
number of bytes (bounds). In case the total number of bytes readable has been
exceeded then an according IOException
is thrown.-
Constructor Summary
ConstructorDescriptionBoundedInputStream
(InputStream aInputStream, int aTotalBytes) Constructs aBoundedInputStream
instances by decorating the givenInputStream
with the constraint of the given total number of bytes (bounds) which can be read. -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
int
Returns the total number of bytes to which thisInputStream
is bounded.int
Returns the number of bytes already been read by this stream.int
The total number of bytes (bounds) which can be read from thisInputStream
.void
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) byte[]
int
readNBytes
(byte[] arg0, int arg1, int arg2) void
reset()
long
skip
(long n) long
transferTo
(OutputStream out) Methods inherited from class java.io.InputStream
nullInputStream, readNBytes, skipNBytes
-
Constructor Details
-
BoundedInputStream
Constructs aBoundedInputStream
instances by decorating the givenInputStream
with the constraint of the given total number of bytes (bounds) which can be read.- Parameters:
aInputStream
- TheInputStream
to be decorated.aTotalBytes
- The total number of bytes (bounds) available for reading.
-
-
Method Details
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
- if an I/O error occurs or the total number of bytes readable would be exceeded (has already been consumed).
-
getTotalBytes
public int getTotalBytes()The total number of bytes (bounds) which can be read from thisInputStream
.- Returns:
- The overall number of bytes which can be read.
-
getBytesRead
public int getBytesRead()Returns the number of bytes already been read by this stream.- Returns:
- The number of bytes already read.
-
getBytesAvaialable
public int getBytesAvaialable()Returns the total number of bytes to which thisInputStream
is bounded.- Returns:
- The total number of bytes (bounds).
-
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
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
readAllBytes
- Overrides:
readAllBytes
in classInputStream
- Throws:
IOException
-
readNBytes
- Overrides:
readNBytes
in classInputStream
- Throws:
IOException
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
transferTo
- Overrides:
transferTo
in classInputStream
- Throws:
IOException
-