- java.lang.Object
-
- com.aoapps.lang.io.FastObjectOutput
-
- All Implemented Interfaces:
DataOutput,ObjectOutput,AutoCloseable
public class FastObjectOutput extends Object implements ObjectOutput
Utilities to writeFastExternalizable,Externalizable, andSerializableobjects.When multiple objects are being written, this avoids the repetitive writing of classnames and serialVersionUIDs.
- Author:
- AO Industries, Inc.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()voidunwrap()Unwraps the object output.static FastObjectOutputwrap(ObjectOutput out)Gets the wrapper for the providedObjectOutput, creating if needed.voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteBytes(String s)voidwriteChar(int v)voidwriteChars(String s)voidwriteDouble(double v)protected voidwriteFastObject(FastExternalizable obj)Writes aFastExternalizableobject to the provided stream, supportingnullvalues.voidwriteFastUTF(String value)Writes aStringto the output, not writing any duplicates.voidwriteFloat(float v)voidwriteInt(int v)voidwriteLong(long v)voidwriteObject(Object obj)Writes the provided object in the most efficient manner possible, with no object graph tracking (if possible).voidwriteShort(int v)voidwriteUTF(String s)
-
-
-
Method Detail
-
wrap
public static FastObjectOutput wrap(ObjectOutput out) throws IOException
Gets the wrapper for the providedObjectOutput, creating if needed. To avoid memory leaks, it must also beunwrappedin a finally block.TODO: Can
FastObjectOutputitself implementAutoCloseableforunwrap()? Maybe this means it no longer implementsObjectOutputdirectly?- Throws:
IOException
-
unwrap
public void unwrap() throws IllegalStateExceptionUnwraps the object output.- Throws:
IllegalStateException- if not wrapped
-
writeObject
public void writeObject(Object obj) throws IOException
Writes the provided object in the most efficient manner possible, with no object graph tracking (if possible). This allows individual objects to switch betweenFastExternalizableand standard serialization without calling code needing to know the difference.If the object is
null, writes a single byte ofNULL.If the object is
FastExternalizable, callswriteFastObject(com.aoapps.lang.io.FastExternalizable).Otherwise, writes
STANDARDand then uses standard Java serialization.- Specified by:
writeObjectin interfaceObjectOutput- Throws:
IOException- See Also:
FastObjectInput.readObject()
-
writeFastObject
protected void writeFastObject(FastExternalizable obj) throws IOException
Writes aFastExternalizableobject to the provided stream, supportingnullvalues.- Throws:
IOException- See Also:
FastObjectInput.readFastObject(int)
-
writeFastUTF
public void writeFastUTF(String value) throws IOException
Writes aStringto the output, not writing any duplicates. Supportsnull.TODO: Any benefit to string prefix compression, like in CompressedDataOutput?
- Throws:
IOException
-
write
public void write(int b) throws IOException- Specified by:
writein interfaceDataOutput- Specified by:
writein interfaceObjectOutput- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Specified by:
writein interfaceDataOutput- Specified by:
writein interfaceObjectOutput- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Specified by:
writein interfaceDataOutput- Specified by:
writein interfaceObjectOutput- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceObjectOutput- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceObjectOutput- Throws:
IOException
-
writeBoolean
public void writeBoolean(boolean v) throws IOException- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
public void writeByte(int v) throws IOException- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeShort
public void writeShort(int v) throws IOException- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeChar
public void writeChar(int v) throws IOException- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeInt
public void writeInt(int v) throws IOException- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
public void writeLong(long v) throws IOException- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeFloat
public void writeFloat(float v) throws IOException- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeDouble
public void writeDouble(double v) throws IOException- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeBytes
public void writeBytes(String s) throws IOException
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeUTF
public void writeUTF(String s) throws IOException
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
-