aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2018-08-17 18:16:03 -0700
committerScott Jackson <daneren2005@gmail.com>2018-08-17 18:16:03 -0700
commitbdf560352c24e58a371ed878cb96105b69c347b5 (patch)
treeebcbaa5eb06245e5a48d93caf6a80db5ad2fbf42 /app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java
parentc09258017d0523a769b2b4de5e703b5a3b2ba50a (diff)
downloaddsub-bdf560352c24e58a371ed878cb96105b69c347b5.tar.gz
dsub-bdf560352c24e58a371ed878cb96105b69c347b5.tar.bz2
dsub-bdf560352c24e58a371ed878cb96105b69c347b5.zip
Fixes #872 use native serialization so Auto doesn't crash on entries
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java41
1 files changed, 41 insertions, 0 deletions
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<Entry> {