Whole document tree
java.io
|
Inner Class Summary | |
static class |
ObjectOutputStream.PutField
Provide programatic access to the persistent fields to be written to ObjectOutput. |
Constructor Summary | |
protected |
ObjectOutputStream()
Provide a way for subclasses that are completely reimplementing ObjectOutputStream to not have to allocate private data just used by this implementation of ObjectOutputStream. |
|
ObjectOutputStream(OutputStream out)
Creates an ObjectOutputStream that writes to the specified OutputStream. |
Method Summary | |
protected void |
annotateClass(Class cl)
Subclasses may implement this method to allow class data to be stored in the stream. |
protected void |
annotateProxyClass(Class cl)
Subclasses may implement this method to store custom data in the stream along with descriptors for dynamic proxy classes. |
void |
close()
Closes the stream. |
void |
defaultWriteObject()
Write the non-static and non-transient fields of the current class to this stream. |
protected void |
drain()
Drain any buffered data in ObjectOutputStream. |
protected boolean |
enableReplaceObject(boolean enable)
Enable the stream to do replacement of objects in the stream. |
void |
flush()
Flushes the stream. |
ObjectOutputStream.PutField |
putFields()
Retrieve the object used to buffer persistent fields to be written to the stream. |
protected Object |
replaceObject(Object obj)
This method will allow trusted subclasses of ObjectOutputStream to substitute one object for another during serialization. |
void |
reset()
Reset will disregard the state of any objects already written to the stream. |
void |
useProtocolVersion(int version)
Specify stream protocol version to use when writing the stream. |
void |
write(byte[] b)
Writes an array of bytes. |
void |
write(byte[] b,
int off,
int len)
Writes a sub array of bytes. |
void |
write(int data)
Writes a byte. |
void |
writeBoolean(boolean data)
Writes a boolean. |
void |
writeByte(int data)
Writes an 8 bit byte. |
void |
writeBytes(String data)
Writes a String as a sequence of bytes. |
void |
writeChar(int data)
Writes a 16 bit char. |
void |
writeChars(String data)
Writes a String as a sequence of chars. |
protected void |
writeClassDescriptor(ObjectStreamClass classdesc)
Write the specified class descriptor to the ObjectOutputStream. |
void |
writeDouble(double data)
Writes a 64 bit double. |
void |
writeFields()
Write the buffered fields to the stream. |
void |
writeFloat(float data)
Writes a 32 bit float. |
void |
writeInt(int data)
Writes a 32 bit int. |
void |
writeLong(long data)
Writes a 64 bit long. |
void |
writeObject(Object obj)
Write the specified object to the ObjectOutputStream. |
protected void |
writeObjectOverride(Object obj)
Method used by subclasses to override the default writeObject method. |
void |
writeShort(int data)
Writes a 16 bit short. |
protected void |
writeStreamHeader()
The writeStreamHeader method is provided so subclasses can append or prepend their own header to the stream. |
void |
writeUTF(String s)
Primitive data write of this String in UTF format. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ObjectOutputStream(OutputStream out) throws IOException
out
- OutputStream
to read fromIOException
- Any exception thrown by the underlying
OutputStream.protected ObjectOutputStream() throws IOException, SecurityException
If there is a security manager installed, this method first calls the
security manager's checkPermission
method with a
SerializablePermission("enableSubclassImplementation")
permission to ensure it's ok to enable subclassing.
IOException
- Thrown if not called by a subclass.SecurityException
- if a security manager exists and its
checkPermission
method denies
enabling subclassing.SecurityManager.checkPermission(java.security.Permission)
,
SerializablePermission
Method Detail |
protected void writeObjectOverride(Object obj) throws IOException
obj
- object to be written to the underlying streamIOException
- if there are I/O errors while writing to the
underlying streamObjectOutputStream()
,
writeObject(Object)
public void useProtocolVersion(int version) throws IOException
This routine provides a hook to enable the current version of Serialization to write in a format that is backwards compatible to a previous version of the stream format.
Every effort will be made to avoid introducing additional backwards incompatibilities; however, sometimes there is no other alternative.
version
- use ProtocolVersion from java.io.ObjectStreamConstants.IllegalStateException
- Thrown if called after any objects
have been serialized.IllegalArgumentException
- if invalid version is passed in.IOException
- if I/O errors occurObjectStreamConstants.PROTOCOL_VERSION_1
,
ObjectStreamConstants.PROTOCOL_VERSION_2
public final void writeObject(Object obj) throws IOException
Exceptions are thrown for problems with the OutputStream and for classes that should not be serialized. All exceptions are fatal to the OutputStream, which is left in an indeterminate state, and it is up to the caller to ignore or recover the stream state.
writeObject
in interface ObjectOutput
InvalidClassException
- Something is wrong with a class used by
serialization.NotSerializableException
- Some object to be serialized does not
implement the java.io.Serializable interface.IOException
- Any exception thrown by the underlying OutputStream.public void defaultWriteObject() throws IOException
IOException
- if I/O errors occur while writing to the underlying
OutputStream
public ObjectOutputStream.PutField putFields() throws IOException
IOException
- if I/O errors occurpublic void writeFields() throws IOException
IOException
- if I/O errors occur while writing to the underlying
streamNotActiveException
- Called when a classes writeObject
method was not called to write the state of the object.public void reset() throws IOException
IOException
- if reset() is invoked while serializing an object.protected void annotateClass(Class cl) throws IOException
cl
- the class to annotate custom data forIOException
- Any exception thrown by the underlying OutputStream.protected void annotateProxyClass(Class cl) throws IOException
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 writtem by annotateProxyClass
.
cl
- the proxy class to annotate custom data forIOException
- any exception thrown by the underlying
OutputStream
ObjectInputStream.resolveProxyClass(String[])
protected Object replaceObject(Object obj) throws IOException
The ObjectOutputStream.writeObject method takes a parameter of type Object (as opposed to type Serializable) to allow for cases where non-serializable objects are replaced by serializable ones. When a subclass is replacing objects it must insure that either a complementary substitution must be made during deserialization or 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.
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. This method should return the object to be substituted or the original object.
Null can be returned as the object to be substituted, but may cause NullReferenceException in classes that contain references to the original object since they may be expecting an object instead of null.
obj
- the object to be replacedIOException
- Any exception thrown by the underlying
OutputStream.protected boolean enableReplaceObject(boolean enable) throws SecurityException
When enabled, the replaceObject method is called for every object being serialized.
If enable is true, and there is a security manager installed,
this method first calls the
security manager's checkPermission
method with a
SerializablePermission("enableSubstitution")
permission to ensure it's ok to
enable the stream to do replacement of objects in the stream.
enable
- boolean parameter to enable replacement of objectsSecurityException
- if a security manager exists and its
checkPermission
method denies
enabling the stream to do replacement of objects in the stream.SecurityManager.checkPermission(java.security.Permission)
,
SerializablePermission
protected void writeStreamHeader() throws IOException
IOException
- if I/O errors occur while writing to the underlying
streamprotected void writeClassDescriptor(ObjectStreamClass classdesc) throws IOException
readClassDescriptor
, should then be overridden to
reconstitute the class descriptor from its custom stream representation.
By default, this method writes class descriptors according to the format
defined in the Object Serialization specification.
Note that this method will only be called if the ObjectOutputStream is
not using the old serialization stream format (set by calling
ObjectOutputStream's useProtocolVersion
method). If this
serialization stream is using the old format
(PROTOCOL_VERSION_1
), the class descriptor will be written
internally in a manner that cannot be overridden or customized.
classdesc
- class descriptor to write to the streamIOException
- If an I/O error has occurred.ObjectInputStream.readClassDescriptor()
,
useProtocolVersion(int)
,
ObjectStreamConstants.PROTOCOL_VERSION_1
public void write(int data) throws IOException
write
in interface ObjectOutput
write
in class OutputStream
data
- the byte to be written to the streamIOException
- If an I/O error has occurred.public void write(byte[] b) throws IOException
write
in interface ObjectOutput
write
in class OutputStream
b
- the data to be writtenIOException
- If an I/O error has occurred.public void write(byte[] b, int off, int len) throws IOException
write
in interface ObjectOutput
write
in class OutputStream
b
- the data to be writtenoff
- the start offset in the datalen
- the number of bytes that are writtenIOException
- If an I/O error has occurred.public void flush() throws IOException
flush
in interface ObjectOutput
flush
in class OutputStream
IOException
- If an I/O error has occurred.protected void drain() throws IOException
IOException
- if I/O errors occur while writing to the underlying
streampublic void close() throws IOException
close
in interface ObjectOutput
close
in class OutputStream
IOException
- If an I/O error has occurred.public void writeBoolean(boolean data) throws IOException
writeBoolean
in interface DataOutput
data
- the boolean to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeByte(int data) throws IOException
writeByte
in interface DataOutput
data
- the byte value to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeShort(int data) throws IOException
writeShort
in interface DataOutput
data
- the short value to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeChar(int data) throws IOException
writeChar
in interface DataOutput
data
- the char value to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeInt(int data) throws IOException
writeInt
in interface DataOutput
data
- the integer value to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeLong(long data) throws IOException
writeLong
in interface DataOutput
data
- the long value to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeFloat(float data) throws IOException
writeFloat
in interface DataOutput
data
- the float value to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeDouble(double data) throws IOException
writeDouble
in interface DataOutput
data
- the double value to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeBytes(String data) throws IOException
writeBytes
in interface DataOutput
data
- the String of bytes to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeChars(String data) throws IOException
writeChars
in interface DataOutput
data
- the String of chars to be writtenIOException
- if I/O errors occur while writing to the underlying
streampublic void writeUTF(String s) throws IOException
writeUTF
in interface DataOutput
s
- the String in UTF formatIOException
- if I/O errors occur while writing to the underlying
stream
|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.