inputstreamhook.java
来自「JAVA 所有包」· Java 代码 · 共 454 行 · 第 1/2 页
JAVA
454 行
/* * @(#)InputStreamHook.java 1.20 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.io;import java.io.IOException;import java.io.StreamCorruptedException;import java.io.NotActiveException;import java.io.InputStream;import java.io.ObjectInputStream;import java.util.*;import java.lang.reflect.Array;import java.lang.reflect.Constructor;import org.omg.CORBA.portable.ValueInputStream;import com.sun.corba.se.spi.orb.ORB;import com.sun.corba.se.spi.orb.ORBVersion;import com.sun.corba.se.spi.orb.ORBVersionFactory;import com.sun.corba.se.spi.logging.CORBALogDomains;import com.sun.corba.se.impl.logging.UtilSystemException;import com.sun.corba.se.impl.logging.OMGSystemException;public abstract class InputStreamHook extends ObjectInputStream{ // These should be visible in all the nested classes static final OMGSystemException omgWrapper = OMGSystemException.get( CORBALogDomains.RPC_ENCODING ) ; static final UtilSystemException utilWrapper = UtilSystemException.get( CORBALogDomains.RPC_ENCODING ) ; private class HookGetFields extends ObjectInputStream.GetField { private Map fields = null; HookGetFields(Map fields){ this.fields = fields; } /** * Get the ObjectStreamClass that describes the fields in the stream. * * REVISIT! This doesn't work since we have our own ObjectStreamClass. */ public java.io.ObjectStreamClass getObjectStreamClass() { return null; } /** * Return true if the named field is defaulted and has no value * in this stream. */ public boolean defaulted(String name) throws IOException, IllegalArgumentException { return (!fields.containsKey(name)); } /** * Get the value of the named boolean field from the persistent field. */ public boolean get(String name, boolean defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return ((Boolean)fields.get(name)).booleanValue(); } /** * Get the value of the named char field from the persistent fields. */ public char get(String name, char defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return ((Character)fields.get(name)).charValue(); } /** * Get the value of the named byte field from the persistent fields. */ public byte get(String name, byte defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return ((Byte)fields.get(name)).byteValue(); } /** * Get the value of the named short field from the persistent fields. */ public short get(String name, short defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return ((Short)fields.get(name)).shortValue(); } /** * Get the value of the named int field from the persistent fields. */ public int get(String name, int defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return ((Integer)fields.get(name)).intValue(); } /** * Get the value of the named long field from the persistent fields. */ public long get(String name, long defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return ((Long)fields.get(name)).longValue(); } /** * Get the value of the named float field from the persistent fields. */ public float get(String name, float defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return ((Float)fields.get(name)).floatValue(); } /** * Get the value of the named double field from the persistent field. */ public double get(String name, double defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return ((Double)fields.get(name)).doubleValue(); } /** * Get the value of the named Object field from the persistent field. */ public Object get(String name, Object defvalue) throws IOException, IllegalArgumentException { if (defaulted(name)) return defvalue; else return fields.get(name); } public String toString(){ return fields.toString(); } } public InputStreamHook() throws IOException { super(); } public void defaultReadObject() throws IOException, ClassNotFoundException, NotActiveException { readObjectState.beginDefaultReadObject(this); defaultReadObjectDelegate(); readObjectState.endDefaultReadObject(this); } public abstract void defaultReadObjectDelegate(); abstract void readFields(java.util.Map fieldToValueMap) throws java.io.InvalidClassException, java.io.StreamCorruptedException, ClassNotFoundException, java.io.IOException; // See java.io.ObjectInputStream.GetField // Remember that this is equivalent to defaultReadObject // in RMI-IIOP public ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException, NotActiveException { HashMap fieldValueMap = new HashMap(); // We were treating readFields same as defaultReadObject. It is // incorrect if the state is readOptionalData. If this line // is uncommented, it will throw a stream corrupted exception. // _REVISIT_: The ideal fix would be to add a new state. In // writeObject user may do one of the following // 1. Call defaultWriteObject() // 2. Put out optional fields // 3. Call writeFields // We have the state defined for (1) and (2) but not for (3), so // we should ideally introduce a new state for 3 and have the // beginDefaultReadObject do nothing. //readObjectState.beginDefaultReadObject(this); readFields(fieldValueMap); readObjectState.endDefaultReadObject(this); return new HookGetFields(fieldValueMap); } // The following is a State pattern implementation of what // should be done when the sender's Serializable has a // writeObject method. This was especially necessary for // RMI-IIOP stream format version 2. Please see the // state diagrams in the docs directory of the workspace.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?