Guest User

Untitled

a guest
Jun 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public class SerializationHelper {
  2. public static byte[] serialize(Object object) throws IOException{
  3. ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  4. ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
  5. // transform object to stream and then to a byte array
  6. objectOutputStream.writeObject(object);
  7. objectOutputStream.flush();
  8. objectOutputStream.close();
  9. return byteArrayOutputStream.toByteArray();
  10. }
  11.  
  12. public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException{
  13. ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
  14. ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
  15. return objectInputStream.readObject();
  16. }
  17. }
Add Comment
Please, Sign In to add comment