Search in sources :

Example 1 with TorrentException

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);
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) TOTorrent(com.biglybt.core.torrent.TOTorrent) IOException(java.io.IOException) TorrentException(com.biglybt.pif.torrent.TorrentException)

Example 2 with TorrentException

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);
    }
}
Also used : RPRequest(com.biglybt.pifimpl.remote.RPRequest) RPException(com.biglybt.pifimpl.remote.RPException) RPObject(com.biglybt.pifimpl.remote.RPObject) TorrentException(com.biglybt.pif.torrent.TorrentException)

Example 3 with TorrentException

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));
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) RPException(com.biglybt.pifimpl.remote.RPException) RPReply(com.biglybt.pifimpl.remote.RPReply) TorrentException(com.biglybt.pif.torrent.TorrentException)

Example 4 with TorrentException

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);
    }
}
Also used : RPRequest(com.biglybt.pifimpl.remote.RPRequest) RPException(com.biglybt.pifimpl.remote.RPException) TorrentException(com.biglybt.pif.torrent.TorrentException)

Example 5 with TorrentException

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));
}
Also used : File(java.io.File) DownloadManager(com.biglybt.core.download.DownloadManager) TorrentException(com.biglybt.pif.torrent.TorrentException) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) GlobalManagerDownloadRemovalVetoException(com.biglybt.core.global.GlobalManagerDownloadRemovalVetoException) IOException(java.io.IOException) TorrentException(com.biglybt.pif.torrent.TorrentException) TOTorrentException(com.biglybt.core.torrent.TOTorrentException)

Aggregations

TorrentException (com.biglybt.pif.torrent.TorrentException)5 RPException (com.biglybt.pifimpl.remote.RPException)3 RPRequest (com.biglybt.pifimpl.remote.RPRequest)2 IOException (java.io.IOException)2 DownloadManager (com.biglybt.core.download.DownloadManager)1 GlobalManagerDownloadRemovalVetoException (com.biglybt.core.global.GlobalManagerDownloadRemovalVetoException)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 Torrent (com.biglybt.pif.torrent.Torrent)1 ResourceDownloaderException (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)1 RPObject (com.biglybt.pifimpl.remote.RPObject)1 RPReply (com.biglybt.pifimpl.remote.RPReply)1 File (java.io.File)1 InputStream (java.io.InputStream)1