Class MarshalInputStream
- All Implemented Interfaces:
Closeable,DataInput,ObjectInput,ObjectStreamConstants,AutoCloseable,ObjectStreamContext
ObjectInputStream that implements the dynamic class loading
semantics of Java(TM) Remote Method Invocation (Java RMI) argument and result unmarshalling
(using RMIClassLoader). A MarshalInputStream is intended to read data
written by a corresponding MarshalOutputStream.
MarshalInputStream implements the input side of the dynamic class loading
semantics by overriding resolveClass and resolveProxyClass to resolve class descriptors in the stream
using ClassLoading.loadClass and ClassLoading.loadProxyClass (which, in turn, use RMIClassLoader.loadClass and RMIClassLoader.loadProxyClass),
optionally with codebase annotation strings written by a MarshalOutputStream.
By default, a MarshalInputStream ignores all codebase annotation strings, instead
using a codebase value of null when loading classes. Codebase annotation strings
will only be used by a MarshalInputStream after its useCodebaseAnnotations method has been invoked.
MarshalInputStream supports optional verification that all codebase annotation
URLs that are used to load classes resolved by the stream provide content integrity (see Security.verifyCodebaseIntegrity). Whether or not a particular
MarshalInputStream instance verifies that codebase annotation URLs provide content
integrity is determined by the verifyCodebaseIntegrity constructor argument. See
ClassLoading.loadClass and ClassLoading.loadProxyClass for details of how codebase integrity verification is performed.
MarshalInputStream reads class annotations from its own stream; a subclass can
override the readAnnotation method to read the class annotations from a
different location.
A MarshalInputStream is not guaranteed to be safe for concurrent use by multiple
threads.
- Since:
- 2.0
- Author:
- Sun Microsystems, Inc.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.io.ObjectInputStream
ObjectInputStream.GetField -
Field Summary
Fields inherited from interface java.io.ObjectStreamConstants
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, SERIAL_FILTER_PERMISSION, 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
ConstructorsConstructorDescriptionMarshalInputStream(InputStream in, ClassLoader defaultLoader, boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) Creates a newMarshalInputStreamthat reads marshalled data from the specified underlyingInputStream. -
Method Summary
Modifier and TypeMethodDescriptionReturns the collection of context information objects that was passed to this stream's constructor.protected StringReads and returns a class annotation string value (possiblynull) that was written by a correspondingMarshalOutputStreamimplementation.protected ClassresolveClass(ObjectStreamClass classDesc) Resolves the appropriateClassobject for the stream class descriptorclassDesc.protected ClassresolveProxyClass(String[] interfaceNames) Resolves the appropriateClassobject for the proxy class described by the interface namesinterfaceNames.voidEnables the use of codebase annotation strings written by the correspondingMarshalOutputStream.Methods inherited from class java.io.ObjectInputStream
available, close, defaultReadObject, enableResolveObject, getObjectInputFilter, read, read, readBoolean, readByte, readChar, readClassDescriptor, readDouble, readFields, readFloat, readFully, readFully, readInt, readLine, readLong, readObject, readObjectOverride, readShort, readStreamHeader, readUnshared, readUnsignedByte, readUnsignedShort, readUTF, registerValidation, resolveObject, setObjectInputFilter, skipBytesMethods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferToMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.io.ObjectInput
read, skip
-
Constructor Details
-
MarshalInputStream
public MarshalInputStream(InputStream in, ClassLoader defaultLoader, boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) throws IOException Creates a newMarshalInputStreamthat reads marshalled data from the specified underlyingInputStream.This constructor passes
into the superclass constructor that has anInputStreamparameter.defaultLoaderwill be passed as thedefaultLoaderargument toClassLoading.loadClassandClassLoading.loadProxyClasswhenever those methods are invoked byresolveClassandresolveProxyClass.If
verifyCodebaseIntegrityistrue, then the created stream will verify that all codebase annotation URLs that are used to load classes resolved by the stream provide content integrity, and wheneverSecurity.verifyCodebaseIntegrityis invoked to enforce that verification,verifierLoaderwill be passed as theloaderargument. SeeClassLoading.loadClassandClassLoading.loadProxyClassfor details of how codebase integrity verification is performed.contextwill be used as the return value of the created stream'sgetObjectStreamContextmethod.- Parameters:
in- the input stream to read marshalled data fromdefaultLoader- the class loader value (possiblynull) to pass as thedefaultLoaderargument toClassLoadingmethodsverifyCodebaseIntegrity- iftrue, this stream will verify that codebase annotation URLs used to load classes resolved by this stream provide content integrityverifierLoader- the class loader value (possiblynull) to pass toSecurity.verifyCodebaseIntegrity, ifverifyCodebaseIntegrityistruecontext- the collection of context information objects to be returned by this stream'sgetObjectStreamContextmethod- Throws:
IOException- if the superclass's constructor throws anIOExceptionSecurityException- if the superclass's constructor throws aSecurityExceptionNullPointerException- ifinorcontextisnull
-
-
Method Details
-
useCodebaseAnnotations
public void useCodebaseAnnotations()Enables the use of codebase annotation strings written by the correspondingMarshalOutputStream.If this method has not been invoked on this stream, then the
resolveClassandresolveProxyClassmethods ignore the class annotation strings and just use anullcodebase value when loading classes. After this method has been invoked, then theresolveClassandresolveProxyClassmethods use the class annotation strings as codebase values. -
getObjectStreamContext
Returns the collection of context information objects that was passed to this stream's constructor.- Specified by:
getObjectStreamContextin interfaceObjectStreamContext- Returns:
- a collection of this stream's context objects
-
resolveClass
protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException Resolves the appropriateClassobject for the stream class descriptorclassDesc.MarshalInputStreamimplements this method as follows:This method first invokes this stream's
readAnnotationmethod to read the annotation string value (possiblynull) for the class descriptor. IfreadAnnotationthrows an exception, then this method throws that exception. Otherwise, a codebase value is chosen as follows: if theuseCodebaseAnnotationsmethod has been invoked on this stream, then the codebase value chosen is the value that was returned byreadAnnotation; otherwise, the codebase value chosen isnull.This method then invokes
ClassLoading.loadClasswith the chosen codebase value as the first argument, the name of the class described byclassDescas the second argument, and thedefaultLoader,verifyCodebaseIntegrity, andverifierLoadervalues that were passed to this stream's constructor as the third, fourth, and fifth arguments. IfClassLoading.loadClassthrows aClassNotFoundExceptionand the name of the class described byclassDescequals the Java programming language keyword for a primitive type orvoid, then this method returns theClasscorresponding to that primitive type orvoid(Integer.TYPEforint,Void.TYPEforvoid, and so forth). Otherwise, ifClassLoading.loadClassthrows an exception, this method throws that exception, and if it returns normally, this method returns theClassreturned byClassLoading.loadClass.- Overrides:
resolveClassin classObjectInputStream- Parameters:
classDesc- the stream class descriptor to resolve- Returns:
- the resolved class
- Throws:
IOException- ifreadAnnotationthrows anIOException, or ifClassLoading.loadClassthrows aMalformedURLExceptionClassNotFoundException- ifreadAnnotationorClassLoading.loadClassthrows aClassNotFoundExceptionNullPointerException- ifclassDescisnull
-
resolveProxyClass
protected Class resolveProxyClass(String[] interfaceNames) throws IOException, ClassNotFoundException Resolves the appropriateClassobject for the proxy class described by the interface namesinterfaceNames.MarshalInputStreamimplements this method as follows:This method first invokes this stream's
readAnnotationmethod to read the annotation string value (possiblynull) for the class descriptor. IfreadAnnotationthrows an exception, then this method throws that exception. Otherwise, a codebase value is chosen as follows: if theuseCodebaseAnnotationsmethod has been invoked on this stream, then the codebase value chosen is the value that was returned byreadAnnotation; otherwise, the codebase value chosen isnull.This method then invokes
ClassLoading.loadProxyClasswith the chosen codebase value as the first argument,interfaceNamesas the second argument, and thedefaultLoader,verifyCodebaseIntegrity, andverifierLoadervalues that were passed to this stream's constructor as the third, fourth, and fifth arguments. IfClassLoading.loadProxyClassthrows an exception, then this method throws that exception. Otherwise, this method returns theClassreturned byClassLoading.loadProxyClass.- Overrides:
resolveProxyClassin classObjectInputStream- Parameters:
interfaceNames- the list of interface names that were deserialized in the proxy class descriptor- Returns:
- the resolved dynamic proxy class
- Throws:
IOException- ifreadAnnotationthrows anIOException, or ifClassLoading.loadProxyClassthrows aMalformedURLExceptionClassNotFoundException- ifreadAnnotationorClassLoading.loadProxyClassthrows aClassNotFoundExceptionNullPointerException- ifinterfaceNamesisnullor if any element ofinterfaceNamesisnull
-
readAnnotation
Reads and returns a class annotation string value (possiblynull) that was written by a correspondingMarshalOutputStreamimplementation.MarshalInputStreamimplements this method to just read the annotation value from this stream usingreadObject, and ifreadObjectreturns a non-nullvalue that is not aString, anInvalidObjectExceptionis thrown.A subclass can override this method to read the annotation from a different location.
- Returns:
- the class annotation string value read (possibly
null) - Throws:
IOException- if an I/O exception occurs reading the annotationClassNotFoundException- if aClassNotFoundExceptionoccurs reading the annotation
-