Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Make happening client serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
cutoffthetop committed Jun 20, 2017
1 parent 7ee1a93 commit 6eb9801
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion service/src/main/java/blue/happening/HappeningClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6eb9801

Please sign in to comment.