Package org.johnnei.javatorrent.torrent
Class AbstractFileSet
- java.lang.Object
-
- org.johnnei.javatorrent.torrent.AbstractFileSet
-
- Direct Known Subclasses:
TorrentFileSet
public abstract class AbstractFileSet extends Object
-
-
Constructor Summary
Constructors Constructor Description AbstractFileSet(int blockSize)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intcountCompletedPieces()Calculates the amount of pieces which still need to be downloadedlongcountRemainingBytes()Calculates the amount of bytes which still need to be downloadedabstract byte[]getBitfieldBytes()Gets the have pieces in bitfield format as specified by BEP #3.intgetBlockSize()Gets the size of a non-truncated blockFileInfogetFileForBytes(int pieceIndex, int blockIndex, int byteOffset)Gets the FileInfo for the given piece and blockList<FileInfo>getFiles()Creates an unmodifiable view of the list of files in this fileset.Stream<Piece>getNeededPieces()Creates a stream with only the pieces which are not donePiecegetPiece(int index)Gets the piece with the given indexintgetPieceCount()Gets the amount of pieces in this torrentabstract longgetPieceSize()Gets the size of a non-truncated piece.abstract IFileSetRequestFactorygetRequestFactory()longgetTotalFileSize()Gets the sum of the file sizes which are defined in thisAbstractFileSetbooleanhasPiece(int pieceIndex)Checks if this piece has been completed.booleanisDone()Tests if all pieces of this fileset have been completed.voidsetHavingPiece(int pieceIndex)Marks a piece as completed.
-
-
-
Field Detail
-
pieces
protected List<Piece> pieces
The pieces which contain all the information to complete the downloading of the files.
-
fileInfos
protected List<FileInfo> fileInfos
The file info about all the files which are contained within thisAbstractFileSet
-
-
Method Detail
-
hasPiece
public boolean hasPiece(int pieceIndex)
Checks if this piece has been completed.- Parameters:
pieceIndex- the index of the piece- Returns:
trueif the piece has been completed, otherwisefalse- Throws:
IllegalArgumentException- if the requested piece index is outside of the amount of pieces.
-
setHavingPiece
public void setHavingPiece(int pieceIndex)
Marks a piece as completed.- Parameters:
pieceIndex- the index of the piece- Throws:
NoSuchElementException- if the requested piece index is outside of the amount of pieces.
-
getFileForBytes
public FileInfo getFileForBytes(int pieceIndex, int blockIndex, int byteOffset)
Gets the FileInfo for the given piece and block- Parameters:
pieceIndex- The piece indexblockIndex- The block index within the piecebyteOffset- The offset within the block- Returns:
- The FileInfo for the given data
- Throws:
IllegalArgumentException- When information being requested is outside of this fileset.
-
getPiece
public Piece getPiece(int index)
Gets the piece with the given index- Parameters:
index- The index of the piece to get- Returns:
- The piece at the index
- Throws:
IllegalArgumentException- if the index is outside of the files.
-
getRequestFactory
public abstract IFileSetRequestFactory getRequestFactory()
- Returns:
- The request factory which can create requests for this
AbstractFileSet.
-
getPieceSize
public abstract long getPieceSize()
Gets the size of a non-truncated piece.- Returns:
- the size of a piece
-
getBlockSize
public int getBlockSize()
Gets the size of a non-truncated block- Returns:
- the size of a block
-
isDone
public boolean isDone()
Tests if all pieces of this fileset have been completed.- Returns:
truewhen all pieces are done an verified, otherwisefalse
-
getNeededPieces
public Stream<Piece> getNeededPieces()
Creates a stream with only the pieces which are not done- Returns:
- A stream with pieces which need to be downloaded
-
getPieceCount
public int getPieceCount()
Gets the amount of pieces in this torrent- Returns:
- The amount of pieces in this file set
-
getTotalFileSize
public long getTotalFileSize()
Gets the sum of the file sizes which are defined in thisAbstractFileSet- Returns:
- The total size of all files in this file set.
-
countRemainingBytes
public long countRemainingBytes()
Calculates the amount of bytes which still need to be downloaded- Returns:
- The amount of bytes still needed to be downloaded
-
countCompletedPieces
public int countCompletedPieces()
Calculates the amount of pieces which still need to be downloaded- Returns:
- The amount of pieces still needed to be downloaded.
-
getBitfieldBytes
public abstract byte[] getBitfieldBytes()
Gets the have pieces in bitfield format as specified by BEP #3.- Returns:
- The bitfield associated with this fileset.
- Throws:
UnsupportedOperationException- When this implementation doesn't produce the Bitfield as defined in BEP #3.
-
-