- java.lang.Object
-
- java.io.InputStream
-
- org.refcodes.io.BoundedInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class BoundedInputStream extends InputStream
ABoundedInputStreamdecorates anInputStreamand restricts reading bytes from theInputStreamdecoratee up to a given total number of bytes (bounds). In case the total number of bytes readable has been exceeded then an accordingIOExceptionis thrown.
-
-
Constructor Summary
Constructors Constructor Description BoundedInputStream(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()intgetBytesAvaialable()Returns the total number of bytes to which thisInputStreamis bounded.intgetBytesRead()Returns the number of bytes already been read by this stream.intgetTotalBytes()The total number of bytes (bounds) which can be read from thisInputStream.voidmark(int readlimit)booleanmarkSupported()intread()intread(byte[] b)intread(byte[] b, int off, int len)byte[]readAllBytes()intreadNBytes(byte[] arg0, int arg1, int arg2)voidreset()longskip(long n)longtransferTo(OutputStream out)-
Methods inherited from class java.io.InputStream
nullInputStream, readNBytes
-
-
-
-
Constructor Detail
-
BoundedInputStream
public BoundedInputStream(InputStream aInputStream, int aTotalBytes)
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 Detail
-
read
public int read() throws IOException- 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
public int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
close
public void close() throws IOException- 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
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
readAllBytes
public byte[] readAllBytes() throws IOException- Overrides:
readAllBytesin classInputStream- Throws:
IOException
-
readNBytes
public int readNBytes(byte[] arg0, int arg1, int arg2) throws IOException- Overrides:
readNBytesin classInputStream- Throws:
IOException
-
reset
public void reset() throws IOException- Overrides:
resetin classInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classInputStream- Throws:
IOException
-
transferTo
public long transferTo(OutputStream out) throws IOException
- Overrides:
transferToin classInputStream- Throws:
IOException
-
-