in flex-maven-tools/flex-sdk-converter/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java [188:242]
protected void performFastDownload(URL sourceUrl, File targetFile) throws IOException {
URLConnection connection;
ProxySettings proxySettings = ProxySettings.getProxySettings();
if(proxySettings != null) {
SocketAddress socketAddress = new InetSocketAddress(proxySettings.getHost(), proxySettings.getPort());
Proxy proxy = new Proxy(Proxy.Type.valueOf(proxySettings.getProtocol().toUpperCase()), socketAddress);
connection = sourceUrl.openConnection(proxy);
} else {
connection = sourceUrl.openConnection();
}
ReadableByteChannel rbc = null;
FileOutputStream fos = null;
try {
rbc = Channels.newChannel(connection.getInputStream());
fos = new FileOutputStream(targetFile);
////////////////////////////////////////////////////////////////////////////////
// Do the downloading.
////////////////////////////////////////////////////////////////////////////////
final long expectedSize = connection.getContentLength();
long transferedSize = 0L;
LOG.info("===========================================================");
LOG.info("Downloading " + sourceUrl.toString());
if (expectedSize > 1014 * 1024) {
LOG.info("Expected size: " + (expectedSize / 1024 / 1024) + "MB");
} else {
LOG.info("Expected size: " + (expectedSize / 1024) + "KB");
}
final ProgressBar progressBar = new ProgressBar(expectedSize);
while (transferedSize < expectedSize) {
transferedSize += fos.getChannel().transferFrom(rbc, transferedSize, 1 << 20);
progressBar.updateProgress(transferedSize);
}
} finally {
if(rbc != null) {
try {
rbc.close();
} catch (IOException e) {
// Ignore ...
}
}
if(fos != null) {
try {
fos.close();
} catch (IOException e) {
// Ignore ...
}
}
}
LOG.info("");
LOG.info("Finished downloading.");
LOG.info("===========================================================");
}