From e140481f14631cf2efc899a72cbbf19f41dcadd4 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 13 Oct 2017 20:47:14 +0800 Subject: [PATCH] Wrap wrapper with buffer --- .../magisk/asyncs/ProcessRepoZip.java | 7 ++- .../magisk/container/InputStreamWrapper.java | 59 +++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/container/InputStreamWrapper.java diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java index 324f04156..400e7691b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java @@ -11,6 +11,7 @@ import android.widget.Toast; import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.container.InputStreamWrapper; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.WebService; @@ -116,7 +117,7 @@ public class ProcessRepoZip extends ParallelTask { break; } while (true); - InputStream in = new ProgressUpdateInputStream(conn.getInputStream()); + InputStream in = new BufferedInputStream(new ProgressInputStream(conn.getInputStream())); // Temp files File temp1 = new File(activity.getCacheDir(), "1.zip"); @@ -186,9 +187,9 @@ public class ProcessRepoZip extends ParallelTask { return this; } - private class ProgressUpdateInputStream extends BufferedInputStream { + private class ProgressInputStream extends InputStreamWrapper { - ProgressUpdateInputStream(@NonNull InputStream in) { + ProgressInputStream(InputStream in) { super(in); } diff --git a/app/src/main/java/com/topjohnwu/magisk/container/InputStreamWrapper.java b/app/src/main/java/com/topjohnwu/magisk/container/InputStreamWrapper.java new file mode 100644 index 000000000..06626d8df --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/container/InputStreamWrapper.java @@ -0,0 +1,59 @@ +package com.topjohnwu.magisk.container; + +import android.support.annotation.NonNull; + +import java.io.IOException; +import java.io.InputStream; + +public class InputStreamWrapper extends InputStream { + private InputStream in; + + public InputStreamWrapper(InputStream in) { + this.in = in; + } + + @Override + public int available() throws IOException { + return in.available(); + } + + @Override + public void close() throws IOException { + in.close(); + } + + @Override + public synchronized void mark(int readlimit) { + in.mark(readlimit); + } + + @Override + public boolean markSupported() { + return in.markSupported(); + } + + @Override + public synchronized int read() throws IOException { + return in.read(); + } + + @Override + public int read(@NonNull byte[] b) throws IOException { + return read(b, 0, b.length); + } + + @Override + public synchronized int read(@NonNull byte[] b, int off, int len) throws IOException { + return in.read(b, off, len); + } + + @Override + public synchronized void reset() throws IOException { + in.reset(); + } + + @Override + public long skip(long n) throws IOException { + return in.skip(n); + } +}