Top Inners Fields Constructors Methods
com.thoughtworks.xstream.core.util

public Class CustomObjectOutputStream

extends ObjectOutputStream
Class Inheritance
Imports
java.io.IOException, .ObjectOutput, .ObjectOutputStream, java.util.Map, com.thoughtworks.xstream.converters.DataHolder, com.thoughtworks.xstream.converters.reflection.ObjectAccessException, com.thoughtworks.xstream.io.StreamException

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
public static interface

Field Summary

Modifier and TypeField and Description
private FastStack
private FastStack
private static final String

Constructor Summary

AccessConstructor and Description
public
CustomObjectOutputStream(CustomObjectOutputStream.StreamCallback callback)

Warning, this object is expensive to create (due to functionality inherited from superclass).

Method Summary

Modifier and TypeMethod and Description
public void
public void
defaultWriteObject()

Overrides java.io.ObjectOutputStream.defaultWriteObject.

Methods to delegate to callback
public void
public static synchronized CustomObjectOutputStream
public CustomObjectOutputStream.StreamCallback
public CustomObjectOutputStream.StreamCallback
public void
pushCallback(CustomObjectOutputStream.StreamCallback callback)

Allows the CustomObjectOutputStream (which is expensive to create) to be reused.

public ObjectOutputStream.PutField
putFields()

Overrides java.io.ObjectOutputStream.putFields.

Retrieve the object used to buffer persistent fields to be written to the stream.
public void
reset()

Overrides java.io.ObjectOutputStream.reset.

Unsupported methods
public void
useProtocolVersion(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(byte[]
the data to be written
buf
)

Overrides java.io.ObjectOutputStream.write.

Implements java.io.ObjectOutput.write.

Writes an array of bytes.
public void
write(int
the byte to be written to the stream
val
)

Overrides java.io.ObjectOutputStream.write.

Implements java.io.ObjectOutput.write.

Writes a byte.
public void
write(byte[]
the data to be written
buf
,
int
the start offset in the data
off
,
int
the number of bytes that are written
len
)

Overrides java.io.ObjectOutputStream.write.

Implements java.io.ObjectOutput.write.

Writes a sub array of bytes.
public void
writeBoolean(boolean
the boolean to be written
val
)

Overrides java.io.ObjectOutputStream.writeBoolean.

Implements java.io.DataOutput.writeBoolean.

Writes a boolean.
public void
writeByte(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(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(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(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.
public void
writeDouble(double
the double value to be written
val
)

Overrides java.io.ObjectOutputStream.writeDouble.

Implements java.io.DataOutput.writeDouble.

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

Overrides java.io.ObjectOutputStream.writeFields.

Write the buffered fields to the stream.
public void
writeFloat(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(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(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(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(int
the short value to be written
val
)

Overrides java.io.ObjectOutputStream.writeShort.

Implements java.io.DataOutput.writeShort.

Writes a 16-bit short.
public void
writeUnshared(Object
object to write to stream
obj
)

Overrides java.io.ObjectOutputStream.writeUnshared.

Writes an "unshared" object to the ObjectOutputStream.
public void
writeUTF(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:
annotateClassannotateProxyClassdrainenableReplaceObjectreplaceObjectwriteClassDescriptorwriteObjectwriteStreamHeader

Field Detail

callbacksback to summary
private FastStack callbacks
customFieldsback to summary
private FastStack customFields
DATA_HOLDER_KEYback to summary
private static final String DATA_HOLDER_KEY

Constructor Detail

CustomObjectOutputStreamback to summary
public CustomObjectOutputStream(CustomObjectOutputStream.StreamCallback callback) throws IOException, SecurityException

Warning, this object is expensive to create (due to functionality inherited from superclass). Use the static fetch() method instead, wherever possible.

See Also
getInstance(com.thoughtworks.xstream.converters.DataHolder, com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.ObjectOutputStream.close.

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

Doc from java.io.ObjectOutputStream.close.

Closes the stream. This method must be called to release any resources associated with the stream.

Exceptions
IOException:
If an I/O error has occurred.
defaultWriteObjectback to summary
public void defaultWriteObject() throws IOException

Overrides java.io.ObjectOutputStream.defaultWriteObject.

Methods to delegate to callback

Exceptions
IOException:

Doc from java.io.ObjectOutputStream.defaultWriteObject.

if I/O errors occur while writing to the underlying OutputStream

flushback to summary
public void flush() throws IOException

Overrides java.io.ObjectOutputStream.flush.

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

Doc from java.io.ObjectOutputStream.flush.

Flushes the stream. This will write any buffered output bytes and flush through to the underlying stream.

Exceptions
IOException:
If an I/O error has occurred.
getInstanceback to summary
public static synchronized CustomObjectOutputStream getInstance(DataHolder whereFrom, CustomObjectOutputStream.StreamCallback callback)
peekCallbackback to summary
public CustomObjectOutputStream.StreamCallback peekCallback()
popCallbackback to summary
public CustomObjectOutputStream.StreamCallback popCallback()
pushCallbackback to summary
public void pushCallback(CustomObjectOutputStream.StreamCallback callback)

Allows the CustomObjectOutputStream (which is expensive to create) to be reused.

putFieldsback to summary
public ObjectOutputStream.PutField putFields()

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

resetback to summary
public void reset()

Overrides java.io.ObjectOutputStream.reset.

Unsupported methods

useProtocolVersionback to summary
public void useProtocolVersion(int version)

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.

writeback to summary
public void write(byte[] buf) throws IOException

Overrides java.io.ObjectOutputStream.write.

Implements java.io.ObjectOutput.write.

Doc from java.io.ObjectOutputStream.write.

Writes an array of bytes. This method will block until the bytes are actually written.

Parameters
buf:byte[]

the data to be written

Exceptions
IOException:
If an I/O error has occurred.
writeback to summary
public void write(int val) throws IOException

Overrides java.io.ObjectOutputStream.write.

Implements java.io.ObjectOutput.write.

Doc from java.io.ObjectOutputStream.write.

Writes a byte. This method will block until the byte is actually written.

Parameters
val:int

the byte to be written to the stream

Exceptions
IOException:
If an I/O error has occurred.
writeback to summary
public void write(byte[] buf, int off, int len) throws IOException

Overrides java.io.ObjectOutputStream.write.

Implements java.io.ObjectOutput.write.

Doc from java.io.ObjectOutputStream.write.

Writes a sub array of bytes.

Parameters
buf:byte[]

the data to be written

off:int

the start offset in the data

len:int

the number of bytes that are written

Exceptions
IOException:
If an I/O error has occurred.
writeBooleanback to summary
public void writeBoolean(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(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(String str)

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

writeCharback to summary
public void writeChar(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(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
writeDoubleback to summary
public void writeDouble(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 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(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(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(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(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(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
writeUnsharedback to summary
public void writeUnshared(Object obj)

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

writeUTFback to summary
public void writeUTF(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
com.thoughtworks.xstream.core.util back to summary

private Class CustomObjectOutputStream.CustomPutField

extends PutField
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Map<K, V>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Map<K, V>
public void
put(String
the name of the serializable field
name
,
Object
the value to assign to the field (which may be null)
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named Object field into the persistent field.
public void
put(String
the name of the serializable field
name
,
byte
the value to assign to the field
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named byte field into the persistent field.
public void
put(String
the name of the serializable field
name
,
char
the value to assign to the field
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named char field into the persistent field.
public void
put(String
the name of the serializable field
name
,
double
the value to assign to the field
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named double field into the persistent field.
public void
put(String
the name of the serializable field
name
,
float
the value to assign to the field
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named float field into the persistent field.
public void
put(String
the name of the serializable field
name
,
int
the value to assign to the field
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named int field into the persistent field.
public void
put(String
the name of the serializable field
name
,
long
the value to assign to the field
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named long field into the persistent field.
public void
put(String
the name of the serializable field
name
,
short
the value to assign to the field
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named short field into the persistent field.
public void
put(String
the name of the serializable field
name
,
boolean
the value to assign to the field
val
)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Put the value of the named boolean field into the persistent field.
public void
write(ObjectOutput
the stream to write the data and fields to
out
)

Implements abstract java.io.ObjectOutputStream.PutField.write.

Write the data and fields to the specified ObjectOutput stream, which must be the same stream that produced this PutField object.

Field Detail

fieldsback to summary
private final Map<K, V> fields

Constructor Detail

CustomPutFieldback to summary
private CustomPutField()

Method Detail

asMapback to summary
public Map<K, V> asMap()
putback to summary
public void put(String name, Object val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named Object field into the persistent field.

Parameters
name:String

the name of the serializable field

val:Object

the value to assign to the field (which may be null)

putback to summary
public void put(String name, byte val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named byte field into the persistent field.

Parameters
name:String

the name of the serializable field

val:byte

the value to assign to the field

putback to summary
public void put(String name, char val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named char field into the persistent field.

Parameters
name:String

the name of the serializable field

val:char

the value to assign to the field

putback to summary
public void put(String name, double val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named double field into the persistent field.

Parameters
name:String

the name of the serializable field

val:double

the value to assign to the field

putback to summary
public void put(String name, float val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named float field into the persistent field.

Parameters
name:String

the name of the serializable field

val:float

the value to assign to the field

putback to summary
public void put(String name, int val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named int field into the persistent field.

Parameters
name:String

the name of the serializable field

val:int

the value to assign to the field

putback to summary
public void put(String name, long val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named long field into the persistent field.

Parameters
name:String

the name of the serializable field

val:long

the value to assign to the field

putback to summary
public void put(String name, short val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named short field into the persistent field.

Parameters
name:String

the name of the serializable field

val:short

the value to assign to the field

putback to summary
public void put(String name, boolean val)

Implements abstract java.io.ObjectOutputStream.PutField.put.

Doc from java.io.ObjectOutputStream.PutField.put.

Put the value of the named boolean field into the persistent field.

Parameters
name:String

the name of the serializable field

val:boolean

the value to assign to the field

writeback to summary
public void write(ObjectOutput out) throws IOException

Implements abstract java.io.ObjectOutputStream.PutField.write.

Doc from java.io.ObjectOutputStream.PutField.write.

Write the data and fields to the specified ObjectOutput stream, which must be the same stream that produced this PutField object.

Parameters
out:ObjectOutput

the stream to write the data and fields to

Exceptions
IOException:
if I/O errors occur while writing to the underlying stream
com.thoughtworks.xstream.core.util back to summary

public Interface CustomObjectOutputStream.StreamCallback


Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
writeFieldsToStream(Map<K, V> fields)

public void

Method Detail

closeback to summary
public void close() throws IOException
defaultWriteObjectback to summary
public void defaultWriteObject() throws IOException
flushback to summary
public void flush() throws IOException
writeFieldsToStreamback to summary
public void writeFieldsToStream(Map<K, V> fields) throws IOException
writeToStreamback to summary
public void writeToStream(Object object) throws IOException