corba/src/share/classes/com/sun/corba/se/impl/io/OutputStreamHook.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 /*
  26  * Licensed Materials - Property of IBM
  27  * RMI-IIOP v1.0
  28  * Copyright IBM Corp. 1998 1999  All Rights Reserved
  29  *
  30  */
  31 
  32 package com.sun.corba.se.impl.io;
  33 
  34 import java.io.IOException;
  35 import java.io.OutputStream;
  36 import java.io.ObjectOutputStream;
  37 import java.io.ObjectOutput;
  38 import java.util.Hashtable;

  39 
  40 import org.omg.CORBA.INTERNAL;
  41 
  42 public abstract class OutputStreamHook extends ObjectOutputStream
  43 {
  44     private HookPutFields putFields = null;
  45 
  46     /**
  47      * Since ObjectOutputStream.PutField methods specify no exceptions,
  48      * we are not checking for null parameters on put methods.
  49      */
  50     private class HookPutFields extends ObjectOutputStream.PutField
  51     {
  52         private Hashtable fields = new Hashtable();
  53 
  54         /**
  55          * Put the value of the named boolean field into the persistent field.
  56          */
  57         public void put(String name, boolean value){
  58             fields.put(name, new Boolean(value));
  59         }
  60 
  61         /**
  62          * Put the value of the named char field into the persistent fields.
  63          */
  64         public void put(String name, char value){
  65             fields.put(name, new Character(value));
  66         }
  67 
  68         /**
  69          * Put the value of the named byte field into the persistent fields.
  70          */
  71         public void put(String name, byte value){
  72             fields.put(name, new Byte(value));


 123 
 124             ObjectStreamField[] osfields = hook.getFieldsNoCopy();
 125 
 126             // Write the fields to the stream in the order
 127             // provided by the ObjectStreamClass.  (They should
 128             // be sorted appropriately already.)
 129             for (int i = 0; i < osfields.length; i++) {
 130 
 131                 Object value = fields.get(osfields[i].getName());
 132 
 133                 hook.writeField(osfields[i], value);
 134             }
 135         }
 136     }
 137 
 138     abstract void writeField(ObjectStreamField field, Object value) throws IOException;
 139 
 140     public OutputStreamHook()
 141         throws java.io.IOException {
 142         super();
 143 
 144     }
 145 
 146     public void defaultWriteObject() throws IOException {
 147 
 148         writeObjectState.defaultWriteObject(this);
 149 
 150         defaultWriteObjectDelegate();
 151     }
 152 
 153     public abstract void defaultWriteObjectDelegate();
 154 
 155     public ObjectOutputStream.PutField putFields()
 156         throws IOException {
 157         putFields = new HookPutFields();
 158         return putFields;
 159     }
 160 
 161     // Stream format version, saved/restored during recursive calls
 162     protected byte streamFormatVersion = 1;
 163 


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 /*
  26  * Licensed Materials - Property of IBM
  27  * RMI-IIOP v1.0
  28  * Copyright IBM Corp. 1998 1999  All Rights Reserved
  29  *
  30  */
  31 
  32 package com.sun.corba.se.impl.io;
  33 
  34 import java.io.IOException;
  35 import java.io.OutputStream;
  36 import java.io.ObjectOutputStream;
  37 import java.io.ObjectOutput;
  38 import java.util.Map;
  39 import java.util.HashMap;
  40 
  41 import org.omg.CORBA.INTERNAL;
  42 
  43 public abstract class OutputStreamHook extends ObjectOutputStream
  44 {
  45     private HookPutFields putFields = null;
  46 
  47     /**
  48      * Since ObjectOutputStream.PutField methods specify no exceptions,
  49      * we are not checking for null parameters on put methods.
  50      */
  51     private class HookPutFields extends ObjectOutputStream.PutField
  52     {
  53         private Map<String,Object> fields = new HashMap<>();
  54 
  55         /**
  56          * Put the value of the named boolean field into the persistent field.
  57          */
  58         public void put(String name, boolean value){
  59             fields.put(name, new Boolean(value));
  60         }
  61 
  62         /**
  63          * Put the value of the named char field into the persistent fields.
  64          */
  65         public void put(String name, char value){
  66             fields.put(name, new Character(value));
  67         }
  68 
  69         /**
  70          * Put the value of the named byte field into the persistent fields.
  71          */
  72         public void put(String name, byte value){
  73             fields.put(name, new Byte(value));


 124 
 125             ObjectStreamField[] osfields = hook.getFieldsNoCopy();
 126 
 127             // Write the fields to the stream in the order
 128             // provided by the ObjectStreamClass.  (They should
 129             // be sorted appropriately already.)
 130             for (int i = 0; i < osfields.length; i++) {
 131 
 132                 Object value = fields.get(osfields[i].getName());
 133 
 134                 hook.writeField(osfields[i], value);
 135             }
 136         }
 137     }
 138 
 139     abstract void writeField(ObjectStreamField field, Object value) throws IOException;
 140 
 141     public OutputStreamHook()
 142         throws java.io.IOException {
 143         super();

 144     }
 145 
 146     public void defaultWriteObject() throws IOException {
 147 
 148         writeObjectState.defaultWriteObject(this);
 149 
 150         defaultWriteObjectDelegate();
 151     }
 152 
 153     public abstract void defaultWriteObjectDelegate();
 154 
 155     public ObjectOutputStream.PutField putFields()
 156         throws IOException {
 157         putFields = new HookPutFields();
 158         return putFields;
 159     }
 160 
 161     // Stream format version, saved/restored during recursive calls
 162     protected byte streamFormatVersion = 1;
 163