this.strategy = strategy;
this.metadata = metadata;
this.hash = new TorrentHash(this, metadata.getInfoHash());
// parse file list
final MetadataInfo info = metadata.getInfo();
final byte[] pieceHashes = info.getPieceHashes();
final int pieces = pieceHashes.length / 20;
long piecesLength = 0;
for (int i = 0; i < pieces; i++) {
final byte[] hash = Arrays.copyOfRange(pieceHashes, i * 20,
(i + 1) * 20);
final int length = (int) (i + 1 == pieces ? (info.getLength() - piecesLength)
: info.getPieceLength());
this.pieces.add(new TorrentPiece(this, hash, i, info
.getPieceLength() * i, length));
piecesLength += length;
}
final Path torrentPath = Paths.get(info.getName());
long offset = 0;
for (final MetadataFile metaFile : info.getFiles()) {
byte[] hash = null;
if (metaFile.getHash() != null)
hash = MD5.fromString(metaFile.getHash());
final List<TorrentPiece> filePieces = getPieces(Range
.getRangeByLength(offset, metaFile.getLength()));