Java Object Serialize and Deserialize serializeAndDeserialize(Object o)

Here you can find the source of serializeAndDeserialize(Object o)

Description

serialize And Deserialize

License

Apache License

Declaration

public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
/*/*from   ww  w.  j  a  v a  2  s. c  o  m*/
 * The Spring Framework is published under the terms
 * of the Apache Software License.
 */

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Main {
    public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(o);
        oos.flush();
        baos.flush();
        byte[] bytes = baos.toByteArray();

        ByteArrayInputStream is = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(is);
        Object o2 = ois.readObject();

        return o2;
    }
}

Related

  1. deserializeProperties(byte[] bytes)
  2. deserializeRaw(byte[] array)
  3. deserializeSafe(byte[] buf, T obj)
  4. deserializeShort(byte[] inbuf, int offset)
  5. deserializeStream(final String witness)
  6. serializeAndDeserialize(Object o)
  7. serializeAndDeserialize(Object obj)
  8. serializeAndDeserialize(T input)
  9. serializeAndDeserialize(T instance)