From 882fbf927567c617d70510a888c0ebee6ddbc189 Mon Sep 17 00:00:00 2001 From: DafabHoid Date: Fri, 18 May 2018 18:18:37 +0200 Subject: [PATCH 1/2] Fix crash on loading not yet finished downloads from .giga files --- .../main/java/us/shandian/giga/get/DownloadMission.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/us/shandian/giga/get/DownloadMission.java b/app/src/main/java/us/shandian/giga/get/DownloadMission.java index c48e5ffbc..f02eaae28 100644 --- a/app/src/main/java/us/shandian/giga/get/DownloadMission.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadMission.java @@ -5,6 +5,7 @@ import android.os.Looper; import android.util.Log; import java.io.File; +import java.io.ObjectInputStream; import java.io.Serializable; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -312,6 +313,13 @@ public class DownloadMission implements Serializable { } } + private void readObject(ObjectInputStream inputStream) + throws java.io.IOException, ClassNotFoundException + { + inputStream.defaultReadObject(); + mListeners = new ArrayList<>(); + } + private void deleteThisFromFile() { new File(getMetaFilename()).delete(); } From ae8121b680a3c11f1a21f3091278510804f0f8f3 Mon Sep 17 00:00:00 2001 From: DafabHoid Date: Fri, 18 May 2018 18:23:32 +0200 Subject: [PATCH 2/2] Utility: Buffer the output to files when serializing --- .../java/us/shandian/giga/util/Utility.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/us/shandian/giga/util/Utility.java b/app/src/main/java/us/shandian/giga/util/Utility.java index 2d44e8c15..de9a16a1b 100644 --- a/app/src/main/java/us/shandian/giga/util/Utility.java +++ b/app/src/main/java/us/shandian/giga/util/Utility.java @@ -12,6 +12,7 @@ import android.widget.Toast; import org.schabi.newpipe.R; import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -59,17 +60,17 @@ public class Utility { ObjectOutputStream objectOutputStream = null; try { - objectOutputStream = new ObjectOutputStream(new FileOutputStream(fileName)); + objectOutputStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(fileName))); objectOutputStream.writeObject(serializable); } catch (Exception e) { //nothing to do - } - - if(objectOutputStream != null) { - try { - objectOutputStream.close(); - } catch (Exception e) { - //nothing to do + } finally { + if(objectOutputStream != null) { + try { + objectOutputStream.close(); + } catch (Exception e) { + //nothing to do + } } } }