public class LimitedInputStream extends java.io.InputStream
BufferedReader is decorated).
The focus of this class is to make sure that not more characters than specified can be read from the underlying reader. It can
e.g. be used to ensure that reading beyond the read ahead limit of a call of mark(int) is not possible.
LimitedReader| Constructor and Description |
|---|
LimitedInputStream(java.io.InputStream decoratedStream,
long limit)
Creates a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
long |
availableCharacters()
The number of bytes available, before the specified maximum number will have been read from the decorated input stream.
|
void |
close()
Closes the decorated input stream, if that is currently allowed.
|
long |
getLimit()
Returns the maximum number of bytes that will be read from the decorated stream.
|
boolean |
isAllowClose()
Determines whether closing this input stream shall currently be prevented.
|
boolean |
isLimitReached()
Checks whether the specified maximum number of bytes has been read from the decorated input stream.
|
void |
mark(int readAheadLimit) |
boolean |
markSupported() |
int |
read()
Returns the next byte from the decorated stream or -1 if either the end of the decorated stream or the limit specified to
this stream have been reached.
|
void |
reset() |
void |
setAllowClose(boolean allowClose)
Allows to specify whether closing this input stream shall currently be prevented.
|
long |
skip(long n) |
public LimitedInputStream(java.io.InputStream decoratedStream, long limit)
decoratedStream - the input stream to be decoratedlimit - the maximum number of bytes that shall be read from the decorated input streampublic long getLimit()
public long availableCharacters()
public boolean isLimitReached()
true, if the maximum number of bytes has not yet been read, even if the end of
the stream was already reached. In such cases it can be used to determine whether the limit or the real end of the stream
have been reached.true if the maximum number of bytes was read, false if the limit is not yet reachedpublic boolean isAllowClose()
close() will throw
an ClosingNotAllowedException in such cases.true, if closing this reader will currently be prevented or false otherwisepublic void setAllowClose(boolean allowClose)
close() will then throw
an ClosingNotAllowedException.allowClose - Specify true here, if closing shall be prevented from now on or false otherwise.public void close() throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamClosingNotAllowedException - if isAllowClose() currently returns true. (Calling this method, if
the decorated stream was already closed will also throw this exception, if closing is currently not allowed.)java.io.IOException - if an I/O error occurssetAllowClose(boolean),
Reader.close()public int read() throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.InputStreampublic int available() throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic void mark(int readAheadLimit)
mark in class java.io.InputStreampublic void reset() throws java.io.IOException
reset in class java.io.InputStreamjava.io.IOExceptionpublic long skip(long n) throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOException