public final class BufferedFileChannelInputStream extends InputStream
InputStream implementation which uses direct buffer to read a file to avoid extra copy of data between Java
and native memory which happens when using BufferedInputStream. Unfortunately, this is not something
already available in JDK, sun.nio.ch.ChannelInputStream supports reading a file using NIO, but does not
support buffering.
This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19 where it was
called NioBufferedFileInputStream.
| Constructor and Description |
|---|
BufferedFileChannelInputStream(File file)
Constructs a new instance for the given File.
|
BufferedFileChannelInputStream(File file,
int bufferSizeInBytes)
Constructs a new instance for the given File and buffer size.
|
BufferedFileChannelInputStream(Path path)
Constructs a new instance for the given Path.
|
BufferedFileChannelInputStream(Path path,
int bufferSizeInBytes)
Constructs a new instance for the given Path and buffer size.
|
| 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 BufferedFileChannelInputStream(File file) throws IOException
file - The file to stream.IOException - If an I/O error occurspublic BufferedFileChannelInputStream(File file, int bufferSizeInBytes) throws IOException
file - The file to stream.bufferSizeInBytes - buffer size.IOException - If an I/O error occurspublic BufferedFileChannelInputStream(Path path) throws IOException
path - The path to stream.IOException - If an I/O error occurspublic BufferedFileChannelInputStream(Path path, int bufferSizeInBytes) throws IOException
path - The path to stream.bufferSizeInBytes - buffer size.IOException - If an I/O error occurspublic 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.