Lines 1-16
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2004, 2007 Composent, Inc. All rights reserved. This |
2 |
* Copyright (c) 2004, 2008 Composent, Inc. All rights reserved. This |
3 |
* program and the accompanying materials are made available under the terms of |
3 |
* program and the accompanying materials are made available under the terms of |
4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
6 |
* |
6 |
* |
7 |
* Contributors: Composent, Inc. - initial API and implementation |
7 |
* Contributors: Composent, Inc. - initial API and implementation |
|
|
8 |
* Benjamin Cabe <benjamin.cabe@anyware-tech.com> - bug 220258 |
8 |
******************************************************************************/ |
9 |
******************************************************************************/ |
9 |
package org.eclipse.ecf.provider.filetransfer.retrieve; |
10 |
package org.eclipse.ecf.provider.filetransfer.retrieve; |
10 |
|
11 |
|
11 |
import java.io.*; |
12 |
import java.io.*; |
12 |
import java.net.MalformedURLException; |
13 |
import java.net.MalformedURLException; |
13 |
import java.net.URL; |
14 |
import java.net.URL; |
|
|
15 |
import java.text.DecimalFormat; |
14 |
import java.util.Map; |
16 |
import java.util.Map; |
15 |
import org.eclipse.core.net.proxy.IProxyData; |
17 |
import org.eclipse.core.net.proxy.IProxyData; |
16 |
import org.eclipse.core.net.proxy.IProxyService; |
18 |
import org.eclipse.core.net.proxy.IProxyService; |
Lines 69-74
Link Here
|
69 |
|
71 |
|
70 |
protected IConnectContext connectContext; |
72 |
protected IConnectContext connectContext; |
71 |
|
73 |
|
|
|
74 |
protected long jobStartTime; |
75 |
|
72 |
public void setConnectContextForAuthentication(IConnectContext connectContext) { |
76 |
public void setConnectContextForAuthentication(IConnectContext connectContext) { |
73 |
this.connectContext = connectContext; |
77 |
this.connectContext = connectContext; |
74 |
} |
78 |
} |
Lines 113-123
Link Here
|
113 |
bytesReceived += bytes; |
117 |
bytesReceived += bytes; |
114 |
localFileContents.write(buf, 0, bytes); |
118 |
localFileContents.write(buf, 0, bytes); |
115 |
fireTransferReceiveDataEvent(); |
119 |
fireTransferReceiveDataEvent(); |
|
|
120 |
double downloadRateBps = (bytesReceived / ((System.currentTimeMillis() + 1 - jobStartTime) / 1000.0)); |
121 |
monitor.setTaskName(getRemoteFileURL().toString() + Messages.AbstractRetrieveFileTransfer_Progress_Data + NLS.bind(Messages.AbstractRetrieveFileTransfer_InfoDownloadRate, toHumanReadableBytes(downloadRateBps))); |
116 |
monitor.worked((int) Math.round(factor * bytes)); |
122 |
monitor.worked((int) Math.round(factor * bytes)); |
117 |
} else |
123 |
} else |
118 |
done = true; |
124 |
done = true; |
119 |
} |
125 |
} |
120 |
|
126 |
|
|
|
127 |
public static String toHumanReadableBytes(double size) { |
128 |
double convertedSize; |
129 |
String unit; |
130 |
|
131 |
if (size / (1024 * 1024 * 1024) >= 1) { |
132 |
convertedSize = size / (1024 * 1024 * 1024); |
133 |
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitGB; |
134 |
} else if (size / (1024 * 1024) >= 1) { |
135 |
convertedSize = size / (1024 * 1024); |
136 |
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitMB; |
137 |
} else if (size / 1024 >= 1) { |
138 |
convertedSize = size / 1024; |
139 |
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitKB; |
140 |
} else { |
141 |
convertedSize = size; |
142 |
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitBytes; |
143 |
} |
144 |
|
145 |
DecimalFormat df = new DecimalFormat(NLS.bind(Messages.AbstractRetrieveFileTransfer_DownloadRateFormat, unit)); |
146 |
return df.format(convertedSize); |
147 |
} |
148 |
|
121 |
public class FileTransferJob extends Job { |
149 |
public class FileTransferJob extends Job { |
122 |
|
150 |
|
123 |
public FileTransferJob(String name) { |
151 |
public FileTransferJob(String name) { |
Lines 125-130
Link Here
|
125 |
} |
153 |
} |
126 |
|
154 |
|
127 |
protected IStatus run(IProgressMonitor monitor) { |
155 |
protected IStatus run(IProgressMonitor monitor) { |
|
|
156 |
jobStartTime = System.currentTimeMillis(); |
128 |
final byte[] buf = new byte[buff_length]; |
157 |
final byte[] buf = new byte[buff_length]; |
129 |
final long totalWork = ((fileLength == -1) ? 100 : fileLength); |
158 |
final long totalWork = ((fileLength == -1) ? 100 : fileLength); |
130 |
double factor = (totalWork > Integer.MAX_VALUE) ? (((double) Integer.MAX_VALUE) / ((double) totalWork)) : 1.0; |
159 |
double factor = (totalWork > Integer.MAX_VALUE) ? (((double) Integer.MAX_VALUE) / ((double) totalWork)) : 1.0; |