public class LimitedReader extends java.io.Reader
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.
LimitedInputStream| Constructor and Description |
|---|
LimitedReader(java.io.Reader decoratedReader,
long limit)
Creates a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
long |
availableCharacters()
The number of characters available, before the specified maximum number will have been read from the decorated reader.
|
void |
close()
Closes the decorated reader, if that is currently allowed.
|
long |
getLimit()
Returns the maximum number of characters that will be read from the decorated reader.
|
boolean |
isAllowClose()
Determines whether closing this reader shall currently be prevented.
|
boolean |
isLimitReached()
Checks whether the specified maximum number of characters has been read from the underlying reader.
|
void |
mark(int readAheadLimit) |
boolean |
markSupported() |
int |
read(char[] buffer,
int offset,
int length) |
boolean |
ready() |
void |
reset() |
void |
setAllowClose(boolean allowClose)
Allows to specify whether closing this reader shall currently be prevented.
|
long |
skip(long n) |
public LimitedReader(java.io.Reader decoratedReader, long limit)
decoratedReader - the reader to be decoratedlimit - the maximum number of characters that shall be read from the decorated readerpublic long getLimit()
public long availableCharacters()
public boolean isLimitReached()
true if the maximum number of characters was readpublic 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.ReaderClosingNotAllowedException - if isAllowClose() currently returns true. (Calling this method, if
the decorated reader 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(char[] buffer, int offset, int length) throws java.io.IOException
read in class java.io.Readerjava.io.IOExceptionpublic long skip(long n) throws java.io.IOException
skip in class java.io.Readerjava.io.IOExceptionpublic void mark(int readAheadLimit) throws java.io.IOException
mark in class java.io.Readerjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.Readerpublic boolean ready() throws java.io.IOException
ready in class java.io.Readerjava.io.IOExceptionpublic void reset() throws java.io.IOException
reset in class java.io.Readerjava.io.IOException