Search in sources :

Example 1 with IFileID

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

the class HttpClientRetrieveFileTransfer method fireConnectStartEvent.

protected void fireConnectStartEvent() {
    // $NON-NLS-1$
    Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, this.getClass(), "fireConnectStartEvent");
    // TODO: should the following be in super.fireReceiveStartEvent();
    listener.handleTransferEvent(new IFileTransferConnectStartEvent() {

        public IFileID getFileID() {
            return remoteFileID;
        }

        public void cancel() {
            HttpClientRetrieveFileTransfer.this.cancel();
        }

        public FileTransferJob prepareConnectJob(FileTransferJob j) {
            return HttpClientRetrieveFileTransfer.this.prepareConnectJob(j);
        }

        public void connectUsingJob(FileTransferJob j) {
            HttpClientRetrieveFileTransfer.this.connectUsingJob(j);
        }

        public String toString() {
            // $NON-NLS-1$
            final StringBuffer sb = new StringBuffer("IFileTransferConnectStartEvent[");
            sb.append(getFileID());
            // $NON-NLS-1$
            sb.append("]");
            return sb.toString();
        }

        public Object getAdapter(Class adapter) {
            return HttpClientRetrieveFileTransfer.this.getAdapter(adapter);
        }
    });
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) FileTransferJob(org.eclipse.ecf.filetransfer.FileTransferJob) IFileTransferConnectStartEvent(org.eclipse.ecf.filetransfer.events.IFileTransferConnectStartEvent)

Example 2 with IFileID

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

the class RetrieveFileTransfer method openStreams.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
	 * #openStreams()
	 */
protected void openStreams() throws IncomingFileTransferException {
    try {
        final IFileStore fileStore = EFS.getStore(new URI(getRemoteFileURL().getPath()));
        final IFileInfo info = fileStore.fetchInfo();
        setFileLength(info.getLength());
        setInputStream(fileStore.openInputStream(0, null));
        setLastModifiedTime(info.getLastModified());
        fileName = info.getName();
        listener.handleTransferEvent(new IIncomingFileTransferReceiveStartEvent() {

            public IIncomingFileTransfer getSource() {
                return RetrieveFileTransfer.this;
            }

            public IFileID getFileID() {
                return remoteFileID;
            }

            public IIncomingFileTransfer receive(File localFileToSave) throws IOException {
                return receive(localFileToSave, null);
            }

            public IIncomingFileTransfer receive(File localFileToSave, FileTransferJob fileTransferJob) throws IOException {
                setOutputStream(new BufferedOutputStream(new FileOutputStream(localFileToSave)));
                setupAndScheduleJob(fileTransferJob);
                return RetrieveFileTransfer.this;
            }

            public String toString() {
                final StringBuffer sb = new StringBuffer(// $NON-NLS-1$
                "IIncomingFileTransferReceiveStartEvent[");
                // $NON-NLS-1$ //$NON-NLS-2$
                sb.append("isdone=").append(done).append(";");
                // $NON-NLS-1$
                sb.append("bytesReceived=").append(bytesReceived).append(// $NON-NLS-1$
                "]");
                return sb.toString();
            }

            public void cancel() {
                hardClose();
            }

            /**
             * @param streamToStore
             * @return incoming file transfer instance.
             * @throws IOException
             *             not thrown in this implementation.
             */
            public IIncomingFileTransfer receive(OutputStream streamToStore) throws IOException {
                return receive(streamToStore, null);
            }

            /**
             * @throws IOException
             *             not actually thrown by this implementation.
             */
            public IIncomingFileTransfer receive(OutputStream streamToStore, FileTransferJob fileTransferJob) throws IOException {
                setOutputStream(streamToStore);
                setCloseOutputStream(false);
                setupAndScheduleJob(fileTransferJob);
                return RetrieveFileTransfer.this;
            }

            public Map getResponseHeaders() {
                return null;
            }
        });
    } catch (final Exception e) {
        throw new IncomingFileTransferException(e);
    }
}
Also used : IIncomingFileTransferReceiveStartEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent) URI(java.net.URI) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) Map(java.util.Map)

Example 3 with IFileID

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

the class URLCancelTest method testReceive.

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

Example 4 with IFileID

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

the class URLPartialRetrieveTest method testReceiveHttp.

protected void testReceiveHttp(final long start, final long end, String url) throws Exception {
    assertNotNull(transferInstance);
    final IFileTransferListener listener = new IFileTransferListener() {

        public void handleTransferEvent(IFileTransferEvent event) {
            if (event instanceof IIncomingFileTransferReceiveResumedEvent) {
                try {
                    final IIncomingFileTransferReceiveResumedEvent rse = (IIncomingFileTransferReceiveResumedEvent) event;
                    session = rse.receive(outs);
                } catch (final Exception e) {
                    fail(e.getLocalizedMessage());
                }
            } else if (event instanceof IIncomingFileTransferReceiveStartEvent) {
                final IIncomingFileTransferReceiveStartEvent rse = (IIncomingFileTransferReceiveStartEvent) event;
                try {
                    outs = new FileOutputStream(FILENAME);
                    session = rse.receive(outs);
                    pausable = (IFileTransferPausable) session.getAdapter(IFileTransferPausable.class);
                    if (pausable == null)
                        fail("pausable is null");
                } catch (final IOException e) {
                    fail(e.getLocalizedMessage());
                }
            } else if (event instanceof IIncomingFileTransferReceiveDataEvent) {
                System.out.println("data=" + event);
            } else if (event instanceof IIncomingFileTransferReceivePausedEvent) {
                System.out.println("paused=" + event);
            } else if (event instanceof IIncomingFileTransferReceiveDoneEvent) {
                closeOutputStream();
                System.out.println("done=" + event);
                synchronized (notify) {
                    isDone = true;
                    notify.notify();
                }
                session = ((IIncomingFileTransferReceiveDoneEvent) event).getSource();
            }
        }
    };
    final IFileID fileID = FileIDFactory.getDefault().createFileID(transferInstance.getRetrieveNamespace(), url);
    IFileRangeSpecification rangeSpecification = null;
    if (start != -1) {
        rangeSpecification = new IFileRangeSpecification() {

            public long getEndPosition() {
                return end;
            }

            public long getStartPosition() {
                return start;
            }
        };
    }
    transferInstance.sendRetrieveRequest(fileID, rangeSpecification, listener, null);
    if (!isDone) {
        synchronized (notify) {
            notify.wait();
        }
    }
    final Exception e = session.getException();
    if (e != null)
        throw e;
    incomingFile = new File(FILENAME);
    final long fileLength = incomingFile.length();
    final long bytesReceived = session.getBytesReceived();
    System.out.println("start=" + start);
    System.out.println("end=" + end);
    System.out.println("bytes received=" + bytesReceived);
    System.out.println("fileLength=" + fileLength);
    if (start != -1) {
        assertTrue(fileLength == bytesReceived);
        if (end != -1) {
            assertTrue(fileLength == (end - start + 1));
        }
    }
}
Also used : IIncomingFileTransferReceiveResumedEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveResumedEvent) IFileRangeSpecification(org.eclipse.ecf.filetransfer.IFileRangeSpecification) IFileTransferPausable(org.eclipse.ecf.filetransfer.IFileTransferPausable) IIncomingFileTransferReceiveStartEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) IOException(java.io.IOException) IOException(java.io.IOException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) IFileTransferEvent(org.eclipse.ecf.filetransfer.events.IFileTransferEvent) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) FileOutputStream(java.io.FileOutputStream) IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent) IIncomingFileTransferReceivePausedEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceivePausedEvent) IIncomingFileTransferReceiveDataEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDataEvent) File(java.io.File)

Example 5 with IFileID

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

the class URLRetrieveTestCancelConnectJob 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)

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