Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SerializationHelper {
- public static byte[] serialize(Object object) throws IOException{
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
- // transform object to stream and then to a byte array
- objectOutputStream.writeObject(object);
- objectOutputStream.flush();
- objectOutputStream.close();
- return byteArrayOutputStream.toByteArray();
- }
- public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException{
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
- ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
- return objectInputStream.readObject();
- }
- }
Add Comment
Please, Sign In to add comment