cdrinputstream_1_0.java

来自「java jdk 1.4的源码」· Java 代码 · 共 2,002 行 · 第 1/5 页

JAVA
2,002
字号
/* * @(#)CDRInputStream_1_0.java	1.81 03/01/23 * * Copyright 2003 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.internal.iiop;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.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.math.BigDecimal;import java.rmi.Remote;import java.rmi.StubNotFoundException;import org.omg.CORBA.SystemException;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.MARSHAL;import org.omg.CORBA.DATA_CONVERSION;import org.omg.CORBA.BAD_PARAM;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.NO_IMPLEMENT;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.portable.ObjectImpl;import org.omg.CORBA.MARSHAL;import javax.rmi.PortableRemoteObject;import javax.rmi.CORBA.Tie;import javax.rmi.CORBA.Util;import javax.rmi.CORBA.ValueHandler;import com.sun.corba.se.internal.corba.ServerDelegate;import com.sun.corba.se.internal.corba.PrincipalImpl;import com.sun.corba.se.internal.corba.TypeCodeImpl;import com.sun.corba.se.internal.core.IOR;import com.sun.corba.se.internal.core.SubcontractRegistry;import com.sun.corba.se.internal.core.ServerSubcontract;import com.sun.corba.se.internal.core.ClientSubcontract;import com.sun.corba.se.internal.core.GIOPVersion;import com.sun.corba.se.internal.core.ORBVersionImpl;import com.sun.corba.se.internal.core.ORBVersion;import com.sun.corba.se.internal.core.CodeSetConversion;import com.sun.corba.se.internal.util.Utility;import com.sun.corba.se.internal.orbutil.RepositoryIdStrings;import com.sun.corba.se.internal.orbutil.RepositoryIdInterface;import com.sun.corba.se.internal.orbutil.RepositoryIdUtility;import com.sun.corba.se.internal.orbutil.RepositoryIdFactory;import com.sun.corba.se.internal.orbutil.ORBUtility;import com.sun.corba.se.internal.orbutil.CacheTable;import com.sun.corba.se.internal.orbutil.MinorCodes;import com.sun.corba.se.internal.ior.ObjectKeyTemplate ;import com.sun.org.omg.CORBA.portable.ValueHelper;import com.sun.org.omg.SendingContext.CodeBase;import java.security.AccessController;import java.security.PrivilegedExceptionAction;import java.security.PrivilegedActionException;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 com.sun.corba.se.internal.corba.ORB orb;    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 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;        // Template method    public CDRInputStreamBase dup() {        CDRInputStreamBase result;        try {            result = (CDRInputStreamBase)this.getClass().newInstance();        } catch (InstantiationException e) {            debugPrintThrowable(e);            throw new INTERNAL();        } catch (IllegalAccessException e) {            debugPrintThrowable(e);            throw new INTERNAL();        }        result.init(this.orb,                    this.bbwi.buf,                    this.bbwi.buflen,                    this.littleEndian,                    this.bufferManagerRead);        ((CDRInputStream_1_0)result).bbwi.index = this.bbwi.index;        return result;    }    /**     * NOTE:  size passed to init means buffer size     */    public void init(org.omg.CORBA.ORB orb,                      byte[] data,                      int size,                      boolean littleEndian,                     BufferManagerRead bufferManager)     {        this.orb = (com.sun.corba.se.internal.corba.ORB)orb;        this.littleEndian = littleEndian;        this.bufferManagerRead = bufferManager;        this.bbwi = new ByteBufferWithInfo(data, 0);        this.bbwi.buflen = size;        this.markAndResetHandler = bufferManagerRead.getMarkAndResetHandler();        // The ORB seems to be null in some cases due to primitive        // TypeCodeImpls (which are singletons) not having ORB instances.        if (orb != null)            debug = ((com.sun.corba.se.internal.corba.ORB)orb).transportDebugFlag;    }    // See description in CDRInputStream    void performORBVersionSpecificInit() {        createRepositoryIdHandlers();    }    private final void createRepositoryIdHandlers()    {        if (orb != null) {            // Get the appropriate versions based on the ORB version.  The            // ORB versioning info is only in the corba ORB.            repIdUtil = RepositoryIdFactory.getRepIdUtility(orb);            repIdStrs = RepositoryIdFactory.getRepIdStringsFactory(orb);        } else {            // Get the latest versions            repIdUtil = RepositoryIdFactory.getRepIdUtility();            repIdStrs = RepositoryIdFactory.getRepIdStringsFactory();        }    }    public GIOPVersion getGIOPVersion() {        return GIOPVersion.V1_0;    }    protected final int computeAlignment(int align) {        if (align > 1) {            int incr = bbwi.index & (align - 1);            if (incr != 0)                return align - incr;        }        return 0;    }    public int getSize()    {        return bbwi.index;    }    protected void checkBlockLength() {	// Since chunks can end at arbitrary points (though not within	// primitive CDR types, arrays of primitives, strings, or wstrings),	// we must check here for termination of the current chunk.	// This also takes care of terminating an open chunk when a	// value tag is encountered.        if (!isChunked)            return;	if (blockLength == get_offset()) {	    blockLength = maxBlockLength;	    start_block();	} else if (blockLength < get_offset()) {	    // current chunk has overflowed	    throw new MARSHAL("Chunk overflow at offset " + get_offset(),			      com.sun.corba.se.internal.orbutil.MinorCodes.CHUNK_OVERFLOW,                               CompletionStatus.COMPLETED_NO);	}    }    protected void alignAndCheck(int align, int n) {        checkBlockLength();        bbwi.index += computeAlignment(align);    	if (bbwi.index + 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();    }    // No such type in java    public final double read_longdouble() {	throw new NO_IMPLEMENT(com.sun.corba.se.internal.orbutil.MinorCodes.SEND_DEFERRED_NOTIMPLEMENTED,			       CompletionStatus.COMPLETED_MAYBE);    }    public final boolean read_boolean() {	return (read_octet() != 0);    }    public final char read_char() {        alignAndCheck(1, 1);        return getConvertedChars(1, getCharConverter())[0];    }    public char read_wchar() {        // Don't allow transmission of wchar/wstring data with        // foreign ORBs since it's against the spec.        if (ORBUtility.isForeignORB((com.sun.corba.se.internal.corba.ORB)orb)) {            throw new MARSHAL(MinorCodes.WCHAR_DATA_IN_GIOP_1_0,                              CompletionStatus.COMPLETED_MAYBE);        }        // If we're talking to one of our legacy ORBs, do what        // they did:        int b1, b2;	alignAndCheck(2, 2);	if (littleEndian) {	    b2 = bbwi.buf[bbwi.index++] & 0x00FF;	    b1 = bbwi.buf[bbwi.index++] & 0x00FF;	} else {	    b1 = bbwi.buf[bbwi.index++] & 0x00FF;	    b2 = bbwi.buf[bbwi.index++] & 0x00FF;	}	return (char)((b1 << 8) + (b2 << 0));    }    public final byte read_octet() {        alignAndCheck(1, 1);    	return bbwi.buf[bbwi.index++];    }    public final short read_short() {    	int b1, b2;    	alignAndCheck(2, 2);    	if (littleEndian) {    	    b2 = (bbwi.buf[bbwi.index++] << 0) & 0x000000FF;    	    b1 = (bbwi.buf[bbwi.index++] << 8) & 0x0000FF00;    	} else {    	    b1 = (bbwi.buf[bbwi.index++] << 8) & 0x0000FF00;    	    b2 = (bbwi.buf[bbwi.index++] << 0) & 0x000000FF;    	}    	return (short)(b1 | b2);    }    public final short read_ushort() {	return read_short();    }    public final int read_long() {    	int b1, b2, b3, b4;        alignAndCheck(4, 4);    	if (littleEndian) {    	    b4 = bbwi.buf[bbwi.index++] & 0xFF;    	    b3 = bbwi.buf[bbwi.index++] & 0xFF;    	    b2 = bbwi.buf[bbwi.index++] & 0xFF;    	    b1 = bbwi.buf[bbwi.index++] & 0xFF;    	} else {    	    b1 = bbwi.buf[bbwi.index++] & 0xFF;    	    b2 = bbwi.buf[bbwi.index++] & 0xFF;    	    b3 = bbwi.buf[bbwi.index++] & 0xFF;    	    b4 = bbwi.buf[bbwi.index++] & 0xFF;    	}    	return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;    }

⌨️ 快捷键说明

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