public class ReadAheadInputStream
extends java.io.InputStream
InputStream
implementation which asynchronously reads ahead from the underlying input
stream when specified amount of data has been read from the current buffer. It does it by
maintaining two buffers - active buffer and read ahead buffer. Active buffer contains data
which should be returned when a read() call is issued. The read ahead buffer is used to
asynchronously read from the underlying input stream and once the current active buffer is
exhausted, we flip the two buffers so that we can start reading from the read ahead buffer
without being blocked in disk I/O.Constructor and Description |
---|
ReadAheadInputStream(java.io.InputStream inputStream,
int bufferSizeInBytes,
int readAheadThresholdInBytes)
Creates a
ReadAheadInputStream with the specified buffer size and read-ahead
threshold |
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
int |
read() |
int |
read(byte[] b,
int offset,
int len) |
long |
skip(long n) |
public ReadAheadInputStream(java.io.InputStream inputStream, int bufferSizeInBytes, int readAheadThresholdInBytes)
ReadAheadInputStream
with the specified buffer size and read-ahead
thresholdinputStream
- The underlying input stream.bufferSizeInBytes
- The buffer size.readAheadThresholdInBytes
- If the active buffer has less data than the read-ahead
threshold, an async read is triggered.public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int offset, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface AutoCloseable
close
in class java.io.InputStream
java.io.IOException