Search in sources :

Example 16 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class FileIDFactoryTest method testCreateFromURL.

public void testCreateFromURL() throws Exception {
    final IFileID fileID = createFileID(getRetrieveAdapter().getRetrieveNamespace(), new URL("http://www.eclipse.org/ecf"));
    assertNotNull(fileID);
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) URL(java.net.URL)

Example 17 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class FileIDFactoryTest method testCreateFromObjectArray.

public void testCreateFromObjectArray() throws Exception {
    final IFileID fileID = createFileID(getRetrieveAdapter().getRetrieveNamespace(), new Object[] { "http://www.eclipse.org/ecf" });
    assertNotNull(fileID);
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID)

Example 18 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class GetRemoteFileNameTest method testReceive.

protected void testReceive(String url) throws Exception {
    assertNotNull(retrieveAdapter);
    final IFileTransferListener listener = createFileTransferListener();
    final IFileID fileID = createFileID(new URL(url));
    done = false;
    retrieveAdapter.sendRetrieveRequest(fileID, listener, null);
    synchronized (lock) {
        try {
            lock.wait(7000);
        } catch (InterruptedException e) {
        }
    }
    if (!done)
        fail();
    System.out.println("remote file name=" + incomingFileTransfer.getRemoteFileName());
    waitForDone(10000);
    assertHasEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
    assertHasMoreThanEventCount(dataEvents, IIncomingFileTransferReceiveDataEvent.class, 0);
    assertDoneOK();
    assertTrue(tmpFile.exists());
    assertTrue(tmpFile.length() > 0);
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) URL(java.net.URL)

Example 19 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class URLRetrieveTestUnknownHost method testReceive.

protected void testReceive(String url, IFileTransferListener listener) throws Exception {
    assertNotNull(retrieveAdapter);
    final IFileID fileID = createFileID(new URL(url));
    retrieveAdapter.sendRetrieveRequest(fileID, listener, null);
    waitForDone(10000);
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) URL(java.net.URL)

Example 20 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID 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;
        }
    });
}
Also used : Torrent(org.eclipse.ecf.protocol.bittorrent.Torrent) UserCancelledException(org.eclipse.ecf.filetransfer.UserCancelledException) OutputStream(java.io.OutputStream) IIncomingFileTransferReceiveStartEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent) IOException(java.io.IOException) IIncomingFileTransfer(org.eclipse.ecf.filetransfer.IIncomingFileTransfer) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) FileTransferJob(org.eclipse.ecf.filetransfer.FileTransferJob) TorrentFile(org.eclipse.ecf.protocol.bittorrent.TorrentFile) TorrentFile(org.eclipse.ecf.protocol.bittorrent.TorrentFile) File(java.io.File) Map(java.util.Map)

Aggregations

IFileID (org.eclipse.ecf.filetransfer.identity.IFileID)20 URL (java.net.URL)10 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)7 File (java.io.File)3 IOException (java.io.IOException)3 FileTransferJob (org.eclipse.ecf.filetransfer.FileTransferJob)3 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)3 MalformedURLException (java.net.MalformedURLException)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 IConnectContext (org.eclipse.ecf.core.security.IConnectContext)2 Proxy (org.eclipse.ecf.core.util.Proxy)2 IRemoteFile (org.eclipse.ecf.filetransfer.IRemoteFile)2 IRemoteFileAttributes (org.eclipse.ecf.filetransfer.IRemoteFileAttributes)2 IRemoteFileInfo (org.eclipse.ecf.filetransfer.IRemoteFileInfo)2 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)2 IRemoteFileSystemBrowser (org.eclipse.ecf.filetransfer.service.IRemoteFileSystemBrowser)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 ConnectException (java.net.ConnectException)1