public class LookaheadInputStream extends InputStream
The recommended usage pattern of this class is:
try (InputStream lookahead = new LookaheadInputStream(stream, n)) {
processStream(lookahead);
}
This usage pattern guarantees that only up to n bytes from the original stream can ever be read, and that the stream will have been marked and then reset to its original state once the above code block exits. No code in the fictional processStream() method can affect the the state of the original stream.
| Constructor and Description |
|---|
LookaheadInputStream(InputStream stream,
int n)
Creates a lookahead wrapper for the given input stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
readpublic LookaheadInputStream(InputStream stream, int n)
null stream is treated as an empty stream.stream - input stream, can be nulln - maximum number of bytes to look aheadpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic int read()
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
read in class InputStreamIOExceptionpublic long skip(long n)
throws IOException
skip in class InputStreamIOExceptionpublic int available()
available in class InputStreampublic boolean markSupported()
markSupported in class InputStreampublic void mark(int readlimit)
mark in class InputStreampublic void reset()
reset in class InputStreamCopyright © 2007–2021 The Apache Software Foundation. All rights reserved.