Class TorrentBuilder.Result

java.lang.Object
com.frostwire.jlibtorrent.TorrentBuilder.Result
Enclosing class:
TorrentBuilder

public static final class TorrentBuilder.Result extends Object
Result of torrent creation containing metadata and bencoded data.

Result contains the successful output of torrent file creation including the bencoded torrent entry and metadata about the created torrent (number of pieces, piece sizes, etc.). This information can be used to save the .torrent file or display torrent information to the user.

Accessing Torrent Data:

 TorrentBuilder.Result result = builder.build();

 // Get bencoded torrent entry for saving to file
 Entry torrentEntry = result.entry();
 byte[] torrentData = torrentEntry.bencode();

 // Save to .torrent file
 Files.write(Paths.get(\"file.torrent\"), torrentData);
 

Querying Torrent Metadata:

 TorrentBuilder.Result result = builder.build();

 // Number of pieces in the torrent
 int pieceCount = result.numPieces();
 System.out.println(\"Total pieces: \" + pieceCount);

 // Standard piece length (except possibly the last piece)
 int pieceLen = result.pieceLength();
 System.out.println(\"Piece size: \" + pieceLen + \" bytes\");

 // Size of a specific piece (last piece may be smaller)
 for (int i = 0; i < result.numPieces(); i++) {
     int size = result.pieceSize(i);
     System.out.println(\"Piece \" + i + \": \" + size + \" bytes\");
 }
 

Creating TorrentInfo from Result:

 TorrentBuilder.Result result = builder.build();

 // Create bencoded data
 byte[] torrentBytes = result.entry().bencode();

 // Create TorrentInfo from the bencoded data
 TorrentInfo ti = new TorrentInfo(torrentBytes);

 // Now can inspect the created torrent
 System.out.println(\"Info-hash: \" + ti.infoHash());
 System.out.println(\"Files: \" + ti.numFiles());
 System.out.println(\"Total size: \" + ti.totalSize());
 
  • Method Details

    • entry

      public Entry entry()
    • numPieces

      public int numPieces()
    • pieceLength

      public int pieceLength()
    • pieceSize

      public int pieceSize(int index)