GeezerVison is showing docs.oracle.com — ObjectInputStream (Java Platform SE 7 )
Java™ Platform Standard Ed. 7
java.io
Class ObjectInputStream
-
-
Nested Class Summary
Nested Classes
| Modifier and Type |
Class and Description |
static class |
ObjectInputStream.GetField
Provide access to the persistent fields read from the input stream.
|
-
Field Summary
-
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING
-
Constructor Summary
Constructors
| Modifier |
Constructor and Description |
protected |
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
Methods
| Modifier and Type |
Method and 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()
|
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.
|
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
readObjectOverride
protected Object readObjectOverride()
throws IOException,
ClassNotFoundException
This method is called by trusted subclasses of ObjectOutputStream that
constructed ObjectOutputStream using the protected no-arg constructor.
The subclass is expected to provide an override method with the modifier
"final".
- Returns:
- the Object read from the stream.
- Throws:
ClassNotFoundException - Class definition of a serialized object
cannot be found.
OptionalDataException - Primitive data was found in the stream
instead of objects.
IOException - if I/O errors occurred while reading from the
underlying stream- Since:
- 1.2
- See Also:
ObjectInputStream(),
readObject()
-
defaultReadObject
public void defaultReadObject()
throws IOException,
ClassNotFoundException
Read the non-static and non-transient fields of the current class from
this stream. This may only be called from the readObject method of the
class being deserialized. It will throw the NotActiveException if it is
called otherwise.
- Throws:
ClassNotFoundException - if the class of a serialized object
could not be found.
IOException - if an I/O error occurs.
NotActiveException - if the stream is not currently reading
objects.
-
registerValidation
public void registerValidation(ObjectInputValidation obj,
int prio)
throws NotActiveException,
InvalidObjectException
Register an object to be validated before the graph is returned. While
similar to resolveObject these validations are called after the entire
graph has been reconstituted. Typically, a readObject method will
register the object with the stream so that when all of the objects are
restored a final set of validations can be performed.
- Parameters:
obj - the object to receive the validation callback.prio - controls the order of callbacks;zero is a good default.
Use higher numbers to be called back earlier, lower numbers for
later callbacks. Within a priority, callbacks are processed in
no particular order.
- Throws:
NotActiveException - The stream is not currently reading objects
so it is invalid to register a callback.
InvalidObjectException - The validation object is null.
-
readStreamHeader
protected void readStreamHeader()
throws IOException,
StreamCorruptedException
The readStreamHeader method is provided to allow subclasses to read and
verify their own stream headers. It reads and verifies the magic number
and version number.
- Throws:
IOException - if there are I/O errors while reading from the
underlying InputStream
StreamCorruptedException - if control information in the stream
is inconsistent
-
readClassDescriptor
protected ObjectStreamClass readClassDescriptor()
throws IOException,
ClassNotFoundException
Read a class descriptor from the serialization stream. This method is
called when the ObjectInputStream expects a class descriptor as the next
item in the serialization stream. Subclasses of ObjectInputStream may
override this method to read in class descriptors that have been written
in non-standard formats (by subclasses of ObjectOutputStream which have
overridden the writeClassDescriptor method). By default,
this method reads class descriptors according to the format defined in
the Object Serialization specification.
- Returns:
- the class descriptor read
- Throws:
IOException - If an I/O error has occurred.
ClassNotFoundException - If the Class of a serialized object used
in the class descriptor representation cannot be found- Since:
- 1.3
- See Also:
ObjectOutputStream.writeClassDescriptor(java.io.ObjectStreamClass)
-
read
public int read(byte[] buf,
int off,
int len)
throws IOException
Reads into an array of bytes. This method will block until some input
is available. Consider using java.io.DataInputStream.readFully to read
exactly 'length' bytes.
- Specified by:
read in interface ObjectInput
- Overrides:
read in class InputStream
- Parameters:
buf - the buffer into which the data is readoff - the start offset of the datalen - the maximum number of bytes read
- Returns:
- the actual number of bytes read, -1 is returned when the end of
the stream is reached.
- Throws:
IOException - If an I/O error has occurred.- See Also:
DataInputStream.readFully(byte[],int,int)
-
readFully
public void readFully(byte[] buf,
int off,
int len)
throws IOException
Reads bytes, blocking until all bytes are read.
- Specified by:
readFully in interface DataInput
- Parameters:
buf - the buffer into which the data is readoff - the start offset of the datalen - the maximum number of bytes to read
- Throws:
EOFException - If end of file is reached.
IOException - If other I/O error has occurred.
-
readLine
@Deprecated
public String readLine()
throws IOException
Deprecated. This method does not properly convert bytes to characters.
see DataInputStream for the details and alternatives.
Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
- Specified by:
readLine in interface DataInput
- Returns:
- a String copy of the line.
- Throws:
IOException - if there are I/O errors while reading from the
underlying InputStream
Java™ Platform Standard Ed. 7
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2020, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|