cdrinputstream_1_0.java

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

JAVA
2,002
字号
    public final int read_ulong() {	return read_long();    }    public final long read_longlong() {    	long i1, i2;    	alignAndCheck(8, 8);    	if (littleEndian) {    	    i2 = read_long() & 0xFFFFFFFFL;    	    i1 = (long)read_long() << 32;    	} else {    	    i1 = (long)read_long() << 32;    	    i2 = read_long() & 0xFFFFFFFFL;    	}    	return (i1 | i2);    }    public final long read_ulonglong() {	return read_longlong();    }    public final float read_float() {	return Float.intBitsToFloat(read_long());    }    public final double read_double() {	return Double.longBitsToDouble(read_longlong());    }    protected final void checkForNegativeLength(int length) {        if (length < 0)            throw new MARSHAL("Bad string length: " + length,                              MinorCodes.NEGATIVE_STRING_LENGTH,                              CompletionStatus.COMPLETED_MAYBE);    }    protected final String readStringOrIndirection(boolean allowIndirection) {    	int len = read_long();        //        // Check for indirection        //        if (allowIndirection) {            if (len == 0xffffffff)		return null;	    else		stringIndirection = get_offset() - 4;	}        checkForNegativeLength(len);        if (orb != null && ORBUtility.isLegacyORB((com.sun.corba.se.internal.corba.ORB)orb))            return legacyReadString(len);        else            return internalReadString(len);    }    private final String internalReadString(int len) {    	// Workaround for ORBs which send string lengths of    	// zero to mean empty string.        // IMPORTANT: Do not replace 'new String("")' with "", it may result        // in a Serialization bug (See serialization.zerolengthstring) and        // bug id: 4728756 for details     	if (len == 0)    	    return new String("");        char[] result = getConvertedChars(len - 1, getCharConverter());        // Skip over the 1 byte null        read_octet();        return new String(result, 0, getCharConverter().getNumChars());    }    private final String legacyReadString(int len) {    	//    	// Workaround for ORBs which send string lengths of    	// zero to mean empty string.    	//        // IMPORTANT: Do not replace 'new String("")' with "", it may result        // in a Serialization bug (See serialization.zerolengthstring) and        // bug id: 4728756 for details     	if (len == 0)    	    return new String("");        len--;        char[] c = new char[len];    	int n = 0;    	while (n < len) {    	    int avail;    	    int bytes;    	    int wanted;    	    avail = bbwi.buflen - bbwi.index;            if (avail <= 0) {                grow(1, 1);                avail = bbwi.buflen - bbwi.index;            }    	    wanted = len - n;    	    bytes = (wanted < avail) ? wanted : avail;            for (int i=0; i<bytes; i++) {        	c[n+i] = (char) (bbwi.buf[bbwi.index+i] & 0xFF);            }    	    bbwi.index += bytes;    	    n += bytes;    	}        //        // Skip past terminating null byte        //        if (bbwi.index + 1 > bbwi.buflen)            alignAndCheck(1, 1);    	bbwi.index++;    	return new String(c);    }    public final String read_string() {        return readStringOrIndirection(false);    }    public String read_wstring() {        // 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);        }    	int len = read_long();    	//    	// Workaround for ORBs which send string lengths of    	// zero to mean empty string.    	//        // IMPORTANT: Do not replace 'new String("")' with "", it may result        // in a Serialization bug (See serialization.zerolengthstring) and        // bug id: 4728756 for details     	if (len == 0)    	    return new String("");        checkForNegativeLength(len);        len--;        char[] c = new char[len];        for (int i = 0; i < len; i++)            c[i] = read_wchar();        // skip the two null terminator bytes        read_wchar();        // bbwi.index += 2;        return new String(c);    }    public final void read_octet_array(byte[] b, int offset, int length) {    	if ( b == null )    	    throw new BAD_PARAM();        // Must call alignAndCheck at least once to ensure        // we aren't at the end of a chunk.  Of course, we        // should only call it if we actually need to read        // something, otherwise we might end up with an        // exception at the end of the stream.        if (length == 0)            return;        alignAndCheck(1, 1);    	int n = offset;    	while (n < length+offset) {    	    int avail;    	    int bytes;    	    int wanted;    	    avail = bbwi.buflen - bbwi.index;            if (avail <= 0) {                grow(1, 1);                avail = bbwi.buflen - bbwi.index;            }    	    wanted = (length + offset) - n;    	    bytes = (wanted < avail) ? wanted : avail;    	    System.arraycopy(bbwi.buf, bbwi.index, b, n, bytes);    	    bbwi.index += bytes;    	    n += bytes;    	}    }    public Principal read_Principal() {    	int len = read_long();    	byte[] pvalue = new byte[len];    	read_octet_array(pvalue,0,len);    	Principal p = new PrincipalImpl();    	p.name(pvalue);	    	return p;    }    public TypeCode read_TypeCode() {        TypeCodeImpl tc = new TypeCodeImpl(orb);        tc.read_value(parent);	return tc;    }      public Any read_any() {        Any any = orb.create_any();        TypeCodeImpl tc = new TypeCodeImpl(orb);        // read off the typecode        // REVISIT We could avoid this try-catch if we could peek the typecode kind        // off this stream and see if it is a tk_value.        // Looking at the code we know that for tk_value the Any.read_value() below        // ignores the tc argument anyway (except for the kind field).        // But still we would need to make sure that the whole typecode, including        // encapsulations, is read off.        try {            tc.read_value(parent);        } catch (MARSHAL ex) {            if (tc.kind().value() != TCKind._tk_value)                throw ex;            // We can be sure that the whole typecode encapsulation has been read off.            //System.out.println("Error reading value tc " + tc + ", falling back on ValueHandler");            debugPrintThrowable(ex);        }        // read off the value of the any        any.read_value(parent, tc);        return any;    }    public org.omg.CORBA.Object read_Object() {         return read_Object(null);    }    // ------------ RMI related methods --------------------------    // IDL to Java ptc-00-01-08 1.21.4.1    //    // The clz argument to read_Object can be either a stub    // Class or the "Class object for the RMI/IDL interface type     // that is statically expected."    public org.omg.CORBA.Object read_Object(Class clz) {	IOR ior = new IOR(parent) ;        if (clz == null || ObjectImpl.class.isAssignableFrom(clz)) {            // We were given null or a stub class            return CDRInputStream_1_0.internalIORToObject(ior, clz, orb);        } else {            // We must have been given the Class object for the RMI/IDL            // interface            try {                Class stubClass                     = Utility.loadStubClass(ior.getTypeId(),                                            ior.getCodebase(),                                            clz);                return CDRInputStream_1_0.internalIORToObject(ior,                                                               stubClass,                                                               orb);            } catch (ClassNotFoundException cnfe) {                // Failed to load the stub class.                throw new MARSHAL("Failed to load stub for "                                   + ior.getTypeId()                                  + " with Class "                                   + (clz == null ? "null" : clz.getName()),                                  MinorCodes.READ_OBJECT_EXCEPTION,                                   CompletionStatus.COMPLETED_NO);            }        }    }    /*     * This is used as a general utility (e.g., the PortableInterceptor     * implementation uses it.  NOTE:  The Class passed in must be the     * Stub Class.     */    public static org.omg.CORBA.Object internalIORToObject(        IOR ior, Class stubClass, com.sun.corba.se.internal.core.ORB orb)    {        if (ior.is_nil())             return null;	    	if (ior.isLocal()) {	    // Ok so far. Can we get a valid servant?	    ServerSubcontract sc = ior.getServerSubcontract() ;	    if (sc != null && (sc.isServantSupported())) {		java.lang.Object servant = sc.getServant(ior);		if (servant != null ) {			    		    // Got a valid servant. Is it a Tie?		    if (servant instanceof Tie) {			// Yes, so it is a local servant. Load a stub			// for it using the codebase from the IOR and			// the delegate from the tie.			String codebase = ior.getCodebase();			org.omg.CORBA.Object objref = (org.omg.CORBA.Object)			    Utility.loadStub((Tie)servant,stubClass,codebase,false);			    			// If we managed to load a stub, return it, otherwise we			// must fail...			if (objref != null) {			    return objref;   			} else {			    throw new MARSHAL(				com.sun.corba.se.internal.orbutil.MinorCodes.READ_OBJECT_EXCEPTION, 				CompletionStatus.COMPLETED_NO);			}		    } else if (servant instanceof org.omg.CORBA.Object) {			if (servant instanceof org.omg.CORBA.portable.InvokeHandler) {			    // Old ImplBase stubs are CORBA.Objects.			    // However, they are not stubs.			    return createDelegate(ior, stubClass, orb);			} else {			    // No, so assume IDL style stub...			    return (org.omg.CORBA.Object) servant;			}		    } else			throw new INTERNAL( MinorCodes.BAD_SERVANT_READ_OBJECT,			    CompletionStatus.COMPLETED_NO ) ;		}            }    	}	return createDelegate(ior, stubClass, orb);    }    protected static org.omg.CORBA.Object createDelegate(        IOR ior, Class stubClass, com.sun.corba.se.internal.core.ORB orb)    {	SubcontractRegistry registry = orb.getSubcontractRegistry() ;	ObjectKeyTemplate temp = ior.getProfile().getTemplate().getObjectKeyTemplate() ;    	ClientSubcontract rep = registry.getClientSubcontract(temp);    	rep.unmarshal(ior);    	rep.setOrb(orb);        // Load stub, set the delegate and return it...                    return loadStub(ior,stubClass,(Delegate)rep);    }    protected static ObjectImpl loadStub(IOR ior,                                          Class stubClass,                                         Delegate delegate) {	                                                    // Use the stubClass, if we have it...                if (stubClass != null) {            try {                return newStub(stubClass,delegate);            } catch (Throwable e) {                if (e instanceof ThreadDeath) {                    throw (ThreadDeath) e;                }            }	} else {                        // Try to load from the ior...            try {         		String repID = ior.getTypeId();				// If the repID is "", fall thru to returning the default		// stub, otherwise try to load the class...						if (repID.length() > 0) {		    String codebase = ior.getCodebase();                    Class clz = Utility.loadStubClass(repID, codebase, null); //d11638                    return newStub(clz,delegate);                }            } catch (Throwable e) {                if (e instanceof ThreadDeath) {                    throw (ThreadDeath) e;                }            }            // Return the "default" stub...            	                ObjectImpl objref = new org.omg.CORBA_2_3.portable.ObjectImpl() {                public String[] _ids() {		    String[] typeids = new String[1];		    typeids[0] = "IDL:omg.org/CORBA/Object:1.0";		    return typeids;                }	    };        	        	    objref._set_delegate(delegate);    	    return objref;	}

⌨️ 快捷键说明

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