Package dev.gmitch215.bytebox.io
Class ObjectInputStream
java.lang.Object
dev.gmitch215.bytebox.io.ObjectInputStream
- All Implemented Interfaces:
AutoCloseable
Reads objects in Java's serialization format, standing in for
java.io.ObjectInputStream.
Reads what a JVM wrote. readObject(java.lang.Class<T>) takes the whole stream, because the format's handle
table belongs to one stream and a partial read cannot know where the object ends.
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(wire))) {
Order order = in.readObject(Order.class);
}
readObject() with no type is here for a caller that has to look like a JVM's. It answers
Object, which a caller then casts, and the cast is unchecked on this platform because there
is no class metadata behind it to check against. readObject(Class) is the one to use.
- Since:
- 1.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Reads the object without naming its type.<T> TreadObject(Class<T> type) Reads the object.
-
Constructor Details
-
ObjectInputStream
- Parameters:
in- where the bytes come from
-
-
Method Details
-
readObject
Reads the object.- Type Parameters:
T- the type- Parameters:
type- what to read- Returns:
- the object
- Throws:
IOException- if the underlying stream cannot be readSerialException- if the stream is malformed or names a type with no codec
-
readObject
Reads the object without naming its type.- Returns:
- the object
- Throws:
IOException- if the underlying stream cannot be readSerialException- if the stream is malformed or names a type with no codec
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-