Class BoundedInputStream
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
ConstructorsConstructorDescriptionBoundedInputStream(InputStream aInputStream, int aTotalBytes) Constructs aBoundedInputStreaminstances by decorating the givenInputStreamwith the constraint of the given total number of bytes (bounds) which can be read. -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()intReturns the total number of bytes to which thisInputStreamis bounded.intReturns the number of bytes already been read by this stream.intThe total number of bytes (bounds) which can be read from thisInputStream.voidmark(int readlimit) booleanintread()intread(byte[] b) intread(byte[] b, int off, int len) byte[]intreadNBytes(byte[] arg0, int arg1, int arg2) voidreset()longskip(long n) longtransferTo(OutputStream out) Methods inherited from class InputStream
nullInputStream, readNBytes, skipNBytes
-
Constructor Details
-
BoundedInputStream
Constructs aBoundedInputStreaminstances by decorating the givenInputStreamwith the constraint of the given total number of bytes (bounds) which can be read.- Parameters:
aInputStream- TheInputStreamto be decorated.aTotalBytes- The total number of bytes (bounds) available for reading.
-
-
Method Details
-
read
- Specified by:
readin 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 thisInputStreamis bounded.- Returns:
- The total number of bytes (bounds).
-
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
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
readAllBytes
- Overrides:
readAllBytesin classInputStream- Throws:
IOException
-
readNBytes
- Overrides:
readNBytesin classInputStream- Throws:
IOException
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
transferTo
- Overrides:
transferToin classInputStream- Throws:
IOException
-