Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-02-11 02:29:25 -0500
committerslewis2009-02-11 02:29:25 -0500
commitd02242328717c819c8c76e7f4af415faac5c5c0a (patch)
tree3b0826d0d5e40ef1f0922436956c5dc121bbcd55 /providers/bundles/org.eclipse.ecf.provider.filetransfer
parente19c96a021aec2245d102c5f0549795173c4f3de (diff)
downloadorg.eclipse.ecf-d02242328717c819c8c76e7f4af415faac5c5c0a.tar.gz
org.eclipse.ecf-d02242328717c819c8c76e7f4af415faac5c5c0a.tar.xz
org.eclipse.ecf-d02242328717c819c8c76e7f4af415faac5c5c0a.zip
Code formatting changes
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.filetransfer')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java566
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java72
2 files changed, 254 insertions, 384 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
index 14cd878e4..789485a4d 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
@@ -36,8 +36,7 @@ import org.eclipse.ecf.provider.filetransfer.util.PollingInputStream;
import org.eclipse.ecf.provider.filetransfer.util.TimeoutInputStream;
import org.eclipse.osgi.util.NLS;
-public abstract class AbstractRetrieveFileTransfer implements
- IIncomingFileTransfer, IRetrieveFileTransfer, IFileTransferPausable {
+public abstract class AbstractRetrieveFileTransfer implements IIncomingFileTransfer, IRetrieveFileTransfer, IFileTransferPausable {
public static final int DEFAULT_BUF_LENGTH = 4096;
@@ -100,25 +99,17 @@ public abstract class AbstractRetrieveFileTransfer implements
transferStartTime = System.currentTimeMillis();
final byte[] buf = new byte[buff_length];
final long totalWork = ((fileLength == -1) ? 100 : fileLength);
- double factor = (totalWork > Integer.MAX_VALUE) ? (((double) Integer.MAX_VALUE) / ((double) totalWork))
- : 1.0;
- int work = (totalWork > Integer.MAX_VALUE) ? Integer.MAX_VALUE
- : (int) totalWork;
- monitor
- .beginTask(
- getRemoteFileURL().toString()
- + Messages.AbstractRetrieveFileTransfer_Progress_Data,
- work);
- InputStream readInputStream = new PollingInputStream(
- remoteFileContents, POLLING_RETRY_ATTEMPTS, monitor);
+ double factor = (totalWork > Integer.MAX_VALUE) ? (((double) Integer.MAX_VALUE) / ((double) totalWork)) : 1.0;
+ int work = (totalWork > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) totalWork;
+ monitor.beginTask(getRemoteFileURL().toString() + Messages.AbstractRetrieveFileTransfer_Progress_Data, work);
+ InputStream readInputStream = new PollingInputStream(remoteFileContents, POLLING_RETRY_ATTEMPTS, monitor);
try {
while (!isDone() && !isPaused()) {
try {
final int bytes = readInputStream.read(buf);
handleReceivedData(buf, bytes, factor, monitor);
} catch (OperationCanceledException e) {
- throw new UserCancelledException(
- Messages.AbstractRetrieveFileTransfer_Exception_User_Cancelled);
+ throw new UserCancelledException(Messages.AbstractRetrieveFileTransfer_Exception_User_Cancelled);
}
}
} catch (final Exception e) {
@@ -129,9 +120,7 @@ public abstract class AbstractRetrieveFileTransfer implements
if (readInputStream != null)
readInputStream.close();
} catch (final IOException e) {
- Activator.getDefault().log(
- new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- IStatus.ERROR, "hardClose", e)); //$NON-NLS-1$
+ Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "hardClose", e)); //$NON-NLS-1$
}
hardClose();
monitor.done();
@@ -142,15 +131,7 @@ public abstract class AbstractRetrieveFileTransfer implements
fireTransferReceiveDoneEvent();
} catch (Exception e) {
// simply log
- Activator
- .getDefault()
- .log(
- new Status(
- IStatus.ERROR,
- Activator.PLUGIN_ID,
- IStatus.ERROR,
- Messages.AbstractRetrieveFileTransfer_EXCEPTION_IN_FINALLY,
- e));
+ Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.AbstractRetrieveFileTransfer_EXCEPTION_IN_FINALLY, e));
}
}
return getFinalStatus(exception);
@@ -163,8 +144,7 @@ public abstract class AbstractRetrieveFileTransfer implements
}
protected void setInputStream(InputStream ins) {
- remoteFileContents = new TimeoutInputStream(ins,
- TIMEOUT_INPUTSTREAM_BUFFER_SIZE, READ_TIMEOUT, CLOSE_TIMEOUT);
+ remoteFileContents = new TimeoutInputStream(ins, TIMEOUT_INPUTSTREAM_BUFFER_SIZE, READ_TIMEOUT, CLOSE_TIMEOUT);
}
protected void setOutputStream(OutputStream outs) {
@@ -187,20 +167,12 @@ public abstract class AbstractRetrieveFileTransfer implements
return options;
}
- protected void handleReceivedData(byte[] buf, int bytes, double factor,
- IProgressMonitor monitor) throws IOException {
+ protected void handleReceivedData(byte[] buf, int bytes, double factor, IProgressMonitor monitor) throws IOException {
if (bytes != -1) {
bytesReceived += bytes;
localFileContents.write(buf, 0, bytes);
- downloadRateBytesPerSecond = (bytesReceived / ((System
- .currentTimeMillis() + 1 - transferStartTime) / 1000.0));
- monitor
- .setTaskName(createJobName()
- + Messages.AbstractRetrieveFileTransfer_Progress_Data
- + NLS
- .bind(
- Messages.AbstractRetrieveFileTransfer_InfoTransferRate,
- toHumanReadableBytes(downloadRateBytesPerSecond)));
+ downloadRateBytesPerSecond = (bytesReceived / ((System.currentTimeMillis() + 1 - transferStartTime) / 1000.0));
+ monitor.setTaskName(createJobName() + Messages.AbstractRetrieveFileTransfer_Progress_Data + NLS.bind(Messages.AbstractRetrieveFileTransfer_InfoTransferRate, toHumanReadableBytes(downloadRateBytesPerSecond)));
monitor.worked((int) Math.round(factor * bytes));
fireTransferReceiveDataEvent();
} else
@@ -225,8 +197,7 @@ public abstract class AbstractRetrieveFileTransfer implements
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitBytes;
}
- DecimalFormat df = new DecimalFormat(NLS.bind(
- Messages.AbstractRetrieveFileTransfer_TransferRateFormat, unit));
+ DecimalFormat df = new DecimalFormat(NLS.bind(Messages.AbstractRetrieveFileTransfer_TransferRateFormat, unit));
return df.format(convertedSize);
}
@@ -241,26 +212,11 @@ public abstract class AbstractRetrieveFileTransfer implements
protected IStatus getFinalStatus(Throwable exception1) {
if (exception1 == null)
- return new Status(
- IStatus.OK,
- Activator.getDefault().getBundle().getSymbolicName(),
- 0,
- Messages.AbstractRetrieveFileTransfer_Status_Transfer_Completed_OK,
- null);
+ return new Status(IStatus.OK, Activator.getDefault().getBundle().getSymbolicName(), 0, Messages.AbstractRetrieveFileTransfer_Status_Transfer_Completed_OK, null);
else if (exception1 instanceof UserCancelledException)
- return new Status(
- IStatus.CANCEL,
- Activator.PLUGIN_ID,
- FILETRANSFER_ERRORCODE,
- Messages.AbstractRetrieveFileTransfer_Exception_User_Cancelled,
- exception1);
+ return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, FILETRANSFER_ERRORCODE, Messages.AbstractRetrieveFileTransfer_Exception_User_Cancelled, exception1);
else
- return new Status(
- IStatus.ERROR,
- Activator.PLUGIN_ID,
- FILETRANSFER_ERRORCODE,
- Messages.AbstractRetrieveFileTransfer_Status_Transfer_Exception,
- exception1);
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, FILETRANSFER_ERRORCODE, Messages.AbstractRetrieveFileTransfer_Status_Transfer_Exception, exception1);
}
protected void hardClose() {
@@ -268,17 +224,13 @@ public abstract class AbstractRetrieveFileTransfer implements
if (remoteFileContents != null)
remoteFileContents.close();
} catch (final IOException e) {
- Activator.getDefault().log(
- new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- IStatus.ERROR, "hardClose", e)); //$NON-NLS-1$
+ Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "hardClose", e)); //$NON-NLS-1$
}
try {
if (localFileContents != null && closeOutputStream)
localFileContents.close();
} catch (final IOException e) {
- Activator.getDefault().log(
- new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- IStatus.ERROR, "hardClose", e)); //$NON-NLS-1$
+ Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "hardClose", e)); //$NON-NLS-1$
}
job = null;
remoteFileContents = null;
@@ -286,69 +238,62 @@ public abstract class AbstractRetrieveFileTransfer implements
}
protected void fireTransferReceivePausedEvent() {
- listener
- .handleTransferEvent(new IIncomingFileTransferReceivePausedEvent() {
+ listener.handleTransferEvent(new IIncomingFileTransferReceivePausedEvent() {
- private static final long serialVersionUID = -1317411290525985140L;
+ private static final long serialVersionUID = -1317411290525985140L;
- public IIncomingFileTransfer getSource() {
- return AbstractRetrieveFileTransfer.this;
- }
+ public IIncomingFileTransfer getSource() {
+ return AbstractRetrieveFileTransfer.this;
+ }
- public String toString() {
- final StringBuffer sb = new StringBuffer(
- "IIncomingFileTransferReceivePausedEvent["); //$NON-NLS-1$
- sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
- .append(";fileLength=").append(fileLength).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
- return sb.toString();
- }
- });
+ public String toString() {
+ final StringBuffer sb = new StringBuffer("IIncomingFileTransferReceivePausedEvent["); //$NON-NLS-1$
+ sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
+ .append(";fileLength=").append(fileLength).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return sb.toString();
+ }
+ });
}
protected void fireTransferReceiveDoneEvent() {
- listener
- .handleTransferEvent(new IIncomingFileTransferReceiveDoneEvent() {
+ listener.handleTransferEvent(new IIncomingFileTransferReceiveDoneEvent() {
- private static final long serialVersionUID = 6925524078226825710L;
+ private static final long serialVersionUID = 6925524078226825710L;
- public IIncomingFileTransfer getSource() {
- return AbstractRetrieveFileTransfer.this;
- }
+ public IIncomingFileTransfer getSource() {
+ return AbstractRetrieveFileTransfer.this;
+ }
- public Exception getException() {
- return AbstractRetrieveFileTransfer.this.getException();
- }
+ public Exception getException() {
+ return AbstractRetrieveFileTransfer.this.getException();
+ }
- public String toString() {
- final StringBuffer sb = new StringBuffer(
- "IIncomingFileTransferReceiveDoneEvent["); //$NON-NLS-1$
- sb
- .append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
- .append(";fileLength=").append(fileLength).append(";exception=").append(getException()) //$NON-NLS-1$ //$NON-NLS-2$
- .append("]"); //$NON-NLS-1$
- return sb.toString();
- }
- });
+ public String toString() {
+ final StringBuffer sb = new StringBuffer("IIncomingFileTransferReceiveDoneEvent["); //$NON-NLS-1$
+ sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
+ .append(";fileLength=").append(fileLength).append(";exception=").append(getException()) //$NON-NLS-1$ //$NON-NLS-2$
+ .append("]"); //$NON-NLS-1$
+ return sb.toString();
+ }
+ });
}
protected void fireTransferReceiveDataEvent() {
- listener
- .handleTransferEvent(new IIncomingFileTransferReceiveDataEvent() {
- private static final long serialVersionUID = -5656328374614130161L;
+ listener.handleTransferEvent(new IIncomingFileTransferReceiveDataEvent() {
+ private static final long serialVersionUID = -5656328374614130161L;
- public IIncomingFileTransfer getSource() {
- return AbstractRetrieveFileTransfer.this;
- }
+ public IIncomingFileTransfer getSource() {
+ return AbstractRetrieveFileTransfer.this;
+ }
- public String toString() {
- final StringBuffer sb = new StringBuffer(
- "IIncomingFileTransferReceiveDataEvent["); //$NON-NLS-1$
- sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
- .append(";fileLength=").append(fileLength) //$NON-NLS-1$
- .append("]"); //$NON-NLS-1$
- return sb.toString();
- }
- });
+ public String toString() {
+ final StringBuffer sb = new StringBuffer("IIncomingFileTransferReceiveDataEvent["); //$NON-NLS-1$
+ sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
+ .append(";fileLength=").append(fileLength) //$NON-NLS-1$
+ .append("]"); //$NON-NLS-1$
+ return sb.toString();
+ }
+ });
}
/*
@@ -358,8 +303,7 @@ public abstract class AbstractRetrieveFileTransfer implements
* setConnectContextForAuthentication
* (org.eclipse.ecf.core.security.IConnectContext)
*/
- public void setConnectContextForAuthentication(
- IConnectContext connectContext) {
+ public void setConnectContextForAuthentication(IConnectContext connectContext) {
this.connectContext = connectContext;
}
@@ -392,8 +336,7 @@ public abstract class AbstractRetrieveFileTransfer implements
public void cancel() {
if (isPaused()) {
done = true;
- this.exception = new UserCancelledException(
- Messages.AbstractRetrieveFileTransfer_Exception_User_Cancelled);
+ this.exception = new UserCancelledException(Messages.AbstractRetrieveFileTransfer_Exception_User_Cancelled);
fireTransferReceiveDoneEvent();
} else if (job != null)
job.cancel();
@@ -459,10 +402,8 @@ public abstract class AbstractRetrieveFileTransfer implements
if (adapter.isInstance(this)) {
return this;
}
- final IAdapterManager adapterManager = Activator.getDefault()
- .getAdapterManager();
- return (adapterManager == null) ? null : adapterManager.loadAdapter(
- this, adapter.getName());
+ final IAdapterManager adapterManager = Activator.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
/**
@@ -483,9 +424,7 @@ public abstract class AbstractRetrieveFileTransfer implements
* sendRetrieveRequest(org.eclipse.ecf.filetransfer.identity.IFileID,
* org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map)
*/
- public void sendRetrieveRequest(final IFileID remoteFileID1,
- IFileTransferListener transferListener, Map options1)
- throws IncomingFileTransferException {
+ public void sendRetrieveRequest(final IFileID remoteFileID1, IFileTransferListener transferListener, Map options1) throws IncomingFileTransferException {
sendRetrieveRequest(remoteFileID1, null, transferListener, options1);
}
@@ -496,8 +435,7 @@ public abstract class AbstractRetrieveFileTransfer implements
* getRetrieveNamespace()
*/
public Namespace getRetrieveNamespace() {
- return IDFactory.getDefault().getNamespaceByName(
- FileTransferNamespace.PROTOCOL);
+ return IDFactory.getDefault().getNamespaceByName(FileTransferNamespace.PROTOCOL);
}
/*
@@ -576,203 +514,185 @@ public abstract class AbstractRetrieveFileTransfer implements
}
protected void fireReceiveStartEvent() {
- listener
- .handleTransferEvent(new IIncomingFileTransferReceiveStartEvent() {
- private static final long serialVersionUID = -513800598918052184L;
-
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferEvent#getFileID()
- */
- public IIncomingFileTransfer getSource() {
- return AbstractRetrieveFileTransfer.this;
- }
+ listener.handleTransferEvent(new IIncomingFileTransferReceiveStartEvent() {
+ private static final long serialVersionUID = -513800598918052184L;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferEvent#getFileID()
+ */
+ public IIncomingFileTransfer getSource() {
+ return AbstractRetrieveFileTransfer.this;
+ }
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferReceiveStartEvent#getFileID()
- */
- public IFileID getFileID() {
- return remoteFileID;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferReceiveStartEvent#getFileID()
+ */
+ public IFileID getFileID() {
+ return remoteFileID;
+ }
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferReceiveStartEvent
- * #receive(java.io.File)
- */
- public IIncomingFileTransfer receive(File localFileToSave)
- throws IOException {
- return receive(localFileToSave, null);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferReceiveStartEvent
+ * #receive(java.io.File)
+ */
+ public IIncomingFileTransfer receive(File localFileToSave) throws IOException {
+ return receive(localFileToSave, null);
+ }
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferReceiveStartEvent
- * #receive(java.io.File,
- * org.eclipse.ecf.filetransfer.FileTransferJob)
- */
- public IIncomingFileTransfer receive(File localFileToSave,
- FileTransferJob fileTransferJob) throws IOException {
- setOutputStream(new BufferedOutputStream(
- new FileOutputStream(localFileToSave)));
- setupAndScheduleJob(fileTransferJob);
- return AbstractRetrieveFileTransfer.this;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferReceiveStartEvent
+ * #receive(java.io.File,
+ * org.eclipse.ecf.filetransfer.FileTransferJob)
+ */
+ public IIncomingFileTransfer receive(File localFileToSave, FileTransferJob fileTransferJob) throws IOException {
+ setOutputStream(new BufferedOutputStream(new FileOutputStream(localFileToSave)));
+ setupAndScheduleJob(fileTransferJob);
+ return AbstractRetrieveFileTransfer.this;
+ }
- /**
- * @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);
- }
+ /**
+ * @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 AbstractRetrieveFileTransfer.this;
- }
+ /**
+ * @throws IOException
+ * not actually thrown by this implementation.
+ */
+ public IIncomingFileTransfer receive(OutputStream streamToStore, FileTransferJob fileTransferJob) throws IOException {
+ setOutputStream(streamToStore);
+ setCloseOutputStream(false);
+ setupAndScheduleJob(fileTransferJob);
+ return AbstractRetrieveFileTransfer.this;
+ }
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferReceiveStartEvent#cancel()
- */
- public void cancel() {
- hardClose();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferReceiveStartEvent#cancel()
+ */
+ public void cancel() {
+ hardClose();
+ }
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- public String toString() {
- final StringBuffer sb = new StringBuffer(
- "IIncomingFileTransferReceiveStartEvent["); //$NON-NLS-1$
- sb.append("isdone=").append(done).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
- sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
- .append("]"); //$NON-NLS-1$
- return sb.toString();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ final StringBuffer sb = new StringBuffer("IIncomingFileTransferReceiveStartEvent["); //$NON-NLS-1$
+ sb.append("isdone=").append(done).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
+ .append("]"); //$NON-NLS-1$
+ return sb.toString();
+ }
- });
+ });
}
protected void fireReceiveResumedEvent() {
- listener
- .handleTransferEvent(new IIncomingFileTransferReceiveResumedEvent() {
+ listener.handleTransferEvent(new IIncomingFileTransferReceiveResumedEvent() {
- private static final long serialVersionUID = 7111739642849612839L;
+ private static final long serialVersionUID = 7111739642849612839L;
- public IIncomingFileTransfer getSource() {
- return AbstractRetrieveFileTransfer.this;
- }
+ public IIncomingFileTransfer getSource() {
+ return AbstractRetrieveFileTransfer.this;
+ }
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferReceiveStartEvent#getFileID()
- */
- public IFileID getFileID() {
- return remoteFileID;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferReceiveStartEvent#getFileID()
+ */
+ public IFileID getFileID() {
+ return remoteFileID;
+ }
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferReceiveStartEvent
- * #receive(java.io.File)
- */
- public IIncomingFileTransfer receive(File localFileToSave,
- boolean append) throws IOException {
- return receive(localFileToSave, null, append);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferReceiveStartEvent
+ * #receive(java.io.File)
+ */
+ public IIncomingFileTransfer receive(File localFileToSave, boolean append) throws IOException {
+ return receive(localFileToSave, null, append);
+ }
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferReceiveStartEvent
- * #receive(java.io.File,
- * org.eclipse.ecf.filetransfer.FileTransferJob)
- */
- public IIncomingFileTransfer receive(File localFileToSave,
- FileTransferJob fileTransferJob, boolean append)
- throws IOException {
- setOutputStream(new BufferedOutputStream(
- new FileOutputStream(localFileToSave.getName(),
- append)));
- setupAndScheduleJob(fileTransferJob);
- return AbstractRetrieveFileTransfer.this;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferReceiveStartEvent
+ * #receive(java.io.File,
+ * org.eclipse.ecf.filetransfer.FileTransferJob)
+ */
+ public IIncomingFileTransfer receive(File localFileToSave, FileTransferJob fileTransferJob, boolean append) throws IOException {
+ setOutputStream(new BufferedOutputStream(new FileOutputStream(localFileToSave.getName(), append)));
+ setupAndScheduleJob(fileTransferJob);
+ return AbstractRetrieveFileTransfer.this;
+ }
- /**
- * @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);
- }
+ /**
+ * @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 AbstractRetrieveFileTransfer.this;
- }
+ /**
+ * @throws IOException
+ * not actually thrown by this implementation.
+ */
+ public IIncomingFileTransfer receive(OutputStream streamToStore, FileTransferJob fileTransferJob) throws IOException {
+ setOutputStream(streamToStore);
+ setCloseOutputStream(false);
+ setupAndScheduleJob(fileTransferJob);
+ return AbstractRetrieveFileTransfer.this;
+ }
- /*
- * (non-Javadoc)
- *
- * @seeorg.eclipse.ecf.filetransfer.events.
- * IIncomingFileTransferReceiveStartEvent#cancel()
- */
- public void cancel() {
- hardClose();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.filetransfer.events.
+ * IIncomingFileTransferReceiveStartEvent#cancel()
+ */
+ public void cancel() {
+ hardClose();
+ }
- public String toString() {
- final StringBuffer sb = new StringBuffer(
- "IIncomingFileTransferReceiveResumedEvent["); //$NON-NLS-1$
- sb.append("isdone=").append(done).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
- sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
- .append("]"); //$NON-NLS-1$
- return sb.toString();
- }
+ public String toString() {
+ final StringBuffer sb = new StringBuffer("IIncomingFileTransferReceiveResumedEvent["); //$NON-NLS-1$
+ sb.append("isdone=").append(done).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append("bytesReceived=").append(bytesReceived) //$NON-NLS-1$
+ .append("]"); //$NON-NLS-1$
+ return sb.toString();
+ }
- });
+ });
}
/*
@@ -794,16 +714,9 @@ public abstract class AbstractRetrieveFileTransfer implements
* org.eclipse.ecf.filetransfer.IFileRangeSpecification,
* org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map)
*/
- public void sendRetrieveRequest(IFileID rFileID,
- IFileRangeSpecification rangeSpec,
- IFileTransferListener transferListener, Map ops)
- throws IncomingFileTransferException {
- Assert.isNotNull(rFileID,
- Messages.AbstractRetrieveFileTransfer_RemoteFileID_Not_Null);
- Assert
- .isNotNull(
- transferListener,
- Messages.AbstractRetrieveFileTransfer_TransferListener_Not_Null);
+ public void sendRetrieveRequest(IFileID rFileID, IFileRangeSpecification rangeSpec, IFileTransferListener transferListener, Map ops) throws IncomingFileTransferException {
+ Assert.isNotNull(rFileID, Messages.AbstractRetrieveFileTransfer_RemoteFileID_Not_Null);
+ Assert.isNotNull(transferListener, Messages.AbstractRetrieveFileTransfer_TransferListener_Not_Null);
this.job = null;
this.remoteFileURL = null;
this.remoteFileID = rFileID;
@@ -822,11 +735,7 @@ public abstract class AbstractRetrieveFileTransfer implements
try {
this.remoteFileURL = rFileID.getURL();
} catch (final MalformedURLException e) {
- throw new IncomingFileTransferException(
- NLS
- .bind(
- Messages.AbstractRetrieveFileTransfer_MalformedURLException,
- rFileID), e);
+ throw new IncomingFileTransferException(NLS.bind(Messages.AbstractRetrieveFileTransfer_MalformedURLException, rFileID), e);
}
setupProxies();
openStreams();
@@ -863,8 +772,7 @@ public abstract class AbstractRetrieveFileTransfer implements
* of length 0.
* @return proxy data selected from the proxies provided.
*/
- protected IProxyData selectProxyFromProxies(String protocol,
- IProxyData[] proxies) {
+ protected IProxyData selectProxyFromProxies(String protocol, IProxyData[] proxies) {
if (proxies == null || proxies.length == 0)
return null;
// If only one proxy is available, then use that
@@ -893,25 +801,15 @@ public abstract class AbstractRetrieveFileTransfer implements
// settings
if (proxy == null) {
try {
- IProxyService proxyService = Activator.getDefault()
- .getProxyService();
+ IProxyService proxyService = Activator.getDefault().getProxyService();
// Only do this if platform service exists
if (proxyService != null && proxyService.isProxiesEnabled()) {
// Setup via proxyService entry
URL target = getRemoteFileURL();
- final IProxyData[] proxies = proxyService
- .getProxyDataForHost(target.getHost());
- IProxyData selectedProxy = selectProxyFromProxies(target
- .getProtocol(), proxies);
+ final IProxyData[] proxies = proxyService.getProxyDataForHost(target.getHost());
+ IProxyData selectedProxy = selectProxyFromProxies(target.getProtocol(), proxies);
if (selectedProxy != null) {
- proxy = new Proxy(
- ((selectedProxy.getType()
- .equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS
- : Proxy.Type.HTTP), new ProxyAddress(
- selectedProxy.getHost(), selectedProxy
- .getPort()), selectedProxy
- .getUserId(), selectedProxy
- .getPassword());
+ proxy = new Proxy(((selectedProxy.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS : Proxy.Type.HTTP), new ProxyAddress(selectedProxy.getHost(), selectedProxy.getPort()), selectedProxy.getUserId(), selectedProxy.getPassword());
}
}
} catch (Exception e) {
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java
index f54c82bba..125689794 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java
@@ -21,8 +21,7 @@ import org.eclipse.ecf.internal.provider.filetransfer.*;
import org.eclipse.ecf.provider.filetransfer.util.JREProxyHelper;
import org.eclipse.osgi.util.NLS;
-public class UrlConnectionRetrieveFileTransfer extends
- AbstractRetrieveFileTransfer {
+public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTransfer {
private static final String USERNAME_PREFIX = Messages.UrlConnectionRetrieveFileTransfer_USERNAME_PROMPT;
@@ -79,8 +78,7 @@ public class UrlConnectionRetrieveFileTransfer extends
if (getRemoteFileURL().getProtocol().equalsIgnoreCase("jar")) { //$NON-NLS-1$
urlConnection.setUseCaches(false);
}
- IURLConnectionModifier connectionModifier = Activator.getDefault()
- .getURLConnectionModifier();
+ IURLConnectionModifier connectionModifier = Activator.getDefault().getURLConnectionModifier();
if (connectionModifier != null) {
connectionModifier.setSocketFactoryForConnection(urlConnection);
}
@@ -92,28 +90,22 @@ public class UrlConnectionRetrieveFileTransfer extends
protected void setResumeRequestHeaderValues() throws IOException {
if (this.bytesReceived <= 0 || this.fileLength <= this.bytesReceived)
- throw new IOException(
- Messages.UrlConnectionRetrieveFileTransfer_RESUME_START_ERROR);
+ throw new IOException(Messages.UrlConnectionRetrieveFileTransfer_RESUME_START_ERROR);
setRangeHeader("bytes=" + this.bytesReceived + "-"); //$NON-NLS-1$ //$NON-NLS-2$
// set max-age for cache control to 0 for bug
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249990
urlConnection.setRequestProperty("Cache-Control", "max-age=0"); //$NON-NLS-1$//$NON-NLS-2$
}
- protected void setRequestHeaderValues()
- throws InvalidFileRangeSpecificationException {
+ protected void setRequestHeaderValues() throws InvalidFileRangeSpecificationException {
final IFileRangeSpecification rangeSpec = getFileRangeSpecification();
if (rangeSpec != null && isHTTP()) {
final long startPosition = rangeSpec.getStartPosition();
final long endPosition = rangeSpec.getEndPosition();
if (startPosition < 0)
- throw new InvalidFileRangeSpecificationException(
- Messages.UrlConnectionRetrieveFileTransfer_RESUME_START_POSITION_LESS_THAN_ZERO,
- rangeSpec);
+ throw new InvalidFileRangeSpecificationException(Messages.UrlConnectionRetrieveFileTransfer_RESUME_START_POSITION_LESS_THAN_ZERO, rangeSpec);
if (endPosition != -1L && endPosition <= startPosition)
- throw new InvalidFileRangeSpecificationException(
- Messages.UrlConnectionRetrieveFileTransfer_RESUME_ERROR_END_POSITION_LESS_THAN_START,
- rangeSpec);
+ throw new InvalidFileRangeSpecificationException(Messages.UrlConnectionRetrieveFileTransfer_RESUME_ERROR_END_POSITION_LESS_THAN_START, rangeSpec);
setRangeHeader("bytes=" + startPosition + "-" + ((endPosition == -1L) ? "" : ("" + endPosition))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
// Add http 1.1 'Connection: close' header in order to potentially avoid
@@ -178,19 +170,15 @@ public class UrlConnectionRetrieveFileTransfer extends
protected void getResponseHeaderValues() throws IOException {
if (!isConnected())
- throw new ConnectException(
- Messages.UrlConnectionRetrieveFileTransfer_CONNECT_EXCEPTION_NOT_CONNECTED);
+ throw new ConnectException(Messages.UrlConnectionRetrieveFileTransfer_CONNECT_EXCEPTION_NOT_CONNECTED);
if (getResponseCode() == -1)
- throw new IOException(
- Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_INVALID_SERVER_RESPONSE);
+ throw new IOException(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_INVALID_SERVER_RESPONSE);
setLastModifiedTime(urlConnection.getLastModified());
setFileLength(urlConnection.getContentLength());
- String contentDispositionValue = urlConnection
- .getHeaderField(HttpHelper.CONTENT_DISPOSITION_HEADER);
+ String contentDispositionValue = urlConnection.getHeaderField(HttpHelper.CONTENT_DISPOSITION_HEADER);
if (contentDispositionValue != null) {
- remoteFileName = HttpHelper
- .getRemoteFileNameFromContentDispositionHeader(contentDispositionValue);
+ remoteFileName = HttpHelper.getRemoteFileNameFromContentDispositionHeader(contentDispositionValue);
}
if (remoteFileName == null) {
@@ -207,14 +195,11 @@ public class UrlConnectionRetrieveFileTransfer extends
protected void getResumeResponseHeaderValues() throws IOException {
if (!isConnected())
- throw new ConnectException(
- Messages.UrlConnectionRetrieveFileTransfer_CONNECT_EXCEPTION_NOT_CONNECTED);
+ throw new ConnectException(Messages.UrlConnectionRetrieveFileTransfer_CONNECT_EXCEPTION_NOT_CONNECTED);
if (getResponseCode() != HTTP_RANGE_RESPONSE)
- throw new IOException(
- Messages.UrlConnectionRetrieveFileTransfer_INVALID_SERVER_RESPONSE_TO_PARTIAL_RANGE_REQUEST);
+ throw new IOException(Messages.UrlConnectionRetrieveFileTransfer_INVALID_SERVER_RESPONSE_TO_PARTIAL_RANGE_REQUEST);
if (lastModifiedTime != urlConnection.getLastModified())
- throw new IOException(
- Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_FILE_MODIFIED_SINCE_LAST_ACCESS);
+ throw new IOException(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_FILE_MODIFIED_SINCE_LAST_ACCESS);
}
/**
@@ -225,25 +210,20 @@ public class UrlConnectionRetrieveFileTransfer extends
proxyHelper.setupProxy(proxy2);
}
- protected void setupAuthentication() throws IOException,
- UnsupportedCallbackException {
+ protected void setupAuthentication() throws IOException, UnsupportedCallbackException {
if (connectContext == null)
return;
- final CallbackHandler callbackHandler = connectContext
- .getCallbackHandler();
+ final CallbackHandler callbackHandler = connectContext.getCallbackHandler();
if (callbackHandler == null)
return;
final NameCallback usernameCallback = new NameCallback(USERNAME_PREFIX);
final ObjectCallback passwordCallback = new ObjectCallback();
// Call callback with username and password callbacks
- callbackHandler.handle(new Callback[] { usernameCallback,
- passwordCallback });
+ callbackHandler.handle(new Callback[] {usernameCallback, passwordCallback});
username = usernameCallback.getName();
Object o = passwordCallback.getObject();
if (!(o instanceof String))
- throw new UnsupportedCallbackException(
- passwordCallback,
- Messages.UrlConnectionRetrieveFileTransfer_UnsupportedCallbackException);
+ throw new UnsupportedCallbackException(passwordCallback, Messages.UrlConnectionRetrieveFileTransfer_UnsupportedCallbackException);
password = (String) passwordCallback.getObject();
// Now set authenticator to our authenticator with user and password
Authenticator.setDefault(new UrlConnectionAuthenticator());
@@ -267,8 +247,7 @@ public class UrlConnectionRetrieveFileTransfer extends
* setConnectContextForAuthentication
* (org.eclipse.ecf.core.security.IConnectContext)
*/
- public void setConnectContextForAuthentication(
- IConnectContext connectContext) {
+ public void setConnectContextForAuthentication(IConnectContext connectContext) {
super.setConnectContextForAuthentication(connectContext);
this.username = null;
this.password = null;
@@ -293,11 +272,7 @@ public class UrlConnectionRetrieveFileTransfer extends
getResponseHeaderValues();
fireReceiveStartEvent();
} catch (final Exception e) {
- IncomingFileTransferException except = new IncomingFileTransferException(
- NLS
- .bind(
- Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT,
- getRemoteFileURL().toString()), e);
+ IncomingFileTransferException except = new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e);
hardClose();
throw except;
}
@@ -363,11 +338,9 @@ public class UrlConnectionRetrieveFileTransfer extends
}
private void setupTimeouts() {
- String existingTimeout = System
- .getProperty(JRE_CONNECT_TIMEOUT_PROPERTY);
+ String existingTimeout = System.getProperty(JRE_CONNECT_TIMEOUT_PROPERTY);
if (existingTimeout == null) {
- System.setProperty(JRE_CONNECT_TIMEOUT_PROPERTY,
- DEFAULT_CONNECT_TIMEOUT);
+ System.setProperty(JRE_CONNECT_TIMEOUT_PROPERTY, DEFAULT_CONNECT_TIMEOUT);
}
existingTimeout = System.getProperty(JRE_READ_TIMEOUT_PROPERTY);
if (existingTimeout == null) {
@@ -435,8 +408,7 @@ public class UrlConnectionRetrieveFileTransfer extends
private void setCompressionRequestHeader() {
if (rangeSpecification == null)
- urlConnection.setRequestProperty(ACCEPT_ENCODING,
- CONTENT_ENCODING_ACCEPTED);
+ urlConnection.setRequestProperty(ACCEPT_ENCODING, CONTENT_ENCODING_ACCEPTED);
}
private Compression getCompressionResponseHeader() {

Back to the top