diff --git a/service/src/main/java/blue/happening/HappeningClient.java b/service/src/main/java/blue/happening/HappeningClient.java index 11049cf..3dc1ce2 100644 --- a/service/src/main/java/blue/happening/HappeningClient.java +++ b/service/src/main/java/blue/happening/HappeningClient.java @@ -3,8 +3,17 @@ import android.os.Parcel; import android.os.Parcelable; +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.io.Serializable; -public class HappeningClient implements Parcelable { + +public class HappeningClient implements Parcelable, Serializable { private String uuid; private String name; @@ -46,6 +55,25 @@ public void readFromParcel(Parcel in) { name = in.readString(); } + public static HappeningClient fromBytes(byte[] bytes) { + try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInput in = new ObjectInputStream(bis)) { + return (HappeningClient) in.readObject(); + } catch (IOException | ClassNotFoundException e) { + return null; + } + } + + public byte[] toBytes() { + try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(bos)) { + out.writeObject(this); + return bos.toByteArray(); + } catch (IOException e) { + return null; + } + } + public String getUuid() { return uuid; }