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.
To build an instance, see BufferedFileChannelInputStream.Builder
.
This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19 where it was called NioBufferedFileInputStream
.
Modifier and Type | Class and Description |
---|---|
static class |
BufferedFileChannelInputStream.Builder
Builds a new
BufferedFileChannelInputStream instance. |
Constructor and Description |
---|
BufferedFileChannelInputStream(File file)
Deprecated.
|
BufferedFileChannelInputStream(File file,
int bufferSize)
Deprecated.
|
BufferedFileChannelInputStream(Path path)
Deprecated.
|
BufferedFileChannelInputStream(Path path,
int bufferSize)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
static BufferedFileChannelInputStream.Builder |
builder()
Constructs a new
BufferedFileChannelInputStream.Builder . |
void |
close() |
int |
read() |
int |
read(byte[] b,
int offset,
int len) |
long |
skip(long n) |
mark, markSupported, read, reset
@Deprecated public BufferedFileChannelInputStream(File file) throws IOException
builder()
, BufferedFileChannelInputStream.Builder
, and BufferedFileChannelInputStream.Builder.get()
file
- The file to stream.IOException
- If an I/O error occurs@Deprecated public BufferedFileChannelInputStream(File file, int bufferSize) throws IOException
builder()
, BufferedFileChannelInputStream.Builder
, and BufferedFileChannelInputStream.Builder.get()
file
- The file to stream.bufferSize
- buffer size.IOException
- If an I/O error occurs@Deprecated public BufferedFileChannelInputStream(Path path) throws IOException
builder()
, BufferedFileChannelInputStream.Builder
, and BufferedFileChannelInputStream.Builder.get()
path
- The path to stream.IOException
- If an I/O error occurs@Deprecated public BufferedFileChannelInputStream(Path path, int bufferSize) throws IOException
builder()
, BufferedFileChannelInputStream.Builder
, and BufferedFileChannelInputStream.Builder.get()
path
- The path to stream.bufferSize
- buffer size.IOException
- If an I/O error occurspublic static BufferedFileChannelInputStream.Builder builder()
BufferedFileChannelInputStream.Builder
.BufferedFileChannelInputStream.Builder
.public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int offset, int len) throws IOException
read
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.