public class ReadAheadInputStream
extends java.io.FilterInputStream
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.
To build an instance, see ReadAheadInputStream.Builder
.
This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19.
Modifier and Type | Class and Description |
---|---|
static class |
ReadAheadInputStream.Builder
Builds a new
ReadAheadInputStream instance. |
Constructor and Description |
---|
ReadAheadInputStream(java.io.InputStream inputStream,
int bufferSizeInBytes)
Deprecated.
|
ReadAheadInputStream(java.io.InputStream inputStream,
int bufferSizeInBytes,
java.util.concurrent.ExecutorService executorService)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
static ReadAheadInputStream.Builder |
builder()
Constructs a new
ReadAheadInputStream.Builder . |
void |
close() |
int |
read() |
int |
read(byte[] b,
int offset,
int len) |
long |
skip(long n) |
@Deprecated public ReadAheadInputStream(java.io.InputStream inputStream, int bufferSizeInBytes)
builder()
, ReadAheadInputStream.Builder
, and ReadAheadInputStream.Builder.get()
inputStream
- The underlying input stream.bufferSizeInBytes
- The buffer size.@Deprecated public ReadAheadInputStream(java.io.InputStream inputStream, int bufferSizeInBytes, java.util.concurrent.ExecutorService executorService)
builder()
, ReadAheadInputStream.Builder
, and ReadAheadInputStream.Builder.get()
inputStream
- The underlying input stream.bufferSizeInBytes
- The buffer size.executorService
- An executor service for the read-ahead thread.public static ReadAheadInputStream.Builder builder()
ReadAheadInputStream.Builder
.ReadAheadInputStream.Builder
.public int available() throws java.io.IOException
available
in class java.io.FilterInputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.FilterInputStream
java.io.IOException
public int read() throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public int read(byte[] b, int offset, int len) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.FilterInputStream
java.io.IOException
Copyright © 2010 - 2023 Adobe. All Rights Reserved