public final class LimitReader extends Reader
If a read call causes the limit to be exceeded and the limit reader is configured to throw an exception, the call will lead to a
LimitExceededException
to be thrown. Every subsequent read call will return -1
.
Constructor and Description |
---|
LimitReader(Reader reader,
long limit)
Creates a new limiting reader.
|
LimitReader(Reader reader,
long limit,
LimitExceededStrategy strategy)
Creates a new limiting reader.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
mark(int readAheadLimit) |
boolean |
markSupported() |
int |
read() |
int |
read(char[] cbuf,
int off,
int len) |
boolean |
ready() |
void |
reset() |
long |
skip(long n) |
public LimitReader(Reader reader, long limit)
reader
- The reader for which to limit the number of characters that can be read.limit
- The maximum number of characters that can be read.NullPointerException
- If the given reader is null
.IllegalArgumentException
- If the given limit is negative.public LimitReader(Reader reader, long limit, LimitExceededStrategy strategy)
reader
- The reader for which to limit the number of characters that can be read.limit
- The maximum number of characters that can be read.strategy
- The strategy to follow when the maximum number of characters has exceeded.NullPointerException
- If the given reader or strategy is null
.IllegalArgumentException
- If the given limit is negative.public int read() throws IOException
read
in class Reader
IOException
public int read(char[] cbuf, int off, int len) throws IOException
read
in class Reader
IOException
public long skip(long n) throws IOException
skip
in class Reader
IOException
public boolean ready() throws IOException
ready
in class Reader
IOException
public boolean markSupported()
markSupported
in class Reader
public void mark(int readAheadLimit) throws IOException
mark
in class Reader
IOException
public void reset() throws IOException
reset
in class Reader
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Reader
IOException
Copyright © 2020–2024. All rights reserved.