Java Serialize serializedCopy(T object)

Here you can find the source of serializedCopy(T object)

Description

serialized Copy

License

LGPL

Declaration

@SuppressWarnings("unchecked")
    static <T> T serializedCopy(T object) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Main {
    @SuppressWarnings("unchecked")
    static <T> T serializedCopy(T object) {
        try {// www . j a  v  a2 s  .c  o m
            ByteArrayOutputStream baout = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(baout);

            out.writeObject(object);
            out.flush();

            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baout.toByteArray()));
            return (T) in.readObject();
        } catch (Exception e) {
            throw new AssertionError(e);
        }
    }
}

Related

  1. serializeClone(final Object obj)
  2. serializeCookie(Object object, String filePath)
  3. serializedCopy(Object obj)
  4. serializeDistributionType(String distributionType, String HadoopDistribution)
  5. serializeExecutor(Object executor)
  6. serializeFromString(final String pString)
  7. serializeGZip(T obj)