日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java ObjectInputStream enableResolveObject()方法与示例

發(fā)布時間:2025/3/11 java 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java ObjectInputStream enableResolveObject()方法与示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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”)調(diào)用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()方法是一個非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名訪問該方法,則會收到錯誤消息。

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

    enableResolveObject()方法在檢查要替換的對象狀態(tài)時可能會引發(fā)異常。

    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()方法不允許啟用流以允許從流讀取的對象被替換,則可能引發(fā)此異常。

Syntax:

句法:

public boolean enableResolveObject(boolean status);

Parameter(s):

參數(shù):

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

    布爾狀態(tài) –如果將其設置為true,則意味著對每個反序列化的對象啟用resolveObject()的使用。

Return value:

返回值:

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

該方法的返回類型為boolean ,它在調(diào)用此方法之前獲得了舊設置。

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 FileOutputStreamFileOutputStream 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 classobj_out_stm.writeObject(new DefaultObjectClass());obj_out_stm.flush();// By using readObject() method is to// read an object from the Serialized classDefaultObjectClass 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 ObjectInputStreamobj_stm.defaultReadObject();}} }

Output

輸出量

enableResolveObject invoked resoveObject: Java

翻譯自: https://www.includehelp.com/java/objectinputstream-enableresolveobject-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Java ObjectInputStream enableResolveObject()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。