OutputStream tos = new TruncatingOutputStream(out,
DownloadHandler.INITIAL_SNIFF_BYTES
+ (_rangeStart % Store.DATA_BLOCK_SIZE),
(_rangeEnd - _rangeStart) + 1
- DownloadHandler.INITIAL_SNIFF_BYTES);
Download dl = new Download(_reqUrl, _length, _lastModified, startBlock,
endBlock, tos);
long startTime = System.currentTimeMillis();
dl.start();
long totalTime = System.currentTimeMillis() - startTime;
String actualMD5 = out.getMD5Sum();
String correctMD5 = downloadMd5();
synchronized (recentDownloads) {
while (recentDownloads.size() >= MAX_RECENT_DOWNLOADS) {
recentDownloads.removeLast();
}
StringBuffer rd = new StringBuffer(200);
rd.append("<tr>");
rd.append("<td>"
+ _reqUrl.toString().substring(
_reqUrl.toString().lastIndexOf("/") + 1,
_reqUrl.toString().length()) + "</td>");
rd.append("<td>" + (_length / 1024) + "</td>");
rd
.append("<td>"
+ ((int) ((1000f * (float) dl.getDownloaded()) / (1024f * (float) totalTime)))
+ "</td>");
String md5Colour;
if (correctMD5 == null) {
md5Colour = "#000000";
} else {
if (correctMD5.equalsIgnoreCase(actualMD5)) {
md5Colour = "#00FF00";
} else {
md5Colour = "#FF0000";
Logger.warning("File " + _reqUrl + " failed MD5Sum check!");
}
}
rd.append("<td><font color=\"" + md5Colour + "\">" + actualMD5
+ "</font></td>");
rd.append("<td>"
+ Math.min(100, (dl.getBytesFromCache() * 100)
/ dl.getDownloaded()) + "</td>");
rd.append("</tr>");
recentDownloads.addFirst(rd.toString());
}
}