Here you can find the source of deepClone(Serializable serializable)
Parameter | Description |
---|---|
serializable | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static Serializable deepClone(Serializable serializable) throws Exception
//package com.java2s; /*//from w ww. j a v a 2 s. com * **************************************************- * Ingrid Server OpenSearch * ================================================== * Copyright (C) 2014 - 2017 wemove digital solutions GmbH * ================================================== * Licensed under the EUPL, Version 1.1 or ? as soon they will be * approved by the European Commission - subsequent versions of the * EUPL (the "Licence"); * * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * http://ec.europa.eu/idabc/eupl5 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * **************************************************# */ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { /** * @param serializable * @return a deep cloned object includiding complete stack * @throws Exception */ public static Serializable deepClone(Serializable serializable) throws Exception { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); new ObjectOutputStream(arrayOutputStream).writeObject(serializable); ByteArrayInputStream bais = new ByteArrayInputStream( arrayOutputStream.toByteArray()); return (Serializable) new ObjectInputStream(bais).readObject(); } }