Package dev.gmitch215.bytebox.io
Class ObjectOutputStream
java.lang.Object
dev.gmitch215.bytebox.io.ObjectOutputStream
- All Implemented Interfaces:
AutoCloseable
Writes objects in Java's serialization format, standing in for
java.io.ObjectOutputStream.
The compiler substitutes the class library's for this one, which the class library does not have at all, so a library that serialises the ordinary way works unchanged.
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try (ObjectOutputStream out = new ObjectOutputStream(bytes)) {
out.writeObject(new Order("abc", 2, 3L));
}
One object per stream. A JVM writes a header once and then any number of objects, sharing the
handle table between them; here each writeObject(java.lang.Object) is a complete stream, so writing twice
throws rather than producing bytes a reader would misread.
Every type written needs a codec, which the build writes for anything annotated
SerialType. Serial is the same thing without a stream in the way.
- Since:
- 1.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()Flushes the underlying stream.voidwriteObject(Object value) Writes an object.
-
Constructor Details
-
ObjectOutputStream
- Parameters:
out- where the bytes go
-
-
Method Details
-
writeObject
Writes an object.- Parameters:
value- the object, which may benull- Throws:
IOException- if the underlying stream refuses the bytesSerialException- if the object, or anything it holds, has no codec
-
flush
Flushes the underlying stream.- Throws:
IOException- if the underlying stream refuses
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-