2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package tests.support;
20 import java.io.IOException;
21 import java.io.ObjectInputStream;
22 import java.io.ObjectOutputStream;
23 import java.io.Serializable;
26 * Support class to test the methods of {@code ObjectInputStream.GetField} and
27 * {@code ObjectOutputStream.PutField}. The difference with class
28 * {@code Support_GetPutFields} is that it uses the deprecated method
29 * {@code ObjectOutputStream.PutField.write(ObjectOutput)} to write the fields
30 * to the output stream.
32 public class Support_GetPutFieldsDeprecated implements Serializable {
34 private static final long serialVersionUID = 1L;
36 public ObjectInputStream.GetField getField;
37 public ObjectOutputStream.PutField putField;
39 public boolean booleanValue = false;
40 public byte byteValue = 0;
41 public char charValue = 0;
42 public double doubleValue = 0.0;
43 public float floatValue = 0.0f;
44 public long longValue = 0;
45 public int intValue = 0;
46 public short shortValue = 0;
47 public SimpleClass objectValue = null;
49 class SimpleClass implements Serializable {
51 private static final long serialVersionUID = 1L;
55 public SimpleClass(int aValue, String bValue) {
64 public String getB() {
68 public boolean equals(Object obj) {
69 if (obj == null || obj.getClass() != this.getClass()) {
73 SimpleClass other = (SimpleClass) obj;
74 return (a == other.getA() && b.equals(other.getB()));
78 public void initTestValues() {
80 byteValue = (byte) 0xbe;
82 doubleValue = 1231.342;
84 longValue = 1560732321l;
86 objectValue = new SimpleClass(2001, "A Space Odyssey");
90 public boolean equals(Object obj) {
91 if (obj == null || obj.getClass() != this.getClass()) {
95 Support_GetPutFields other = (Support_GetPutFields) obj;
96 return (booleanValue == other.booleanValue &&
97 byteValue == other.byteValue &&
98 charValue == other.charValue &&
99 doubleValue == other.doubleValue &&
100 floatValue == other.floatValue &&
101 longValue == other.longValue &&
102 intValue == other.intValue &&
103 objectValue.equals(other.objectValue) &&
104 shortValue == other.shortValue
108 private void readObject(ObjectInputStream ois) throws Exception {
109 booleanValue = getField.get("booleanValue", false);
110 byteValue = getField.get("byteValue", (byte) 0);
111 charValue = getField.get("charValue", (char) 0);
112 doubleValue = getField.get("doubleValue", 0.0);
113 floatValue = getField.get("floatValue", 0.0f);
114 longValue = getField.get("longValue", (long) 0);
115 intValue = getField.get("intValue", 0);
116 objectValue = (Support_GetPutFieldsDeprecated.SimpleClass)
117 getField.get("objectValue", (Object) null);
118 shortValue = getField.get("shortValue", (short) 0);
121 private void writeObject(ObjectOutputStream oos) throws IOException {
122 putField = oos.putFields();
123 putField.put("booleanValue", booleanValue);
124 putField.put("byteValue", byteValue);
125 putField.put("charValue", charValue);
126 putField.put("doubleValue", doubleValue);
127 putField.put("floatValue", floatValue);
128 putField.put("longValue", longValue);
129 putField.put("intValue", intValue);
130 putField.put("objectValue", objectValue);
131 putField.put("shortValue", shortValue);