Class AbstractOutgoingFileTransfer

java.lang.Object
org.eclipse.ecf.provider.filetransfer.outgoing.AbstractOutgoingFileTransfer
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, IIdentifiable, IFileTransfer, IOutgoingFileTransfer, ISendFileTransferContainerAdapter, ISendFileTransfer
Direct Known Subclasses:
AbstractUrlConnectionOutgoingFileTransfer, LocalFileOutgoingFileTransfer

public abstract class AbstractOutgoingFileTransfer extends Object implements IOutgoingFileTransfer, ISendFileTransfer
  • Field Details

    • DEFAULT_BUF_LENGTH

      public static final int DEFAULT_BUF_LENGTH
      See Also:
    • job

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

      protected URL remoteFileURL
    • remoteFileID

      protected IFileID remoteFileID
    • listener

      protected IFileTransferListener listener
    • buff_length

      protected int buff_length
    • done

      protected boolean done
    • bytesSent

      protected long bytesSent
    • localFileContents

      protected InputStream localFileContents
    • remoteFileContents

      protected OutputStream remoteFileContents
    • exception

      protected Exception exception
    • fileTransferInfo

      protected IFileTransferInfo fileTransferInfo
    • options

      protected Map options
    • connectContext

      protected IConnectContext connectContext
    • proxy

      protected Proxy proxy
  • Constructor Details

    • AbstractOutgoingFileTransfer

      public AbstractOutgoingFileTransfer()
  • Method Details

    • getRemoteFileURL

      protected URL getRemoteFileURL()
    • setInputStream

      protected void setInputStream(InputStream ins)
    • setOutputStream

      protected void setOutputStream(OutputStream outs)
    • getFileTransferInfo

      protected IFileTransferInfo getFileTransferInfo()
    • getOptions

      protected Map getOptions()
    • getFinalStatus

      protected org.eclipse.core.runtime.IStatus getFinalStatus(Throwable exception1)
    • hardClose

      protected void hardClose()
    • getID

      public ID getID()
      Description copied from interface: IIdentifiable
      Return the ID for this 'identifiable' object. The returned ID should be unique within its namespace. May return null.
      Specified by:
      getID in interface IIdentifiable
      Returns:
      the ID for this identifiable object. May return null.
    • fireTransferSendDoneEvent

      protected void fireTransferSendDoneEvent()
    • fireTransferSendDataEvent

      protected void fireTransferSendDataEvent()
    • getBytesSent

      public long getBytesSent()
      Description copied from interface: IOutgoingFileTransfer
      Get the number of bytes sent for this outgoing file transfer. Returns 0 if transfer has not be started, and -1 if underlying provider does not support reporting number of bytes sent during transfer.
      Specified by:
      getBytesSent in interface IOutgoingFileTransfer
      Returns:
      number of bytes sent. Returns 0 if the outgoing file transfer has not been started, and -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 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.

      If the the file transfer was canceled by the user, then the exception returned will be an instance of UserCancelledException.

      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
    • getFileLength

      public long getFileLength()
      Description copied from interface: IFileTransfer
      Return resulting file length (in bytes) for this file transfer instance. If the length is not known, -1 will be returned. Note that if a IFileRangeSpecification is provided that the returned file length is the expected file length of just the range retrieved (and not the entire file).
      Specified by:
      getFileLength in interface IFileTransfer
      Returns:
      long file length
    • 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 Object getAdapter(Class adapter)
      Specified by:
      getAdapter in interface org.eclipse.core.runtime.IAdaptable
    • openStreams

      protected abstract void openStreams() throws SendFileTransferException
      Open incoming and outgoing streams associated with this file transfer. Subclasses must implement this method to open input and output streams. The remoteFileContents and localFileContent must be non-null after successful completion of the implementation of this method.
      Throws:
      SendFileTransferException - if some problem
    • getOutgoingNamespace

      public Namespace getOutgoingNamespace()
      Description copied from interface: ISendFileTransferContainerAdapter
      Get namespace for outgoing file transfer.
      Specified by:
      getOutgoingNamespace in interface ISendFileTransferContainerAdapter
      Returns:
      Namespace for outgoing IFileID instances. Will not return null.
    • getListener

      public IFileTransferListener getListener()
    • createJobName

      protected String createJobName()
    • setupAndScheduleJob

      protected void setupAndScheduleJob()
    • fireSendStartEvent

      protected void fireSendStartEvent()
    • setupProxy

      protected abstract void setupProxy(Proxy proxy)
    • setupProxies

      protected void setupProxies()
    • selectProxyFromProxies

      protected org.eclipse.core.net.proxy.IProxyData selectProxyFromProxies(String protocol, org.eclipse.core.net.proxy.IProxyData[] proxies)
      Select a single proxy from a set of proxies available for the given host. This implementation selects in the following manner: 1) If proxies provided is null or array of 0 length, null is returned. If only one proxy is available (array of length 1) then the entry is returned. If proxies provided is length greater than 1, then if the type of a proxy in the array matches the given protocol (e.g. http, https), then the first matching proxy is returned. If the protocol does not match any of the proxies, then the *first* proxy (i.e. proxies[0]) is returned. Subclasses may override if desired.
      Parameters:
      protocol - the target protocol (e.g. http, https, scp, etc). Will not be null.
      proxies - the proxies to select from. May be null or array of length 0.
      Returns:
      proxy data selected from the proxies provided.
    • sendOutgoingRequest

      public void sendOutgoingRequest(IFileID targetReceiver, IFileTransferInfo localFileToSend, IFileTransferListener transferListener, Map ops) throws SendFileTransferException
      Description copied from interface: ISendFileTransferContainerAdapter
      Send request for outgoing file transfer. This method is used to initiate a file transfer to a targetReceiver (first parameter) of the localFileToSend (second parameter). File transfer events are asynchronously delivered to the file transferListener (third parameter)
      Specified by:
      sendOutgoingRequest in interface ISendFileTransferContainerAdapter
      Parameters:
      targetReceiver - the ID of the remote to receive the file transfer request. Must not be should not be null.
      localFileToSend - the IFileTransferInfo for the local file to send. Must not be should not be null.
      transferListener - a IFileTransferListener for responding to file transfer events. Must not be should not be null.. If the target receiver responds then an IOutgoingFileTransferResponseEvent will be delivered to the listener
      ops - a Map of options associated with sendOutgoingRequest. The particular name/value pairs will be unique to the individual providers. May be should not be null..
      Throws:
      SendFileTransferException - if the provider is not connected or is not in the correct state for initiating file transfer
    • sendOutgoingRequest

      public void sendOutgoingRequest(IFileID targetReceiver, File localFileToSend, IFileTransferListener transferListener, Map ops) throws SendFileTransferException
      Description copied from interface: ISendFileTransferContainerAdapter
      Send request for outgoing file transfer. This method is used to initiate a file transfer to a targetReceiver (first parameter) of the localFileToSend (second parameter). File transfer events are asynchronously delivered to the file transferListener (third parameter)
      Specified by:
      sendOutgoingRequest in interface ISendFileTransferContainerAdapter
      Parameters:
      targetReceiver - the ID of the remote to receive the file transfer request. Must not be null.
      localFileToSend - the File for the local file to send. Must not be null.
      transferListener - a IFileTransferListener for responding to file transfer events. Must not be null. If the target receiver responds then an IOutgoingFileTransfer will be delivered to the listener
      ops - a Map of options associated with sendOutgoingRequest. The particular name/value pairs will be unique to the individual providers. May be null.
      Throws:
      SendFileTransferException - if the provider is not connected or is not in the correct state for initiating file transfer
    • addListener

      public void addListener(IIncomingFileTransferRequestListener l)
      Description copied from interface: ISendFileTransferContainerAdapter
      Add incoming file transfer listener. If the underlying provider supports receiving file transfer requests
      Specified by:
      addListener in interface ISendFileTransferContainerAdapter
      Parameters:
      l - to receive incoming file transfer request events. Must not be null.
    • removeListener

      public boolean removeListener(IIncomingFileTransferRequestListener l)
      Description copied from interface: ISendFileTransferContainerAdapter
      Remove incoming file transfer listener
      Specified by:
      removeListener in interface ISendFileTransferContainerAdapter
      Parameters:
      l - the listener to remove. Must not be null.
      Returns:
      true if listener actually removed, false otherwise
    • setConnectContextForAuthentication

      public void setConnectContextForAuthentication(IConnectContext connectContext)
      Description copied from interface: ISendFileTransferContainerAdapter
      Set connect context for authentication upon subsequent ISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map). This method should be called with a non-null connectContext in order to allow authentication to occur during call to ISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map).
      Specified by:
      setConnectContextForAuthentication in interface ISendFileTransferContainerAdapter
      Parameters:
      connectContext - the connect context to use for authenticating during subsequent call to ISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map). If null, then no authentication will be attempted.
    • setProxy

      public void setProxy(Proxy proxy)
      Description copied from interface: ISendFileTransferContainerAdapter
      Set proxy for use upon subsequent ISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map). This method should be called with a non-null proxy to allow the given proxy to be used in subsequent calls to ISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map).
      Specified by:
      setProxy in interface ISendFileTransferContainerAdapter
      Parameters:
      proxy - the proxy to use for subsequent calls to ISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map). If null, then no proxy will be used.