java.lang.Object
org.klomp.snark.Storage.FileCursor
Enclosing class:
Storage

private final class Storage.FileCursorextends Object
Cursor over the torrent's files, mapping an absolute byte position in the torrent to the containing file and the offset within it. Used for sequential reads and writes across file boundaries.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    Index of the file holding the piece.
    private long
    Length of the file being read.
    private long
    Offset where the piece starts in the file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FileCursor(long pos)
    Position the cursor at the given absolute byte offset in the torrent.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    (package private) void
    advance(int len, int need)
    Advance the cursor past a consumed chunk, moving to the next file when the chunk ended at a file boundary.
    (package private) int
    chunk(int need)
    The chunk length from the cursor position to the end of the current file, or need, whichever is smaller.
    (package private) Storage.TorrentFile
    The file containing the cursor position.
    (package private) long
    The offset of the cursor within the current file.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • i

      private int i
      Index of the file holding the piece.
    • raflen

      private long raflen
      Length of the file being read.
    • start

      private long start
      Offset where the piece starts in the file.
  • Constructor Details

    • FileCursor

      FileCursor(long pos)
      Position the cursor at the given absolute byte offset in the torrent.
      Parameters:
      pos - the byte position in the torrent
  • Method Details

    • getFile

      The file containing the cursor position.
      Returns:
      the file the cursor currently sits in
    • getOffset

      long getOffset()
      The offset of the cursor within the current file.
      Returns:
      the byte offset inside that file
    • chunk

      int chunk(int need)
      The chunk length from the cursor position to the end of the current file, or need, whichever is smaller.
      Parameters:
      need - the number of bytes wanted
      Returns:
      the chunk length
    • advance

      void advance(int len, int need)
      Advance the cursor past a consumed chunk, moving to the next file when the chunk ended at a file boundary.
      Parameters:
      len - the chunk length just consumed
      need - the number of bytes wanted before the chunk was taken