- java.lang.Object
-
- com.aoapps.lang.io.FastObjectInput
-
- All Implemented Interfaces:
DataInput,ObjectInput,AutoCloseable
public class FastObjectInput extends Object implements ObjectInput
Utilities to readFastExternalizable,Externalizable, andSerializableobjects.When multiple objects are being written, this avoids the repetitive writing of classnames and serialVersionUIDs.
Any object that is
ObjectInputValidationis validated immediately - there is no need and no mechanism to register the validation since this is for simple value objects that don't participate in more complex object graphs.- Author:
- AO Industries, Inc.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()intread()intread(byte[] b)intread(byte[] b, int off, int len)booleanreadBoolean()bytereadByte()charreadChar()doublereadDouble()protected FastExternalizablereadFastObject()Reads aFastExternalizableobject from the stream.StringreadFastUTF()Reads a fast serializedStringfrom the stream.floatreadFloat()voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)intreadInt()StringreadLine()longreadLong()ObjectreadObject()Reads a possibly-FastExternalizableobject from the stream.shortreadShort()intreadUnsignedByte()intreadUnsignedShort()StringreadUTF()longskip(long n)intskipBytes(int n)voidunwrap()Unwraps the object input.static FastObjectInputwrap(ObjectInput in)Gets the wrapper for the providedObjectInput, creating if needed.
-
-
-
Method Detail
-
wrap
public static FastObjectInput wrap(ObjectInput in) throws IOException
Gets the wrapper for the providedObjectInput, creating if needed. To avoid memory leaks, it must also beunwrappedin a finally block.TODO: Can
FastObjectInputitself implementAutoCloseableforunwrap()? Maybe this means it no longer implementsObjectInputdirectly?- Throws:
IOException
-
unwrap
public void unwrap() throws IllegalStateExceptionUnwraps the object input.- Throws:
IllegalStateException- if not wrapped
-
readObject
public Object readObject() throws IOException, ClassNotFoundException
Reads a possibly-FastExternalizableobject from the stream.- Specified by:
readObjectin interfaceObjectInput- Throws:
IOExceptionClassNotFoundException- See Also:
FastObjectOutput.writeObject(java.lang.Object)
-
readFastObject
protected FastExternalizable readFastObject() throws IOException, ClassNotFoundException
Reads aFastExternalizableobject from the stream.
-
readFastUTF
public String readFastUTF() throws IOException
Reads a fast serializedStringfrom the stream.- Throws:
IOException- See Also:
FastObjectOutput.writeFastUTF(java.lang.String)
-
read
public int read() throws IOException- Specified by:
readin interfaceObjectInput- Throws:
IOException
-
read
public int read(byte[] b) throws IOException- Specified by:
readin interfaceObjectInput- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Specified by:
readin interfaceObjectInput- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Specified by:
skipin interfaceObjectInput- Throws:
IOException
-
available
public int available() throws IOException- Specified by:
availablein interfaceObjectInput- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceObjectInput- Throws:
IOException
-
readFully
public void readFully(byte[] b) throws IOException- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException- Specified by:
skipBytesin interfaceDataInput- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOException- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
readByte
public byte readByte() throws IOException- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readUnsignedByte
public int readUnsignedByte() throws IOException- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readShort
public short readShort() throws IOException- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readUnsignedShort
public int readUnsignedShort() throws IOException- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readChar
public char readChar() throws IOException- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readInt
public int readInt() throws IOException- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readLong
public long readLong() throws IOException- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readFloat
public float readFloat() throws IOException- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readDouble
public double readDouble() throws IOException- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readUTF
public String readUTF() throws IOException
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
-