- Java.io package classes
- Java.io - Home
- Java.io - BufferedInputStream
- Java.io - BufferedOutputStream
- Java.io - BufferedReader
- Java.io - BufferedWriter
- Java.io - ByteArrayInputStream
- Java.io - ByteArrayOutputStream
- Java.io - CharArrayReader
- Java.io - CharArrayWriter
- Java.io - Console
- Java.io - DataInputStream
- Java.io - DataOutputStream
- Java.io - File
- Java.io - FileDescriptor
- Java.io - FileInputStream
- Java.io - FileOutputStream
- Java.io - FilePermission
- Java.io - FileReader
- Java.io - FileWriter
- Java.io - FilterInputStream
- Java.io - FilterOutputStream
- Java.io - FilterReader
- Java.io - FilterWriter
- Java.io - InputStream
- Java.io - InputStreamReader
- Java.io - LineNumberInputStream
- Java.io - LineNumberReader
- Java.io - ObjectInputStream
- Java.io - ObjectInputStream.GetField
- Java.io - ObjectOutputStream
- io - ObjectOutputStream.PutField
- Java.io - ObjectStreamClass
- Java.io - ObjectStreamField
- Java.io - OutputStream
- Java.io - OutputStreamWriter
- Java.io - PipedInputStream
- Java.io - PipedOutputStream
- Java.io - PipedReader
- Java.io - PipedWriter
- Java.io - PrintStream
- Java.io - PrintWriter
- Java.io - PushbackInputStream
- Java.io - PushbackReader
- Java.io - RandomAccessFile
- Java.io - Reader
- Java.io - SequenceInputStream
- Java.io - SerializablePermission
- Java.io - StreamTokenizer
- Java.io - StringBufferInputStream
- Java.io - StringReader
- Java.io - StringWriter
- Java.io - Writer
- Java.io package extras
- Java.io - Interfaces
- Java.io - Exceptions
- Java.io package Useful Resources
- Java.io - Discussion
Java.io.ObjectOutputStream annotateProxyClass() Method
Description
The java.io.ObjectOutputStream.annotateProxyClass(Class<?> cl) can be implemented by subclasses to store custom data in the stream along with descriptors for dynamic proxy classes.
This method is called exactly once for each unique proxy class descriptor in the stream. The default implementation of this method in ObjectOutputStream does nothing.
The corresponding method in ObjectInputStream is resolveProxyClass. For a given subclass of ObjectOutputStream that overrides this method, the resolveProxyClass method in the corresponding subclass of ObjectInputStream must read any data or objects written by annotateProxyClass.
Declaration
Following is the declaration for java.io.ObjectOutputStream.annotateProxyClass() method.
protected void annotateProxyClass(Class<?> cl)
Parameters
cl − The proxy class to annotate custom data for.
Return Value
This method does not return a value.
Exception
IOException − Any exception thrown by the underlying OutputStream.
Example
The following example shows the usage of java.io.ObjectOutputStream.annotateProxyClass() method.
package com.tutorialspoint; import java.io.*; public class ObjectOutputStreamDemo extends ObjectOutputStream { public ObjectOutputStreamDemo(OutputStream out) throws IOException { super(out); } public static void main(String[] args) { int i = 319874; try { // create a new file with an ObjectOutputStream FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStreamDemo oout = new ObjectOutputStreamDemo(out); // write something in the file oout.writeInt(i); oout.writeInt(1653984); oout.flush(); // call annotateProxyClass but it does nothing oout.annotateProxyClass(Integer.class); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print an int System.out.println("" + ois.readInt()); // read and print an int System.out.println("" + ois.readInt()); } catch (Exception ex) { ex.printStackTrace(); } } }
Let us compile and run the above program, this will produce the following result −
319874 1653984