org.apache.hadoop.fs

## Interface PositionedReadable

- All Known Implementing Classes:
    CryptoFSDataInputStream, FSDataInputStream, FSInputStream

      @InterfaceAudience.Public
       @InterfaceStability.Evolving
      public interface PositionedReadable

  Stream that permits positional reading. Implementations are required to implement thread-safe operations; this may be supported by concurrent access to the data, or by using a synchronization mechanism to serialize access. Not all implementations meet this requirement. Those that do not cannot be used as a backing store for some applications, such as Apache HBase. Independent of whether or not they are thread safe, some implementations may make the intermediate state of the system, specifically the position obtained in `Seekable.getPos()` visible.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.

- - ### Method Detail

    - #### read

          int read(long position,
                   byte[] buffer,
                   int offset,
                   int length)
            throws IOException

      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.
      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.

    - #### readFully

          void readFully(long position,
                         byte[] buffer,
                         int offset,
                         int length)
                  throws IOException

      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.
      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

          void readFully(long position,
                         byte[] buffer)
                  throws IOException

      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.
      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

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.