public abstract class Bitfield extends Object
Instances of this class are thread-safe.
Modifier and Type | Field and Description |
---|---|
protected BitSet |
bitmask
Bitmask indicating availability of pieces.
|
protected ReadWriteLock |
lock |
protected int |
piecesTotal
Total number of pieces in torrent.
|
Modifier | Constructor and Description |
---|---|
protected |
Bitfield(int piecesTotal)
Creates empty bitfield.
|
protected |
Bitfield(int piecesTotal,
BitSet bitSet)
Creates a bitfield for with the bitset initially set to the passed in BitSet
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkAndMarkVerified(int pieceIndex)
Marks the piece as verified and returns whether it was verified before it was marked as verified.
|
BitSet |
getBitmask() |
int |
getPiecesComplete() |
int |
getPiecesIncomplete() |
int |
getPiecesTotal() |
boolean |
isComplete(int pieceIndex)
Shortcut method to find out if the piece has been downloaded.
|
protected boolean |
isPieceVerified(int pieceIndex) |
boolean |
isVerified(int pieceIndex)
Shortcut method to find out if the piece has been downloaded and verified.
|
protected void |
markVerified(int pieceIndex)
Mark piece as complete and verified.
|
byte[] |
toByteArray(BitOrder bitOrder) |
protected void |
validatePieceIndex(int pieceIndex) |
protected final BitSet bitmask
protected final int piecesTotal
protected final ReadWriteLock lock
protected Bitfield(int piecesTotal)
piecesTotal
- Total number of pieces in torrent.protected Bitfield(int piecesTotal, BitSet bitSet)
piecesTotal
- Total number of pieces in torrentbitSet
- the initial values of the bitfieldpublic BitSet getBitmask()
public byte[] toByteArray(BitOrder bitOrder)
bitOrder
- Order of bits to use to create the byte arraypublic int getPiecesTotal()
public int getPiecesComplete()
public int getPiecesIncomplete()
protected boolean isPieceVerified(int pieceIndex)
protected boolean checkAndMarkVerified(int pieceIndex)
pieceIndex
- the index of the piece to check and mark verifiedpublic boolean isComplete(int pieceIndex)
pieceIndex
- Piece index (0-based)public boolean isVerified(int pieceIndex)
pieceIndex
- Piece index (0-based)protected void markVerified(int pieceIndex)
pieceIndex
- Piece index (0-based)DataDescriptor.getChunkDescriptors()
protected void validatePieceIndex(int pieceIndex)
Copyright © 2016–2021. All rights reserved.