博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java ObjectInputStream enableResolveObject()方法与示例
阅读量:2527 次
发布时间:2019-05-11

本文共 3549 字,大约阅读时间需要 11 分钟。

ObjectInputStream类enableResolveObject()方法 (ObjectInputStream Class enableResolveObject() method)

  • enableResolveObject() method is available in java.io package.

    enableResolveObject()方法在java.io包中可用。

  • enableResolveObject() method is used to enable the ObjectInputStream to permit objects read from the stream to be replaced. When a boolean variable is set to true and SecurityManager installed and it first invoked the checkPermission() method with SerializablePermission(“enableSubstitution”) of SecurityManager to ensure that it is ready to activate this ObjectInputStream to permit objects read from the stream ObjectInputStream to be replaced.

    enableResolveObject()方法用于启用ObjectInputStream以允许替换从流中读取的对象。 将布尔变量设置为true并安装SecurityManager时,它首先使用SecurityManager的SerializablePermission(“ enableSubstitution”)调用checkPermission()方法,以确保已准备好激活此ObjectInputStream以允许从流ObjectInputStream读取的对象被替换。

  • enableResolveObject() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    enableResolveObject()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。

  • enableResolveObject() method may throw an exception at the time of checking object status to replace.

    enableResolveObject()方法在检查要替换的对象状态时可能会引发异常。

    SecurityException: This exception may throw when its checkPermission() method does not allow to enable the stream to permit objects read from the stream to be replaced when SecurityManager exists.

    SecurityException :当SecurityManager存在时,如果其checkPermission()方法不允许启用流以允许从流读取的对象被替换,则可能引发此异常。

Syntax:

句法:

public boolean  enableResolveObject(boolean status);

Parameter(s):

参数:

  • boolean status – if it sets to true that means to enable use of resolveObject() for each object being deserialized.

    布尔状态 –如果将其设置为true,则意味着对每个反序列化的对象启用resolveObject()的使用。

Return value:

返回值:

The return type of the method is boolean, it gets the old setting before this method was called.

该方法的返回类型为boolean ,它在调用此方法之前获得了旧设置。

Example:

例:

// Java program to demonstrate the example // of void defaultReadObject() method // of ObjectInputStreamimport java.io.*;public class DefaultReadObject {
public static void main(String[] args) throws Exception {
// Instantiates ObjectOutputStream , ObjectInputStream // FileInputStream and FileOutputStream FileOutputStream file_out_stm = new FileOutputStream("D:\\includehelp.txt"); ObjectOutputStream obj_out_stm = new ObjectOutputStream(file_out_stm); FileInputStream file_in_stm = new FileInputStream("D:\\includehelp.txt"); ObjectInputStream obj_in_stm = new ObjectInputStream(file_in_stm); // By using writeObject() method is to // write object to Serialized class obj_out_stm.writeObject(new DefaultObjectClass()); obj_out_stm.flush(); // By using readObject() method is to // read an object from the Serialized class DefaultObjectClass def_obj = (DefaultObjectClass) obj_in_stm.readObject(); // Using both readObject and defaultReadObject(); System.out.println("obj_in_stm.defaultReadObject(): " + def_obj.str); System.out.println("obj_in_stm.defaultReadObject(): " + def_obj.in); } static class DefaultObjectClass implements Serializable {
String str = "Java Programming"; Integer in = new Integer(10); private void readObject(ObjectInputStream obj_stm) throws IOException, ClassNotFoundException {
// By using defaultReadObject() method is // to read non-static fields of the present // class from the ObjectInputStream obj_stm.defaultReadObject(); } }}

Output

输出量

enableResolveObject invokedresoveObject: Java

翻译自:

转载地址:http://lctzd.baihongyu.com/

你可能感兴趣的文章
feign调用spring clound eureka 注册中心服务
查看>>
ZT:Linux上安装JDK,最准确
查看>>
LimeJS指南3
查看>>
关于C++ const成员的一些细节
查看>>
《代码大全》学习摘要(五)软件构建中的设计(下)
查看>>
C#检测驱动是否安装的问题
查看>>
web-4. 装饰页面的图像
查看>>
微信测试账户
查看>>
Android ListView上拉获取下一页
查看>>
算法练习题
查看>>
学习使用Django一 安装虚拟环境
查看>>
Hibernate视频学习笔记(8)Lazy策略
查看>>
CSS3 结构性伪类选择器(1)
查看>>
IOS 杂笔-14(被人遗忘的owner)
查看>>
自动测试用工具
查看>>
前端基础之BOM和DOM
查看>>
[T-ARA/筷子兄弟][Little Apple]
查看>>
编译Libgdiplus遇到的问题
查看>>
【NOIP 模拟赛】Evensgn 剪树枝 树形dp
查看>>
java学习笔记④MySql数据库--01/02 database table 数据的增删改
查看>>