Package org.apache.commons.io.input

# Class BufferedFileChannelInputStream

java.lang.Object
java.io.InputStream
org.apache.commons.io.input.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.

To build an instance, use `BufferedFileChannelInputStream.Builder`.

This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19 where it was called `NioBufferedFileInputStream`.

Since:
  2.9.0
See Also:
  - `BufferedFileChannelInputStream.Builder`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `BufferedFileChannelInputStream.Builder`
  Builds a new `BufferedFileChannelInputStream`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BufferedFileChannelInputStream(File file)`
  Deprecated.
  Use `builder()`, `BufferedFileChannelInputStream.Builder`, and `BufferedFileChannelInputStream.Builder.get()`
  `BufferedFileChannelInputStream(File file, int bufferSize)`
  Deprecated.
  Use `builder()`, `BufferedFileChannelInputStream.Builder`, and `BufferedFileChannelInputStream.Builder.get()`
  `BufferedFileChannelInputStream(Path path)`
  Deprecated.
  Use `builder()`, `BufferedFileChannelInputStream.Builder`, and `BufferedFileChannelInputStream.Builder.get()`
  `BufferedFileChannelInputStream(Path path, int bufferSize)`
  Deprecated.
  Use `builder()`, `BufferedFileChannelInputStream.Builder`, and `BufferedFileChannelInputStream.Builder.get()`

- ## Method Summary

  Modifier and Type
  Method
  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)`

  ### Methods inherited from class java.io.InputStream

  `mark, markSupported, read, reset`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### BufferedFileChannelInputStream

    @Deprecated public BufferedFileChannelInputStream(File file) throws IOException
    Deprecated.
    Use `builder()`, `BufferedFileChannelInputStream.Builder`, and `BufferedFileChannelInputStream.Builder.get()`
    Constructs a new instance for the given File.
    Parameters:
      `file` - The file to stream.
    Throws:
      `IOException` - If an I/O error occurs

  - ### BufferedFileChannelInputStream

    @Deprecated public BufferedFileChannelInputStream(File file, int bufferSize) throws IOException
    Deprecated.
    Use `builder()`, `BufferedFileChannelInputStream.Builder`, and `BufferedFileChannelInputStream.Builder.get()`
    Constructs a new instance for the given File and buffer size.
    Parameters:
      `file` - The file to stream.
      `bufferSize` - buffer size.
    Throws:
      `IOException` - If an I/O error occurs

  - ### BufferedFileChannelInputStream

    @Deprecated public BufferedFileChannelInputStream(Path path) throws IOException
    Deprecated.
    Use `builder()`, `BufferedFileChannelInputStream.Builder`, and `BufferedFileChannelInputStream.Builder.get()`
    Constructs a new instance for the given Path.
    Parameters:
      `path` - The path to stream.
    Throws:
      `IOException` - If an I/O error occurs

  - ### BufferedFileChannelInputStream

    @Deprecated public BufferedFileChannelInputStream(Path path, int bufferSize) throws IOException
    Deprecated.
    Use `builder()`, `BufferedFileChannelInputStream.Builder`, and `BufferedFileChannelInputStream.Builder.get()`
    Constructs a new instance for the given Path and buffer size.
    Parameters:
      `path` - The path to stream.
      `bufferSize` - buffer size.
    Throws:
      `IOException` - If an I/O error occurs

- ## Method Details

  - ### builder

    public static BufferedFileChannelInputStream.Builder builder()
    Constructs a new `BufferedFileChannelInputStream.Builder`.
    Returns:
      a new `BufferedFileChannelInputStream.Builder`.
    Since:
      2.12.0

  - ### available

    public int available() throws IOException
    Overrides:
      `available` in class `InputStream`
    Throws:
      `IOException`

  - ### close

    public void close() throws IOException
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `InputStream`
    Throws:
      `IOException`

  - ### read

    public int read() throws IOException
    Specified by:
      `read` in class `InputStream`
    Throws:
      `IOException`

  - ### read

    public int read(byte[] b, int offset, int len) throws IOException
    Overrides:
      `read` in class `InputStream`
    Throws:
      `IOException`

  - ### skip

    public long skip(long n) throws IOException
    Overrides:
      `skip` in class `InputStream`
    Throws:
      `IOException`