Class ObjectInputStream

java.lang.Object
dev.gmitch215.bytebox.io.ObjectInputStream
All Implemented Interfaces:
AutoCloseable

public class ObjectInputStream extends Object implements 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 Details

    • ObjectInputStream

      public ObjectInputStream(InputStream in)
      Parameters:
      in - where the bytes come from
  • Method Details

    • readObject

      public <T> T readObject(Class<T> type) throws IOException
      Reads the object.
      Type Parameters:
      T - the type
      Parameters:
      type - what to read
      Returns:
      the object
      Throws:
      IOException - if the underlying stream cannot be read
      SerialException - if the stream is malformed or names a type with no codec
    • readObject

      public Object readObject() throws IOException
      Reads the object without naming its type.
      Returns:
      the object
      Throws:
      IOException - if the underlying stream cannot be read
      SerialException - if the stream is malformed or names a type with no codec
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException