Skip navigation links

Bt 1.10 API

See most often used API classes and code examples below.

See: Description

Packages 
Package Description
bt  
bt.bencoding  
bt.bencoding.model  
bt.bencoding.model.rule  
bt.bencoding.serializers  
bt.bencoding.types  
bt.data  
bt.data.digest  
bt.data.file  
bt.data.range  
bt.dht  
bt.dht.stream  
bt.event  
bt.magnet  
bt.metainfo  
bt.module  
bt.net  
bt.net.buffer  
bt.net.crypto  
bt.net.extended  
bt.net.pipeline  
bt.net.portmapping  
bt.net.portmapping.impl  
bt.peer  
bt.peer.lan  
bt.peerexchange  
bt.portmapping.upnp  
bt.portmapping.upnp.jetty  
bt.processor  
bt.processor.listener  
bt.processor.magnet  
bt.processor.torrent  
bt.protocol  
bt.protocol.crypto  
bt.protocol.extended  
bt.protocol.handler  
bt.runtime  
bt.service  
bt.torrent  
bt.torrent.annotation  
bt.torrent.callbacks  
bt.torrent.compiler  
bt.torrent.data  
bt.torrent.fileselector  
bt.torrent.maker  
bt.torrent.messaging  
bt.torrent.selector  
bt.tracker  
bt.tracker.http  
bt.tracker.http.urlencoding  
bt.tracker.udp  
See most often used API classes and code examples below.

Most often used API classes

Creating runtimes and clients

Bt
BtRuntime
BtRuntimeBuilder
TorrentClientBuilder
BtClient

Configuring runtime parameters

Config

Programmatically creating magnet links

MagnetUri

Programmatically creating .torrent files

TorrentBuilder

Subscribing to runtime events

EventSource

Usage examples

Download a torrent from a magnet link


// enable multithreaded verification of torrent data
Config config = new Config() {
    @Override
    public int getNumOfHashingThreads() {
        return Runtime.getRuntime().availableProcessors() * 2;
    }
};

// enable bootstrapping from public routers
Module dhtModule = new DHTModule(new DHTConfig() {
    @Override
    public boolean shouldUseRouterBootstrap() {
        return true;
    }
});

// get download directory
Path targetDirectory = Paths.get(System.getProperty("user.home"), "Downloads");

// create file system based backend for torrent data
Storage storage = new FileSystemStorage(targetDirectory);

// create client with a private runtime
BtClient client = Bt.client()
        .config(config)
        .storage(storage)
        .magnet("magnet:?xt=urn:btih:af0d9aa01a9ae123a73802cfa58ccaf355eb19f1")
        .autoLoadModules()
        .module(dhtModule)
        .stopWhenDownloaded()
        .build();

// launch
client.startAsync().join();

Create a torrent


Path torrentRoot = Paths.get("/home/torrents/mytorrent");
Path file1 = Paths.get("/home/torrents/mytorrent/file1.bin");
Path file2 = Paths.get("/home/torrents/mytorrent/file2.bin");
Path dirToAdd = Paths.get("/home/torrents/mytorrent/dir_with_files");
byte[] torrentBytes = new TorrentBuilder()
        .rootPath(torrentRoot)
        .addFiles(file1, file2, dirToAdd)
        .announce("http://example.com/announce")
        .build();
Files.write(Paths.get("/home/torrents/mytorrent.torrent"), torrentBytes);

Skip navigation links

Copyright © 2016–2021. All rights reserved.