Top Description Fields Constructors Methods
org.jboss.marshalling

public abstract Class MarshallerObjectOutputStream

extends ObjectOutputStream
implements ByteOutput
Class Inheritance
All Implemented Interfaces
org.jboss.marshalling.ByteOutput, java.io.Flushable, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.jboss.marshalling.cloner.SerializingCloner.StepObjectOutputStream
Imports
java.io.ObjectOutputStream, .IOException, .ObjectStreamClass

A marshaller's object output stream. Used by marshallers for compatibility with Java serialization. Instances of this class may be passed in to the overridden serialization methods for a class implementing java.io.Serializable.

This class is not part of the marshalling API; rather it is intended for marshaller implementers to make it easier to develop Java serialization-compatible marshallers.

Field Summary

Modifier and TypeField and Description
private final Marshaller

Constructor Summary

AccessConstructor and Description
protected
MarshallerObjectOutputStream(final Marshaller
the delegate marshaller
output
)

Construct a new instance that delegates to the given marshaller.

Method Summary

Modifier and TypeMethod and Description
protected final void
annotateClass(final Class<?>
the class to annotate custom data for
cl
)

Overrides java.io.ObjectOutputStream.annotateClass.

Subclasses may implement this method to allow class data to be stored in the stream.
protected final void
annotateProxyClass(final Class<?>
the proxy class to annotate custom data for
cl
)

Overrides java.io.ObjectOutputStream.annotateProxyClass.

Subclasses may implement this method to store custom data in the stream along with descriptors for dynamic proxy classes.
public final void
close()

Overrides java.io.ObjectOutputStream.close.

Implements java.io.Closeable.close, java.io.ObjectOutput.close.

Closes this stream and releases any system resources associated with it.
public abstract void
defaultWriteObject()

Overrides java.io.ObjectOutputStream.defaultWriteObject.

Write the non-static and non-transient fields of the current class to this stream.
protected final void
drain()

Overrides java.io.ObjectOutputStream.drain.

Drain any buffered data in ObjectOutputStream.
protected final boolean
enableReplaceObject(final boolean
true for enabling use of replaceObject for every object being serialized
enable
)

Overrides java.io.ObjectOutputStream.enableReplaceObject.

Enables the stream to do replacement of objects written to the stream.
public void
flush()

Overrides java.io.ObjectOutputStream.flush.

Implements java.io.Flushable.flush, java.io.ObjectOutput.flush.

Flushes this stream by writing any buffered output to the underlying stream.
public abstract ObjectOutputStream.PutField
putFields()

Overrides java.io.ObjectOutputStream.putFields.

Retrieve the object used to buffer persistent fields to be written to the stream.
protected final Object
replaceObject(final Object
the object to be replaced
obj
)

Overrides java.io.ObjectOutputStream.replaceObject.

This method will allow trusted subclasses of ObjectOutputStream to substitute one object for another during serialization.
public final void
reset()

Overrides java.io.ObjectOutputStream.reset.

Reset will disregard the state of any objects already written to the stream.
public final void
useProtocolVersion(final int
use ProtocolVersion from java.io.ObjectStreamConstants.
version
)

Overrides java.io.ObjectOutputStream.useProtocolVersion.

Specify stream protocol version to use when writing the stream.
public void
write(final int
the byte to write
val
)

Overrides java.io.ObjectOutputStream.write.

Implements org.jboss.marshalling.ByteOutput.write, java.io.ObjectOutput.write.

Writes to the output stream the eight low-order bits of the argument b.
public void
write(final byte[]
the byte array
buf
)

Overrides java.io.ObjectOutputStream.write.

Implements org.jboss.marshalling.ByteOutput.write, java.io.ObjectOutput.write.

Write all the bytes from the given array to the stream.
public void
write(final byte[]
the byte array
buf
,
final int
the index to start writing from
off
,
final int
the number of bytes to write
len
)

Overrides java.io.ObjectOutputStream.write.

Implements org.jboss.marshalling.ByteOutput.write, java.io.ObjectOutput.write.

Write some of the bytes from the given array to the stream.
public void
writeBoolean(final boolean
the boolean to be written
val
)

Overrides java.io.ObjectOutputStream.writeBoolean.

Implements java.io.DataOutput.writeBoolean.

Writes a boolean.
public void
writeByte(final int
the byte value to be written
val
)

Overrides java.io.ObjectOutputStream.writeByte.

Implements java.io.DataOutput.writeByte.

Writes an 8-bit byte.
public void
writeBytes(final String
the String of bytes to be written
str
)

Overrides java.io.ObjectOutputStream.writeBytes.

Implements java.io.DataOutput.writeBytes.

Writes a String as a sequence of bytes.
public void
writeChar(final int
the char value to be written
val
)

Overrides java.io.ObjectOutputStream.writeChar.

Implements java.io.DataOutput.writeChar.

Writes a 16-bit char.
public void
writeChars(final String
the String of chars to be written
str
)

Overrides java.io.ObjectOutputStream.writeChars.

Implements java.io.DataOutput.writeChars.

Writes a String as a sequence of chars.
protected final void
writeClassDescriptor(final ObjectStreamClass
class descriptor to write to the stream
desc
)

Overrides java.io.ObjectOutputStream.writeClassDescriptor.

Write the specified class descriptor to the ObjectOutputStream.
public void
writeDouble(final double
the double value to be written
val
)

Overrides java.io.ObjectOutputStream.writeDouble.

Implements java.io.DataOutput.writeDouble.

Writes a 64-bit double.
public abstract void
writeFields()

Overrides java.io.ObjectOutputStream.writeFields.

Write the buffered fields to the stream.
public void
writeFloat(final float
the float value to be written
val
)

Overrides java.io.ObjectOutputStream.writeFloat.

Implements java.io.DataOutput.writeFloat.

Writes a 32-bit float.
public void
writeInt(final int
the integer value to be written
val
)

Overrides java.io.ObjectOutputStream.writeInt.

Implements java.io.DataOutput.writeInt.

Writes a 32-bit int.
public void
writeLong(final long
the long value to be written
val
)

Overrides java.io.ObjectOutputStream.writeLong.

Implements java.io.DataOutput.writeLong.

Writes a 64-bit long.
protected void
writeObjectOverride(final Object
object to be written to the underlying stream
obj
)

Overrides java.io.ObjectOutputStream.writeObjectOverride.

Method used by subclasses to override the default writeObject method.
public void
writeShort(final int
the short value to be written
val
)

Overrides java.io.ObjectOutputStream.writeShort.

Implements java.io.DataOutput.writeShort.

Writes a 16-bit short.
protected final void
writeStreamHeader()

Overrides java.io.ObjectOutputStream.writeStreamHeader.

The writeStreamHeader method is provided so subclasses can append or prepend their own header to the stream.
public void
writeUnshared(final Object
object to write to stream
obj
)

Overrides java.io.ObjectOutputStream.writeUnshared.

Writes an "unshared" object to the ObjectOutputStream.
public void
writeUTF(final String
the String to be written
str
)

Overrides java.io.ObjectOutputStream.writeUTF.

Implements java.io.DataOutput.writeUTF.

Primitive data write of this String in modified UTF-8 format.
Inherited from java.io.ObjectOutputStream:
writeObject

Field Detail

outputback to summary
private final Marshaller output

Constructor Detail

MarshallerObjectOutputStreamback to summary
protected MarshallerObjectOutputStream(final Marshaller output) throws IOException, SecurityException

Construct a new instance that delegates to the given marshaller.

Parameters
output:Marshaller

the delegate marshaller

Exceptions
IOException:
if an I/O error occurs
SecurityException:
if the caller does not have permission to construct an instance of this class

Method Detail

annotateClassback to summary
protected final void annotateClass(final Class<?> cl) throws IOException

Overrides java.io.ObjectOutputStream.annotateClass.

Doc from java.io.ObjectOutputStream.annotateClass.

Subclasses may implement this method to allow class data to be stored in the stream. By default this method does nothing. The corresponding method in ObjectInputStream is resolveClass. This method is called exactly once for each unique class in the stream. The class name and signature will have already been written to the stream. This method may make free use of the ObjectOutputStream to save any representation of the class it deems suitable (for example, the bytes of the class file). The resolveClass method in the corresponding subclass of ObjectInputStream must read and use any data or objects written by annotateClass.

Parameters
cl:Class<?>

the class to annotate custom data for

Exceptions
IOException:
Any exception thrown by the underlying OutputStream.
annotateProxyClassback to summary
protected final void annotateProxyClass(final Class<?> cl) throws IOException

Overrides java.io.ObjectOutputStream.annotateProxyClass.

Doc from java.io.ObjectOutputStream.annotateProxyClass.

Subclasses may implement this method 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.

Parameters
cl:Class<?>

the proxy class to annotate custom data for

Exceptions
IOException:
any exception thrown by the underlying OutputStream
closeback to summary
public final void close() throws IOException

Overrides java.io.ObjectOutputStream.close.

Implements java.io.Closeable.close, java.io.ObjectOutput.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Exceptions
IOException:
if an I/O error occurs
defaultWriteObjectback to summary
public abstract void defaultWriteObject() throws IOException

Overrides java.io.ObjectOutputStream.defaultWriteObject.

Doc from java.io.ObjectOutputStream.defaultWriteObject.

Write the non-static and non-transient fields of the current class to this stream. This may only be called from the writeObject method of the class being serialized. It will throw the NotActiveException if it is called otherwise.

Exceptions
IOException:
if I/O errors occur while writing to the underlying OutputStream
drainback to summary
protected final void drain() throws IOException

Overrides java.io.ObjectOutputStream.drain.

Doc from java.io.ObjectOutputStream.drain.

Drain any buffered data in ObjectOutputStream. Similar to flush but does not propagate the flush to the underlying stream.

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
enableReplaceObjectback to summary
protected final boolean enableReplaceObject(final boolean enable) throws SecurityException

Overrides java.io.ObjectOutputStream.enableReplaceObject.

Doc from java.io.ObjectOutputStream.enableReplaceObject.

Enables the stream to do replacement of objects written to the stream. When enabled, the replaceObject method is called for every object being serialized.

If object replacement is currently not enabled, and enable is true, and there is a security manager installed, this method first calls the security manager's checkPermission method with the SerializablePermission("enableSubstitution") permission to ensure that the caller is permitted to enable the stream to do replacement of objects written to the stream.

Parameters
enable:boolean

true for enabling use of replaceObject for every object being serialized

Returns:boolean

the previous setting before this method was invoked

Exceptions
SecurityException:
if a security manager exists and its checkPermission method denies enabling the stream to do replacement of objects written to the stream.
flushback to summary
public void flush() throws IOException

Overrides java.io.ObjectOutputStream.flush.

Implements java.io.Flushable.flush, java.io.ObjectOutput.flush.

Doc from java.io.Flushable.flush.

Flushes this stream by writing any buffered output to the underlying stream.

Exceptions
IOException:
If an I/O error occurs
putFieldsback to summary
public abstract ObjectOutputStream.PutField putFields() throws IOException

Overrides java.io.ObjectOutputStream.putFields.

Doc from java.io.ObjectOutputStream.putFields.

Retrieve the object used to buffer persistent fields to be written to the stream. The fields will be written to the stream when writeFields method is called.

Returns:ObjectOutputStream.PutField

an instance of the class Putfield that holds the serializable fields

Exceptions
IOException:
if I/O errors occur
replaceObjectback to summary
protected final Object replaceObject(final Object obj) throws IOException

Overrides java.io.ObjectOutputStream.replaceObject.

Doc from java.io.ObjectOutputStream.replaceObject.

This method will allow trusted subclasses of ObjectOutputStream to substitute one object for another during serialization. Replacing objects is disabled until enableReplaceObject is called. The enableReplaceObject method checks that the stream requesting to do replacement can be trusted. The first occurrence of each object written into the serialization stream is passed to replaceObject. Subsequent references to the object are replaced by the object returned by the original call to replaceObject. To ensure that the private state of objects is not unintentionally exposed, only trusted streams may use replaceObject.

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 ensure 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 NullPointerException in classes that contain references to the original object since they may be expecting an object instead of null.

Parameters
obj:Object

the object to be replaced

Returns:Object

the alternate object that replaced the specified one

Exceptions
IOException:
Any exception thrown by the underlying OutputStream.
resetback to summary
public final void reset() throws IOException

Overrides java.io.ObjectOutputStream.reset.

Doc from java.io.ObjectOutputStream.reset.

Reset will disregard the state of any objects already written to the stream. The state is reset to be the same as a new ObjectOutputStream. The current point in the stream is marked as reset so the corresponding ObjectInputStream will be reset at the same point. Objects previously written to the stream will not be referred to as already being in the stream. They will be written to the stream again.

Exceptions
IOException:
if reset() is invoked while serializing an object.
useProtocolVersionback to summary
public final void useProtocolVersion(final int version) throws IOException

Overrides java.io.ObjectOutputStream.useProtocolVersion.

Doc from java.io.ObjectOutputStream.useProtocolVersion.

Specify stream protocol version to use when writing the stream.

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.

Parameters
version:int

use ProtocolVersion from java.io.ObjectStreamConstants.

Exceptions
IOException:
if I/O errors occur
writeback to summary
public void write(final int val) throws IOException

Overrides java.io.ObjectOutputStream.write.

Implements org.jboss.marshalling.ByteOutput.write, java.io.ObjectOutput.write.

Doc from org.jboss.marshalling.ByteOutput.write.

Writes to the output stream the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
val:int

the byte to write

Exceptions
IOException:
if an error occurs
writeback to summary
public void write(final byte[] buf) throws IOException

Overrides java.io.ObjectOutputStream.write.

Implements org.jboss.marshalling.ByteOutput.write, java.io.ObjectOutput.write.

Doc from org.jboss.marshalling.ByteOutput.write.

Write all the bytes from the given array to the stream.

Parameters
buf:byte[]

the byte array

Exceptions
IOException:
if an error occurs
writeback to summary
public void write(final byte[] buf, final int off, final int len) throws IOException

Overrides java.io.ObjectOutputStream.write.

Implements org.jboss.marshalling.ByteOutput.write, java.io.ObjectOutput.write.

Doc from org.jboss.marshalling.ByteOutput.write.

Write some of the bytes from the given array to the stream.

Parameters
buf:byte[]

the byte array

off:int

the index to start writing from

len:int

the number of bytes to write

Exceptions
IOException:
if an error occurs
writeBooleanback to summary
public void writeBoolean(final boolean val) throws IOException

Overrides java.io.ObjectOutputStream.writeBoolean.

Implements java.io.DataOutput.writeBoolean.

Doc from java.io.ObjectOutputStream.writeBoolean.

Writes a boolean.

Parameters
val:boolean

the boolean to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeByteback to summary
public void writeByte(final int val) throws IOException

Overrides java.io.ObjectOutputStream.writeByte.

Implements java.io.DataOutput.writeByte.

Doc from java.io.ObjectOutputStream.writeByte.

Writes an 8-bit byte.

Parameters
val:int

the byte value to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeBytesback to summary
public void writeBytes(final String str) throws IOException

Overrides java.io.ObjectOutputStream.writeBytes.

Implements java.io.DataOutput.writeBytes.

Doc from java.io.ObjectOutputStream.writeBytes.

Writes a String as a sequence of bytes.

Parameters
str:String

the String of bytes to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeCharback to summary
public void writeChar(final int val) throws IOException

Overrides java.io.ObjectOutputStream.writeChar.

Implements java.io.DataOutput.writeChar.

Doc from java.io.ObjectOutputStream.writeChar.

Writes a 16-bit char.

Parameters
val:int

the char value to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeCharsback to summary
public void writeChars(final String str) throws IOException

Overrides java.io.ObjectOutputStream.writeChars.

Implements java.io.DataOutput.writeChars.

Doc from java.io.ObjectOutputStream.writeChars.

Writes a String as a sequence of chars.

Parameters
str:String

the String of chars to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeClassDescriptorback to summary
protected final void writeClassDescriptor(final ObjectStreamClass desc) throws IOException

Overrides java.io.ObjectOutputStream.writeClassDescriptor.

Doc from java.io.ObjectOutputStream.writeClassDescriptor.

Write the specified class descriptor to the ObjectOutputStream. Class descriptors are used to identify the classes of objects written to the stream. Subclasses of ObjectOutputStream may override this method to customize the way in which class descriptors are written to the serialization stream. The corresponding method in ObjectInputStream, 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 Java 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.

Parameters
desc:ObjectStreamClass

class descriptor to write to the stream

Exceptions
IOException:
If an I/O error has occurred.
writeDoubleback to summary
public void writeDouble(final double val) throws IOException

Overrides java.io.ObjectOutputStream.writeDouble.

Implements java.io.DataOutput.writeDouble.

Doc from java.io.ObjectOutputStream.writeDouble.

Writes a 64-bit double.

Parameters
val:double

the double value to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeFieldsback to summary
public abstract void writeFields() throws IOException

Overrides java.io.ObjectOutputStream.writeFields.

Doc from java.io.ObjectOutputStream.writeFields.

Write the buffered fields to the stream.

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeFloatback to summary
public void writeFloat(final float val) throws IOException

Overrides java.io.ObjectOutputStream.writeFloat.

Implements java.io.DataOutput.writeFloat.

Doc from java.io.ObjectOutputStream.writeFloat.

Writes a 32-bit float.

Parameters
val:float

the float value to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeIntback to summary
public void writeInt(final int val) throws IOException

Overrides java.io.ObjectOutputStream.writeInt.

Implements java.io.DataOutput.writeInt.

Doc from java.io.ObjectOutputStream.writeInt.

Writes a 32-bit int.

Parameters
val:int

the integer value to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeLongback to summary
public void writeLong(final long val) throws IOException

Overrides java.io.ObjectOutputStream.writeLong.

Implements java.io.DataOutput.writeLong.

Doc from java.io.ObjectOutputStream.writeLong.

Writes a 64-bit long.

Parameters
val:long

the long value to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeObjectOverrideback to summary
protected void writeObjectOverride(final Object obj) throws IOException

Overrides java.io.ObjectOutputStream.writeObjectOverride.

Doc from java.io.ObjectOutputStream.writeObjectOverride.

Method used by subclasses to override the default writeObject method. This method is called by trusted subclasses of ObjectOutputStream that constructed ObjectOutputStream using the protected no-arg constructor. The subclass is expected to provide an override method with the modifier "final".

Parameters
obj:Object

object to be written to the underlying stream

Exceptions
IOException:
if there are I/O errors while writing to the underlying stream
writeShortback to summary
public void writeShort(final int val) throws IOException

Overrides java.io.ObjectOutputStream.writeShort.

Implements java.io.DataOutput.writeShort.

Doc from java.io.ObjectOutputStream.writeShort.

Writes a 16-bit short.

Parameters
val:int

the short value to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeStreamHeaderback to summary
protected final void writeStreamHeader() throws IOException

Overrides java.io.ObjectOutputStream.writeStreamHeader.

Doc from java.io.ObjectOutputStream.writeStreamHeader.

The writeStreamHeader method is provided so subclasses can append or prepend their own header to the stream. It writes the magic number and version to the stream.

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
writeUnsharedback to summary
public void writeUnshared(final Object obj) throws IOException

Overrides java.io.ObjectOutputStream.writeUnshared.

Doc from java.io.ObjectOutputStream.writeUnshared.

Writes an "unshared" object to the ObjectOutputStream. This method is identical to writeObject, except that it always writes the given object as a new, unique object in the stream (as opposed to a back-reference pointing to a previously serialized instance). Specifically:

  • An object written via writeUnshared is always serialized in the same manner as a newly appearing object (an object that has not been written to the stream yet), regardless of whether or not the object has been written previously.
  • If writeObject is used to write an object that has been previously written with writeUnshared, the previous writeUnshared operation is treated as if it were a write of a separate object. In other words, ObjectOutputStream will never generate back-references to object data written by calls to writeUnshared.
While writing an object via writeUnshared does not in itself guarantee a unique reference to the object when it is deserialized, it allows a single object to be defined multiple times in a stream, so that multiple calls to readUnshared by the receiver will not conflict. Note that the rules described above only apply to the base-level object written with writeUnshared, and not to any transitively referenced sub-objects in the object graph to be serialized.

ObjectOutputStream subclasses which override this method can only be constructed in security contexts possessing the "enableSubclassImplementation" SerializablePermission; any attempt to instantiate such a subclass without this permission will cause a SecurityException to be thrown.

Parameters
obj:Object

object to write to stream

Exceptions
IOException:
if an I/O error occurs during serialization
writeUTFback to summary
public void writeUTF(final String str) throws IOException

Overrides java.io.ObjectOutputStream.writeUTF.

Implements java.io.DataOutput.writeUTF.

Doc from java.io.ObjectOutputStream.writeUTF.

Primitive data write of this String in modified UTF-8 format. Note that there is a significant difference between writing a String into the stream as primitive data or as an Object. A String instance written by writeObject is written into the stream as a String initially. Future writeObject() calls write references to the string into the stream.

Parameters
str:String

the String to be written

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream