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.InputStreamInputStreamimplementation 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.ChannelInputStreamsupports 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.- Since:
- 2.9.0
-
-
Constructor Summary
Constructors Constructor Description BufferedFileChannelInputStream(java.io.File file)Constructs a new instance for the given File.BufferedFileChannelInputStream(java.io.File file, int bufferSizeInBytes)Constructs a new instance for the given File and buffer size.BufferedFileChannelInputStream(java.nio.file.Path path)Constructs a new instance for the given Path.BufferedFileChannelInputStream(java.nio.file.Path path, int bufferSizeInBytes)Constructs a new instance for the given Path and buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()intread()intread(byte[] b, int offset, int len)longskip(long n)
-
-
-
Constructor Detail
-
BufferedFileChannelInputStream
public BufferedFileChannelInputStream(java.io.File file) throws java.io.IOExceptionConstructs a new instance for the given File.- Parameters:
file- The file to stream.- Throws:
java.io.IOException- If an I/O error occurs
-
BufferedFileChannelInputStream
public BufferedFileChannelInputStream(java.io.File file, int bufferSizeInBytes) throws java.io.IOExceptionConstructs a new instance for the given File and buffer size.- Parameters:
file- The file to stream.bufferSizeInBytes- buffer size.- Throws:
java.io.IOException- If an I/O error occurs
-
BufferedFileChannelInputStream
public BufferedFileChannelInputStream(java.nio.file.Path path) throws java.io.IOExceptionConstructs a new instance for the given Path.- Parameters:
path- The path to stream.- Throws:
java.io.IOException- If an I/O error occurs
-
BufferedFileChannelInputStream
public BufferedFileChannelInputStream(java.nio.file.Path path, int bufferSizeInBytes) throws java.io.IOExceptionConstructs a new instance for the given Path and buffer size.- Parameters:
path- The path to stream.bufferSizeInBytes- buffer size.- Throws:
java.io.IOException- If an I/O error occurs
-
-
Method Detail
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- 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.InputStream- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int offset, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.InputStream- Throws:
java.io.IOException
-
-