use of com.turn.ttorrent.client.storage.FileCollectionStorage in project teamcity-torrent-plugin by JetBrains.
the class TeamcityTorrentClient method downloadAndShareOrFail.
public void downloadAndShareOrFail(@NotNull final File torrentFile, @NotNull final List<String> fileNames, @NotNull final String hexInfoHash, @NotNull final File destFile, @NotNull final File destDir, @NotNull final FileProgress fileDownloadProgress, final int downloadTimeoutMs, final int minSeedersCount, final int maxTimeoutForConnect) throws Exception {
checkThatTorrentContainsFile(fileNames, destFile);
destDir.mkdirs();
if (myCommunicationManager.containsTorrentWithHash(hexInfoHash)) {
LOG.info("Already seeding torrent with hash " + hexInfoHash + ". Stop seeding and try download again");
stopSeeding(torrentFile);
}
LOG.info(String.format("Will attempt to download uninterruptibly %s into %s. Timeout:%d", destFile.getAbsolutePath(), destDir.getAbsolutePath(), downloadTimeoutMs));
TorrentMetadataProvider metadataProvider = new FileMetadataProvider(torrentFile.getAbsolutePath());
TorrentMetadata metadata = metadataProvider.getTorrentMetadata();
FileCollectionStorage fileCollectionStorage = FileCollectionStorage.create(metadata, destDir);
PieceStorage pieceStorage = EmptyPieceStorageFactory.INSTANCE.createStorage(metadata, fileCollectionStorage);
TorrentDownloader torrentDownloader = new TorrentDownloader(metadata, fileDownloadProgress, minSeedersCount, maxTimeoutForConnect, downloadTimeoutMs);
myCommunicationManager.addTorrent(metadataProvider, pieceStorage, Collections.<TorrentListener>singletonList(torrentDownloader));
Exception exception = null;
try {
torrentDownloader.awaitDownload();
} catch (Exception e) {
exception = e;
}
try {
myCommunicationManager.removeTorrent(metadata.getHexInfoHash());
pieceStorage.close();
} finally {
boolean downloadFailed = exception != null;
if (downloadFailed) {
fileCollectionStorage.delete();
throw exception;
}
}
}
Aggregations