See: Description
// 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();
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);
Copyright © 2016–2021. All rights reserved.