Java Object Deep Clone deepClone(Object src)

Here you can find the source of deepClone(Object src)

Description

deep Clone

License

LGPL

Declaration

public static Object deepClone(Object src) throws IOException, ClassNotFoundException 

Method Source Code


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

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 deepClone(Object src) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream betyArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(betyArrayOutputStream);
        objectOutputStream.writeObject(src);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(betyArrayOutputStream.toByteArray());
        ObjectInputStream objInputStream = new ObjectInputStream(byteArrayInputStream);
        return objInputStream.readObject();
    }/*from w  w  w.  jav a2s.  com*/
}

Related

  1. deepClone(final E object)
  2. deepClone(final T objectToBeClonned)
  3. deepClone(Object obj)
  4. deepClone(Object objToClone)
  5. deepClone(Object src)
  6. deepClone(Serializable o)
  7. deepClone(Serializable serializable)
  8. deepClone(T toClone, final ClassLoader classLoader)
  9. deepCloneObj(Object src)