java.lang.Object
org.klomp.snark.Storage.FileCursor
- Enclosing class:
Storage
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
Constructor Summary
ConstructorsConstructorDescriptionFileCursor(long pos) Position the cursor at the given absolute byte offset in the torrent.Method Summary
All MethodsModifier and TypeMethodDescription(package private) voidadvance(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) intchunk(int need) The chunk length from the cursor position to the end of the current file, or need, whichever is smaller.(package private) Storage.TorrentFilegetFile()The file containing the cursor position.(package private) longThe offset of the cursor within the current file.
Field Details
i
private int iIndex of the file holding the piece.raflen
private long raflenLength of the file being read.start
private long startOffset 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
Storage.TorrentFile 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 consumedneed- the number of bytes wanted before the chunk was taken