Created
May 30, 2011 06:59
-
-
Save magnetik/998530 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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