From bdf560352c24e58a371ed878cb96105b69c347b5 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 17 Aug 2018 18:16:03 -0700 Subject: Fixes #872 use native serialization so Auto doesn't crash on entries --- .../daneren2005/dsub/domain/MusicDirectory.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java') diff --git a/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java b/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java index 5f7b2412..bd7928fd 100644 --- a/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java +++ b/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java @@ -25,6 +25,13 @@ import android.media.MediaMetadataRetriever; import android.os.Build; import android.util.Log; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; import java.text.Collator; import java.util.ArrayList; import java.util.Iterator; @@ -628,6 +635,40 @@ public class MusicDirectory implements Serializable { public String toString() { return title; } + + public byte[] toByteArray() throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutput out = null; + try { + out = new ObjectOutputStream(bos); + out.writeObject(this); + out.flush(); + return bos.toByteArray(); + } finally { + try { + bos.close(); + } catch (IOException ex) { + // ignore close exception + } + } + } + + public static Entry fromByteArray(byte[] byteArray) throws IOException, ClassNotFoundException { + ByteArrayInputStream bis = new ByteArrayInputStream(byteArray); + ObjectInput in = null; + try { + in = new ObjectInputStream(bis); + return (Entry) in.readObject(); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException ex) { + // ignore close exception + } + } + } } public static class EntryComparator implements Comparator { -- cgit v1.2.3