Class TorrentBuilder

java.lang.Object
com.frostwire.jlibtorrent.TorrentBuilder

public final class TorrentBuilder extends Object
  • Field Details

    • MODIFICATION_TIME

      public static final create_flags_t MODIFICATION_TIME
      This will include the file modification time as part of the torrent. This is not enabled by default, as it might cause problems when you create a torrent from separate files with the same content, hoping to yield the same info-hash. If the files have different modification times, with this option enabled, you would get different info-hashes for the files.
    • V2_ONLY

      public static final create_flags_t V2_ONLY
      Do not generate v1 metadata. The resulting torrent will only be usable by clients which support v2. This requires setting all v2 hashes, with set_hash2() before calling generate(). Setting v1 hashes (with set_hash()) is an error with this flag set.
    • V1_ONLY

      public static final create_flags_t V1_ONLY
      Do not generate v2 metadata or enforce v2 alignment and padding rules this is mainly for tests, not recommended for production use. This requires setting all v1 hashes, with set_hash(), before calling generate(). Setting v2 hashes (with set_hash2()) is an error with this flag set.
    • CANONICAL_FILES

      public static final create_flags_t CANONICAL_FILES
      This flag only affects v1-only torrents, and is only relevant together with the v1_only_flag. This flag will force the same file order and padding as a v2 (or hybrid) torrent would have. It has the effect of ordering files and inserting pad files to align them with piece boundaries.
  • Constructor Details

    • TorrentBuilder

      public TorrentBuilder()
  • Method Details

    • path

      public File path()
    • path

      public TorrentBuilder path(File value)
      Sets the path by the specified file
    • pieceSize

      public int pieceSize()
      The ``piece_size`` is the size of each piece in bytes. It must be a power of 2 and a minimum of 16 kiB. If a piece size of 0 is specified, a piece_size will be set automatically.
    • pieceSize

      public TorrentBuilder pieceSize(int value)
      The size of each piece in bytes. It must be a multiple of 16 kiB. If a piece size of 0 is specified, a pieceSize will be calculated such that the torrent file is roughly 40 kB.
    • flags

      public create_flags_t flags()
      create_flags_t is a type alias that simplifies the usage of the bitfield_flag structure for a specific case within the libtorrent namespace.

      The bitfield_flag structure in the provided code is a utility for managing flags in a bitfield, which is essentially a data structure that compactly stores bits.

      create_flags_t is a type alias for bitfield_flag<std::uint32_t, create_flags_tag>, specifically designed to handle creation flags in libtorrent.

      It provides a compact, efficient way to manage binary flags using bitwise operations, with the additional type safety provided by the create_flags_tag.

    • flags

      public TorrentBuilder flags(create_flags_t value)
      Specifies options for the torrent creation. It can be any combination of the flags defined by create_flags_t
    • alignment

      public int alignment()
    • alignment

      public TorrentBuilder alignment(int value)
      Used when pad files are enabled. This is the size eligible files are aligned to. The default is -1, which means the piece size of the torrent.
    • comment

      public String comment()
      The comment for the torrent. The comment in a torrent file is optional.
    • comment

      public TorrentBuilder comment(String value)
      Sets the comment for the torrent. The comment in a torrent file is optional.
    • creator

      public String creator()
      The creator of the torrent. This is optional.
    • creator

      public TorrentBuilder creator(String value)
      Sets the creator of the torrent. This is optional.
    • creationDate

      public long creationDate()
      The "creation time" field. Defaults to the system clock at the time of construction. The timestamp is specified in seconds, posix time. If the creation date is set to 0, the "creation date" field will be omitted from the generated torrent.
    • creationDate

      public TorrentBuilder creationDate(long timestamp)
      Set the "creation time" field. Defaults to the system clock at the time of construction. The timestamp is specified in seconds, posix time. If the creation date is set to 0, the "creation date" field will be omitted from the generated torrent.
    • urlSeeds

      public List<String> urlSeeds()
    • addUrlSeeds

      public TorrentBuilder addUrlSeeds(List<String> value)
      This adds a list of url seeds to the torrent. You can have any number of url seeds. For a single file torrent, this should be an HTTP url, pointing to a file with identical content as the file of the torrent. For a multi-file torrent, it should point to a directory containing a directory with the same name as this torrent, and all the files of the torrent in it.
    • addUrlSeed

      public TorrentBuilder addUrlSeed(String value)
      This adds a URL seed to the torrent. You can have any number of url seeds. For a single file torrent, this should be an HTTP url, pointing to a file with identical content as the file of the torrent. For a multi-file torrent, it should point to a directory containing a directory with the same name as this torrent, and all the files of the torrent in it.
    • nodes

      public List<Pair<String,Integer>> nodes()
      Lists specified DHT nodes in the torrent (added with addNodes(List<Pair<String, Integer>>)). A node is a hostname and a port number where there is a DHT node running.
    • addNodes

      public TorrentBuilder addNodes(List<Pair<String,Integer>> value)
      This adds a DHT node to the torrent. This especially useful if you're creating a tracker less torrent. It can be used by clients to bootstrap their DHT node from. The node is a hostname and a port number where there is a DHT node running. You can have any number of DHT nodes in a torrent.
    • addNode

      public TorrentBuilder addNode(Pair<String,Integer> value)
      This adds a DHT node to the torrent. This especially useful if you're creating a tracker less torrent. It can be used by clients to bootstrap their DHT node from. The node is a hostname and a port number where there is a DHT node running. You can have any number of DHT nodes in a torrent.
    • trackers

      public List<Pair<String,Integer>> trackers()
    • addTrackers

      public TorrentBuilder addTrackers(List<Pair<String,Integer>> value)
      Adds a list of trackers to the torrent.
      See Also:
    • addTracker

      public TorrentBuilder addTracker(Pair<String,Integer> value)
      Adds a tracker to the torrent. This is not strictly required, but most torrents use a tracker as their main source of peers. The url should be a http:// or udp:// url to a machine running a bittorrent tracker that accepts announces for this torrent's info-hash. The tier is the fallback priority of the tracker. All trackers with tier 0 are tried first (in any order). If all fail, trackers with tier 1 are tried. If all of those fail, trackers with tier 2 are tried, and so on.
    • addTracker

      public TorrentBuilder addTracker(String url, int tier)
      Adds a tracker to the torrent. This is not strictly required, but most torrents use a tracker as their main source of peers. The url should be a http:// or udp:// url to a machine running a bittorrent tracker that accepts announces for this torrent's info-hash. The tier is the fallback priority of the tracker. All trackers with tier 0 are tried first (in any order). If all fail, trackers with tier 1 are tried. If all of those fail, trackers with tier 2 are tried, and so on.
    • addTracker

      public TorrentBuilder addTracker(String url)
      Adds a tracker on tier 0 to the torrent.
    • isPrivate

      public boolean isPrivate()
      Torrents with the private flag set ask clients to not use any other sources than the tracker for peers, and to not advertise itself publicly, apart from the tracker.
    • setPrivate

      public TorrentBuilder setPrivate(boolean value)
      Sets the private flag of the torrent.

      Torrents with the private flag set ask clients to not use any other sources than the tracker for peers, and to not advertise itself publicly, apart from the tracker.

    • similarTorrents

      public List<Sha1Hash> similarTorrents()
      See Also:
    • addSimilarTorrents

      public TorrentBuilder addSimilarTorrents(List<Sha1Hash> value)
      See Also:
    • addSimilarTorrent

      public TorrentBuilder addSimilarTorrent(Sha1Hash value)
      Add similar torrents (by info-hash).

      Similar torrents are expected to share some files with this torrent. Torrents sharing a collection name with this torrent are also expected to share files with this torrent. A torrent may have more than one collection and more than one similar torrents. For more information, see BEP 38.

      BEP 38: ...

    • collections

      public List<String> collections()
    • addCollections

      public TorrentBuilder addCollections(List<String> value)
    • addCollection

      public TorrentBuilder addCollection(String value)
      Add collections of similar torrents.

      Similar torrents are expected to share some files with this torrent. Torrents sharing a collection name with this torrent are also expected to share files with this torrent. A torrent may have more than one collection and more than one similar torrents. For more information, see BEP 38.

      BEP 38: ...

    • listener

      public TorrentBuilder.Listener listener()
    • listener

      public TorrentBuilder listener(TorrentBuilder.Listener value)
    • generate

      public TorrentBuilder.Result generate() throws IOException
      This function will generate a result with the .torrent file as a bencoded tree.
      Throws:
      IOException