Class AbstractFileSet

    • Field Detail

      • pieces

        protected List<Piece> pieces
        The pieces which contain all the information to complete the downloading of the files.
    • Constructor Detail

      • AbstractFileSet

        public AbstractFileSet​(int blockSize)
    • Method Detail

      • hasPiece

        public boolean hasPiece​(int pieceIndex)
        Checks if this piece has been completed.
        Parameters:
        pieceIndex - the index of the piece
        Returns:
        true if the piece has been completed, otherwise false
        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 index
        blockIndex - The block index within the piece
        byteOffset - 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.
      • 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:
        true when all pieces are done an verified, otherwise false
      • 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 this AbstractFileSet
        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.
      • getFiles

        public List<FileInfo> getFiles()
        Creates an unmodifiable view of the list of files in this fileset.
        Returns:
        The list of files in this set.