📜  Java Java类设置 2

📅  最后修改于: 2022-05-13 01:54:45.056000             🧑  作者: Mango

Java Java类设置 2

Java Java类设置 1
笔记 :
本文中提到的Java代码不会在 Online IDE 上运行,因为代码中使用的文件在线上不存在。因此,为了验证代码的工作,您可以将它们复制到您的系统并在那里运行它。
ObjectInputStream 类的更多方法:

  • defaultReadObject() : Java.io.ObjectInputStream.defaultReadObject()从输入流中读取当前类的非静态字段。我们使用序列化类的 readObject() 方法来调用该方法。
    句法 :
public void defaultReadObject()
Parameters : 
-----------
Return : 
void
Exception :
-> IOException : in case of any IO error occurs.
-> ClassNotFoundException : if the class of Object(being serialized) is not found
-> NotActiveException : if the Stream is not reading.
  • readObject() : Java.io.ObjectInputStream.readObject()从序列化类中读取一个对象。该方法用于调用defaultReadObject。如果该类默认反序列化,则可以使用 readObject 和 writeObject 方法覆盖它。
    句法 :
public void defaultReadObject()
Parameters : 
public final Object readObject()
Return : 
void
Exception :
-> IOException : in case of any IO error occurs.
-> ClassNotFoundException : if the class of Object(being serialized) is not found
-> OptionalDataException : if instead of object, primitive data is found.
-> InvalidClassException : is there is something wrong with serialized class
  • available() : Java.io.ObjectInputStream.available()告诉不。的字节可以被读取而不会被阻塞
    句法 :
public int available()
Parameters : 
-----------
Return : 
no. of bytes of that can be read without being blocked
Exception :
-> IOException : in case of any IO error occurs.
  • close() : Java.io.ObjectInputStream.close()关闭 Input Stream 并释放所有分配给 Stream 的资源
    句法 :
public void close()
Parameters : 
-----------
Return : 
void
Exception :
-> IOException : in case of any IO error occurs.
  • readShort() : Java.io.ObjectInputStream.readShort()读取 16 位短。
    句法 :
public short readShort()
Parameters : 
public final Object readObject()
Return : 
reads 16 bit short.
Exception :
-> IOException : in case of any IO error occurs.
-> EOFException : if End of stream is reached
  • readUTF() : Java.io.ObjectInputStream.readUTF()以修改后的 UTF-8(Unicode 转换格式)格式读取字符串。 UTF -8 意味着它使用 8 位块来表示一个字符。
    句法 :
public String readUTF()
Parameters : 
public final Object readObject()
Return : 
reads String in modified UTF-8 (Unicode Transformation Format) format
Exception :
-> IOException : in case of any IO error occurs.
  • skipBytes(int maxlen) : Java.io.ObjectInputStream.skipBytes(int maxlen)跳过“maxlen”号。读取时的字节数。
    句法 :
public int skipBytes(int maxlen)
Parameters : 
maxlen : max. no. of bytes to be skipped
Return : 
no. of bytes to be skipped
Exception :
-> IOException : in case of any IO error occurs.
  • readFully(byte[] destination) : Java.io.ObjectInputStream.readFully(byte[] destination)将所有字节从源读取到目标数组。
    句法 :
public void readFully(byte[] destination)
Parameters : 
destination : the buffer in which the data is to be read
Return : 
returns the 32 bit float read
Exception :
-> IOException : in case of any IO error occurs.
-> EOFException : if End of stream is reached
  • readFully(byte[] destination, int offset, int maxlen) : Java.io.ObjectInputStream.readFully(byte[] destination, int offset, int maxlen)从源读取一些字节(从偏移到 maxlen 位置)到目标大批 。
    句法 :
public void readFully(byte[] destination, int offset, int maxlen)
Parameters : 
destination : the buffer in which the data is to be read
offset : starting position of the buffer
maxlen : max no. of bytes to be read
Return : 
void
Exception :
-> IOException : in case of any IO error occurs.
-> EOFException : if End of stream is reached
  • readFields() : Java.io.ObjectInputStream.readFields()从输入流中读取常量字段并指明名称。
    句法 :
public ObjectInputStream.GetField readFields()
Parameters : 
-------
Return : 
GetField object reading the constant fields
Exception :
-> IOException : in case of any IO error occurs.
-> ClassNotFoundException : if class of serialized object is not found
  • resolveClass() : Java.io.ObjectInputStream.resolveClass(ObjectStreamClass INS_class)加载一个实例类到指定的流类来代替它。
    句法 :
protected Class resolveClass(ObjectStreamClass desc)

 : means that the class object can be of any type, it is to be specified by the coder.
Parameters : 
INS_class : instance of the specified Stream Class
Return : 
Class Object equivalent to the Specified Stream Class
Exception :
-> IO Exception : if any IO exception occurs
-> ClassNotFoundException : if the argumented class is not available.
  • registerValidation() : Java.io.ObjectInputStream.registerValidation(ObjectInputValidation object, int order)注册对象以验证它。
    句法 :
public void registerValidation(ObjectInputValidation object, int order)
Parameters : 
-------
Return : 
object : object to be validated 
order : Controls the order of callback. These are processed in no particular order
Exception :
-> NotActiveException : If IO stream is not ready to be read
-> InvalidObjectException : if the argumented object to be validated is NULL.
  • resolveObject(Object o) : Java.io.ObjectInputStream.resolveObject(Object o)将对象替换为来自另一个受信任子类的 ObjectInputStream。我们不能替换对象,直到
    enableResolveObject 被调用。在读取对象后调用它。
    句法 :
protected Object resolveObject(Object o)
Parameters : 
o : object we want to substitute
Return : 
---------
Exception :
-> IOException : If IO error occurs.
  • enableResolveObject() : Java.io.ObjectInputStream.enableResolveObject(boolean check)允许resolveObject 方法将对象替换为来自另一个受信任类的ObjectInputStream。
    enableResolveObject 被调用。在读取对象后调用它。
    句法 :
protected boolean enableResolveObject(boolean enable)
Parameters : 
check : "true" to allow resolveObject() method
Return : 
----
  • readClassDescriptor() : Java.io.ObjectInputStream.readClassDescriptor()从序列化流中读取类描述符,如果描述符被 ObjectInputStream 接受,则调用此方法。默认情况下,描述符由 readClassDescriptor() 方法 acc 调用。对象序列化中定义的格式
    句法 :
protected ObjectStreamClass readClassDescriptor()
Parameters : 
-------
Return : 
reads class descriptor
  • readObjectOverride() : Java.io.ObjectInputStream.readObjectOverride()使用受保护的无参数构造函数从 ObjectOutputStream 读取对象
    句法 :
protected Object readObjectOverride()
Parameters : 
-------
Return : 
reads object from the Stream
  • readStreamHeader() : Java.io.ObjectInputStream.readStreamHeader()允许子类读取和验证其标头并验证版本号
    句法 :
protected void readStreamHeader()
Parameters : 
-------
Return : 
void
  • resolveProxyClass(String[] in_list) : Java.io.resolveProxyClass(String[] in_list)返回一个代理类,实现在代理类描述符中命名的那些接口。使用这种方法,我们可以从动态代理类中读取描述符
    句法 :
protected Class resolveProxyClass(String[] in_list)
Parameters : 
in_List : interface names list, deserialized in the proxy class descriptor
Return : 
Proxy class for specific Interface mentioned in the list