FSInputStream (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.fs, class: FSInputStream

Package org.apache.hadoop.fs

# Class FSInputStream

java.lang.Object
java.io.InputStream
org.apache.hadoop.fs.FSInputStream

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `PositionedReadable`, `Seekable`

Direct Known Subclasses:
  `FSInputChecker`, `FTPInputStream`

@Public @Evolving public abstract class FSInputStream extends InputStream implements Seekable, PositionedReadable
FSInputStream is a generic old InputStream with a little bit of RAF-style seek ability.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FSInputStream()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract long`
  `getPos()`
  Return the current offset from the start of the file
  `int`
  `read(long position, byte[] buffer, int offset, int length)`
  Read up to the specified number of bytes, from a given position within a file, and return the number of bytes read.
  `void`
  `readFully(long position, byte[] buffer)`
  Read number of bytes equal to the length of the buffer, from a given position within a file.
  `void`
  `readFully(long position, byte[] buffer, int offset, int length)`
  Read the specified number of bytes, from a given position within a file.
  `abstract void`
  `seek(long pos)`
  Seek to the given offset from the start of the file.
  `abstract boolean`
  `seekToNewSource(long targetPos)`
  Seeks a different copy of the data.
  `String`
  `toString()`
  toString method returns the superclass toString, but if the subclass implements `IOStatisticsSource` then those statistics are extracted and included in the output.
  `protected void`
  `validatePositionedReadArgs(long position, byte[] buffer, int offset, int length)`
  Validation code, available for use in subclasses.

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

  `available, close, mark, markSupported, nullInputStream, read, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo`

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

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

  ### Methods inherited from interface org.apache.hadoop.fs.PositionedReadable

  `maxReadSizeForVectorReads, minSeekForVectorReads, readVectored, readVectored`

- ## Constructor Details

  - ### FSInputStream

    public FSInputStream()

- ## Method Details

  - ### seek

    public abstract void seek(long pos) throws IOException
    Seek to the given offset from the start of the file. The next read() will be from that location. Can't seek past the end of the file.
    Specified by:
      `seek` in interface `Seekable`
    Parameters:
      `pos` - offset from the start of the file.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### getPos

    public abstract long getPos() throws IOException
    Return the current offset from the start of the file
    Specified by:
      `getPos` in interface `Seekable`
    Returns:
      offset from the start of the file.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### seekToNewSource

    public abstract boolean seekToNewSource(long targetPos) throws IOException
    Seeks a different copy of the data. Returns true if found a new source, false otherwise.
    Specified by:
      `seekToNewSource` in interface `Seekable`
    Parameters:
      `targetPos` - target position.
    Returns:
      true if found a new source, false otherwise.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### read

    public int read(long position, byte[] buffer, int offset, int length) throws IOException
    Description copied from interface: `PositionedReadable`
    Read up to the specified number of bytes, from a given position within a file, and return the number of bytes read. This does not change the current offset of a file, and is thread-safe. Warning: Not all filesystems satisfy the thread-safety requirement.
    Specified by:
      `read` in interface `PositionedReadable`
    Parameters:
      `position` - position within file
      `buffer` - destination buffer
      `offset` - offset in the buffer
      `length` - number of bytes to read
    Returns:
      actual number of bytes read; -1 means "none"
    Throws:
      `IOException` - IO problems.

  - ### validatePositionedReadArgs

    protected void validatePositionedReadArgs(long position, byte[] buffer, int offset, int length) throws EOFException
    Validation code, available for use in subclasses.
    Parameters:
      `position` - position: if negative an EOF exception is raised
      `buffer` - destination buffer
      `offset` - offset within the buffer
      `length` - length of bytes to read
    Throws:
      `EOFException` - if the position is negative
      `IndexOutOfBoundsException` - if there isn't space for the amount of data requested.
      `IllegalArgumentException` - other arguments are invalid.

  - ### readFully

    public void readFully(long position, byte[] buffer, int offset, int length) throws IOException
    Description copied from interface: `PositionedReadable`
    Read the specified number of bytes, from a given position within a file. This does not change the current offset of a file, and is thread-safe. Warning: Not all filesystems satisfy the thread-safety requirement.
    Specified by:
      `readFully` in interface `PositionedReadable`
    Parameters:
      `position` - position within file
      `buffer` - destination buffer
      `offset` - offset in the buffer
      `length` - number of bytes to read
    Throws:
      `IOException` - IO problems.
      `EOFException` - the end of the data was reached before the read operation completed

  - ### readFully

    public void readFully(long position, byte[] buffer) throws IOException
    Description copied from interface: `PositionedReadable`
    Read number of bytes equal to the length of the buffer, from a given position within a file. This does not change the current offset of a file, and is thread-safe. Warning: Not all filesystems satisfy the thread-safety requirement.
    Specified by:
      `readFully` in interface `PositionedReadable`
    Parameters:
      `position` - position within file
      `buffer` - destination buffer
    Throws:
      `IOException` - IO problems.
      `EOFException` - the end of the data was reached before the read operation completed

  - ### toString

    public String toString()
    toString method returns the superclass toString, but if the subclass implements `IOStatisticsSource` then those statistics are extracted and included in the output. That is: statistics of subclasses are automatically reported.
    Overrides:
      `toString` in class `Object`
    Returns:
      a string value.