org.apache.cassandra.io.util

## Class FileHandle

- java.lang.Object
- - org.apache.cassandra.utils.concurrent.SharedCloseableImpl
  - - org.apache.cassandra.io.util.FileHandle

- All Implemented Interfaces:
    java.lang.AutoCloseable, SharedCloseable

      public class FileHandle
      extends SharedCloseableImpl

  `FileHandle` provides access to a file for reading, including the ones written by various `SequentialWriter` instances, and it is typically used by `SSTableReader`. Use `FileHandle.Builder` to create an instance, and call `createReader()` (and its variants) to access the readers for the underlying file. You can use `FileHandle.Builder.complete()` several times during its lifecycle with different `overrideLength`(i.e. early opening file). For that reason, the builder keeps a reference to the file channel and makes a copy for each `FileHandle.Builder.complete()` call. Therefore, it is important to close the `FileHandle.Builder` when it is no longer needed, as well as any `FileHandle` instances.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `FileHandle.Builder` Configures how the file will be read (compressed, mmapped, use cache etc.)

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `ChannelProxy` | `channel`
    `long` | `onDiskLength`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addTo(Ref.IdentityCollection identities)`
    `java.util.Optional<CompressionMetadata>` | `compressionMetadata()`
    `RandomAccessReader` | `createReader()` Create `RandomAccessReader` with configured method of reading content of the file.
    `FileDataInput` | `createReader(long position)`
    `RandomAccessReader` | `createReader(com.google.common.util.concurrent.RateLimiter limiter)` Create `RandomAccessReader` with configured method of reading content of the file.
    `long` | `dataLength()`
    `void` | `dropPageCache(long before)` Drop page cache from start to given `before`.
    `java.lang.String` | `path()`
    `RebuffererFactory` | `rebuffererFactory()`
    `FileHandle` | `sharedCopy()`
    `java.lang.String` | `toString()`

    - ### Methods inherited from class org.apache.cassandra.utils.concurrent.SharedCloseableImpl

      `close, close, isCleanedUp`

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

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

- - ### Field Detail

    - #### channel

          public final ChannelProxy channel

    - #### onDiskLength

          public final long onDiskLength

  - ### Method Detail

    - #### path

          public java.lang.String path()

      Returns:
        Path to the file this factory is referencing

    - #### dataLength

          public long dataLength()

    - #### rebuffererFactory

          public RebuffererFactory rebuffererFactory()

    - #### compressionMetadata

          public java.util.Optional<CompressionMetadata> compressionMetadata()

    - #### addTo

          public void addTo(Ref.IdentityCollection identities)

      Specified by:
        `addTo` in interface `SharedCloseable`
      Overrides:
        `addTo` in class `SharedCloseableImpl`

    - #### sharedCopy

          public FileHandle sharedCopy()

      Returns:
        a new instance of the object representing the same state and backed by the same underlying resources. Coordinates with the original (and other instances) when the underlying resource should be closed. Throws an exception if the shared resource has already been closed.

    - #### createReader

          public RandomAccessReader createReader()

      Create `RandomAccessReader` with configured method of reading content of the file.
      Returns:
        RandomAccessReader for the file

    - #### createReader

          public RandomAccessReader createReader(com.google.common.util.concurrent.RateLimiter limiter)

      Create `RandomAccessReader` with configured method of reading content of the file. Reading from file will be rate limited by given `RateLimiter`.
      Parameters:
        `limiter` - RateLimiter to use for rate limiting read
      Returns:
        RandomAccessReader for the file

    - #### createReader

          public FileDataInput createReader(long position)

    - #### dropPageCache

          public void dropPageCache(long before)

      Drop page cache from start to given `before`.
      Parameters:
        `before` - uncompressed position from start of the file to be dropped from cache. if 0, to end of file.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

Copyright © 2018 The Apache Software Foundation