test/jdk/java/io/Serializable/subclass/XObjectOutputStream.java
author rriggs
Fri, 11 Oct 2019 13:11:56 -0400
changeset 58565 baa5969ecf34
parent 47216 71c04702a3d5
permissions -rw-r--r--
8231427: Warning cleanup in tests of java.io.Serializable Reviewed-by: darcy, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.lang.reflect.Modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
public class XObjectOutputStream extends AbstractObjectOutputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    XObjectOutputStream(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
        super(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    protected boolean enableReplaceObject(boolean enable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        throw new Error("not implemented");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    protected void annotateClass(Class<?> cl) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public void close() throws IOException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected Object replaceObject(Object obj) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        return obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected void writeStreamHeader() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        super.writeStreamHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 5506
diff changeset
    56
    protected final void writeObjectOverride(Object obj) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        Object prevCurrentObject = currentObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        currentObject = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        System.out.println("writeObjectOverride(" + obj.toString() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        //     ** Preserving reference semantics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        //     if (obj already serialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        //       look up streamId for obj and write it into 'this' stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        //       return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        //     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        //     if (obj instanceof Class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        //       //Special processing for classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        //       //Might need to call this.annotateClass(obj.getClass())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        //       //someday.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        //       return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        //     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        //     **Replacement semantics
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        //     Object replacement = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        //     if (enableReplace)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        //       replacement = this.writeReplace(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        //     if (replacement instanceof Replaceable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        //       replacement = ((Replaceable)replacement).replaceObject(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        //     if (obj != replacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        //       //record that all future occurances of obj should be replaced
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        //       //with replacement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        //     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        //     if obj is Externalizeable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        //      Object[] argList = {this};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        //      invokeMethod(obj, writeExternalMethod, argList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        //     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        Method writeObjectMethod = getWriteObjectMethod(obj.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (writeObjectMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            Object[] arglist = {this};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            invokeMethod(obj, writeObjectMethod, arglist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            currentObject = prevCurrentObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /* Since defaultWriteObject() does not take the object to write as a parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * implementation is required to store currentObject when writeObject is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void defaultWriteObject() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        Object obj = currentObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        System.out.println("XObjectOutputStream.defaultWriteObject(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                            obj.toString() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        //In order to access package, private and protected fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        //one needs to use Priviledged Access and be trusted code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        //This test will avoid that problem by only serializing public fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        Field[] fields = obj.getClass().getFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        for (int i= 0; i < fields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            //Skip non-Serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            int mods = fields[i].getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if (Modifier.isStatic(mods) || Modifier.isTransient(mods))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                continue;
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   119
            Class<?> FieldType = fields[i].getType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            if (FieldType.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                System.out.println("Field " + fields[i].getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                    " has primitive type " + FieldType.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                System.out.println("**Field " + fields[i].getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                   " is an Object of type " + FieldType.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    writeObject(fields[i].get(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    if (FieldType.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        Object[] array = ((Object[]) fields[i].get(obj));
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   130
                        Class<?> componentType = FieldType.getComponentType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        if (componentType.isPrimitive())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                            System.out.println("Output " + array.length + " primitive elements of" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                               componentType.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                            System.out.println("Output " + array.length + " of Object elements of" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                               componentType.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                            for (int k = 0; k < array.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                writeObject(array[k]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    throw new IOException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public PutField putFields() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        currentPutField = new InternalPutField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return currentPutField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public void writeFields() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        currentPutField.write(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    static final class InternalPutField extends ObjectOutputStream.PutField {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        String fieldName[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        int    intValue[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        InternalPutField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            fieldName = new String[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            intValue = new int[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            next = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         * Put the value of the named boolean field into the persistent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        public void put(String name, boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * Put the value of the named char field into the persistent fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        public void put(String name, char value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         * Put the value of the named byte field into the persistent fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        public void put(String name, byte value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * Put the value of the named short field into the persistent fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        public void put(String name, short value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         * Put the value of the named int field into the persistent fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        public void put(String name, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (next < fieldName.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                fieldName[next] = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                intValue[next] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                next++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * Put the value of the named long field into the persistent fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        public void put(String name, long value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         * Put the value of the named float field into the persistent fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        public void put(String name, float value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * Put the value of the named double field into the persistent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        public void put(String name, double value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         * Put the value of the named Object field into the persistent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        public void put(String name, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
         * Write the data and fields to the specified ObjectOutput stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
         */
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   230
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        public void write(ObjectOutput out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            for (int i = 0; i < next; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                System.out.println(fieldName[i] + "=" + intValue[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Writes a byte. This method will block until the byte is actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param b the byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @exception IOException If an I/O error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void write(int data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Writes an array of bytes. This method will block until the bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * are actually written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param b the data to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @exception IOException If an I/O error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public void write(byte b[]) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Writes a sub array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param b the data to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param off       the start offset in the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param len       the number of bytes that are written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @exception IOException If an I/O error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public void write(byte b[], int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public void writeBoolean(boolean data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public void writeByte(int data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public void writeShort(int data)  throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public void writeChar(int data)  throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void writeInt(int data)  throws IOException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void writeLong(long data)  throws IOException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public void writeFloat(float data) throws IOException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public void writeDouble(double data) throws IOException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public void writeBytes(String data) throws IOException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public void writeChars(String data) throws IOException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public void writeUTF(String data) throws IOException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public void reset() throws IOException {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public void available() throws IOException {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void drain() throws IOException {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private Object currentObject = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    private InternalPutField currentPutField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /********************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /* CODE LIFTED FROM ObjectStreamClass constuctor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * ObjectStreamClass.writeObjectMethod is private.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Look for the writeObject method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Set the accessible flag on it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Subclass of AbstractObjectOutputStream will call it as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   304
    public static Method getWriteObjectMethod(final Class<?> cl) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   306
        Method writeObjectMethod =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            java.security.AccessController.doPrivileged
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   308
            (new java.security.PrivilegedAction<Method>() {
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   309
                public Method run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    Method m = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    try {
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   312
                        Class<?>[] args = {ObjectOutputStream.class};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        m = cl.getDeclaredMethod("writeObject", args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        int mods = m.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        // Method must be private and non-static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        if (!Modifier.isPrivate(mods) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                            Modifier.isStatic(mods)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                            m = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                            m.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        m = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return writeObjectMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /*************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /* CODE LIFTED FROM ObjectOutputStream. */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 5506
diff changeset
   334
    private static void invokeMethod(final Object obj, final Method m,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                                        final Object[] argList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            java.security.AccessController.doPrivileged
58565
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   340
                (new java.security.PrivilegedExceptionAction<Void>() {
baa5969ecf34 8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents: 47216
diff changeset
   341
                    public Void run() throws InvocationTargetException,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                        java.lang.IllegalAccessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        m.invoke(obj, argList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } catch (java.security.PrivilegedActionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            Exception ex = e.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            if (ex instanceof InvocationTargetException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                Throwable t =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                        ((InvocationTargetException)ex).getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                if (t instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    throw (IOException)t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                else if (t instanceof RuntimeException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    throw (RuntimeException) t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                else if (t instanceof Error)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    throw (Error) t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    throw new Error("interal error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                // IllegalAccessException cannot happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
};