public class SizeLimitInputStream
extends java.io.InputStream
Modifier and Type | Field and Description |
---|---|
protected long |
bytesRead
The number of bytes that have been read
from this stream.
|
protected long |
bytesReadSinceMark
The number of bytes that have been read
from this stream since mark() was called.
|
protected java.io.InputStream |
in
The input stream that is being protected.
|
protected long |
markReadLimitBytes
The number of bytes the user has request
to have been marked for reset.
|
protected long |
maxBytesToRead
The number of bytes to read at most from this
Stream.
|
Constructor and Description |
---|
SizeLimitInputStream(java.io.InputStream in,
long maxBytesToRead)
Create a new size limit input stream from
another stream given a size limit.
|
Modifier and Type | Method and Description |
---|---|
boolean |
allBytesRead()
Tell whether the number of bytes specified
in the constructor have been read yet.
|
int |
available() |
void |
close()
Close this stream and underlying streams.
|
long |
getBytesLeft()
Get the maximum number of bytes left to read
before the limit (set in the constructor) is reached.
|
long |
getBytesRead()
Get the number of bytes actually read
from this stream.
|
long |
getMaxBytesToRead()
Get the number of total bytes (including bytes already read)
that can be read from this stream (as set in the constructor).
|
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
protected java.io.InputStream in
protected long maxBytesToRead
protected long bytesRead
protected long bytesReadSinceMark
protected long markReadLimitBytes
public SizeLimitInputStream(java.io.InputStream in, long maxBytesToRead)
in
- The input stream.maxBytesToRead
- the max number of bytes to allow to be read from the underlying stream.public long getBytesRead()
public long getBytesLeft()
public boolean allBytesRead()
public long getMaxBytesToRead()
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.InputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
Consider wrapping this stream in a NoCloseStream so that clients can call close() with no effect.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
public void mark(int readlimit)
mark
in class java.io.InputStream
public void reset() throws java.io.IOException
reset
in class java.io.InputStream
java.io.IOException
public boolean markSupported()
markSupported
in class java.io.InputStream
Copyright (c) 2001-2020 by Stephen Ostermiller