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) |
read
public LookaheadInputStream(InputStream stream, int n)
null
stream is treated as an empty stream.stream
- input stream, can be null
n
- maximum number of bytes to look aheadpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
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()
available
in class InputStream
public boolean markSupported()
markSupported
in class InputStream
public void mark(int readlimit)
mark
in class InputStream
public void reset()
reset
in class InputStream
Copyright © 2007–2018 The Apache Software Foundation. All rights reserved.