use of com.biglybt.pif.torrent.TorrentException in project BiglyBT by BiglySoftware.
the class TorrentDownloaderImpl method downloadSupport.
private Torrent downloadSupport(ResourceDownloader downloader) throws TorrentException {
InputStream is = null;
try {
is = downloader.download();
TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedInputStream(is);
if (encoding_requested) {
manager.tryToSetTorrentEncoding(torrent, requested_encoding);
} else {
if (set_encoding) {
manager.tryToSetDefaultTorrentEncoding(torrent);
}
}
return (new TorrentImpl(torrent));
} catch (TorrentException e) {
throw (e);
} catch (ResourceDownloaderException e) {
throw (new TorrentException(e));
} catch (Throwable e) {
throw (new TorrentException("TorrentDownloader: download fails", e));
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
Debug.printStackTrace(e);
}
}
}
}
use of com.biglybt.pif.torrent.TorrentException in project BiglyBT by BiglySoftware.
the class RPTorrentDownloader method download.
@Override
public Torrent download(String encoding) throws TorrentException {
try {
RPTorrent resp = (RPTorrent) _dispatcher.dispatch(new RPRequest(this, "download[String]", new Object[] { encoding })).getResponse();
resp._setRemote(_dispatcher);
return (resp);
} catch (RPException e) {
if (e.getCause() instanceof TorrentException) {
throw ((TorrentException) e.getCause());
}
throw (e);
}
}
use of com.biglybt.pif.torrent.TorrentException in project BiglyBT by BiglySoftware.
the class RPTorrentDownloader method _process.
@Override
public RPReply _process(RPRequest request) {
String method = request.getMethod();
if (method.equals("download")) {
try {
Torrent to = delegate.download();
RPTorrent res = RPTorrent.create(to);
return (new RPReply(res));
} catch (TorrentException e) {
return (new RPReply(e));
}
} else if (method.equals("download[String]")) {
try {
Torrent to = delegate.download((String) request.getParams()[0]);
RPTorrent res = RPTorrent.create(to);
return (new RPReply(res));
} catch (TorrentException e) {
return (new RPReply(e));
}
}
throw (new RPException("Unknown method: " + method));
}
use of com.biglybt.pif.torrent.TorrentException in project BiglyBT by BiglySoftware.
the class RPTorrentDownloader method download.
// ************************************************************************
@Override
public Torrent download() throws TorrentException {
try {
RPTorrent resp = (RPTorrent) _dispatcher.dispatch(new RPRequest(this, "download", null)).getResponse();
resp._setRemote(_dispatcher);
return (resp);
} catch (RPException e) {
if (e.getCause() instanceof TorrentException) {
throw ((TorrentException) e.getCause());
}
throw (e);
}
}
use of com.biglybt.pif.torrent.TorrentException in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method addDownload.
public Download addDownload(Torrent torrent, File torrent_file, File data_location, int initial_state) throws DownloadException {
if (torrent_file == null) {
String torrent_dir = null;
if (COConfigurationManager.getBooleanParameter("Save Torrent Files")) {
try {
torrent_dir = COConfigurationManager.getDirectoryParameter("General_sDefaultTorrent_Directory");
} catch (Exception egnore) {
}
}
if (torrent_dir == null || torrent_dir.length() == 0) {
throw (new DownloadException("DownloadManager::addDownload: default torrent save directory must be configured"));
}
torrent_file = new File(torrent_dir + File.separator + torrent.getName() + ".torrent");
try {
torrent.writeToFile(torrent_file);
} catch (TorrentException e) {
throw (new DownloadException("DownloadManager::addDownload: failed to write torrent to '" + torrent_file.toString() + "'", e));
}
} else {
if (!torrent_file.exists()) {
throw new DownloadException("DownloadManager::addDownload: torrent file does not exist - " + torrent_file.toString());
} else if (!torrent_file.isFile()) {
throw new DownloadException("DownloadManager::addDownload: torrent filepath given is not a file - " + torrent_file.toString());
}
}
if (data_location == null) {
String data_dir = COConfigurationManager.getStringParameter("Default save path");
if (data_dir == null || data_dir.length() == 0) {
throw (new DownloadException("DownloadManager::addDownload: default data save directory must be configured"));
}
data_location = new File(data_dir);
FileUtil.mkdirs(data_location);
}
byte[] hash = null;
try {
hash = torrent.getHash();
} catch (Exception e) {
}
boolean for_seeding = torrent.isComplete();
DownloadManager dm = global_manager.addDownloadManager(torrent_file.toString(), hash, data_location.toString(), initial_state, true, for_seeding, null);
if (dm == null) {
throw (new DownloadException("DownloadManager::addDownload - failed, download may already in the process of being added"));
}
addDownloadManager(dm);
return (getDownload(dm));
}
Aggregations