Top Description Inners Fields Constructors Methods
org.springframework.objenesis.instantiator.basic

public Class ObjectInputStreamInstantiator<T>

extends Object
implements ObjectInstantiator<T>
Class Inheritance
All Implemented Interfaces
org.springframework.objenesis.instantiator.ObjectInstantiator
Annotations
@Instantiator:SERIALIZATION
Imports
java.io.ByteArrayOutputStream, .DataOutputStream, .IOException, .InputStream, .NotSerializableException, .ObjectInputStream, .ObjectStreamClass, .ObjectStreamConstants, .Serializable, org.springframework.objenesis.ObjenesisException, org.springframework.objenesis.instantiator.ObjectInstantiator, org.springframework.objenesis.instantiator.annotations.Instantiator, .Typology

Instantiates a class by using a dummy input stream that always feeds data for an empty object of the same kind.

Note

This instantiator may not work properly if the class being instantiated defines a "readResolve" method, since it may return objects that have been returned previously (i.e., there's no guarantee that the returned object is a new one), or even objects from a completely different class.

Author
Leonardo Mesquita
See Also
org.springframework.objenesis.instantiator.ObjectInstantiator

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ObjectInputStream

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public T
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inputStreamback to summary
private final ObjectInputStream inputStream

Constructor Detail

ObjectInputStreamInstantiatorback to summary
public ObjectInputStreamInstantiator(Class<T> clazz)

Method Detail

newInstanceback to summary
public T newInstance()

Implements org.springframework.objenesis.instantiator.ObjectInstantiator.newInstance.

Doc from org.springframework.objenesis.instantiator.ObjectInstantiator.newInstance.

Returns a new instance of an object. The returned object's class is defined by the implementation.

Returns:T

A new instance of an object.

Annotations
@SuppressWarnings:unchecked
org.springframework.objenesis.instantiator.basic back to summary

private Class ObjectInputStreamInstantiator.MockStream

extends InputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final byte[][]
private byte[]
private static byte[]
private static final int[]
private int
private static byte[]
private int

Constructor Summary

AccessConstructor and Description
public
MockStream(Class<?> clazz)

Method Summary

Modifier and TypeMethod and Description
private void
public int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

private static void
public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

Inherited from java.io.InputStream:
closemarkmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

buffersback to summary
private final byte[][] buffers
databack to summary
private byte[] data
HEADERback to summary
private static byte[] HEADER
NEXTback to summary
private static final int[] NEXT
pointerback to summary
private int pointer
REPEATING_DATAback to summary
private static byte[] REPEATING_DATA
sequenceback to summary
private int sequence

Constructor Detail

MockStreamback to summary
public MockStream(Class<?> clazz)

Method Detail

advanceBufferback to summary
private void advanceBuffer()
availableback to summary
public int available()

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.

Annotations
@Override
initializeback to summary
private static void initialize()
readback to summary
public int read()

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
readback to summary
public int read(byte[] b, int off, int len)

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override