Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.io.InputStream
java.io.ObjectInputStream
Nested Class Summary | |
static class |
|
Constructor Summary | |
| |
|
Method Summary | |
int |
|
void |
|
void |
|
protected boolean |
|
int |
|
int |
|
boolean |
|
byte |
|
char |
|
protected ObjectStreamClass |
|
double |
|
ObjectInputStream.GetField |
|
float |
|
void |
|
void |
|
int |
|
String |
|
long |
|
Object |
|
protected Object |
|
short |
|
protected void |
|
String |
|
Object |
|
int |
|
int |
|
void |
|
protected Class> |
|
protected Object |
|
protected Class> |
|
int |
|
Methods inherited from class java.io.InputStream | |
available , close , mark , markSupported , read , read , read , reset , skip |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected ObjectInputStream() throws IOException, SecurityException
Protected constructor that allows subclasses to override deserialization. This constructor should be called by subclasses that wish to overridereadObject (Object)
. This method does a security check NOTE: currently not implemented, then sets a flag that informsreadObject (Object)
to call the subclassesreadObjectOverride (Object)
method.
- See Also:
readObjectOverride()
public ObjectInputStream(InputStream in) throws IOException, StreamCorruptedException
Creates a newObjectInputStream
that will do all of its reading fromin
. This method also checks the stream by reading the header information (stream magic number and stream version).
- Throws:
IOException
- Reading stream header from underlying stream cannot be completed.StreamCorruptedException
- An invalid stream magic number or stream version was read from the stream.
- See Also:
readStreamHeader()
public int available() throws IOException
This method returns the number of bytes that can be read without blocking.
- Specified by:
- available in interface ObjectInput
- Overrides:
- available in interface InputStream
- Returns:
- The number of bytes available before blocking
- Throws:
IOException
- If an error occurs
public void close() throws IOException
This method closes the input source
- Specified by:
- close in interface ObjectInput
- close in interface AutoCloseable
- close in interface Closeable
- Overrides:
- close in interface InputStream
- Throws:
IOException
- If an error occurs
public void defaultReadObject() throws ClassNotFoundException, IOException, NotActiveException
Reads the current objects non-transient, non-static fields from the current class from the underlying output stream. This method is intended to be called from within a object'sprivate void readObject (ObjectInputStream)
method.
- Throws:
ClassNotFoundException
- The class that an object being read in belongs to cannot be found.NotActiveException
- This method was called from a context other than from the current object's and current class'sprivate void readObject (ObjectInputStream)
method.IOException
- Exception from underlyingOutputStream
.
protected boolean enableResolveObject(boolean enable) throws SecurityException
Ifenable
istrue
and this object is trusted, thenresolveObject (Object)
will be called in subsequent calls toreadObject (Object)
. Otherwise,resolveObject (Object)
will not be called.
- Throws:
SecurityException
- This class is not trusted.
public int read() throws IOException
This method reading a byte of data from a stream. It returns that byte as anint
. This method blocks if no data is available to be read.
- Specified by:
- read in interface ObjectInput
- Overrides:
- read in interface InputStream
- Returns:
- The byte of data read
- Throws:
IOException
- If an error occurs
public int read(byte[] data, int offset, int length) throws IOException
This method reads raw bytes and stores them in a byte array bufferbuf
starting at positionoffset
into the buffer. A maximum oflen
bytes will be read. Note that this method blocks if no data is available, but will not necessarily block until it can readlen
bytes of data. That is, a "short count" is possible.
- Specified by:
- read in interface ObjectInput
- Overrides:
- read in interface InputStream
- Parameters:
offset
- The offset intobuf
to start storing data
- Returns:
- The actual number of bytes read or -1 if end of stream
- Throws:
IOException
- If an error occurs
public boolean readBoolean() throws IOException
This method reads a Java boolean value from an input stream. It does so by reading a single byte of data. If that byte is zero, then the value returned isfalse
. If the byte is non-zero, then the value returned istrue
. This method can read aboolean
written by an object implementing thewriteBoolean()
method in theDataOutput
interface.
- Specified by:
- readBoolean in interface DataInput
- Returns:
- The
boolean
value read
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeBoolean(boolean)
public byte readByte() throws IOException
This method reads a Java byte value from an input stream. The value is in the range of -128 to 127. This method can read abyte
written by an object implementing thewriteByte()
method in theDataOutput
interface.
- Returns:
- The
byte
value read
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeByte(int)
public char readChar() throws IOException
This method reads a Javachar
value from an input stream. It operates by reading two bytes from the stream and converting them to a single 16-bit Javachar
. The two bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering. As an example, ifbyte1
andbyte2
represent the first and second byte read from the stream respectively, they will be transformed to achar
in the following manner:(char)((byte1 << 8) + byte2)
This method can read achar
written by an object implementing thewriteChar()
method in theDataOutput
interface.
- Returns:
- The
char
value read
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeChar(int)
protected ObjectStreamClass readClassDescriptor() throws ClassNotFoundException, IOException
This method reads a class descriptor from the real input stream and use these data to create a new instance of ObjectStreamClass. Fields are sorted and ordered for the real read which occurs for each instance of the described class. Be aware that if you call that method you must ensure that the stream is synchronized, in the other case it may be completely desynchronized.
- Returns:
- A new instance of ObjectStreamClass containing the freshly created descriptor.
- Throws:
ClassNotFoundException
- if the required class to build the descriptor has not been found in the system.IOException
- An input/output error occured.
public double readDouble() throws IOException
This method reads a Java double value from an input stream. It operates by first reading along
value from the stream by calling thereadLong()
method in this interface, then converts thatlong
to adouble
using thelongBitsToDouble
method in the classjava.lang.Double
. This method can read adouble
written by an object implementing thewriteDouble()
method in theDataOutput
interface.
- Specified by:
- readDouble in interface DataInput
- Returns:
- The
double
value read
- Throws:
IOException
- If any other error occurs
public ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException, NotActiveException
This method should be called by a method called 'readObject' in the deserializing class (if present). It cannot (and should not)be called outside of it. Its goal is to read all fields in the real input stream and keep them accessible through theObjectInputStream.GetField
class. Calling this method will not alter the deserializing object.
- Returns:
- A valid freshly created 'GetField' instance to get access to the deserialized stream.
- Throws:
IOException
- An input/output exception occured.ClassNotFoundException
-NotActiveException
-
public float readFloat() throws IOException
This method reads a Java float value from an input stream. It operates by first reading anint
value from the stream by calling thereadInt()
method in this interface, then converts thatint
to afloat
using theintBitsToFloat
method in the classjava.lang.Float
. This method can read afloat
written by an object implementing thewriteFloat()
method in theDataOutput
interface.
- Returns:
- The
float
value read
- Throws:
IOException
- If any other error occurs
public int readInt() throws IOException
This method reads a Javaint
value from an input stream It operates by reading four bytes from the stream and converting them to a single Javaint
. The bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering. As an example, ifbyte1
throughbyte4
represent the first four bytes read from the stream, they will be transformed to anint
in the following manner:(int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) + ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF)))
The value returned is in the range of -2147483648 to 2147483647. This method can read anint
written by an object implementing thewriteInt()
method in theDataOutput
interface.
- Returns:
- The
int
value read
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeInt(int)
public long readLong() throws IOException
This method reads a Javalong
value from an input stream It operates by reading eight bytes from the stream and converting them to a single Javalong
. The bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering. As an example, ifbyte1
throughbyte8
represent the first eight bytes read from the stream, they will be transformed to anlong
in the following manner:(long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) + ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) + ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) + ((byte7 & 0xFF) << 8) + (byte8 & 0xFF)))
The value returned is in the range of -9223372036854775808 to 9223372036854775807. This method can read anlong
written by an object implementing thewriteLong()
method in theDataOutput
interface.
- Returns:
- The
long
value read
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeLong(long)
public final Object readObject() throws ClassNotFoundException, IOException
Returns the next deserialized object read from the underlying stream. This method can be overriden by a class by implementingprivate void readObject (ObjectInputStream)
. If an exception is thrown from this method, the stream is left in an undefined state. This method can also throw Errors and RuntimeExceptions if caused by existing readResolve() user code.
- Specified by:
- readObject in interface ObjectInput
- Returns:
- The object read from the underlying stream.
- Throws:
ClassNotFoundException
- The class that an object being read in belongs to cannot be found.IOException
- Exception from underlyingInputStream
.
protected Object readObjectOverride() throws ClassNotFoundException, IOException, OptionalDataException
This method allows subclasses to override the default de serialization mechanism provided byObjectInputStream
. To make this method be used for writing objects, subclasses must invoke the 0-argument constructor on this class from their constructor.
- See Also:
ObjectInputStream()
public short readShort() throws IOException
This method reads a signed 16-bit value into a Java in from the stream. It operates by reading two bytes from the stream and converting them to a single 16-bit Javashort
. The two bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering. As an example, ifbyte1
andbyte2
represent the first and second byte read from the stream respectively, they will be transformed to ashort
in the following manner:(short)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF))
The value returned is in the range of -32768 to 32767. This method can read ashort
written by an object implementing thewriteShort()
method in theDataOutput
interface.
- Returns:
- The
short
value read
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeShort(int)
protected void readStreamHeader() throws IOException, StreamCorruptedException
Reads stream magic and stream version information from the underlying stream.
- Throws:
IOException
- Exception from underlying stream.StreamCorruptedException
- An invalid stream magic number or stream version was read from the stream.
public String readUTF() throws IOException
This method reads aString
from an input stream that is encoded in a modified UTF-8 format. This format has a leading two byte sequence that contains the remaining number of bytes to read. This two byte sequence is read using thereadUnsignedShort()
method of this interface. After the number of remaining bytes have been determined, these bytes are read an transformed intochar
values. Thesechar
values are encoded in the stream using either a one, two, or three byte format. The particular format in use can be determined by examining the first byte read. If the first byte has a high order bit of 0, then that character consists on only one byte. This character value consists of seven bits that are at positions 0 through 6 of the byte. As an example, ifbyte1
is the byte read from the stream, it would be converted to achar
like so:(char)byte1
If the first byte has 110 as its high order bits, then the character consists of two bytes. The bits that make up the character value are in positions 0 through 4 of the first byte and bit positions 0 through 5 of the second byte. (The second byte should have 10 as its high order bits). These values are in most significant byte first (i.e., "big endian") order. As an example, ifbyte1
andbyte2
are the first two bytes read respectively, and the high order bits of them match the patterns which indicate a two byte character encoding, then they would be converted to a Javachar
like so:(char)(((byte1 & 0x1F) << 6) + (byte2 & 0x3F))
If the first byte has a 1110 as its high order bits, then the character consists of three bytes. The bits that make up the character value are in positions 0 through 3 of the first byte and bit positions 0 through 5 of the other two bytes. (The second and third bytes should have 10 as their high order bits). These values are in most significant byte first (i.e., "big endian") order. As an example, ifbyte1
,byte2
, andbyte3
are the three bytes read, and the high order bits of them match the patterns which indicate a three byte character encoding, then they would be converted to a Javachar
like so:(char)(((byte1 & 0x0F) << 12) + ((byte2 & 0x3F) + (byte3 & 0x3F))
Note that all characters are encoded in the method that requires the fewest number of bytes with the exception of the character with the value of\<llll>u0000
which is encoded as two bytes. This is a modification of the UTF standard used to prevent C language styleNUL
values from appearing in the byte stream. This method can read data that was written by an object implementing thewriteUTF()
method inDataOutput
.
- Returns:
- The
String
read
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeUTF(String)
public Object readUnshared() throws IOException, ClassNotFoundException
Returns the next deserialized object read from the underlying stream in an unshared manner. Any object returned by this method will not be returned by subsequent calls to either this method orreadObject()
. This behaviour is achieved by:
- Marking the handles created by successful calls to this method, so that future calls to
readObject()
orreadUnshared()
will throw anObjectStreamException
rather than returning the same object reference.- Throwing an
ObjectStreamException
if the next element in the stream is a reference to an earlier object.
- Returns:
- a reference to the deserialized object.
- Throws:
ClassNotFoundException
- if the class of the object being deserialized can not be found.IOException
- if an I/O error occurs from the stream.
- Since:
- 1.4
- See Also:
readObject()
public int readUnsignedByte() throws IOException
This method reads 8 unsigned bits into a Javaint
value from the stream. The value returned is in the range of 0 to 255. This method can read an unsigned byte written by an object implementing thewriteByte()
method in theDataOutput
interface.
- Specified by:
- readUnsignedByte in interface DataInput
- Returns:
- The unsigned bytes value read as a Java
int
.
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeByte(int)
public int readUnsignedShort() throws IOException
This method reads 16 unsigned bits into a Java int value from the stream. It operates by reading two bytes from the stream and converting them to a single Javaint
. The two bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering. As an example, ifbyte1
andbyte2
represent the first and second byte read from the stream respectively, they will be transformed to anint
in the following manner:(int)(((byte1 0xFF) << 8) + (byte2 & 0xFF))
The value returned is in the range of 0 to 65535. This method can read an unsigned short written by an object implementing thewriteShort()
method in theDataOutput
interface.
- Specified by:
- readUnsignedShort in interface DataInput
- Returns:
- The unsigned short value read as a Java
int
.
- Throws:
IOException
- If any other error occurs
- See Also:
DataOutput.writeShort(int)
public void registerValidation(ObjectInputValidation validator, int priority) throws InvalidObjectException, NotActiveException
Registers aObjectInputValidation
to be carried out on the object graph currently being deserialized before it is returned to the original caller ofreadObject ()
. The order of validation for multipleObjectInputValidation
s can be controled usingpriority
. Validators with higher priorities are called first.
- Throws:
InvalidObjectException
-validator
isnull
NotActiveException
- an attempt was made to add a validator outside of thereadObject
method of the object currently being deserialized
- See Also:
ObjectInputValidation
protected Class> resolveClass(ObjectStreamClass osc) throws ClassNotFoundException, IOException
Called when a class is being deserialized. This is a hook to allow subclasses to read in information written by theannotateClass (Class)
method of anObjectOutputStream
. This implementation looks up the active call stack for aClassLoader
; if aClassLoader
is found, it is used to load the class associated withosc
, otherwise, the default systemClassLoader
is used.
- Throws:
IOException
- Exception from underlyingOutputStream
.
- See Also:
(java.lang.Class)
protected Object resolveObject(Object obj) throws IOException
Allows subclasses to resolve objects that are read from the stream with other objects to be returned in their place. This method is called the first time each object is encountered. This method must be enabled before it will be called in the serialization process.
- Throws:
IOException
- Exception from underlyingOutputStream
.
- See Also:
enableResolveObject(boolean)
protected Class> resolveProxyClass(String[] intfs) throws IOException, ClassNotFoundException
public int skipBytes(int len) throws IOException
This method skips and discards the specified number of bytes in an input stream. Note that this method may skip less than the requested number of bytes. The actual number of bytes skipped is returned. No bytes are skipped if a negative number is passed to this method.
- Parameters:
- Returns:
- The number of bytes actually skipped, which will always be
numBytes
- Throws:
IOException
- If any other error occurs