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 Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected long
protected IConnectContext
static final int
protected boolean
protected Exception
protected IFileTransferInfo
protected org.eclipse.core.runtime.jobs.Job
protected IFileTransferListener
protected InputStream
protected Map
protected Proxy
protected OutputStream
protected IFileID
protected URL
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add incoming file transfer listener.void
cancel()
Cancel this file transfer.protected String
protected void
protected void
protected void
getAdapter
(Class adapter) long
Get the number of bytes sent for this outgoing file transfer.Get any exception associated with this file transfer.long
Return resulting file length (in bytes) for this file transfer instance.protected IFileTransferInfo
protected org.eclipse.core.runtime.IStatus
getFinalStatus
(Throwable exception1) getID()
Return the ID for this 'identifiable' object.protected Map
Get namespace for outgoing file transfer.double
Get the percent complete for this file transfer.protected URL
protected void
boolean
isDone()
Return true if this file transfer is done, false if not yet completed.protected abstract void
Open incoming and outgoing streams associated with this file transfer.boolean
Remove incoming file transfer listenerprotected 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.void
sendOutgoingRequest
(IFileID targetReceiver, File localFileToSend, IFileTransferListener transferListener, Map ops) Send request for outgoing file transfer.void
sendOutgoingRequest
(IFileID targetReceiver, IFileTransferInfo localFileToSend, IFileTransferListener transferListener, Map ops) Send request for outgoing file transfer.void
setConnectContextForAuthentication
(IConnectContext connectContext) Set connect context for authentication upon subsequentISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map)
.protected void
protected void
setOutputStream
(OutputStream outs) void
Set proxy for use upon subsequentISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map)
.protected void
protected void
protected abstract void
setupProxy
(Proxy proxy)
-
Field Details
-
DEFAULT_BUF_LENGTH
public static final int DEFAULT_BUF_LENGTH- See Also:
-
job
protected org.eclipse.core.runtime.jobs.Job job -
remoteFileURL
-
remoteFileID
-
listener
-
buff_length
protected int buff_length -
done
protected boolean done -
bytesSent
protected long bytesSent -
localFileContents
-
remoteFileContents
-
exception
-
fileTransferInfo
-
options
-
connectContext
-
proxy
-
-
Constructor Details
-
AbstractOutgoingFileTransfer
public AbstractOutgoingFileTransfer()
-
-
Method Details
-
getRemoteFileURL
-
setInputStream
-
setOutputStream
-
getFileTransferInfo
-
getOptions
-
getFinalStatus
-
hardClose
protected void hardClose() -
getID
Description copied from interface:IIdentifiable
Return the ID for this 'identifiable' object. The returned ID should be unique within its namespace. May returnnull
.- Specified by:
getID
in interfaceIIdentifiable
- 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 interfaceIOutgoingFileTransfer
- 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 anIFileTransferEvent
being delivered to theIFileTransferListener
indicating that transfer is done (IFileTransfer.isDone()
returns true), and some exception will be made available- Specified by:
cancel
in interfaceIFileTransfer
-
getException
Description copied from interface:IFileTransfer
Get any exception associated with this file transfer. The value returned from this method is valid only ifIFileTransfer.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), thenIFileTransfer.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 interfaceIFileTransfer
- Returns:
- Exception associated with this file transfer.
null
if transfer completed successfully, non-null if transfer completed with some exception. Only valid afterIFileTransfer.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 theIFileTransfer.isDone()
method should be consulted to determine if the file transfer has completed (with or without error).- Specified by:
getPercentComplete
in interfaceIFileTransfer
- 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 aIFileRangeSpecification
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 interfaceIFileTransfer
- 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 theIFileTransfer.getException()
method.- Specified by:
isDone
in interfaceIFileTransfer
- Returns:
- boolean true if file transfer is done, false if file transfer is still in progress.
-
getAdapter
- Specified by:
getAdapter
in interfaceorg.eclipse.core.runtime.IAdaptable
-
openStreams
Open incoming and outgoing streams associated with this file transfer. Subclasses must implement this method to open input and output streams. TheremoteFileContents
andlocalFileContent
must be non-null
after successful completion of the implementation of this method.- Throws:
SendFileTransferException
- if some problem
-
getOutgoingNamespace
Description copied from interface:ISendFileTransferContainerAdapter
Get namespace for outgoing file transfer.- Specified by:
getOutgoingNamespace
in interfaceISendFileTransferContainerAdapter
- Returns:
- Namespace for outgoing IFileID instances. Will not return
null
.
-
getListener
-
createJobName
-
setupAndScheduleJob
protected void setupAndScheduleJob() -
fireSendStartEvent
protected void fireSendStartEvent() -
setupProxy
-
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 benull
.proxies
- the proxies to select from. May benull
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 interfaceISendFileTransferContainerAdapter
- Parameters:
targetReceiver
- the ID of the remote to receive the file transfer request. Must not be should not benull
.localFileToSend
- theIFileTransferInfo
for the local file to send. Must not be should not benull
.transferListener
- aIFileTransferListener
for responding to file transfer events. Must not be should not benull
.. If the target receiver responds then anIOutgoingFileTransferResponseEvent
will be delivered to the listenerops
- a Map of options associated with sendOutgoingRequest. The particular name/value pairs will be unique to the individual providers. May be should not benull
..- 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 interfaceISendFileTransferContainerAdapter
- Parameters:
targetReceiver
- the ID of the remote to receive the file transfer request. Must not benull
.localFileToSend
- theFile
for the local file to send. Must not benull
.transferListener
- aIFileTransferListener
for responding to file transfer events. Must not benull
. If the target receiver responds then an IOutgoingFileTransfer will be delivered to the listenerops
- a Map of options associated with sendOutgoingRequest. The particular name/value pairs will be unique to the individual providers. May benull
.- Throws:
SendFileTransferException
- if the provider is not connected or is not in the correct state for initiating file transfer
-
addListener
Description copied from interface:ISendFileTransferContainerAdapter
Add incoming file transfer listener. If the underlying provider supports receiving file transfer requests- Specified by:
addListener
in interfaceISendFileTransferContainerAdapter
- Parameters:
l
- to receive incoming file transfer request events. Must not benull
.
-
removeListener
Description copied from interface:ISendFileTransferContainerAdapter
Remove incoming file transfer listener- Specified by:
removeListener
in interfaceISendFileTransferContainerAdapter
- Parameters:
l
- the listener to remove. Must not benull
.- Returns:
- true if listener actually removed, false otherwise
-
setConnectContextForAuthentication
Description copied from interface:ISendFileTransferContainerAdapter
Set connect context for authentication upon subsequentISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map)
. This method should be called with a non-null connectContext in order to allow authentication to occur during call toISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map)
.- Specified by:
setConnectContextForAuthentication
in interfaceISendFileTransferContainerAdapter
- Parameters:
connectContext
- the connect context to use for authenticating during subsequent call toISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map)
. Ifnull
, then no authentication will be attempted.
-
setProxy
Description copied from interface:ISendFileTransferContainerAdapter
Set proxy for use upon subsequentISendFileTransferContainerAdapter.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 toISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map)
.- Specified by:
setProxy
in interfaceISendFileTransferContainerAdapter
- Parameters:
proxy
- the proxy to use for subsequent calls toISendFileTransferContainerAdapter.sendOutgoingRequest(IFileID, IFileTransferInfo, IFileTransferListener, Map)
. Ifnull
, then no proxy will be used.
-