The ObjectInput and ObjectOutput Interfaces
As well as the ObjectInputStream and
ObjectOutputStream classes, the
java.io package also provides
ObjectInput
and ObjectOutput
interfaces:
public interface ObjectInput extends DataInput public interface ObjectOutput extends DataOutput
These interfaces are not much used in Java 1.1 and 2. The only
classes in the core API that actually implement them are
ObjectInputStream and
ObjectOutputStream. However, several methods used
for customization of the serialization process are declared to accept
ObjectInput or ObjectOutput
objects as arguments, rather than specifically
ObjectInputStream or
ObjectOutputStream objects. This provides a little
wiggle room for Java to grow in unforeseen ways.
The ObjectInput interface declares seven methods,
all of which ObjectInputStream faithfully
implements:
public abstract Object readObject() throws ClassNotFoundException, IOException public abstract int read() throws IOException public abstract int read(byte[] data) throws IOException public abstract int read(byte[] data, int offset, int length) throws IOException public abstract long skip(long n) throws IOException public abstract int available() throws IOException public abstract void close() throws IOException
The readObject() method has already been discussed
in the context of object input streams. The other six methods behave
exactly as they do for all input streams. In fact, at first glance,
all these methods except readObject() appear superfluous, since ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access