public final class LimitInputStream extends InputStream
If a read call causes the limit to be exceeded and the limit input stream 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 |
---|
LimitInputStream(InputStream input,
long limit)
Creates a new limiting input stream.
|
LimitInputStream(InputStream input,
long limit,
LimitExceededStrategy strategy)
Creates a new limiting input stream.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
void |
mark(int readAheadLimit) |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
read
public LimitInputStream(InputStream input, long limit)
input
- The input stream for which to limit the number of bytes that can be read.limit
- The maximum number of bytes that can be read.NullPointerException
- If the given input stream is null
.IllegalArgumentException
- If the given limit is negative.public LimitInputStream(InputStream input, long limit, LimitExceededStrategy strategy)
input
- The input stream for which to limit the number of bytes that can be read.limit
- The maximum number of bytes that can be read.strategy
- The strategy to follow when the maximum number of bytes has exceeded.NullPointerException
- If the given input stream or strategy is null
.IllegalArgumentException
- If the given limit is negative.public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public int available() throws IOException
available
in class InputStream
IOException
public boolean markSupported()
markSupported
in class InputStream
public void mark(int readAheadLimit)
mark
in class InputStream
public void reset() throws IOException
reset
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
Copyright © 2020–2024. All rights reserved.