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 ...
Get Java I/O now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.