org.eclipse.ecf.provider.filetransfer
Class AbstractRetrieveFileTransfer

java.lang.Object
  extended by org.eclipse.ecf.core.sharedobject.AbstractSharedObject
      extended by org.eclipse.ecf.provider.filetransfer.AbstractRetrieveFileTransfer
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, IIdentifiable, ISharedObject, IEventHandler, IFileTransfer, IFileTransferPausable, IIncomingFileTransfer, IRetrieveFileTransferContainerAdapter
Direct Known Subclasses:
UrlRetrieveFileTransfer

public abstract class AbstractRetrieveFileTransfer
extends AbstractSharedObject
implements IIncomingFileTransfer, IRetrieveFileTransferContainerAdapter, IFileTransferPausable


Field Summary
protected  int buff_length
           
protected  long bytesReceived
           
static int DEFAULT_BUF_LENGTH
           
protected  boolean done
           
protected  java.lang.Exception exception
           
protected  long fileLength
           
protected  org.eclipse.core.runtime.jobs.Job job
           
protected  IFileTransferListener listener
           
protected  java.io.OutputStream localFileContents
           
protected  java.io.InputStream remoteFileContents
           
protected  java.net.URI remoteFileReference
           
 
Constructor Summary
AbstractRetrieveFileTransfer()
           
 
Method Summary
 void cancel()
          Cancel this file transfer.
protected  void fireTransferReceiveDataEvent()
           
protected  void fireTransferReceiveDoneEvent()
           
 java.lang.Object getAdapter(java.lang.Class adapter)
           
 long getBytesReceived()
          Get number of bytes received so far.
 java.lang.Exception getException()
          Get any exception associated with this file transfer.
protected  org.eclipse.core.runtime.IStatus getFinalStatus(java.lang.Throwable exception)
           
 double getPercentComplete()
          Get the percent complete for this file transfer.
protected  java.net.URI getRemoteFileReference()
           
protected  void hardClose()
           
 boolean isDone()
          Return true if this file transfer is done, false if not yet completed.
 boolean isPaused()
           
protected abstract  void openStreams()
          Open incoming and outgoing streams associated with this file transfer.
 boolean pause()
          Pause file transfer.
 boolean resume()
          Resume file transfer after having been paused.
 void sendRetrieveRequest(java.net.URI remoteFileReference, IFileTransferListener transferListener)
          Send request for transfer of a remote file to local file storage.
protected  void setFileLength(long length)
           
protected  void setInputStream(java.io.InputStream ins)
           
protected  void setOutputStream(java.io.OutputStream outs)
           
 
Methods inherited from class org.eclipse.ecf.core.sharedobject.AbstractSharedObject
addEventProcessor, clearEventProcessors, creationCompleted, destroyRemote, destroySelf, destroySelfLocal, dispose, fireEventProcessors, getConfig, getContext, getGroupID, getHomeContainerID, getID, getLocalContainerID, getProperties, getReplicaDescription, getReplicaDescriptions, getSharedObjectMsgFromEvent, handleEvent, handleEvents, handleSharedObjectCreateResponseEvent, handleSharedObjectMsg, handleSharedObjectMsgEvent, handleUnhandledEvent, init, initialize, isConnected, isPrimary, removeEventProcessor, replicateToRemoteContainers, sendSharedObjectMsgTo, sendSharedObjectMsgToPrimary, sendSharedObjectMsgToSelf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.ecf.core.identity.IIdentifiable
getID
 

Field Detail

DEFAULT_BUF_LENGTH

public static final int DEFAULT_BUF_LENGTH
See Also:
Constant Field Values

job

protected org.eclipse.core.runtime.jobs.Job job

remoteFileReference

protected java.net.URI remoteFileReference

listener

protected IFileTransferListener listener

buff_length

protected int buff_length

done

protected boolean done

bytesReceived

protected long bytesReceived

remoteFileContents

protected java.io.InputStream remoteFileContents

localFileContents

protected java.io.OutputStream localFileContents

exception

protected java.lang.Exception exception

fileLength

protected long fileLength
Constructor Detail

AbstractRetrieveFileTransfer

public AbstractRetrieveFileTransfer()
Method Detail

getRemoteFileReference

protected java.net.URI getRemoteFileReference()

setInputStream

protected void setInputStream(java.io.InputStream ins)

setOutputStream

protected void setOutputStream(java.io.OutputStream outs)

setFileLength

protected void setFileLength(long length)

getFinalStatus

protected org.eclipse.core.runtime.IStatus getFinalStatus(java.lang.Throwable exception)

hardClose

protected void hardClose()

fireTransferReceiveDoneEvent

protected void fireTransferReceiveDoneEvent()

fireTransferReceiveDataEvent

protected void fireTransferReceiveDataEvent()

getBytesReceived

public long getBytesReceived()
Description copied from interface: IIncomingFileTransfer
Get number of bytes received so far. If provider does not support reporting the number of bytes received, will return -1.

Specified by:
getBytesReceived in interface IIncomingFileTransfer
Returns:
long number of bytes received. Returns -1 if provider does not support reporting of number of bytes received during transfer

cancel

public void cancel()
Description copied from interface: IFileTransfer
Cancel this file transfer. If file transfer has already been completed, then this method has no effect. If the file transfer has not been completed then calling this method will result in an IFileTransferEvent being delivered to the IFileTransferListener indicating that transfer is done (IFileTransfer.isDone() returns true), and some exception will be made available

Specified by:
cancel in interface IFileTransfer

getException

public java.lang.Exception getException()
Description copied from interface: IFileTransfer
Get any exception associated with this file transfer. The value returned from this method is valid only if IFileTransfer.isDone() method returns true. If the file transfer completed successfully, IFileTransfer.isDone() will return true, and this method will return null. If the file transfer completed unsuccessfully (some exception occurred), then IFileTransfer.isDone() will return true, and this method will return a non-null Exception instance that occurred.

Specified by:
getException in interface IFileTransfer
Returns:
Exception associated with this file transfer. Null if transfer completed successfully, non-null if transfer completed with some exception. Only valid after IFileTransfer.isDone() returns true.

getPercentComplete

public double getPercentComplete()
Description copied from interface: IFileTransfer
Get the percent complete for this file transfer. The returned value will be either -1.0, meaning that the underlying provider does not support reporting percent complete for this file transfer, or a value between 0 and 1 reflecting the percent complete for this file transfer. If 0.0 no data has been sent, if 1.0, the file transfer is 100 percent complete. The value returned from this method should not be used to determine whether the transfer has completed, as it may not show completion in the event of an transfer failure. Note that the IFileTransfer.isDone() method should be consulted to determine if the file transfer has completed (with or without error).

Specified by:
getPercentComplete in interface IFileTransfer
Returns:
double percent complete. Returns -1.0 if the underlying provider does not support reporting percentage complete, or between 0 and 1 to indicate actual percent complete for this file transfer

isDone

public boolean isDone()
Description copied from interface: IFileTransfer
Return true if this file transfer is done, false if not yet completed. The file transfer can be completed successfully, or an exception can occur and the file transfer will have failed. In either case of successful or unsuccessful transfer, this method will return true when the file transfer is complete. To determine whether the transfer completed successfully, it is necessary to also consult the IFileTransfer.getException() method.

Specified by:
isDone in interface IFileTransfer
Returns:
boolean true if file transfer is done, false if file transfer is still in progress.

getAdapter

public java.lang.Object getAdapter(java.lang.Class adapter)
Specified by:
getAdapter in interface org.eclipse.core.runtime.IAdaptable
Overrides:
getAdapter in class AbstractSharedObject

openStreams

protected abstract void openStreams()
                             throws IncomingFileTransferException
Open incoming and outgoing streams associated with this file transfer.

Throws:
IncomingFileTransferException

sendRetrieveRequest

public void sendRetrieveRequest(java.net.URI remoteFileReference,
                                IFileTransferListener transferListener)
                         throws IncomingFileTransferException
Description copied from interface: IRetrieveFileTransferContainerAdapter
Send request for transfer of a remote file to local file storage. This method is used to initiate a file retrieve for a remoteFileID (first parameter). File transfer events are asynchronously delivered a file transfer listener (second parameter). The given remoteFileID and transferListener must not be null.

Specified by:
sendRetrieveRequest in interface IRetrieveFileTransferContainerAdapter
Parameters:
remoteFileReference - reference to the remote target file (e.g. http://www.eclipse.org/index.html) or a reference to a resource that specifies the location of a target file. Implementing providers will determine what protocol schemes are supported (e.g. ftp, http, torrent, file, etc) and the required format of the scheme-specific information. If a protocol is specified that is not supported, or the scheme-specific information is not well-formed, then an IncomingFileTransferException will be thrown. Must not be null
transferListener - a listener for file transfer events. Must not be null
Throws:
IncomingFileTransferException - if the provider is not connected or is not in the correct state for initiating file transfer

isPaused

public boolean isPaused()
Specified by:
isPaused in interface IFileTransferPausable
Returns:
true if file transfer paused, false if not paused

pause

public boolean pause()
Description copied from interface: IFileTransferPausable
Pause file transfer. Returns true if the associated IFileTransfer is successfully paused. Returns false if the implementing file transfer cannot be paused, or transfer has already completed.

Specified by:
pause in interface IFileTransferPausable
Returns:
true if file transfer successfully paused. False if cannot be paused, or the transfer has already completed

resume

public boolean resume()
Description copied from interface: IFileTransferPausable
Resume file transfer after having been paused. If successfully resumed, then returns true. If the associated IFileShare is not already paused, or has already completed then this method returns false.

Specified by:
resume in interface IFileTransferPausable