Class BufferedFileChannelInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    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.

    Since:
    2.9.0
    • Constructor Detail

      • BufferedFileChannelInputStream

        public BufferedFileChannelInputStream​(File file)
                                       throws IOException
        Constructs a new instance for the given File.
        Parameters:
        file - The file to stream.
        Throws:
        IOException - If an I/O error occurs
      • BufferedFileChannelInputStream

        public BufferedFileChannelInputStream​(File file,
                                              int bufferSizeInBytes)
                                       throws IOException
        Constructs a new instance for the given File and buffer size.
        Parameters:
        file - The file to stream.
        bufferSizeInBytes - buffer size.
        Throws:
        IOException - If an I/O error occurs
      • BufferedFileChannelInputStream

        public BufferedFileChannelInputStream​(Path path)
                                       throws IOException
        Constructs a new instance for the given Path.
        Parameters:
        path - The path to stream.
        Throws:
        IOException - If an I/O error occurs
      • BufferedFileChannelInputStream

        public BufferedFileChannelInputStream​(Path path,
                                              int bufferSizeInBytes)
                                       throws IOException
        Constructs a new instance for the given Path and buffer size.
        Parameters:
        path - The path to stream.
        bufferSizeInBytes - buffer size.
        Throws:
        IOException - If an I/O error occurs