📄 iiopoutputstream.java
字号:
/* * @(#)IIOPOutputStream.java 1.52 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 org.omg.CORBA.INTERNAL;import org.omg.CORBA.portable.OutputStream;import java.security.AccessController ;import java.security.PrivilegedAction ;import java.io.IOException;import java.io.DataOutputStream;import java.io.Serializable;import java.io.InvalidClassException;import java.io.StreamCorruptedException;import java.io.Externalizable;import java.io.ObjectStreamException;import java.io.NotSerializableException;import java.io.NotActiveException;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Field;import java.util.Stack;import javax.rmi.CORBA.Util;import javax.rmi.CORBA.ValueHandlerMultiFormat;import sun.corba.Bridge ;import com.sun.corba.se.impl.io.ObjectStreamClass;import com.sun.corba.se.impl.util.Utility;import com.sun.corba.se.impl.util.RepositoryId;import com.sun.corba.se.spi.logging.CORBALogDomains ;import com.sun.corba.se.impl.logging.UtilSystemException ;/** * IIOPOutputStream is ... * * @author Stephen Lewallen * @version 0.01, 4/6/98 * @since JDK1.1.6 */public class IIOPOutputStream extends com.sun.corba.se.impl.io.OutputStreamHook{ private UtilSystemException wrapper = UtilSystemException.get( CORBALogDomains.RPC_ENCODING ) ; private static Bridge bridge = (Bridge)AccessController.doPrivileged( new PrivilegedAction() { public Object run() { return Bridge.get() ; } } ) ; private org.omg.CORBA_2_3.portable.OutputStream orbStream; private Object currentObject = null; private ObjectStreamClass currentClassDesc = null; private int recursionDepth = 0; private int simpleWriteDepth = 0; private IOException abortIOException = null; private java.util.Stack classDescStack = new java.util.Stack(); // Used when calling an object's writeObject method private Object[] writeObjectArgList = {this}; public IIOPOutputStream() throws java.io.IOException { super(); } // If using RMI-IIOP stream format version 2, this tells // the ORB stream (which must be a ValueOutputStream) to // begin a new valuetype to contain the optional data // of the writeObject method. protected void beginOptionalCustomData() { if (streamFormatVersion == 2) { org.omg.CORBA.portable.ValueOutputStream vout = (org.omg.CORBA.portable.ValueOutputStream)orbStream; vout.start_value(currentClassDesc.getRMIIIOPOptionalDataRepId()); } } public final void setOrbStream(org.omg.CORBA_2_3.portable.OutputStream os) { orbStream = os; } public final org.omg.CORBA_2_3.portable.OutputStream getOrbStream() { return orbStream; } public final void increaseRecursionDepth(){ recursionDepth++; } public final int decreaseRecursionDepth(){ return --recursionDepth; } /** * Override the actions of the final method "writeObject()" * in ObjectOutputStream. * @since JDK1.1.6 */ public final void writeObjectOverride(Object obj) throws IOException { writeObjectState.writeData(this); Util.writeAbstractObject((OutputStream)orbStream, obj); } /** * Override the actions of the final method "writeObject()" * in ObjectOutputStream. * @since JDK1.1.6 */ public final void simpleWriteObject(Object obj, byte formatVersion) /* throws IOException */ { byte oldStreamFormatVersion = streamFormatVersion; streamFormatVersion = formatVersion; Object prevObject = currentObject; ObjectStreamClass prevClassDesc = currentClassDesc; simpleWriteDepth++; try { // if (!checkSpecialClasses(obj) && !checkSubstitutableSpecialClasses(obj)) outputObject(obj); } catch (IOException ee) { if (abortIOException == null) abortIOException = ee; } finally { /* Restore state of previous call incase this is a nested call */ streamFormatVersion = oldStreamFormatVersion; simpleWriteDepth--; currentObject = prevObject; currentClassDesc = prevClassDesc; } /* If the recursion depth is 0, test for and clear the pending exception. * If there is a pending exception throw it. */ IOException pending = abortIOException; if (simpleWriteDepth == 0) abortIOException = null; if (pending != null) { bridge.throwException( pending ) ; } } // Required by the superclass. ObjectStreamField[] getFieldsNoCopy() { return currentClassDesc.getFieldsNoCopy(); } /** * Override the actions of the final method "defaultWriteObject()" * in ObjectOutputStream. * @since JDK1.1.6 */ public final void defaultWriteObjectDelegate() /* throws IOException */ { try { if (currentObject == null || currentClassDesc == null) // XXX I18N, Logging needed. throw new NotActiveException("defaultWriteObjectDelegate"); ObjectStreamField[] fields = currentClassDesc.getFieldsNoCopy(); if (fields.length > 0) { outputClassFields(currentObject, currentClassDesc.forClass(), fields); } } catch(IOException ioe) { bridge.throwException(ioe); } } /** * Override the actions of the final method "enableReplaceObject()" * in ObjectOutputStream. * @since JDK1.1.6 */ public final boolean enableReplaceObjectDelegate(boolean enable) /* throws SecurityException */ { return false; } protected final void annotateClass(Class<?> cl) throws IOException{ // XXX I18N, Logging needed. throw new IOException("Method annotateClass not supported"); } public final void close() throws IOException{ // no op } protected final void drain() throws IOException{ // no op } public final void flush() throws IOException{ try{ orbStream.flush(); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } protected final Object replaceObject(Object obj) throws IOException{ // XXX I18N, Logging needed. throw new IOException("Method replaceObject not supported"); } /** * Reset will disregard the state of any objects already written * to the stream. The state is reset to be the same as a new * ObjectOutputStream. The current point in the stream is marked * as reset so the corresponding ObjectInputStream will be reset * at the same point. Objects previously written to the stream * will not be refered to as already being in the stream. They * will be written to the stream again. * @since JDK1.1 */ public final void reset() throws IOException{ try{ //orbStream.reset(); if (currentObject != null || currentClassDesc != null) // XXX I18N, Logging needed. throw new IOException("Illegal call to reset"); abortIOException = null; if (classDescStack == null) classDescStack = new java.util.Stack(); else classDescStack.setSize(0); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void write(byte b[]) throws IOException{ try{ writeObjectState.writeData(this); orbStream.write_octet_array(b, 0, b.length); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void write(byte b[], int off, int len) throws IOException{ try{ writeObjectState.writeData(this); orbStream.write_octet_array(b, off, len); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void write(int data) throws IOException{ try{ writeObjectState.writeData(this); orbStream.write_octet((byte)(data & 0xFF)); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void writeBoolean(boolean data) throws IOException{ try{ writeObjectState.writeData(this); orbStream.write_boolean(data); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void writeByte(int data) throws IOException{ try{ writeObjectState.writeData(this); orbStream.write_octet((byte)data); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void writeBytes(String data) throws IOException{ try{ writeObjectState.writeData(this); byte buf[] = data.getBytes(); orbStream.write_octet_array(buf, 0, buf.length); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void writeChar(int data) throws IOException{ try{ writeObjectState.writeData(this); orbStream.write_wchar((char)data); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void writeChars(String data) throws IOException{ try{ writeObjectState.writeData(this); char buf[] = data.toCharArray(); orbStream.write_wchar_array(buf, 0, buf.length); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void writeDouble(double data) throws IOException{ try{ writeObjectState.writeData(this); orbStream.write_double(data); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ; throw ioexc ; } } public final void writeFloat(float data) throws IOException{ try{ writeObjectState.writeData(this); orbStream.write_float(data); } catch(Error e) { IOException ioexc = new IOException(e.getMessage()); ioexc.initCause(e) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -