public abstract class AbstractRetrieveFileTransfer extends Object implements IIncomingFileTransfer, IRetrieveFileTransfer, IFileTransferPausable
| Modifier and Type | Field and Description |
|---|---|
protected int |
buff_length |
protected long |
bytesReceived |
protected static int |
CLOSE_TIMEOUT |
protected boolean |
closeOutputStream |
protected IConnectContext |
connectContext |
static int |
DEFAULT_BUF_LENGTH |
protected boolean |
done |
protected double |
downloadRateBytesPerSecond |
protected Exception |
exception |
protected long |
fileLength |
protected org.eclipse.core.runtime.jobs.Job |
job |
protected Object |
jobLock |
protected long |
lastModifiedTime |
protected IFileTransferListener |
listener |
protected OutputStream |
localFileContents |
protected Map |
options |
protected boolean |
paused |
protected static int |
POLLING_RETRY_ATTEMPTS |
protected Proxy |
proxy |
protected IFileRangeSpecification |
rangeSpecification |
protected static int |
READ_TIMEOUT |
protected InputStream |
remoteFileContents |
protected IFileID |
remoteFileID |
protected URL |
remoteFileURL |
protected Map |
responseHeaders |
protected static int |
TIMEOUT_INPUTSTREAM_BUFFER_SIZE |
protected long |
transferStartTime |
| Constructor and Description |
|---|
AbstractRetrieveFileTransfer() |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancel this file transfer.
|
protected String |
createJobName() |
protected String |
createRangeName() |
protected abstract boolean |
doPause()
Subclass overridable version of
pause(). |
protected abstract boolean |
doResume()
Subclass overridable version of
resume(). |
protected void |
fireReceiveResumedEvent() |
protected void |
fireReceiveStartEvent() |
protected void |
fireTransferReceiveDataEvent() |
protected void |
fireTransferReceiveDoneEvent() |
protected void |
fireTransferReceivePausedEvent() |
Object |
getAdapter(Class adapter) |
long |
getBytesReceived()
Get number of bytes received so far.
|
Exception |
getException()
Get any exception associated with this file transfer.
|
long |
getFileLength()
Return resulting file length (in bytes) for this file transfer instance.
|
IFileRangeSpecification |
getFileRangeSpecification()
Get file range specification for this incoming file transfer instance.
|
protected org.eclipse.core.runtime.IStatus |
getFinalStatus(Throwable exception1) |
ID |
getID()
Return the ID for this 'identifiable' object.
|
IFileTransferListener |
getListener()
Get listener assigned to this incoming file transfer.
|
protected Map |
getOptions() |
double |
getPercentComplete()
Get the percent complete for this file transfer.
|
String |
getRemoteFileName()
Obtains the name of the remote file if possible.
|
protected URL |
getRemoteFileURL() |
Date |
getRemoteLastModified()
Obtains the timestamp that reflects the time when the remote file was last
modified if possible.
|
Namespace |
getRetrieveNamespace()
Get namespace to be used for creation of remoteFileID for retrieve
request.
|
protected int |
getSocketCloseTimeout() |
protected int |
getSocketReadTimeout() |
protected void |
handleReceivedData(byte[] buf,
int bytes,
double factor,
org.eclipse.core.runtime.IProgressMonitor monitor) |
protected void |
hardClose() |
protected boolean |
isCanceled() |
boolean |
isDone()
Return true if this file transfer is done, false if not yet completed.
|
boolean |
isPaused() |
protected UserCancelledException |
newUserCancelledException() |
protected abstract void |
openStreams()
Open incoming and outgoing streams associated with this file transfer.
|
boolean |
pause()
Pause file transfer.
|
protected void |
resetDoneAndException() |
boolean |
resume()
Resume file transfer after having been paused.
|
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.
|
void |
sendRetrieveRequest(IFileID rFileID,
IFileRangeSpecification rangeSpec,
IFileTransferListener transferListener,
Map ops)
Send request for transfer of a remote file to local file storage.
|
void |
sendRetrieveRequest(IFileID remoteFileID1,
IFileTransferListener transferListener,
Map options1)
Send request for transfer of a remote file to local file storage.
|
protected void |
setCloseOutputStream(boolean close) |
void |
setConnectContextForAuthentication(IConnectContext connectContext)
Set connect context for authentication upon subsequent
IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map). |
protected void |
setDone(boolean done) |
protected void |
setDoneCanceled() |
protected void |
setDoneCanceled(Exception e) |
protected void |
setDoneException(Exception e) |
protected void |
setFileLength(long length) |
protected void |
setInputStream(InputStream ins) |
protected void |
setLastModifiedTime(long timestamp) |
protected void |
setOutputStream(OutputStream outs) |
void |
setProxy(Proxy proxy)
Set proxy for use upon subsequent
IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map). |
protected void |
setupAndScheduleJob(FileTransferJob fileTransferJob) |
protected void |
setupProxies() |
protected abstract void |
setupProxy(Proxy proxy)
Setup ECF proxy.
|
protected boolean |
targetHasGzSuffix(String target) |
static String |
toHumanReadableBytes(double size) |
protected InputStream |
wrapTransferReadInputStream(InputStream inputStream,
org.eclipse.core.runtime.IProgressMonitor monitor) |
public static final int DEFAULT_BUF_LENGTH
protected static final int POLLING_RETRY_ATTEMPTS
protected static final int TIMEOUT_INPUTSTREAM_BUFFER_SIZE
protected static final int READ_TIMEOUT
protected static final int CLOSE_TIMEOUT
protected Object jobLock
protected org.eclipse.core.runtime.jobs.Job job
protected URL remoteFileURL
protected IFileID remoteFileID
protected IFileTransferListener listener
protected int buff_length
protected boolean done
protected volatile long bytesReceived
protected InputStream remoteFileContents
protected OutputStream localFileContents
protected boolean closeOutputStream
protected Exception exception
protected long fileLength
protected long lastModifiedTime
protected Map options
protected boolean paused
protected IFileRangeSpecification rangeSpecification
protected Proxy proxy
protected IConnectContext connectContext
protected long transferStartTime
protected double downloadRateBytesPerSecond
protected Map responseHeaders
protected InputStream wrapTransferReadInputStream(InputStream inputStream, org.eclipse.core.runtime.IProgressMonitor monitor)
protected URL getRemoteFileURL()
protected int getSocketReadTimeout()
protected int getSocketCloseTimeout()
protected void setInputStream(InputStream ins)
protected void setOutputStream(OutputStream outs)
protected void setCloseOutputStream(boolean close)
protected void setFileLength(long length)
protected void setLastModifiedTime(long timestamp)
protected Map getOptions()
protected void handleReceivedData(byte[] buf,
int bytes,
double factor,
org.eclipse.core.runtime.IProgressMonitor monitor)
throws IOException
IOExceptionpublic static String toHumanReadableBytes(double size)
public ID getID()
IIdentifiablenull.getID in interface IIdentifiablenull.protected org.eclipse.core.runtime.IStatus getFinalStatus(Throwable exception1)
protected void hardClose()
protected void fireTransferReceivePausedEvent()
protected void fireTransferReceiveDoneEvent()
protected void fireTransferReceiveDataEvent()
public void setConnectContextForAuthentication(IConnectContext connectContext)
IRetrieveFileTransferContainerAdapterIRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map). This
method should be called with a non-null connectContext in order to allow
authentication to occur during call to
IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map).setConnectContextForAuthentication in interface IRetrieveFileTransferContainerAdapterconnectContext - the connect context to use for authenticating during
subsequent call to
IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map).
If null, then no authentication will be
attempted.public void setProxy(Proxy proxy)
IRetrieveFileTransferContainerAdapterIRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map). This
method should be called with proxy to allow the given proxy to
be used in subsequent calls to
IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map).
When proxy is null or has not been called providers must use
the org.eclipse.core.net proxy API to obtain proxy information
and proxy credentials if they support proxies of the type(s) supported by
that API. The API is provided by an OSGi service of type
org.eclipse.core.net.proxy.IProxyService.
If no information is available via IProxyService
providers may use other defaults.
setProxy in interface IRetrieveFileTransferContainerAdapterproxy - the proxy to use for subsequent calls to
IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map).
If null, then proxy information is obtained from
IProxyService if available. Otherwise provider
defined defaults may be used.public long getBytesReceived()
IIncomingFileTransfergetBytesReceived in interface IIncomingFileTransferprotected UserCancelledException newUserCancelledException()
protected void resetDoneAndException()
protected void setDone(boolean done)
protected void setDoneException(Exception e)
protected boolean isCanceled()
protected void setDoneCanceled()
protected void setDoneCanceled(Exception e)
public void cancel()
IFileTransferIFileTransferEvent being delivered to the
IFileTransferListener indicating that transfer is done (IFileTransfer.isDone()
returns true), and some exception will be made availablecancel in interface IFileTransferpublic Exception getException()
IFileTransferIFileTransfer.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.
getException in interface IFileTransfernull
if transfer completed successfully, non-null if transfer
completed with some exception. Only valid after
IFileTransfer.isDone() returns true.public double getPercentComplete()
IFileTransferIFileTransfer.isDone() method should be consulted to determine if the file
transfer has completed (with or without error).getPercentComplete in interface IFileTransferpublic long getFileLength()
IFileTransferIFileRangeSpecification is provided that the returned
file length is the expected file length of just the range retrieved (and not the entire file).getFileLength in interface IFileTransferpublic Date getRemoteLastModified()
IIncomingFileTransfergetRemoteLastModified in interface IIncomingFileTransfernull if that
information was not available.public boolean isDone()
IFileTransferIFileTransfer.getException() method.isDone in interface IFileTransferpublic Object getAdapter(Class adapter)
getAdapter in interface org.eclipse.core.runtime.IAdaptableprotected abstract void openStreams()
throws IncomingFileTransferException
remoteFileContents and localFileContent
must be non-null after successful completion of the
implementation of this method.IncomingFileTransferException - if some problempublic void sendRetrieveRequest(IFileID remoteFileID1, IFileTransferListener transferListener, Map options1) throws IncomingFileTransferException
IRetrieveFileTransferContainerAdapter
NOTE: if this method completes successfully, the given transferListener
will be asynchronously notified via an IIncomingFileTransferReceiveDoneEvent
(along with other possible events). All implementations are required to
issue this event whether successful or failed. Listeners
can consult IIncomingFileTransferReceiveDoneEvent.getException() to
determine whether the transfer operation completed successfully.
sendRetrieveRequest in interface IRetrieveFileTransferContainerAdapterremoteFileID1 - 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. Typically,
callers will create IFileID instances via calls such as:
IFileID remoteFileID = FileIDFactory.getDefault().createID(
ftc.getRetrieveNamespace(), "http://www.composent.com/index.html");
Must not be null.transferListener - a listener for file transfer events. Must not be null. Must not be null. See Note above.options1 - a Map of options associated with sendRetrieveRequest. The
particular name/value pairs will be unique to the individual
providers. May be null.IncomingFileTransferException - if the provider is not connected or is not in the correct
state for initiating file transferpublic Namespace getRetrieveNamespace()
IRetrieveFileTransferContainerAdapterIDFactory.createID(Namespace, String) to be used as first in
IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map)getRetrieveNamespace in interface IRetrieveFileTransferContainerAdapterIDFactory.createID(Namespace, String). Will not be
null.public boolean isPaused()
isPaused in interface IFileTransferPausableprotected abstract boolean doPause()
pause(). Subclasses must provide
an implementation of this method to support IFileTransferPausable
.false otherwise.public boolean pause()
IFileTransferPausablepause in interface IFileTransferPausableprotected abstract boolean doResume()
resume(). Subclasses must
provide an implementation of this method to support
IFileTransferPausable.false otherwise.public boolean resume()
IFileTransferPausableresume in interface IFileTransferPausablepublic IFileTransferListener getListener()
IIncomingFileTransfernull if no listener
has been provided.getListener in interface IIncomingFileTransferprotected String createRangeName()
protected String createJobName()
protected void setupAndScheduleJob(FileTransferJob fileTransferJob)
protected void fireReceiveStartEvent()
protected void fireReceiveResumedEvent()
public IFileRangeSpecification getFileRangeSpecification()
IIncomingFileTransfernull if the retrieval is of the entire file.getFileRangeSpecification in interface IIncomingFileTransfernull if the retrieval is of the entire file.public void sendRetrieveRequest(IFileID rFileID, IFileRangeSpecification rangeSpec, IFileTransferListener transferListener, Map ops) throws IncomingFileTransferException
IRetrieveFileTransferContainerAdapter
NOTE: if this method completes successfully, the given transferListener
will be asynchronously notified via an IIncomingFileTransferReceiveDoneEvent
(along with other possible events). All implementations are required to
issue this event whether successful or failed. Listeners
can consult IIncomingFileTransferReceiveDoneEvent.getException() to
determine whether the transfer operation completed successfully.
sendRetrieveRequest in interface IRetrieveFileTransferContainerAdapterrFileID - 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. Typically,
callers will create IFileID instances via calls such as:
IFileID remoteFileID = FileIDFactory.getDefault().createID(
ftc.getRetrieveNamespace(), "http://www.composent.com/index.html");
Must not be null.rangeSpec - a range specification for retrieving a portion of the given
remote file. If null the entire file will be retrieved (as per IRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map).
If non-null the given file range will be used to retrieve the given file. For example, if the
rangeSpecification has a start value of 1 and end value of 3, and the total length of the file is
5 bytes with content [a, b, c, d, e], a successful retrieve request would transfer bytes 'b', 'c', and 'd', but not 'a', and 'e'.transferListener - a listener for file transfer events. Must not be null. See Note above.ops - a Map of options associated with sendRetrieveRequest. The
particular name/value pairs will be unique to the individual
providers. May be null.IncomingFileTransferException - if some problem sending retrieve requestprotected abstract void setupProxy(Proxy proxy)
sendRetrieveRequest(IFileID, IFileTransferListener, Map) and
sendRetrieveRequest(IFileID, IFileRangeSpecification, IFileTransferListener, Map)
, prior to the actual call to openStreams().proxy - the proxy to be setup. Will not be null.protected org.eclipse.core.net.proxy.IProxyData selectProxyFromProxies(String protocol, org.eclipse.core.net.proxy.IProxyData[] proxies)
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.protected void setupProxies()
public String getRemoteFileName()
IIncomingFileTransfergetRemoteFileName in interface IIncomingFileTransfernull if no such name can be determined.protected boolean targetHasGzSuffix(String target)
Copyright © 2004–2020 Eclipse Foundation. All rights reserved.