iiopinputstream.java

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

JAVA
1,852
字号
            readObjectState.readData(this);            return orbStream.read_double();        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);            throw marshalException;        } catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    public final float readFloat() throws IOException{        try{            readObjectState.readData(this);            return orbStream.read_float();        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);            throw marshalException;        } catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    public final void readFully(byte data[]) throws IOException{// d11623 : implement readFully, required for serializing some core classes        readFully(data, 0, data.length);    }    public final void readFully(byte data[],  int offset,  int size) throws IOException{// d11623 : implement readFully, required for serializing some core classes        try{            readObjectState.readData(this);            orbStream.read_octet_array(data, offset, size);        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);                        throw marshalException;        } catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    public final int readInt() throws IOException{        try{            readObjectState.readData(this);            return orbStream.read_long();        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);            throw marshalException;        } catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    public final String readLine() throws IOException{	// XXX I18N, logging needed.        throw new IOException("Method readLine not supported");    }    public final long readLong() throws IOException{        try{            readObjectState.readData(this);            return orbStream.read_longlong();        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);            throw marshalException;        } catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    public final short readShort() throws IOException{        try{            readObjectState.readData(this);            return orbStream.read_short();        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);            throw marshalException;        } catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    protected final void readStreamHeader() throws IOException, StreamCorruptedException{        // no op    }    public final int readUnsignedByte() throws IOException{        try{            readObjectState.readData(this);    	    return (orbStream.read_octet() << 0) & 0x000000FF;        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);            throw marshalException;	} catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    public final int readUnsignedShort() throws IOException{        try{            readObjectState.readData(this);    	    return (orbStream.read_ushort() << 0) & 0x0000FFFF;        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);            throw marshalException;        } catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    /**     * Helper method for correcting the Kestrel bug 4367783 (dealing     * with larger than 8-bit chars).  The old behavior is preserved     * in orbutil.IIOPInputStream_1_3 in order to interoperate with     * our legacy ORBs.     */    protected String internalReadUTF(org.omg.CORBA.portable.InputStream stream)    {        return stream.read_wstring();    }    public final String readUTF() throws IOException{        try{            readObjectState.readData(this);            return internalReadUTF(orbStream);        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);            throw marshalException;        } catch(Error e) {	    IOException exc = new IOException(e.getMessage());	    exc.initCause(e);	    throw exc ;	}    }    // If the ORB stream detects an incompatibility between what's    // on the wire and what our Serializable's readObject wants,    // it throws a MARSHAL exception with a specific minor code.    // This is rethrown to the readObject as an OptionalDataException.    // So far in RMI-IIOP, this process isn't specific enough to    // tell the readObject how much data is available, so we always    // set the OptionalDataException's EOF marker to true.    private void handleOptionalDataMarshalException(MARSHAL marshalException,                                                    boolean objectRead)        throws IOException {        // Java Object Serialization spec 3.4: "If the readObject method        // of the class attempts to read more data than is present in the        // optional part of the stream for this class, the stream will        // return -1 for bytewise reads, throw an EOFException for        // primitive data reads, or throw an OptionalDataException        // with the eof field set to true for object reads."        if (marshalException.minor             == OMGSystemException.RMIIIOP_OPTIONAL_DATA_INCOMPATIBLE1) {            IOException result;            if (!objectRead)                result = new EOFException("No more optional data");            else                result = createOptionalDataException();            result.initCause(marshalException);            setState(IN_READ_OBJECT_NO_MORE_OPT_DATA);            throw result;        }    }    public final synchronized void registerValidation(ObjectInputValidation obj,						      int prio)	throws NotActiveException, InvalidObjectException{	// XXX I18N, logging needed.        throw new Error("Method registerValidation not supported");    }    protected final Class resolveClass(ObjectStreamClass v)	throws IOException, ClassNotFoundException{	// XXX I18N, logging needed.        throw new IOException("Method resolveClass not supported");    }    protected final Object resolveObject(Object obj) throws IOException{	// XXX I18N, logging needed.        throw new IOException("Method resolveObject not supported");    }    public final int skipBytes(int len) throws IOException{        try{            readObjectState.readData(this);            byte buf[] = new byte[len];            orbStream.read_octet_array(buf, 0, len);            return len;        } catch (MARSHAL marshalException) {            handleOptionalDataMarshalException(marshalException, false);                        throw marshalException;        } catch(Error e) {            IOException exc = new IOException(e.getMessage());	    exc.initCause(e) ;	    throw exc ;        }    }    private Object inputObject(Class clz,			       String repositoryID,			       com.sun.org.omg.SendingContext.CodeBase sender,                               int offset)	throws IOException, ClassNotFoundException    {    	/*    	 * Get the descriptor and then class of the incoming object.    	 */    	currentClassDesc = ObjectStreamClass.lookup(clz);    	currentClass = currentClassDesc.forClass();    	//currentClassDesc.setClass(currentClass);    	if (currentClass == null)	    // XXX I18N, logging needed.    	    throw new ClassNotFoundException(currentClassDesc.getName());        try {            /* If Externalizable,             *  Create an instance and tell it to read its data.             * else,             *  Handle it as a serializable class.             */            if (currentClassDesc.isExternalizable()) {                try {                    currentObject = (currentClass == null) ?                        null : currentClassDesc.newInstance();                    if (currentObject != null) {                        // Store this object and its beginning position                        // since there might be indirections to it while                        // it's been unmarshalled.                        activeRecursionMgr.addObject(offset, currentObject);                        // Read format version                        readFormatVersion();                        Externalizable ext = (Externalizable)currentObject;                        ext.readExternal(this);		}	    } catch (InvocationTargetException e) {		InvalidClassException exc = new InvalidClassException(		    currentClass.getName(), 		    "InvocationTargetException accessing no-arg constructor");		exc.initCause( e ) ;		throw exc ;	    } catch (UnsupportedOperationException e) {		InvalidClassException exc = new InvalidClassException(		    currentClass.getName(), 		    "UnsupportedOperationException accessing no-arg constructor");		exc.initCause( e ) ;		throw exc ;    	    } catch (InstantiationException e) {		InvalidClassException exc = new InvalidClassException(		    currentClass.getName(), 		    "InstantiationException accessing no-arg constructor");		exc.initCause( e ) ;		throw exc ;    	    }    	} // end : if (currentClassDesc.isExternalizable())	else {    	    /* Count number of classes and descriptors we might have    	     * to work on.    	     */    	    ObjectStreamClass currdesc = currentClassDesc;    	    Class currclass = currentClass;    	    int spBase = spClass;	// current top of stack    	    /* The object's classes should be processed from supertype to subtype    	     * Push all the clases of the current object onto a stack.    	     * Note that only the serializable classes are represented    	     * in the descriptor list.    	     *    	     * Handle versioning where one or more supertypes of    	     * have been inserted or removed.  The stack will    	     * contain pairs of descriptors and the corresponding    	     * class.  If the object has a class that did not occur in    	     * the original the descriptor will be null.  If the    	     * original object had a descriptor for a class not    	     * present in the local hierarchy of the object the class will be    	     * null.    	     *    	     */    	    /*    	     * This is your basic diff pattern, made simpler    	     * because reordering is not allowed.    	     */            // sun.4296963 ibm.11861             // d11861 we should stop when we find the highest serializable class            // We need this so that when we allocate the new object below, we            // can call the constructor of the non-serializable superclass.            // Note that in the JRMP variant of this code the            // ObjectStreamClass.lookup() method handles this, but we've put            // this fix here rather than change lookup because the new behaviour            // is needed in other cases.    	    for (currdesc = currentClassDesc, currclass = currentClass;    		 currdesc != null && currdesc.isSerializable();   /*sun.4296963 ibm.11861*/    		 currdesc = currdesc.getSuperclass()) {    		/*    		 * Search the classes to see if the class of this    		 * descriptor appears further up the hierarchy. Until    		 * it's found assume its an inserted class.  If it's    		 * not found, its the descriptor's class that has been    		 * removed.    		 */    		Class cc = currdesc.forClass();    		Class cl;    		for (cl = currclass; cl != null; cl = cl.getSuperclass()) {    		    if (cc == cl) {    			// found a superclass that matches this descriptor    			break;    		    } else {    			/* Ignore a class that doesn't match.  No    			 * action is needed since it is already    			 * initialized.    			 */    		    }		} // end : for (cl = currclass; cl != null; cl = cl.getSuperclass())     		/* Test if there is room for this new entry.    		 * If not, double the size of the arrays and copy the contents.    		 */    		spClass++;    		if (spClass >= classes.length) {    		    int newlen = classes.length * 2;    		    Class[] newclasses = new Class[newlen];    		    ObjectStreamClass[] newclassdesc = new ObjectStreamClass[newlen];    		    System.arraycopy(classes, 0,				     newclasses, 0,				     classes.length);    		    System.arraycopy(classdesc, 0,    				     newclassdesc, 0,    				     classes.length);

⌨️ 快捷键说明

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