use of org.eclipse.ecf.protocol.bittorrent.TorrentFile in project ecf by eclipse.
the class BitTorrentConnection method connect.
public void connect() throws IOException {
if (torrent == null) {
torrent = TorrentFactory.createTorrent(new TorrentFile(new File(url.getFile())));
torrent.start();
}
}
use of org.eclipse.ecf.protocol.bittorrent.TorrentFile in project ecf by eclipse.
the class BitTorrentContainer method sendRetrieveRequest.
public void sendRetrieveRequest(final IFileID remoteFileReference, final IFileTransferListener transferListener, Map options) throws IncomingFileTransferException {
// $NON-NLS-1$
Assert.isNotNull(remoteFileReference, "remoteFileReference cannot be null");
// $NON-NLS-1$
Assert.isLegal(remoteFileReference instanceof TorrentID, "remoteFileReference must be instanceof TorrentID");
// $NON-NLS-1$
Assert.isNotNull(transferListener, "transferListener cannot be null");
transferListener.handleTransferEvent(new IIncomingFileTransferReceiveStartEvent() {
private IIncomingFileTransfer transfer;
private boolean cancelled = false;
public IIncomingFileTransfer receive(File localFileToSave) throws IOException {
if (cancelled) {
throw new RuntimeException(new UserCancelledException());
}
// $NON-NLS-1$
Assert.isNotNull(localFileToSave, "localFileToSave cannot be null");
if (localFileToSave.exists() && !localFileToSave.canWrite()) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new IOException("file=" + localFileToSave.getAbsolutePath() + " does not exist or cannot be written to");
}
final TorrentFile file = new TorrentFile(((TorrentID) remoteFileReference).getFile());
file.setTargetFile(localFileToSave);
final Torrent torrent = TorrentFactory.createTorrent(file);
transfer = new TorrentFileTransfer(remoteFileReference, transferListener, torrent);
return transfer;
}
public IIncomingFileTransfer receive(File localFileToSave, FileTransferJob fileTransferJob) throws IOException {
if (cancelled) {
throw new RuntimeException(new UserCancelledException());
}
// $NON-NLS-1$
Assert.isNotNull(localFileToSave, "localFileToSave must not be null");
if (localFileToSave.exists() && !localFileToSave.canWrite()) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new IOException("file=" + localFileToSave.getAbsolutePath() + " does not exist or cannot be written to");
}
final TorrentFile file = new TorrentFile(((TorrentID) remoteFileReference).getFile());
file.setTargetFile(localFileToSave);
final Torrent torrent = TorrentFactory.createTorrent(file);
transfer = new TorrentFileTransfer(remoteFileReference, transferListener, torrent);
return transfer;
}
public void cancel() {
if (transfer != null) {
transfer.cancel();
cancelled = true;
}
}
public IFileID getFileID() {
return remoteFileReference;
}
public IIncomingFileTransfer receive(OutputStream streamToStore) throws IOException {
throw new UnsupportedOperationException("receive(OutputStream) not supported by this provider");
}
public IIncomingFileTransfer receive(OutputStream streamToStore, FileTransferJob fileTransferJob) throws IOException {
throw new UnsupportedOperationException("receive(OutputStream,FileTransferJob) not supported by this provider");
}
public IIncomingFileTransfer getSource() {
return transfer;
}
public Map getResponseHeaders() {
return null;
}
});
}
Aggregations