inputstreamhook.java

来自「JAVA 所有包」· Java 代码 · 共 454 行 · 第 1/2 页

JAVA
454
字号
    //    // On the reader's side, the main factors are whether or not    // we have a readObject method and whether or not the    // sender wrote default data    protected void setState(ReadObjectState newState) {        readObjectState = newState;    }    protected abstract byte getStreamFormatVersion();    protected abstract org.omg.CORBA_2_3.portable.InputStream getOrbStream();    // Description of possible actions    protected static class ReadObjectState {        public void beginUnmarshalCustomValue(InputStreamHook stream,                                              boolean calledDefaultWriteObject,                                              boolean hasReadObject) throws IOException {}        public void endUnmarshalCustomValue(InputStreamHook stream) throws IOException {}        public void beginDefaultReadObject(InputStreamHook stream) throws IOException {}        public void endDefaultReadObject(InputStreamHook stream) throws IOException {}        public void readData(InputStreamHook stream) throws IOException {}    }    protected ReadObjectState readObjectState = DEFAULT_STATE;        protected static final ReadObjectState DEFAULT_STATE = new DefaultState();    protected static final ReadObjectState IN_READ_OBJECT_OPT_DATA         = new InReadObjectOptionalDataState();    protected static final ReadObjectState IN_READ_OBJECT_NO_MORE_OPT_DATA        = new InReadObjectNoMoreOptionalDataState();    protected static final ReadObjectState IN_READ_OBJECT_DEFAULTS_SENT        = new InReadObjectDefaultsSentState();    protected static final ReadObjectState NO_READ_OBJECT_DEFAULTS_SENT        = new NoReadObjectDefaultsSentState();    protected static final ReadObjectState IN_READ_OBJECT_REMOTE_NOT_CUSTOM_MARSHALED        = new InReadObjectRemoteDidNotUseWriteObjectState();    protected static final ReadObjectState IN_READ_OBJECT_PAST_DEFAULTS_REMOTE_NOT_CUSTOM        = new InReadObjectPastDefaultsRemoteDidNotUseWOState();    protected static class DefaultState extends ReadObjectState {        public void beginUnmarshalCustomValue(InputStreamHook stream,                                              boolean calledDefaultWriteObject,                                              boolean hasReadObject)            throws IOException {            if (hasReadObject) {                if (calledDefaultWriteObject)                    stream.setState(IN_READ_OBJECT_DEFAULTS_SENT);                else {                    try {                        if (stream.getStreamFormatVersion() == 2)                            ((ValueInputStream)stream.getOrbStream()).start_value();                    } catch( Exception e ) {                        // This will happen for Big Integer which uses                         // writeFields in it's writeObject. We should be past                        // start_value by now.                        // NOTE: If we don't log any exception here we should                        // be fine. If there is an error, it will be caught                         // while reading the optional data.                                     }                    stream.setState(IN_READ_OBJECT_OPT_DATA);                }            } else {                if (calledDefaultWriteObject)                    stream.setState(NO_READ_OBJECT_DEFAULTS_SENT);                else		    // XXX I18N and logging needed.                    throw new StreamCorruptedException("No default data sent");            }        }    }    // REVISIT.  If a readObject exits here without reading    // default data, we won't skip it.  This could be done automatically    // as in line 1492 in IIOPInputStream.    protected static class InReadObjectRemoteDidNotUseWriteObjectState extends ReadObjectState {        public void beginUnmarshalCustomValue(InputStreamHook stream,                                              boolean calledDefaultWriteObject,                                              boolean hasReadObject) 	{	    throw utilWrapper.badBeginUnmarshalCustomValue() ;        }        public void endDefaultReadObject(InputStreamHook stream) {            stream.setState(IN_READ_OBJECT_PAST_DEFAULTS_REMOTE_NOT_CUSTOM);        }        public void readData(InputStreamHook stream) {            stream.throwOptionalDataIncompatibleException();        }    }    protected static class InReadObjectPastDefaultsRemoteDidNotUseWOState extends ReadObjectState {        public void beginUnmarshalCustomValue(InputStreamHook stream,                                              boolean calledDefaultWriteObject,                                              boolean hasReadObject)	{	    throw utilWrapper.badBeginUnmarshalCustomValue() ;        }        public void beginDefaultReadObject(InputStreamHook stream) throws IOException 	{	    // XXX I18N and logging needed.            throw new StreamCorruptedException("Default data already read");        }        public void readData(InputStreamHook stream) {            stream.throwOptionalDataIncompatibleException();        }    }    protected void throwOptionalDataIncompatibleException()     {	throw omgWrapper.rmiiiopOptionalDataIncompatible2() ;    }    protected static class InReadObjectDefaultsSentState extends ReadObjectState {                public void beginUnmarshalCustomValue(InputStreamHook stream,                                              boolean calledDefaultWriteObject,                                              boolean hasReadObject) {            // This should never happen.	    throw utilWrapper.badBeginUnmarshalCustomValue() ;        }        public void endUnmarshalCustomValue(InputStreamHook stream) {            // In stream format version 2, we can skip over            // the optional data this way.  In stream format version 1,            // we will probably wind up with an error if we're            // unmarshaling a superclass.            if (stream.getStreamFormatVersion() == 2) {                ((ValueInputStream)stream.getOrbStream()).start_value();                ((ValueInputStream)stream.getOrbStream()).end_value();            }            stream.setState(DEFAULT_STATE);        }        public void endDefaultReadObject(InputStreamHook stream) throws IOException {            // Read the fake valuetype header in stream format version 2            if (stream.getStreamFormatVersion() == 2)                 ((ValueInputStream)stream.getOrbStream()).start_value();            stream.setState(IN_READ_OBJECT_OPT_DATA);        }        public void readData(InputStreamHook stream) throws IOException {	    org.omg.CORBA.ORB orb = stream.getOrbStream().orb();	    if ((orb == null) ||		    !(orb instanceof com.sun.corba.se.spi.orb.ORB)) {		throw new StreamCorruptedException(				     "Default data must be read first");	    }	    ORBVersion clientOrbVersion = 		((com.sun.corba.se.spi.orb.ORB)orb).getORBVersion();	    // Fix Date interop bug. For older versions of the ORB don't do	    // anything for readData(). Before this used to throw 	    // StreamCorruptedException for older versions of the ORB where	    // calledDefaultWriteObject always returns true.	    if ((ORBVersionFactory.getPEORB().compareTo(clientOrbVersion) <= 0) || 		    (clientOrbVersion.equals(ORBVersionFactory.getFOREIGN()))) {		// XXX I18N and logging needed.		throw new StreamCorruptedException("Default data must be read first");	    }        }    }    protected static class InReadObjectOptionalDataState extends ReadObjectState {        public void beginUnmarshalCustomValue(InputStreamHook stream,                                              boolean calledDefaultWriteObject,                                              boolean hasReadObject) 	{            // This should never happen.	    throw utilWrapper.badBeginUnmarshalCustomValue() ;        }        public void endUnmarshalCustomValue(InputStreamHook stream) throws IOException 	{            if (stream.getStreamFormatVersion() == 2) {                ((ValueInputStream)stream.getOrbStream()).end_value();            }            stream.setState(DEFAULT_STATE);        }                public void beginDefaultReadObject(InputStreamHook stream) throws IOException 	{	    // XXX I18N and logging needed.            throw new StreamCorruptedException("Default data not sent or already read/passed");        }            }    protected static class InReadObjectNoMoreOptionalDataState         extends InReadObjectOptionalDataState {        public void readData(InputStreamHook stream) throws IOException {            stream.throwOptionalDataIncompatibleException();        }    }    protected static class NoReadObjectDefaultsSentState extends ReadObjectState {        public void endUnmarshalCustomValue(InputStreamHook stream) throws IOException {            // Code should read default fields before calling this            if (stream.getStreamFormatVersion() == 2) {                ((ValueInputStream)stream.getOrbStream()).start_value();                ((ValueInputStream)stream.getOrbStream()).end_value();            }            stream.setState(DEFAULT_STATE);        }    }}

⌨️ 快捷键说明

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