Package org.apache.commons.io.input
Class BufferedFileChannelInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.BufferedFileChannelInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public final class BufferedFileChannelInputStream extends java.io.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 usingBufferedInputStream
. 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
.- Since:
- 2.9.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BufferedFileChannelInputStream.Builder
Builds a newBufferedFileChannelInputStream
instance.
-
Constructor Summary
Constructors Constructor Description BufferedFileChannelInputStream(java.io.File file)
Deprecated.BufferedFileChannelInputStream(java.io.File file, int bufferSize)
Deprecated.BufferedFileChannelInputStream(java.nio.file.Path path)
Deprecated.BufferedFileChannelInputStream(java.nio.file.Path path, int bufferSize)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
static BufferedFileChannelInputStream.Builder
builder()
Constructs a newBufferedFileChannelInputStream.Builder
.void
close()
int
read()
int
read(byte[] b, int offset, int len)
long
skip(long n)
-
-
-
Constructor Detail
-
BufferedFileChannelInputStream
@Deprecated public BufferedFileChannelInputStream(java.io.File file) throws java.io.IOException
Deprecated.Constructs a new instance for the given File.- Parameters:
file
- The file to stream.- Throws:
java.io.IOException
- If an I/O error occurs
-
BufferedFileChannelInputStream
@Deprecated public BufferedFileChannelInputStream(java.io.File file, int bufferSize) throws java.io.IOException
Deprecated.Constructs a new instance for the given File and buffer size.- Parameters:
file
- The file to stream.bufferSize
- buffer size.- Throws:
java.io.IOException
- If an I/O error occurs
-
BufferedFileChannelInputStream
@Deprecated public BufferedFileChannelInputStream(java.nio.file.Path path) throws java.io.IOException
Deprecated.Constructs a new instance for the given Path.- Parameters:
path
- The path to stream.- Throws:
java.io.IOException
- If an I/O error occurs
-
BufferedFileChannelInputStream
@Deprecated public BufferedFileChannelInputStream(java.nio.file.Path path, int bufferSize) throws java.io.IOException
Deprecated.Constructs a new instance for the given Path and buffer size.- Parameters:
path
- The path to stream.bufferSize
- buffer size.- Throws:
java.io.IOException
- If an I/O error occurs
-
-
Method Detail
-
builder
public static BufferedFileChannelInputStream.Builder builder()
Constructs a newBufferedFileChannelInputStream.Builder
.- Returns:
- a new
BufferedFileChannelInputStream.Builder
. - Since:
- 2.12.0
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int offset, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.InputStream
- Throws:
java.io.IOException
-
-