iiopinputstream.java

来自「JAVA 所有包」· Java 代码 · 共 1,852 行 · 第 1/5 页

JAVA
1,852
字号
/* * @(#)IIOPInputStream.java	1.75 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * Licensed Materials - Property of IBM * RMI-IIOP v1.0 * Copyright IBM Corp. 1998 1999  All Rights Reserved * * US Government Users Restricted Rights - Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */package com.sun.corba.se.impl.io;import java.io.InputStream;import java.io.IOException;import java.io.StreamCorruptedException;import java.io.ObjectInputValidation;import java.io.NotActiveException;import java.io.InvalidObjectException;import java.io.InvalidClassException;import java.io.DataInputStream;import java.io.OptionalDataException;import java.io.WriteAbortedException;import java.io.Externalizable;import java.io.EOFException;import java.lang.reflect.*;import java.util.Vector;import java.util.Stack;import java.util.Hashtable;import java.util.Enumeration;import sun.corba.Bridge ;import java.security.AccessController ;import java.security.PrivilegedAction ;import com.sun.corba.se.impl.io.ObjectStreamClass;import com.sun.corba.se.impl.util.Utility;import org.omg.CORBA.portable.ValueInputStream;import org.omg.CORBA.ValueMember;import org.omg.CORBA.SystemException;import org.omg.CORBA.TCKind;import org.omg.CORBA.ORB; import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.portable.IndirectionException;import org.omg.CORBA.MARSHAL;import org.omg.CORBA.TypeCode;import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;import com.sun.org.omg.SendingContext.CodeBase;  import javax.rmi.PortableRemoteObject;import javax.rmi.CORBA.Util;import javax.rmi.CORBA.ValueHandler;import java.security.*;import java.util.*;import com.sun.corba.se.impl.orbutil.ObjectUtility ;import com.sun.corba.se.impl.logging.OMGSystemException ;import com.sun.corba.se.impl.logging.UtilSystemException ;import com.sun.corba.se.spi.logging.CORBALogDomains ;/** * IIOPInputStream is used by the ValueHandlerImpl to handle Java serialization * input semantics. * * @author  Stephen Lewallen * @since   JDK1.1.6 */public class IIOPInputStream    extends com.sun.corba.se.impl.io.InputStreamHook{    private static Bridge bridge = 	(Bridge)AccessController.doPrivileged(	    new PrivilegedAction() {		public Object run() {		    return Bridge.get() ;		}	    } 	) ;    private static OMGSystemException omgWrapper = OMGSystemException.get(	CORBALogDomains.RPC_ENCODING ) ;    private static UtilSystemException utilWrapper = UtilSystemException.get(	CORBALogDomains.RPC_ENCODING ) ;    // Necessary to pass the appropriate fields into the    // defaultReadObjectDelegate method (which takes no    // parameters since it's called from     // java.io.ObjectInpuStream defaultReadObject()    // which we can't change).    //    // This is only used in the case where the fields had     // to be obtained remotely because of a serializable    // version difference.  Set in inputObjectUsingFVD.    // Part of serialization evolution fixes for Ladybird,    // bug 4365188.    private ValueMember defaultReadObjectFVDMembers[] = null;    private org.omg.CORBA_2_3.portable.InputStream orbStream;    private CodeBase cbSender;      private ValueHandlerImpl vhandler;  //d4365188    private Object currentObject = null;    private ObjectStreamClass currentClassDesc = null;    private Class currentClass = null;    private int recursionDepth = 0;    private int simpleReadDepth = 0;    // The ActiveRecursionManager replaces the old RecursionManager which    // used to record how many recursions were made, and resolve them after    // an object was completely deserialized.    //    // That created problems (as in bug 4414154) because when custom    // unmarshaling in readObject, there can be recursive references    // to one of the objects currently being unmarshaled, and the    // passive recursion system failed.    ActiveRecursionManager activeRecursionMgr = new ActiveRecursionManager();    private IOException abortIOException = null;    /* Remember the first exception that stopped this stream. */    private ClassNotFoundException abortClassNotFoundException = null;    /* Vector of validation callback objects     * The vector is created as needed. The vector is maintained in     * order of highest (first) priority to lowest     */    private Vector callbacks;    // Serialization machinery fields    /* Arrays used to keep track of classes and ObjectStreamClasses     * as they are being merged; used in inputObject.     * spClass is the stack pointer for both.  */    ObjectStreamClass[] classdesc;    Class[] classes;    int spClass;    private static final String kEmptyStr = "";    // TCKind TypeCodes used in FVD inputClassFields    //public static final TypeCode kRemoteTypeCode = new TypeCodeImpl(TCKind._tk_objref);    //public static final TypeCode kValueTypeCode =  new TypeCodeImpl(TCKind._tk_value);    // removed TypeCodeImpl dependency    public static final TypeCode kRemoteTypeCode = ORB.init().get_primitive_tc(TCKind.tk_objref);    public static final TypeCode kValueTypeCode =  ORB.init().get_primitive_tc(TCKind.tk_value);    // TESTING CODE - useFVDOnly should be made final before FCS in order to    // optimize out the check.    private static final boolean useFVDOnly = false;    private byte streamFormatVersion;    // Since java.io.OptionalDataException's constructors are    // package private, but we need to throw it in some special    // cases, we try to do it by reflection.    private static final Constructor OPT_DATA_EXCEPTION_CTOR;       private Object[] readObjectArgList = { this } ;    static {        OPT_DATA_EXCEPTION_CTOR = getOptDataExceptionCtor();    }    // Grab the OptionalDataException boolean ctor and make    // it accessible.  Note that any exceptions     // will be wrapped in ExceptionInInitializerErrors.    private static Constructor getOptDataExceptionCtor() {        try {            Constructor result =                                (Constructor) AccessController.doPrivileged(                                    new PrivilegedExceptionAction() {                    public java.lang.Object run()                         throws NoSuchMethodException,                        SecurityException {                                                Constructor boolCtor                             = OptionalDataException.class.getDeclaredConstructor(                                                               new Class[] {                                Boolean.TYPE });                                                boolCtor.setAccessible(true);                                                return boolCtor;                    }});                        if (result == null)		// XXX I18N, logging needed.                throw new Error("Unable to find OptionalDataException constructor");                    return result;        } catch (Exception ex) {	    // XXX I18N, logging needed.            throw new ExceptionInInitializerError(ex);        }    }    // Create a new OptionalDataException with the EOF marker    // set to true.  See handleOptionalDataMarshalException.    private OptionalDataException createOptionalDataException() {        try {            OptionalDataException result                = (OptionalDataException)                   OPT_DATA_EXCEPTION_CTOR.newInstance(new Object[] {                        Boolean.TRUE });            if (result == null)		// XXX I18N, logging needed.                throw new Error("Created null OptionalDataException");            return result;        } catch (Exception ex) {	    // XXX I18N, logging needed.            throw new Error("Couldn't create OptionalDataException", ex);        }    }    // Return the stream format version currently being used    // to deserialize an object    protected byte getStreamFormatVersion() {        return streamFormatVersion;    }    // At the beginning of data sent by a writeObject or    // writeExternal method there is a byte telling the    // reader the stream format version.    private void readFormatVersion() throws IOException {        streamFormatVersion = orbStream.read_octet();        if (streamFormatVersion < 1 ||             streamFormatVersion > vhandler.getMaximumStreamFormatVersion()) {	    SystemException sysex = omgWrapper.unsupportedFormatVersion(		    CompletionStatus.COMPLETED_MAYBE);	    // XXX I18N?  Logging for IOException?	    IOException result = new IOException("Unsupported format version: "                                                 + streamFormatVersion);	    result.initCause( sysex ) ;	    throw result ;        }        if (streamFormatVersion == 2) {            if (!(orbStream instanceof ValueInputStream)) {		SystemException sysex = omgWrapper.notAValueinputstream( 		    CompletionStatus.COMPLETED_MAYBE);		// XXX I18N?  Logging for IOException?		IOException result = new IOException("Not a ValueInputStream");		result.initCause( sysex ) ;		throw result;            }        }    }    public static void setTestFVDFlag(boolean val){	//  useFVDOnly = val;    }    /**     * Dummy constructor; passes upper stream a dummy stream;     **/    public IIOPInputStream()    	throws java.io.IOException {    	super();	resetStream();    }	    public final void setOrbStream(org.omg.CORBA_2_3.portable.InputStream os) {    	orbStream = os;    }    public final org.omg.CORBA_2_3.portable.InputStream getOrbStream() {    	return orbStream;    }    //added setSender and getSender    public final void setSender(CodeBase cb) {        cbSender = cb;    }    public final CodeBase getSender() {        return cbSender;    }    // 4365188 this is added to enable backward compatability w/ wrong    // rep-ids    public final void setValueHandler(ValueHandler vh) {        vhandler = (com.sun.corba.se.impl.io.ValueHandlerImpl) vh;    }    public final ValueHandler getValueHandler() {	return (javax.rmi.CORBA.ValueHandler) vhandler;    }	    public final void increaseRecursionDepth(){	recursionDepth++;    }    public final int decreaseRecursionDepth(){	return --recursionDepth;    }    /**     * Override the actions of the final method "readObject()"     * in ObjectInputStream.     * @since     JDK1.1.6     *     * Read an object from the ObjectInputStream.     * The class of the object, the signature of the class, and the values     * of the non-transient and non-static fields of the class and all     * of its supertypes are read.  Default deserializing for a class can be     * overriden using the writeObject and readObject methods.     * Objects referenced by this object are read transitively so     * that a complete equivalent graph of objects is reconstructed by readObject. <p>     *     * The root object is completly restored when all of its fields     * and the objects it references are completely restored.  At this     * point the object validation callbacks are executed in order     * based on their registered priorities. The callbacks are     * registered by objects (in the readObject special methods)     * as they are individually restored.     *     * Exceptions are thrown for problems with the InputStream and for classes     * that should not be deserialized.  All exceptions are fatal to the     * InputStream and leave it in an indeterminate state; it is up to the caller     * to ignore or recover the stream state.     * @exception java.lang.ClassNotFoundException Class of a serialized object     *      cannot be found.     * @exception InvalidClassException Something is wrong with a class used by     *     serialization.     * @exception StreamCorruptedException Control information in the     *     stream is inconsistent.     * @exception OptionalDataException Primitive data was found in the     * stream instead of objects.     * @exception IOException Any of the usual Input/Output related exceptions.     * @since     JDK1.1     */    public final Object readObjectDelegate() throws IOException    {	try {            readObjectState.readData(this);            return orbStream.read_abstract_interface();        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, true);            throw marshalException;	} catch(IndirectionException cdrie)	    {                // The CDR stream had never seen the given offset before,                // so check the recursion manager (it will throw an                // IOException if it doesn't have a reference, either).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?