From 6ea0f6290a7b2c166f4b78395484f62060f88542 Mon Sep 17 00:00:00 2001 From: DafabHoid Date: Mon, 28 May 2018 01:07:30 +0200 Subject: [PATCH] Downloader: Notify the progress every 64K instead of every 512 Bytes This improves downloading performance dramatically when cpu bound: Before, even a high-end cpu from 2013 can't download faster than around 1MB/s. The bigger read buffer size removes the need for a dedicated BufferedInputStream. --- .../main/java/us/shandian/giga/get/DownloadRunnable.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/us/shandian/giga/get/DownloadRunnable.java b/app/src/main/java/us/shandian/giga/get/DownloadRunnable.java index 37dc64a2c..b53f8aea9 100644 --- a/app/src/main/java/us/shandian/giga/get/DownloadRunnable.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadRunnable.java @@ -2,7 +2,6 @@ package us.shandian.giga.get; import android.util.Log; -import java.io.BufferedInputStream; import java.io.RandomAccessFile; import java.net.HttpURLConnection; import java.net.URL; @@ -104,11 +103,11 @@ public class DownloadRunnable implements Runnable { RandomAccessFile f = new RandomAccessFile(mMission.location + "/" + mMission.name, "rw"); f.seek(start); - BufferedInputStream ipt = new BufferedInputStream(conn.getInputStream()); - byte[] buf = new byte[512]; + java.io.InputStream ipt = conn.getInputStream(); + byte[] buf = new byte[64*1024]; while (start < end && mMission.running) { - int len = ipt.read(buf, 0, 512); + int len = ipt.read(buf, 0, buf.length); if (len == -1) { break;