Skip to content

Instantly share code, notes, and snippets.

@magnetik
Created May 30, 2011 06:59
Show Gist options
  • Save magnetik/998530 to your computer and use it in GitHub Desktop.
Save magnetik/998530 to your computer and use it in GitHub Desktop.
public int setMessage(int type, Serializable data) throws IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream oo = new ObjectOutputStream(bo);
oo.writeObject(data);
oo.close();
bo.close();
this.messSize = bo.size();
this.message = new byte[bo.size()];
this.message = bo.toByteArray();
return 1;
}
public Object getData() throws IOException {
Object res = null;
ByteArrayInputStream bi = new ByteArrayInputStream(message);
ObjectInputStream oi = new ObjectInputStream(bi);
try {
res = oi.readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
oi.close();
bi.close();
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment