Advertisement
Evyatar12

Byte Serialization

Jul 28th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. public static byte[] convertToBytes(Object obj) throws IOException
  2. {
  3.     ByteArrayOutputStream output = new ByteArrayOutputStream();
  4.     ObjectOutputStream toWrite = new ObjectOutputStream(output);
  5.     toWrite.writeObject(obj);
  6.     return output.toByteArray();
  7. }
  8.    
  9. public static Object convertFromBytes(byte[] bytes) throws ClassNotFoundException, IOException
  10. {
  11.     ByteArrayInputStream input = new ByteArrayInputStream(bytes);
  12.     ObjectInputStream toRead = new ObjectInputStream(input);
  13.     return toRead.readObject();
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement