📄 objectinputstream.html
字号:
<DD><DL><DT><B>Parameters:</B><DD><CODE>obj</CODE> - the object to receive the validation callback.<DD><CODE>prio</CODE> - controls the order of callbacks;zero is a good default. Use higher numbers to be called back earlier, lower numbers for later callbacks. Within a priority, callbacks are processed in no particular order.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/NotActiveException.html">NotActiveException</A></CODE> - The stream is not currently reading objects so it is invalid to register a callback.<DD><CODE><A HREF="../../java/io/InvalidObjectException.html">InvalidObjectException</A></CODE> - The validation object is null.</DL></DD></DL><HR><A NAME="resolveClass(java.io.ObjectStreamClass)"><!-- --></A><H3>resolveClass</H3><PRE>protected <A HREF="../../java/lang/Class.html">Class</A> <B>resolveClass</B>(<A HREF="../../java/io/ObjectStreamClass.html">ObjectStreamClass</A> v) throws <A HREF="../../java/io/IOException.html">IOException</A>, <A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></PRE><DL><DD>Load the local class equivalent of the specified stream class description. Subclasses may implement this method to allow classes to be fetched from an alternate source. The corresponding method in ObjectOutputStream is annotateClass. This method will be invoked only once for each unique class in the stream. This method can be implemented by subclasses to use an alternate loading mechanism but must return a Class object. Once returned, the serialVersionUID of the class is compared to the serialVersionUID of the serialized class. If there is a mismatch, the deserialization fails and an exception is raised. <p> By default the class name is resolved relative to the class that called readObject. <p><DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>v</CODE> - an instance of class ObjectStreamClass<DT><B>Returns:</B><DD>a Class object corresponding to <code>v</code><DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - Any of the usual Input/Output exceptions.<DD><CODE><A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></CODE> - If class of a serialized object cannot be found.</DL></DD></DL><HR><A NAME="resolveProxyClass(java.lang.String[])"><!-- --></A><H3>resolveProxyClass</H3><PRE>protected <A HREF="../../java/lang/Class.html">Class</A> <B>resolveProxyClass</B>(<A HREF="../../java/lang/String.html">String</A>[] interfaces) throws <A HREF="../../java/io/IOException.html">IOException</A>, <A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></PRE><DL><DD>Returns a proxy class that implements the interfaces named in a proxy class descriptor; subclasses may implement this method to read custom data from the stream along with the descriptors for dynamic proxy classes, allowing them to use an alternate loading mechanism for the interfaces and the proxy class. <p>This method is called exactly once for each unique proxy class descriptor in the stream. <p>The corresponding method in <code>ObjectOutputStream</code> is <code>annotateProxyClass</code>. For a given subclass of <code>ObjectInputStream</code> that overrides this method, the <code>annotateProxyClass</code> method in the corresponding subclass of <code>ObjectOutputStream</code> must write any data or objects read by this method. <p>The default implementation of this method in <code>ObjectInputStream</code> returns the result of calling <code>Proxy.getProxyClass</code> with the list of <code>Class</code> objects for the interfaces that are named in the <code>interfaces</code> parameter. The <code>Class</code> object for each interface name <code>i</code> is the value returned by calling <pre> Class.forName(i, false, loader) </pre> where <code>loader</code> is that of the first non-null class loader up the execution stack, or <code>null</code> if no non-null class loaders are on the stack (the same class loader choice used by the <code>resolveClass</code> method). This same value of <code>loader</code> is also the class loader passed to <code>Proxy.getProxyClass</code>. If <code>Proxy.getProxyClass</code> throws an <code>IllegalArgumentException</code>, <code>resolveProxyClass</code> will throw a <code>ClassNotFoundException</code> containing the <code>IllegalArgumentException</code>.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>interfaces</CODE> - the list of interface names that were deserialized in the proxy class descriptor<DT><B>Returns:</B><DD>a proxy class for the specified interfaces<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - any exception thrown by the underlying <code>InputStream</code><DD><CODE><A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></CODE> - if the proxy class or any of the named interfaces could not be found<DT><B>Since: </B><DD>1.3</DD><DT><B>See Also: </B><DD><A HREF="../../java/io/ObjectOutputStream.html#annotateProxyClass(java.lang.Class)"><CODE>ObjectOutputStream.annotateProxyClass(Class)</CODE></A></DL></DD></DL><HR><A NAME="resolveObject(java.lang.Object)"><!-- --></A><H3>resolveObject</H3><PRE>protected <A HREF="../../java/lang/Object.html">Object</A> <B>resolveObject</B>(<A HREF="../../java/lang/Object.html">Object</A> obj) throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>This method will allow trusted subclasses of ObjectInputStream to substitute one object for another during deserialization. Replacing objects is disabled until enableResolveObject is called. The enableResolveObject method checks that the stream requesting to resolve object can be trusted. Every reference to serializable objects is passed to resolveObject. To insure that the private state of objects is not unintentionally exposed only trusted streams may use resolveObject. <p> This method is called after an object has been read but before it is returned from readObject. The default resolveObject method just returns the same object. <p> When a subclass is replacing objects it must insure that the substituted object is compatible with every field where the reference will be stored. Objects whose type is not a subclass of the type of the field or array element abort the serialization by raising an exception and the object is not be stored. <p> This method is called only once when each object is first encountered. All subsequent references to the object will be redirected to the new object. <P><DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>obj</CODE> - object to be substituted<DT><B>Returns:</B><DD>the substituted object<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - Any of the usual Input/Output exceptions.</DL></DD></DL><HR><A NAME="enableResolveObject(boolean)"><!-- --></A><H3>enableResolveObject</H3><PRE>protected boolean <B>enableResolveObject</B>(boolean enable) throws <A HREF="../../java/lang/SecurityException.html">SecurityException</A></PRE><DL><DD>Enable the stream to allow objects read from the stream to be replaced. When enabled, the resolveObject method is called for every object being deserialized. If <i>enable</i> is true, and there is a security manager installed, this method first calls the security manager's <code>checkPermission</code> method with the <code>SerializablePermission("enableSubstitution")</code> permission to ensure it's ok to enable the stream to allow objects read from the stream to be replaced.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>enable</CODE> - true for enabling use of <code>resolveObject</code> for every object being deserialized<DT><B>Returns:</B><DD>the previous setting before this method was invoked<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkPermission</code> method denies enabling the stream to allow objects read from the stream to be replaced.<DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkPermission(java.security.Permission)"><CODE>SecurityManager.checkPermission(java.security.Permission)</CODE></A>, <A HREF="../../java/io/SerializablePermission.html"><CODE>SerializablePermission</CODE></A></DL></DD></DL><HR><A NAME="readStreamHeader()"><!-- --></A><H3>readStreamHeader</H3><PRE>protected void <B>readStreamHeader</B>() throws <A HREF="../../java/io/IOException.html">IOException</A>, <A HREF="../../java/io/StreamCorruptedException.html">StreamCorruptedException</A></PRE><DL><DD>The readStreamHeader method is provided to allow subclasses to read and verify their own stream headers. It reads and verifies the magic number and version number.<DD><DL></DL></DD><DD><DL><DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if there are I/O errors while reading from the underlying <code>InputStream</code><DD><CODE><A HREF="../../java/io/StreamCorruptedException.html">StreamCorruptedException</A></CODE> - if control information in the stream is inconsistent</DL></DD></DL><HR><A NAME="readClassDescriptor()"><!-- --></A><H3>readClassDescriptor</H3><PRE>protected <A HREF="../../java/io/ObjectStreamClass.html">ObjectStreamClass</A> <B>readClassDescriptor</B>() throws <A HREF="../../java/io/IOException.html">IOException</A>, <A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></PRE><DL><DD>Read a class descriptor from the serialization stream. This method is called when the ObjectInputStream expects a class descriptor as the next item in the serialization stream. Subclasses of ObjectInputStream may override this method to read in class descriptors that have been written in non-standard formats (by subclasses of ObjectOutputStream which have overridden the <code>writeClassDescriptor</code> method). By default, this method reads class descriptors according to the format defined in the Object Serialization specification. <p><DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the class descriptor read<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - If an I/O error has occurred.<DD><CODE><A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></CODE> - If the Class of a serialized object used in the class descriptor representation cannot be found<DT><B>Since: </B><DD>1.3</DD><DT><B>See Also: </B><DD><A HREF="../../java/io/ObjectOutputStream.html#writeClassDescriptor(java.io.ObjectStreamClass)"><CODE>ObjectOutputStream.writeClassDescriptor(java.io.ObjectStreamClass)</CODE></A></DL></DD></DL><HR><A NAME="read()"><!-- --></A><H3>read</H3><PRE>public int <B>read</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Reads a byte of data. This method will block if no input is available.<DD><DL><DT><B>Specified by: </B><DD><CODE><A HREF="../../java/io/ObjectInput.html#read()">read</A></CODE> in interface <CODE><A HREF="../../java/io/ObjectInput.html">ObjectInput</A></CODE><DT><B>Overrides:</B><DD><CODE><A HREF="../../java/io/InputStream.html#read()">read</A></CODE> in class <CODE><A HREF="../../java/io/InputStream.html">InputStream</A></CODE></DL></DD><DD><DL><DT><B>Returns:</B><DD>the byte read, or -1 if the end of the stream is reached.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - If an I/O error has occurred.</DL></DD></DL><HR><A NAME="read(byte[], int, int)"><!-- --></A><H3>read</H3><PRE>public int <B>read</B>(byte[] b, int off, int len) throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Reads into an array of bytes. This method will block until some input is available. Consider using java.io.DataInputStream.readFully to read exactly 'length' bytes.<DD><DL><DT><B>Specified by: </B><DD><CODE><A HREF="../../java/io/ObjectInput.html#read(byte[], int, int)">read</A></CODE> in interface <CODE><A HREF="../../java/io/ObjectInput.html">ObjectInput</A></CODE><DT><B>Overrides:</B><DD><CODE><A HREF="../../java/io/InputStream.html#read(byte[], int, int)">read</A></CODE> in class <CODE><A HREF="../../java/io/InputStream.html">InputStream</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>b</CODE> - the buffer into which the data is read<DD><CODE>off</CODE> - the start offset of the data<DD><CODE>len</CODE> - the maximum number of bytes read<DT><B>Returns:</B><DD>the actual number of bytes read, -1 is returned when the end of the stream is reached.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - If an I/O error has occurred.<DT><B>See Also: </B><DD><A HREF="../../java/io/DataInputStream.html#readFully(byte[], int, int)"><CODE>DataInputStream.readFully(byte[],int,int)</CODE></A></DL></DD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -