Rhyme/五分钟源码Java【Serializable接口III】

五分钟源码Java【Serializable接口I】

五分钟源码Java【Serializable接口II】

五分钟源码Java【Serializable接口III】

Classes that require special handling during the serialization and
* deserialization process must implement special methods with these exact
* signatures:
* 译:
* 需要在序列化和反序列的过程中,
* 进行特殊处理的类必须实现以下这些特定的有特定功能的方法
*
* private void writeObject(java.io.ObjectOutputStream out)
* throws IOException
* private void readObject(java.io.ObjectInputStream in)
* throws IOException, ClassNotFoundException;
* private void readObjectNoData()
* throws ObjectStreamException;
*
*
* The writeObject method is responsible for writing the state of the
* object for its particular class so that the corresponding
* readObject method can restore it. The default mechanism for saving
* the Object’s fields can be invoked by calling
* out.defaultWriteObject. The method does not need to concern
* itself with the state belonging to its superclasses or subclasses.
* State is saved by writing the individual fields to the
* ObjectOutputStream using the writeObject method or by using the
* methods for primitive data types supported by DataOutput.
* 译:
* writeObject方法负责为其特定类编写对象的状态,以便相应的readObject方法可以恢复它。
* 保存对象字段的默认机制可以通过调用out.defaultWriteObject来调用。
* 该方法不需要关注属于其超类或亚类的状态。
* 状态通过使用writeObject方法将单个字段写入ObjectOutputStream
* 或使用DataOutput支持的基本数据类型的方法来保存。
*

The readObject method is responsible for reading from the stream and
* restoring the classes fields. It may call in.defaultReadObject to invoke
* the default mechanism for restoring the object’s non-static and
* non-transient fields. The defaultReadObject method uses information in
* the stream to assign the fields of the object saved in the stream with the
* correspondingly named fields in the current object. This handles the case
* when the class has evolved to add new fields. The method does not need to
* concern itself with the state belonging to its superclasses or subclasses.
* State is saved by writing the individual fields to the
* ObjectOutputStream using the writeObject method or by using the
* methods for primitive data types supported by DataOutput.
* 译:
* readObject方法负责从流中读取数据并恢复类字段。
* 它可以调用in.defaultReadObject来调用默认的机制来恢复对象的非静态和非瞬态字段。
* defaultReadObject方法使用流中的信息来将
* 保存在流中的对象的字段与当前对象中的相应命名字段一起分配。
* 当类已经发展到添加新的字段时,这将处理这种情况。
* 该方法不需要关注属于其超类或亚类的状态。
* 通过使用writeObject方法或使用DataOutput支持的基本数据类型的方法
* 将各个字段写入ObjectOutputStream,可以保存状态。
*
* The readObjectNoData method is responsible for initializing the state of
* the object for its particular class in the event that the serialization
* stream does not list the given class as a superclass of the object being
* deserialized. This may occur in cases where the receiving party uses a
* different version of the deserialized instance’s class than the sending
* party, and the receiver’s version extends classes that are not extended by
* the sender’s version. This may also occur if the serialization stream has
* been tampered; hence, readObjectNoData is useful for initializing
* deserialized objects properly despite a “hostile” or incomplete source
* stream.
* 译:
* readObjectNoData方法负责在序列化流
* 没有列出给定类作为被反序列化的对象的超类的情况下,为其特定类初始化对象的状态。
* 在接收方使用与发送方不同版本的反序列化实例的类的情况下,
* 接收方的版本可能会扩展未被发送方版本扩展的类。
* 如果序列化流已被篡改,也可能发生这种情况。
* 因此,readObjectNoData对于正确初始化反序列化的对象是有用的,
* 尽管是一个“敌对”或不完整的源码流。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值