public class ReadAheadInputStream extends InputStream
InputStream to asynchronously read ahead from an underlying input stream when a specified amount
of data has been read from the current buffer. It does so by maintaining two buffers: an active buffer and a read
ahead buffer. The 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. When 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 by disk I/O.
This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19.
| Constructor and Description |
|---|
ReadAheadInputStream(InputStream inputStream,
int bufferSizeInBytes)
Creates an instance with the specified buffer size and read-ahead threshold
|
ReadAheadInputStream(InputStream inputStream,
int bufferSizeInBytes,
ExecutorService executorService)
Creates an instance 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) |
mark, markSupported, read, resetpublic ReadAheadInputStream(InputStream inputStream, int bufferSizeInBytes)
inputStream - The underlying input stream.bufferSizeInBytes - The buffer size.public ReadAheadInputStream(InputStream inputStream, int bufferSizeInBytes, ExecutorService executorService)
inputStream - The underlying input stream.bufferSizeInBytes - The buffer size.executorService - An executor service for the read-ahead thread.public int available()
throws IOException
available in class InputStreamIOExceptionpublic 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 offset,
int len)
throws IOException
read in class InputStreamIOExceptionpublic long skip(long n)
throws IOException
skip in class InputStreamIOExceptionCopyright © 2002–2021 The Apache Software Foundation. All rights reserved.