cdrinputstream_1_0.java

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

JAVA
1,977
字号
/* * @(#)CDRInputStream_1_0.java	1.134 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.encoding;import java.io.IOException;import java.io.Serializable;import java.io.ByteArrayInputStream;import java.io.ObjectInputStream;import java.io.IOException;import java.io.StreamCorruptedException;import java.io.OptionalDataException;import java.io.IOException;import java.util.Stack;import java.net.URL;import java.net.MalformedURLException;import java.nio.ByteBuffer;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.math.BigDecimal;import java.rmi.Remote;import java.rmi.StubNotFoundException;import java.security.AccessController;import java.security.PrivilegedExceptionAction;import java.security.PrivilegedActionException;import org.omg.CORBA.SystemException;import org.omg.CORBA.Object;import org.omg.CORBA.Principal;import org.omg.CORBA.TypeCode;import org.omg.CORBA.Any;import org.omg.CORBA.portable.Delegate;import org.omg.CORBA.portable.ValueBase;import org.omg.CORBA.portable.IndirectionException;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.TCKind;import org.omg.CORBA.TypeCodePackage.BadKind;import org.omg.CORBA.CustomMarshal;import org.omg.CORBA.TypeCode;import org.omg.CORBA.Principal;import org.omg.CORBA.Any;import org.omg.CORBA.portable.BoxedValueHelper;import org.omg.CORBA.portable.ValueFactory;import org.omg.CORBA.portable.CustomValue;import org.omg.CORBA.portable.StreamableValue;import org.omg.CORBA.MARSHAL;import org.omg.CORBA.portable.IDLEntity;import javax.rmi.PortableRemoteObject;import javax.rmi.CORBA.Tie;import javax.rmi.CORBA.Util;import javax.rmi.CORBA.ValueHandler;import com.sun.corba.se.pept.protocol.MessageMediator;import com.sun.corba.se.pept.transport.ByteBufferPool;import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;import com.sun.corba.se.spi.protocol.CorbaClientDelegate;import com.sun.corba.se.spi.ior.IOR;import com.sun.corba.se.spi.ior.IORFactories;import com.sun.corba.se.spi.ior.iiop.GIOPVersion;import com.sun.corba.se.spi.orb.ORB;import com.sun.corba.se.spi.orb.ORBVersionFactory;import com.sun.corba.se.spi.orb.ORBVersion;import com.sun.corba.se.spi.protocol.CorbaMessageMediator;import com.sun.corba.se.spi.logging.CORBALogDomains;import com.sun.corba.se.spi.presentation.rmi.PresentationManager;import com.sun.corba.se.spi.presentation.rmi.StubAdapter;import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults;import com.sun.corba.se.impl.logging.ORBUtilSystemException;import com.sun.corba.se.impl.logging.OMGSystemException;import com.sun.corba.se.impl.corba.PrincipalImpl;import com.sun.corba.se.impl.corba.TypeCodeImpl;import com.sun.corba.se.impl.corba.CORBAObjectImpl;import com.sun.corba.se.impl.encoding.CDROutputObject;import com.sun.corba.se.impl.encoding.CodeSetConversion;import com.sun.corba.se.impl.util.Utility;import com.sun.corba.se.impl.util.RepositoryId;import com.sun.corba.se.impl.orbutil.RepositoryIdStrings;import com.sun.corba.se.impl.orbutil.RepositoryIdInterface;import com.sun.corba.se.impl.orbutil.RepositoryIdUtility;import com.sun.corba.se.impl.orbutil.RepositoryIdFactory;import com.sun.corba.se.impl.orbutil.ORBUtility;import com.sun.corba.se.impl.orbutil.CacheTable;import com.sun.org.omg.CORBA.portable.ValueHelper;import com.sun.org.omg.SendingContext.CodeBase;public class CDRInputStream_1_0 extends CDRInputStreamBase     implements RestorableInputStream{    private static final String kReadMethod = "read";    private static final int maxBlockLength = 0x7fffff00;    protected BufferManagerRead bufferManagerRead;    protected ByteBufferWithInfo bbwi;    // Set to the ORB's transportDebugFlag value.  This value is    // used if the ORB is null.    private boolean debug = false;    protected boolean littleEndian;    protected ORB orb;    protected ORBUtilSystemException wrapper ;    protected OMGSystemException omgWrapper ;    protected ValueHandler valueHandler = null;    // Value cache    private CacheTable valueCache = null;        // Repository ID cache    private CacheTable repositoryIdCache = null;    // codebase cache    private CacheTable codebaseCache = null;    // Current Class Stack (repository Ids of current class being read)    // private Stack currentStack = null;    // Length of current chunk, or a large positive number if not in a chunk    protected int blockLength = maxBlockLength;    // Read end flag (value nesting depth)    protected int end_flag = 0;    // Beginning with the resolution to interop issue 3526 (4328?),    // only enclosing chunked valuetypes are taken into account    // when computing the nesting level.  However, we still need    // the old computation around for interoperability with our    // older ORBs.    private int chunkedValueNestingLevel = 0;    // Flag used to determine whether blocksize was zero    // private int checkForNullBlock = -1;    // In block flag    // private boolean inBlock = false;    // Indicates whether we are inside a value    // private boolean outerValueDone = true;    // Int used by read_value(Serializable) that is set by this class    // before calling ValueFactory.read_value    protected int valueIndirection = 0;    // Int set by readStringOrIndirection to communicate the actual    // offset of the string length field back to the caller    protected int stringIndirection = 0;    // Flag indicating whether we are unmarshalling a chunked value    protected boolean isChunked = false;    // Repository ID handlers    private RepositoryIdUtility repIdUtil;    private RepositoryIdStrings repIdStrs;    // Code set converters (created when first needed)    private CodeSetConversion.BTCConverter charConverter;    private CodeSetConversion.BTCConverter wcharConverter;    // RMI-IIOP stream format version 2 case in which we know    // that there is no more optional data available.  If the    // Serializable's readObject method tries to read anything,    // we must throw a MARSHAL with the special minor code    // so that the ValueHandler can give the correct exception    // to readObject.  The state is cleared when the ValueHandler    // calls end_value after the readObject method exits.    private boolean specialNoOptionalDataState = false;        // Template method    public CDRInputStreamBase dup()     {        CDRInputStreamBase result = null ;        try {            result = (CDRInputStreamBase)this.getClass().newInstance();        } catch (Exception e) {	    throw wrapper.couldNotDuplicateCdrInputStream( e ) ;        }        result.init(this.orb,                    this.bbwi.byteBuffer,                    this.bbwi.buflen,                    this.littleEndian,                    this.bufferManagerRead);        ((CDRInputStream_1_0)result).bbwi.position(this.bbwi.position());        // To ensure we keep bbwi.byteBuffer.limit in sync with bbwi.buflen.        ((CDRInputStream_1_0)result).bbwi.byteBuffer.limit(this.bbwi.buflen);        return result;    }    /**     * NOTE:  size passed to init means buffer size     */    public void init(org.omg.CORBA.ORB orb,                      ByteBuffer byteBuffer,                      int size,                      boolean littleEndian,                     BufferManagerRead bufferManager)     {        this.orb = (ORB)orb;	this.wrapper = ORBUtilSystemException.get( (ORB)orb,	    CORBALogDomains.RPC_ENCODING ) ;	this.omgWrapper = OMGSystemException.get( (ORB)orb,	    CORBALogDomains.RPC_ENCODING ) ;        this.littleEndian = littleEndian;        this.bufferManagerRead = bufferManager;        this.bbwi = new ByteBufferWithInfo(orb,byteBuffer,0);        this.bbwi.buflen = size;        this.bbwi.byteBuffer.limit(bbwi.buflen);        this.markAndResetHandler = bufferManagerRead.getMarkAndResetHandler();	debug = ((ORB)orb).transportDebugFlag;    }     // See description in CDRInputStream    void performORBVersionSpecificInit() {        createRepositoryIdHandlers();    }    private final void createRepositoryIdHandlers()    {	repIdUtil = RepositoryIdFactory.getRepIdUtility(orb);	repIdStrs = RepositoryIdFactory.getRepIdStringsFactory(orb);    }    public GIOPVersion getGIOPVersion() {        return GIOPVersion.V1_0;    }        // Called by Request and Reply message. Valid for GIOP versions >= 1.2 only.    // Illegal for GIOP versions < 1.2.    void setHeaderPadding(boolean headerPadding) {        throw wrapper.giopVersionError();    }    protected final int computeAlignment(int index, int align) {        if (align > 1) {            int incr = index & (align - 1);            if (incr != 0)                return align - incr;        }        return 0;    }    public int getSize()    {        return bbwi.position();    }    protected void checkBlockLength(int align, int dataSize) {	// Since chunks can end at arbitrary points (though not within	// primitive CDR types, arrays of primitives, strings, wstrings,        // or indirections),	// we must check here for termination of the current chunk.        if (!isChunked)            return;        // RMI-IIOP stream format version 2 case in which we know        // that there is no more optional data available.  If the        // Serializable's readObject method tries to read anything,        // we must throw a MARSHAL exception with the special minor code        // so that the ValueHandler can give the correct exception        // to readObject.  The state is cleared when the ValueHandler        // calls end_value after the readObject method exits.        if (specialNoOptionalDataState) {	    throw omgWrapper.rmiiiopOptionalDataIncompatible1() ;        }        boolean checkForEndTag = false;        // Are we at the end of the current chunk?  If so,        // try to interpret the next long as a chunk length.        // (It has to be either a chunk length, end tag,        // or valuetag.)        //        // If it isn't a chunk length, blockLength will        // remain set to maxBlockLength.	if (blockLength == get_offset()) {	    blockLength = maxBlockLength;	    start_block();            // What's next is either a valuetag or            // an end tag.  If it's a valuetag, we're            // probably being called as part of the process            // to read the valuetag.  If it's an end tag,            // then there isn't enough data left in            // this valuetype to read!            if (blockLength == maxBlockLength)                checkForEndTag = true;	} else         if (blockLength < get_offset()) {	    // Are we already past the end of the current chunk?            // This is always an error.	    throw wrapper.chunkOverflow() ;	}        // If what's next on the wire isn't a chunk length or        // what we want to read (which can't be split across chunks)        // won't fit in the current chunk, throw this exception.        // This probably means that we're in an RMI-IIOP        // Serializable's readObject method or a custom marshaled        // IDL type is reading too much/in an incorrect order        int requiredNumBytes =                             computeAlignment(bbwi.position(), align) + dataSize;        if (blockLength != maxBlockLength &&            blockLength < get_offset() + requiredNumBytes) {	    throw omgWrapper.rmiiiopOptionalDataIncompatible2() ;        }        // REVISIT - We should look at using the built in advancement        //           of using ByteBuffer.get() rather than explicitly        //           advancing the ByteBuffer's position.        //           This is true for anywhere we are incrementing        //           the ByteBuffer's position.        if (checkForEndTag) {            int nextLong = read_long();            bbwi.position(bbwi.position() - 4);            // It was an end tag, so there wasn't enough data            // left in the valuetype's encoding on the wire            // to read what we wanted            if (nextLong < 0)		throw omgWrapper.rmiiiopOptionalDataIncompatible3() ;        }    }    protected void alignAndCheck(int align, int n) {        checkBlockLength(align, n);        // WARNING: Must compute real alignment after calling        // checkBlockLength since it may move the position        int alignResult = computeAlignment(bbwi.position(), align);        bbwi.position(bbwi.position() + alignResult);    	if (bbwi.position() + n > bbwi.buflen)            grow(align, n);    }    //    // This can be overridden....    //    protected void grow(int align, int n) {                        bbwi.needed = n;        bbwi = bufferManagerRead.underflow(bbwi);    }    //    // Marshal primitives.    //    public final void consumeEndian() {	littleEndian = read_boolean();    }

⌨️ 快捷键说明

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