`

deep copy

 
阅读更多
static public Object deepCopy(Object oldObj) {
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(bos);
        // serialize and pass the object
        oos.writeObject(oldObj);
        oos.flush();
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
        ois = new ObjectInputStream(bin);
        // return the new object
        return ois.readObject();
    } catch (Exception e) {
        System.out.println("Exception in ObjectCloner = " + e);
        return null;
    } finally {
        try {
            oos.close();
            ois.close();
        } catch (Exception e) {
            return null;
        }
    }
}

 

as you see, it's the way of making deep copy, just by streams of input and out, first output and then input and last the product object.

here, one problem, why is the parameter of the first constructor of the inputstream chain the bos but oos?

cuz bos locates in the end part of the outputstream chain, it's the most out part of the decorator, right!?

分享到:
评论

相关推荐

    android 浅复制和深复制-Java Generic Deep Copy 篇

    android 浅复制和深复制-Java Generic Deep Copy 篇

    10 numpy的 copy & deep copy (教学教程)

    10_numpy的_copy_&_deep_copy_(教学教程)

    浅拷贝和深拷贝深入理解(shallow copy VS deep copy)

    浅拷贝和深拷贝深入理解(shallow copy VS deep copy) 本文重点讨论引用类型变量的拷贝机制和实现

    php-myclabs-deep-copy-1.10.1-1.el7.remi.noarch.rpm

    php-myclabs-deep-copy-1.10.1-1.el7.remi.noarch.rpm

    python中copy()与deepcopy()的区别小结

    接触python有一段时间了,一直没有系统的学习过,也对copy,deepcoy傻傻的分不清,故抽出时间来理一下。 下面这篇文章主要给大家介绍了关于python中copy()与deepcopy()的区别的相关资料,需要的朋友可以参考下

    Core C++ A Software Engineering Approach

    真是软磨硬泡啊,印象最深的就是作者讲解deep copy and shadow copy 还有 const come in serial area,太棒了,本书初版发行于2000年,是以C++99为标准的。 Core C++ A Software Engineering Approach Victor Shtern...

    ios面试题锦集chm版

    1.Difference between shallow copy and deep copy?
浅复制和深复制的区别?
 答案:浅层复制:只复制指向对象的指针,而不复制引用对象本身。
深层复制:复制引用对象本身。
意思就是说我有个A对象,复制一份...

    python浅拷贝、深拷贝

    在Python中,浅拷贝(shallow copy)和深拷贝(deep copy)是用于创建对象副本的两种常见方式。它们可以应用于不同类型的对象,如列表、字典、集合等。下面是对浅拷贝和深拷贝的描述: 浅拷贝:浅拷贝是创建一个新...

    Absolute C++

    Deep Copy, page 459 Solution to Programming Project 10.5, page 469 Chapter 11 Avoiding Multiple Defi nitions with #ifndef, page 484 Solution to Programming Project 11.5, page 512 Chapter 12 Walk...

    Learning Core Data for iOS(Addison,2013)

    One step at a time, you'll build and extend your skills--even mastering advanced techniques such as complex model migration, deep copy, background processing, and integration with Dropbox, StackMob, ...

    英文原版-Learning Core Data for iOS 1st Edition

    One step at a time, you'll build and extend your skills--even mastering advanced techniques such as complex model migration, deep copy, background processing, and integration with Dropbox, StackMob, ...

    [iOS] Learning Core Data for iOS (英文版)

    One step at a time, you’ll build and extend your skills--even mastering advanced techniques such as complex model migration, deep copy, background processing, and integration with Dropbox, StackMob,...

    python中阶基础

    3.9. * copy ——Shallow and deep copy operations 18 4. 函数 20 4.1. 什么是函数? 20 4.2. 函数的用处 20 4.3. 函数中的参数传递 20 4.4. 默认参数 20 4.5. 不定长参数 21 4.6. 递归函数 21 4.7. 拓展知识:...

    deep-copy-ts:用于TypeScript的Deep-copy实用程序功能

    深度复制基于TypeScript的Deep-copy(aka克隆)实用程序功能。 在探索。安装npm i deep-copy-ts用法import { deepCopy } from "deep-copy-ts" ;const obj = { // Primitive value a : 1 , b : "b" , c : { a : [ { a...

    weapp.qrcode.js

    if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) { if (copyIsArray) { copyIsArray = false; clone = src && isArray(src) ? src : []; } else { ...

    deep-copy-all:深度复制JavaScript数组和对象,包括自定义对象

    deep-copy-all 一种快速,紧凑且强大的方法来深度复制所有JavaScript数据类型 深度复制所有JavaScript对象深度克隆器是: 快速–在普通基准速度测试中排名很高 紧凑–约5k(最小) 强大–正确处理所有标准...

    deep-copy:JSON数据的快速深度复制

    json-deep-copy JSON样式对象的快速深层复制。 特征 简化的lodash.deepClone,复制许多已编译的对象时可能快15倍。 仅支持带有数字,字符串,数组,布尔值的普通对象 用 npm i json-deep-copy const deepCopy = ...

    NETCFSERUP

    <param name="bRecurseIntoSubClasses">A boolean flag that when true performs a deep copy of the parameters, otherwise a shallow copy is performed.</param> <returns>An object that represents the ...

    Sortable前端框架

    You can also define whether lists can give away, give and keep a copy (`clone`), and receive elements. * name: `String` — group name * pull: `true|false|'clone'|function` — ability to move from ...

Global site tag (gtag.js) - Google Analytics