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. and others. |
3 |
* program and the accompanying materials are made available under the terms of |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
5 |
* which accompanies this distribution, and is available at |
|
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* |
7 |
* |
7 |
* Contributors: Composent, Inc. - initial API and implementation |
8 |
* Contributors: |
|
|
9 |
* Composent, Inc. - initial API and implementation |
10 |
* Benjamin Cabe <benjamin.cabe@anyware-tech.com> - bug 220258 |
8 |
******************************************************************************/ |
11 |
******************************************************************************/ |
9 |
package org.eclipse.ecf.provider.filetransfer.retrieve; |
12 |
package org.eclipse.ecf.provider.filetransfer.retrieve; |
10 |
|
13 |
|
11 |
import java.io.*; |
14 |
import java.io.*; |
12 |
import java.net.MalformedURLException; |
15 |
import java.net.MalformedURLException; |
13 |
import java.net.URL; |
16 |
import java.net.URL; |
|
|
17 |
import java.text.DecimalFormat; |
14 |
import java.util.Map; |
18 |
import java.util.Map; |
15 |
import org.eclipse.core.net.proxy.IProxyData; |
19 |
import org.eclipse.core.net.proxy.IProxyData; |
16 |
import org.eclipse.core.net.proxy.IProxyService; |
20 |
import org.eclipse.core.net.proxy.IProxyService; |
Lines 69-80
Link Here
|
69 |
|
73 |
|
70 |
protected IConnectContext connectContext; |
74 |
protected IConnectContext connectContext; |
71 |
|
75 |
|
|
|
76 |
protected long transferStartTime; |
77 |
|
72 |
public AbstractRetrieveFileTransfer() { |
78 |
public AbstractRetrieveFileTransfer() { |
73 |
// |
79 |
// |
74 |
} |
80 |
} |
75 |
|
81 |
|
76 |
private IFileTransferRunnable fileTransferRunnable = new IFileTransferRunnable() { |
82 |
private IFileTransferRunnable fileTransferRunnable = new IFileTransferRunnable() { |
77 |
public IStatus performFileTransfer(IProgressMonitor monitor) { |
83 |
public IStatus performFileTransfer(IProgressMonitor monitor) { |
|
|
84 |
transferStartTime = System.currentTimeMillis(); |
78 |
final byte[] buf = new byte[buff_length]; |
85 |
final byte[] buf = new byte[buff_length]; |
79 |
final long totalWork = ((fileLength == -1) ? 100 : fileLength); |
86 |
final long totalWork = ((fileLength == -1) ? 100 : fileLength); |
80 |
double factor = (totalWork > Integer.MAX_VALUE) ? (((double) Integer.MAX_VALUE) / ((double) totalWork)) : 1.0; |
87 |
double factor = (totalWork > Integer.MAX_VALUE) ? (((double) Integer.MAX_VALUE) / ((double) totalWork)) : 1.0; |
Lines 137-147
Link Here
|
137 |
bytesReceived += bytes; |
144 |
bytesReceived += bytes; |
138 |
localFileContents.write(buf, 0, bytes); |
145 |
localFileContents.write(buf, 0, bytes); |
139 |
fireTransferReceiveDataEvent(); |
146 |
fireTransferReceiveDataEvent(); |
|
|
147 |
double downloadRateBps = (bytesReceived / ((System.currentTimeMillis() + 1 - transferStartTime) / 1000.0)); |
148 |
monitor.setTaskName(getRemoteFileURL().toString() + Messages.AbstractRetrieveFileTransfer_Progress_Data + NLS.bind(Messages.AbstractRetrieveFileTransfer_InfoTransferRate, toHumanReadableBytes(downloadRateBps))); |
140 |
monitor.worked((int) Math.round(factor * bytes)); |
149 |
monitor.worked((int) Math.round(factor * bytes)); |
141 |
} else |
150 |
} else |
142 |
done = true; |
151 |
done = true; |
143 |
} |
152 |
} |
144 |
|
153 |
|
|
|
154 |
public static String toHumanReadableBytes(double size) { |
155 |
double convertedSize; |
156 |
String unit; |
157 |
|
158 |
if (size / (1024 * 1024 * 1024) >= 1) { |
159 |
convertedSize = size / (1024 * 1024 * 1024); |
160 |
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitGB; |
161 |
} else if (size / (1024 * 1024) >= 1) { |
162 |
convertedSize = size / (1024 * 1024); |
163 |
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitMB; |
164 |
} else if (size / 1024 >= 1) { |
165 |
convertedSize = size / 1024; |
166 |
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitKB; |
167 |
} else { |
168 |
convertedSize = size; |
169 |
unit = Messages.AbstractRetrieveFileTransfer_SizeUnitBytes; |
170 |
} |
171 |
|
172 |
DecimalFormat df = new DecimalFormat(NLS.bind(Messages.AbstractRetrieveFileTransfer_TransferRateFormat, unit)); |
173 |
return df.format(convertedSize); |
174 |
} |
175 |
|
145 |
/* (non-Javadoc) |
176 |
/* (non-Javadoc) |
146 |
* @see org.eclipse.ecf.core.identity.IIdentifiable#getID() |
177 |
* @see org.eclipse.ecf.core.identity.IIdentifiable#getID() |
147 |
*/ |
178 |
*/ |