File file = new File(tempDestDir, optional.get().name);
HttpEntity entity = response.getEntity();
final long length = entity.getContentLength();
final CountingOutputStream os = new CountingOutputStream(new FileOutputStream(file));
System.out.printf("Downloading %s to %s...%n", uri, file);
Thread progressThread = new Thread(new Runnable() {
double lastProgress;
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
long copied = os.getCount();
double progress = copied * 100D / length;
if (progress != lastProgress) {
System.out.printf("\rProgress: %s%%", LangUtils.toConciseString(progress, 1));