From d50bfc4b2fb6c92602b034bac7c44dad4ce7a122 Mon Sep 17 00:00:00 2001 From: Wilson Foo Yu Kang Date: Sat, 8 Apr 2023 02:03:22 +0800 Subject: [PATCH] Catch unanticipated EOFException due to empty stream when redirecting. --- src/android/com/silkimen/http/HttpRequest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/android/com/silkimen/http/HttpRequest.java b/src/android/com/silkimen/http/HttpRequest.java index 7e638bb1..973aea25 100644 --- a/src/android/com/silkimen/http/HttpRequest.java +++ b/src/android/com/silkimen/http/HttpRequest.java @@ -37,6 +37,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.Closeable; +import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -2489,10 +2490,14 @@ protected HttpRequest copy(final InputStream input, final OutputStream output) t public HttpRequest run() throws IOException { final byte[] buffer = new byte[bufferSize]; int read; - while ((read = input.read(buffer)) != -1) { - output.write(buffer, 0, read); - totalWritten += read; - progress.onUpload(totalWritten, totalSize); + try{ + while ((read = input.read(buffer)) != -1) { + output.write(buffer, 0, read); + totalWritten += read; + progress.onUpload(totalWritten, totalSize); + } + }catch(EOFException e){ + e.printStackTrace(); } return HttpRequest.this; }