Class ObjectInputStream
All Implemented Interfaces:
Closeable, DataInput, ObjectInput, ObjectStreamConstants, AutoCloseable
Declaration of ObjectInputStream:
public class ObjectInputStream
extends InputStream
implements ObjectInput, ObjectStreamConstants
ObjectInputStream class (java.io.ObjectInputStream) enables you to read Java objects from an InputStream . We wrap an InputStream in a ObjectInputStream and then you can read objects from it. Implementing the Serializable interface allows object serialization to save and restore the entire state of the object.
Normally you will use the ObjectInputStream to read objects written (serialized) by a Java ObjectOutputStream .
Only objects that support the java.io.Serializable or java.io.Externalizable interface can be read from streams.
The method readObject is used to read an object from the stream. Java's safe casting should be used to get the desired type.
The default deserialization mechanism for objects restores the contents of each field to the value and type it had when it was written.
Fields declared as transient or static are ignored by the deserialization process.
Constructor Summary of ObjectInputStream:
|
Constructor
|
Description
|
|
ObjectInputStream()
|
Provide a way for subclasses that are completely reimplementing
ObjectInputStream to not have to allocate private data just used by this
implementation of ObjectInputStream.
|
|
ObjectInputStream(InputStream in)
|
Creates an ObjectInputStream that reads from the specified
InputStream.
|
Method Summary of ObjectInputStream:
|
Modifier
|
Method
Name
|
Description
|
|
int
|
available()
|
Returns the number of bytes that can be read without blocking.
|
|
void
|
close()
|
Closes the input stream.
|
|
void
|
defaultReadObject()
|
Read the non-static and non-transient fields of the current class
from this stream.
|
|
protected Boolean
|
enableResolveObject(boolean enable)
|
Enable the stream to allow objects read from the stream to be
replaced.
|
|
int
|
read()
|
Reads a byte of data.
|
|
int
|
read(byte[] buf, int off, int len)
|
Reads into an array of bytes.
|
|
boolean
|
readBoolean()
|
Reads in a boolean.
|
|
byte
|
readByte()
|
Reads an 8 bit byte.
|
|
char
|
readChar()
|
Reads a 16 bit char.
|
|
protected ObjectStreamClass
|
readClassDescriptor()
|
Read a class descriptor from the serialization stream.
|
|
double
|
readDouble()
|
Reads a 64 bit double.
|
|
ObjectInputStream.GetField
|
readFields()
|
Reads the persistent fields from the stream and makes them available
by name.
|
|
float
|
readFloat()
|
Reads a 32 bit float.
|
|
void
|
readFully(byte[] buf)
|
Reads bytes, blocking until all bytes are read.
|
|
void
|
readFully(byte[] buf, int off, int len)
|
Reads bytes, blocking until all bytes are read.
|
|
int
|
readInt()
|
Reads a 32 bit int.
|
|
String
|
readLine()
|
Deprecated.
This method does not properly convert bytes to characters. see
DataInputStream for the details and alternatives.
|
|
long
|
readLong()
|
Reads a 64 bit long.
|
|
Object
|
readObject()
|
Read an object from the ObjectInputStream.
|
|
protected Object
|
readObjectOverride()
|
This method is called by trusted subclasses of ObjectOutputStream
that constructed ObjectOutputStream using the protected no-arg constructor.
|
|
short
|
readShort()
|
Reads a 16 bit short.
|
|
protected void
|
readStreamHeader()
|
The readStreamHeader method is provided to allow subclasses to read
and verify their own stream headers.
|
|
Object
|
readUnshared()
|
Reads an "unshared" object from the ObjectInputStream.
|
|
int
|
readUnsignedByte()
|
Reads an unsigned 8 bit byte.
|
|
int
|
readUnsignedShort()
|
Reads an unsigned 16 bit short.
|
|
String
|
readUTF()
|
Reads a String in modified UTF-8 format.
|
|
void
|
registerValidation(ObjectInputValidation obj, int prio)
|
Register an object to be validated before the graph is returned.
|
|
protected Class<?>
|
resolveClass(ObjectStreamClass desc)
|
Load the local class equivalent of the specified stream class
description.
|
|
protected Object
|
resolveObject(Object obj)
|
This method will allow trusted subclasses of ObjectInputStream to
substitute one object for another during deserialization.
|
|
protected Class<?>
|
resolveProxyClass(String[] interfaces)
|
Returns a proxy class that implements the interfaces named in a proxy
class descriptor; subclasses may implement this method to read custom data
from the stream along with the descriptors for dynamic proxy classes,
allowing them to use an alternate loading mechanism for the interfaces and
the proxy class.
|
|
int
|
skipBytes(int len)
|
Skips bytes.
|
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.


No comments:
Post a Comment