Package org.apache.commons.io.input
Class ReadAheadInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.commons.io.input.ReadAheadInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ReadAheadInputStream extends java.io.FilterInputStreamImplementsInputStreamto 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, use
ReadAheadInputStream.Builder.This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19.
- Since:
- 2.9.0
- See Also:
ReadAheadInputStream.Builder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReadAheadInputStream.BuilderBuilds a newReadAheadInputStream.
-
Constructor Summary
Constructors Constructor Description ReadAheadInputStream(java.io.InputStream inputStream, int bufferSizeInBytes)Deprecated.ReadAheadInputStream(java.io.InputStream inputStream, int bufferSizeInBytes, java.util.concurrent.ExecutorService executorService)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()static ReadAheadInputStream.Builderbuilder()Constructs a newReadAheadInputStream.Builder.voidclose()intread()intread(byte[] b, int offset, int len)longskip(long n)
-
-
-
Constructor Detail
-
ReadAheadInputStream
@Deprecated public ReadAheadInputStream(java.io.InputStream inputStream, int bufferSizeInBytes)Deprecated.Constructs an instance with the specified buffer size and read-ahead threshold- Parameters:
inputStream- The underlying input stream.bufferSizeInBytes- The buffer size.
-
ReadAheadInputStream
@Deprecated public ReadAheadInputStream(java.io.InputStream inputStream, int bufferSizeInBytes, java.util.concurrent.ExecutorService executorService)Deprecated.Constructs an instance with the specified buffer size and read-ahead threshold- Parameters:
inputStream- The underlying input stream.bufferSizeInBytes- The buffer size.executorService- An executor service for the read-ahead thread.
-
-
Method Detail
-
builder
public static ReadAheadInputStream.Builder builder()
Constructs a newReadAheadInputStream.Builder.- Returns:
- a new
ReadAheadInputStream.Builder. - Since:
- 2.12.0
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int offset, int len) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
-