diff options
author | slewis | 2007-10-01 21:45:04 +0000 |
---|---|---|
committer | slewis | 2007-10-01 21:45:04 +0000 |
commit | f8ed05275c9f8c5bbe881b6f6bba8b66d5325634 (patch) | |
tree | 63848f05a95de819355158206c104e34d0fe4a92 /providers/bundles/org.eclipse.ecf.provider.bittorrent/src/org/eclipse/ecf/internal/provider/bittorrent/BitTorrentContainer.java | |
parent | 02d2b1ffa74ec3334abe4bccc002ac1cfa347907 (diff) | |
download | org.eclipse.ecf-f8ed05275c9f8c5bbe881b6f6bba8b66d5325634.tar.gz org.eclipse.ecf-f8ed05275c9f8c5bbe881b6f6bba8b66d5325634.tar.xz org.eclipse.ecf-f8ed05275c9f8c5bbe881b6f6bba8b66d5325634.zip |
Added IFileRangeSpecification and IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileRangeSpecification, IFileTransferListener, Map options)
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.bittorrent/src/org/eclipse/ecf/internal/provider/bittorrent/BitTorrentContainer.java')
-rw-r--r-- | providers/bundles/org.eclipse.ecf.provider.bittorrent/src/org/eclipse/ecf/internal/provider/bittorrent/BitTorrentContainer.java | 149 |
1 files changed, 63 insertions, 86 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.bittorrent/src/org/eclipse/ecf/internal/provider/bittorrent/BitTorrentContainer.java b/providers/bundles/org.eclipse.ecf.provider.bittorrent/src/org/eclipse/ecf/internal/provider/bittorrent/BitTorrentContainer.java index 31b1a7a1a..2818c4bfd 100644 --- a/providers/bundles/org.eclipse.ecf.provider.bittorrent/src/org/eclipse/ecf/internal/provider/bittorrent/BitTorrentContainer.java +++ b/providers/bundles/org.eclipse.ecf.provider.bittorrent/src/org/eclipse/ecf/internal/provider/bittorrent/BitTorrentContainer.java @@ -33,17 +33,18 @@ import org.eclipse.ecf.core.identity.IDFactory; import org.eclipse.ecf.core.identity.Namespace; import org.eclipse.ecf.core.security.IConnectContext; import org.eclipse.ecf.core.util.Proxy; +import org.eclipse.ecf.filetransfer.IFileRangeSpecification; import org.eclipse.ecf.filetransfer.IFileTransferListener; import org.eclipse.ecf.filetransfer.IIncomingFileTransfer; import org.eclipse.ecf.filetransfer.IncomingFileTransferException; +import org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException; import org.eclipse.ecf.filetransfer.UserCancelledException; import org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent; import org.eclipse.ecf.filetransfer.identity.IFileID; import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransfer; import org.eclipse.osgi.util.NLS; -public final class BitTorrentContainer implements IContainer, - IRetrieveFileTransfer { +public final class BitTorrentContainer implements IContainer, IRetrieveFileTransfer { private final List containerListeners; @@ -52,12 +53,10 @@ public final class BitTorrentContainer implements IContainer, public BitTorrentContainer() throws IDCreateException { id = IDFactory.getDefault().createGUID(); containerListeners = new ArrayList(); - TorrentConfiguration.setConfigurationPath(new File(System - .getProperty("user.home"), ".eclipsebt")); //$NON-NLS-1$ //$NON-NLS-2$ + TorrentConfiguration.setConfigurationPath(new File(System.getProperty("user.home"), ".eclipsebt")); //$NON-NLS-1$ //$NON-NLS-2$ } - public void connect(ID targetID, IConnectContext connectContext) - throws ContainerConnectException { + public void connect(ID targetID, IConnectContext connectContext) throws ContainerConnectException { // do nothing since BitTorrent does not have a central network } @@ -72,8 +71,7 @@ public final class BitTorrentContainer implements IContainer, private void fireContainerEvent(IContainerEvent event) { synchronized (containerListeners) { for (int i = 0; i < containerListeners.size(); i++) { - IContainerListener icl = (IContainerListener) containerListeners - .get(i); + final IContainerListener icl = (IContainerListener) containerListeners.get(i); icl.handleEvent(event); } } @@ -109,91 +107,70 @@ public final class BitTorrentContainer implements IContainer, } } - public void sendRetrieveRequest(final IFileID remoteFileReference, - final IFileTransferListener transferListener, Map options) - throws IncomingFileTransferException { - Assert.isNotNull(remoteFileReference, NLS.bind( - BitTorrentMessages.BitTorrentContainer_NullParameter, - "remoteFileReference")); //$NON-NLS-1$ - Assert.isLegal(remoteFileReference instanceof TorrentID, NLS.bind( - BitTorrentMessages.BitTorrentContainer_ReferenceNotTorrentID, - "remoteFileReference")); //$NON-NLS-1$ - Assert.isNotNull(transferListener, NLS.bind( - BitTorrentMessages.BitTorrentContainer_NullParameter, - "transferListener")); //$NON-NLS-1$ - - transferListener - .handleTransferEvent(new IIncomingFileTransferReceiveStartEvent() { - - private static final long serialVersionUID = 5195806924769910246L; - - private IIncomingFileTransfer transfer; - - private boolean cancelled = false; - - public IIncomingFileTransfer receive(File localFileToSave) - throws IOException { - if (cancelled) { - throw new RuntimeException( - new UserCancelledException()); - } - - Assert - .isNotNull( - localFileToSave, - NLS - .bind( - BitTorrentMessages.BitTorrentContainer_NullParameter, - "localFileToSave")); //$NON-NLS-1$ - - if (localFileToSave.exists() - && !localFileToSave.canWrite()) { - throw new IOException( - NLS - .bind( - BitTorrentMessages.BitTorrentContainer_CannotWriteToFile, - localFileToSave - .getAbsolutePath())); - } - - TorrentFile file = new TorrentFile( - ((TorrentID) remoteFileReference).getFile()); - file.setTargetFile(localFileToSave); - 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( - BitTorrentMessages.BitTorrentContainer_CannotWriteToStream); - } - - }); + public void sendRetrieveRequest(final IFileID remoteFileReference, final IFileTransferListener transferListener, Map options) throws IncomingFileTransferException { + Assert.isNotNull(remoteFileReference, NLS.bind(BitTorrentMessages.BitTorrentContainer_NullParameter, "remoteFileReference")); //$NON-NLS-1$ + Assert.isLegal(remoteFileReference instanceof TorrentID, NLS.bind(BitTorrentMessages.BitTorrentContainer_ReferenceNotTorrentID, "remoteFileReference")); //$NON-NLS-1$ + Assert.isNotNull(transferListener, NLS.bind(BitTorrentMessages.BitTorrentContainer_NullParameter, "transferListener")); //$NON-NLS-1$ + + transferListener.handleTransferEvent(new IIncomingFileTransferReceiveStartEvent() { + + private static final long serialVersionUID = 5195806924769910246L; + + private IIncomingFileTransfer transfer; + + private boolean cancelled = false; + + public IIncomingFileTransfer receive(File localFileToSave) throws IOException { + if (cancelled) { + throw new RuntimeException(new UserCancelledException()); + } + + Assert.isNotNull(localFileToSave, NLS.bind(BitTorrentMessages.BitTorrentContainer_NullParameter, "localFileToSave")); //$NON-NLS-1$ + + if (localFileToSave.exists() && !localFileToSave.canWrite()) { + throw new IOException(NLS.bind(BitTorrentMessages.BitTorrentContainer_CannotWriteToFile, localFileToSave.getAbsolutePath())); + } + + 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(BitTorrentMessages.BitTorrentContainer_CannotWriteToStream); + } + + }); } public Namespace getRetrieveNamespace() { - return IDFactory.getDefault().getNamespaceByName( - BitTorrentProviderPlugin.NAMESPACE_ID); + return IDFactory.getDefault().getNamespaceByName(BitTorrentProviderPlugin.NAMESPACE_ID); } - public void setConnectContextForAuthentication( - IConnectContext connectContext) { + public void setConnectContextForAuthentication(IConnectContext connectContext) { } public void setProxy(Proxy proxy) { } + + /* (non-Javadoc) + * @see org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter#sendRetrieveRequest(org.eclipse.ecf.filetransfer.identity.IFileID, org.eclipse.ecf.filetransfer.IFileRangeSpecification, org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map) + */ + public void sendRetrieveRequest(IFileID remoteFileID, IFileRangeSpecification rangeSpecification, IFileTransferListener transferListener, Map options) throws IncomingFileTransferException { + // TODO Auto-generated method stub + throw new InvalidFileRangeSpecificationException("not supported", rangeSpecification); + } } |