objectcloner.java
来自「CmisJavaApi」· Java 代码 · 共 89 行
JAVA
89 行
/* * The contents of this file are subject to the Dyade Public License, * as defined by the file DYADE_PUBLIC_LICENSE.TXT * * You may not use this file except in compliance with the License. You may * obtain a copy of the License on the Dyade web site (www.dyade.fr). * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific terms governing rights and limitations under the License. * * The Original Code is CmisJava API, including the java package * fr.dyade.cmis, released September 5, 2000. * * The Initial Developer of the Original Code is Dyade. The Original Code and * portions created by Dyade are Copyright Bull and Copyright INRIA. * All Rights Reserved. *//* Copyright 1996-2000 by Institut National de Recherche en Informatique * et en Automatique (INRIA) * All rights reserved. See COPYRIGHT in top-level directory. * * Authors: Laurent Andrey, Eric Dillon, Olivier Festor */// $Id: ObjectCloner.java,v 1.2 2000/09/05 14:43:06 festor Exp $// $Source: /local/resedas/CVS-Repository/CmisJavaApi/src/fr/dyade/cmis/util/ObjectCloner.java,v $////// IMPORTANT NOTE: this code comes from:// http://www.javaworld.com/javaworld/javatips/jw-javatip76_p.htmlpackage fr.dyade.cmis.util;import java.io.*; import java.util.*; import java.awt.*; /** A deeper copier utility. * This class provides a static method that allows to make a deep copy * of any object belonging to a serializable class. * * <p><bf>Notes</bf>: * <menu> * <LI>all classes of <code>fr.dyade.cmis.api.types</code> are serializable. * <LI>The provided {@link #deepCopy(Object) deepCopy} method <b> does not</b> use actual class constructor * thus like static counter and occurrence numbering are not performed during the copy. Clones are real clones... * <p>see <A HREF="http://www.javaworld.com/javaworld/javatips/jw-javatip76_p.html"> the original contribution</A>. */public class ObjectCloner { // so that nobody can accidentally create an ObjectCloner object private ObjectCloner(){} /** The deep copy method * This method return a deep copy of its parameter. * @param the object to deeply copy * @return a deep copy to the parameter */ static public Object deepCopy(Object oldObj) throws Exception { ObjectOutputStream oos = null; ObjectInputStream ois = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); // A oos = new ObjectOutputStream(bos); // B // serialize and pass the object oos.writeObject(oldObj); // C oos.flush(); // D ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); // E ois = new ObjectInputStream(bin); // F // return the new object return ois.readObject(); // G } catch(Exception e){ TraceManager.debugln("Exception in ObjectCloner = " + e); throw(e); } finally { oos.close(); ois.close(); } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?