Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util

public Class ClassLoadingObjectInputStream

extends ObjectInputStream
Class Inheritance
Imports
java.io.IOException, .ObjectInputStream, java.lang.reflect.Modifier, .Proxy

ClassLoadingObjectInputStream For re-inflating serialized objects, this class uses the thread context classloader rather than the jvm's default classloader selection.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
private ThreadLocal<ClassLoader>

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public Object
public Class<?>
resolveClass(ObjectStreamClass
an instance of class ObjectStreamClass
cl
)

Overrides java.io.ObjectInputStream.resolveClass.

Load the local class equivalent of the specified stream class description.

protected Class<?>
resolveProxyClass(String[]
the list of interface names that were deserialized in the proxy class descriptor
interfaces
)

Overrides java.io.ObjectInputStream.resolveProxyClass.

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.

Inherited from java.io.ObjectInputStream:
availableclosedefaultReadObjectenableResolveObjectgetObjectInputFilterreadreadreadBooleanreadBytereadCharreadClassDescriptorreadDoublereadFieldsreadFloatreadFullyreadFullyreadIntreadLinereadLongreadObjectreadObjectOverridereadShortreadStreamHeaderreadUnsharedreadUnsignedBytereadUnsignedShortreadUTFregisterValidationresolveObjectsetObjectInputFilterskipBytes

Field Detail

_classloaderback to summary
private ThreadLocal<ClassLoader> _classloader

Constructor Detail

ClassLoadingObjectInputStreamback to summary
public ClassLoadingObjectInputStream(InputStream in) throws IOException
ClassLoadingObjectInputStreamback to summary
public ClassLoadingObjectInputStream() throws IOException

Method Detail

readObjectback to summary
public Object readObject(ClassLoader loader) throws IOException, ClassNotFoundException
resolveClassback to summary
public Class<?> resolveClass(ObjectStreamClass cl) throws IOException, ClassNotFoundException

Overrides java.io.ObjectInputStream.resolveClass.

Doc from java.io.ObjectInputStream.resolveClass.

Load the local class equivalent of the specified stream class description. Subclasses may implement this method to allow classes to be fetched from an alternate source.

The corresponding method in ObjectOutputStream is annotateClass. This method will be invoked only once for each unique class in the stream. This method can be implemented by subclasses to use an alternate loading mechanism but must return a Class object. Once returned, if the class is not an array class, its serialVersionUID is compared to the serialVersionUID of the serialized class, and if there is a mismatch, the deserialization fails and an InvalidClassException is thrown.

The default implementation of this method in ObjectInputStream returns the result of calling

Class.forName(desc.getName(), false, loader)
Class.forName(desc.getName(), false, loader)
where loader is the first class loader on the current thread's stack (starting from the currently executing method) that is neither the platform class loader nor its ancestor; otherwise, loader is the platform class loader. If this call results in a ClassNotFoundException and the name of the passed ObjectStreamClass instance is the Java language keyword for a primitive type or void, then the Class object representing that primitive type or void will be returned (e.g., an ObjectStreamClass with the name "int" will be resolved to Integer.TYPE). Otherwise, the ClassNotFoundException will be thrown to the caller of this method.
Parameters
cl:ObjectStreamClass

an instance of class ObjectStreamClass

Returns:Class<?>

a Class object corresponding to desc

Annotations
@Override
Exceptions
IOException:
any of the usual Input/Output exceptions.
ClassNotFoundException:
if class of a serialized object cannot be found.
resolveProxyClassback to summary
protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException

Overrides java.io.ObjectInputStream.resolveProxyClass.

Doc from java.io.ObjectInputStream.resolveProxyClass.

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.

This method is called exactly once for each unique proxy class descriptor in the stream.

The corresponding method in ObjectOutputStream is annotateProxyClass. For a given subclass of ObjectInputStream that overrides this method, the annotateProxyClass method in the corresponding subclass of ObjectOutputStream must write any data or objects read by this method.

The default implementation of this method in ObjectInputStream returns the result of calling Proxy.getProxyClass with the list of Class objects for the interfaces that are named in the interfaces parameter. The Class object for each interface name i is the value returned by calling

Class.forName(i, false, loader)
Class.forName(i, false, loader)
where loader is the first class loader on the current thread's stack (starting from the currently executing method) that is neither the platform class loader nor its ancestor; otherwise, loader is the platform class loader. Unless any of the resolved interfaces are non-public, this same value of loader is also the class loader passed to Proxy.getProxyClass; if non-public interfaces are present, their class loader is passed instead (if more than one non-public interface class loader is encountered, an IllegalAccessError is thrown). If Proxy.getProxyClass throws an IllegalArgumentException, resolveProxyClass will throw a ClassNotFoundException containing the IllegalArgumentException.
Parameters
interfaces:String[]

the list of interface names that were deserialized in the proxy class descriptor

Returns:Class<?>

a proxy class for the specified interfaces

Annotations
@Override
Exceptions
IOException:
any exception thrown by the underlying InputStream
ClassNotFoundException:
if the proxy class or any of the named interfaces could not be found
org.eclipse.jetty.util back to summary

protected Class ClassLoadingObjectInputStream.ClassLoaderThreadLocal

extends ThreadLocal<ClassLoader>
Class Inheritance

Field Summary

Modifier and TypeField and Description
protected static final ClassLoader

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected ClassLoader
initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable.

Inherited from java.lang.ThreadLocal:
getremovesetwithInitial

Field Detail

UNSETback to summary
protected static final ClassLoader UNSET

Constructor Detail

ClassLoaderThreadLocalback to summary
protected ClassLoaderThreadLocal()

Method Detail

initialValueback to summary
protected ClassLoader initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Doc from java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable. This method will be invoked the first time a thread accesses the variable with the get method, unless the thread previously invoked the set method, in which case the initialValue method will not be invoked for the thread. Normally, this method is invoked at most once per thread, but it may be invoked again in case of subsequent invocations of remove followed by get.

Returns:ClassLoader

the initial value for this thread-local

Annotations
@Override