0N/A/*
2362N/A * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4089540
0N/A * @summary Verify compatibility with 1.1 externalizable format
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/A
0N/Aclass Foo implements Externalizable {
0N/A private static final long serialVersionUID = 0xbabel;
0N/A
0N/A int x;
0N/A int y;
0N/A Object obj;
0N/A
0N/A public Foo() {
0N/A }
0N/A
0N/A public Foo(int x, int y, Object obj) {
0N/A this.x = x;
0N/A this.y = y;
0N/A this.obj = obj;
0N/A }
0N/A
0N/A public void writeExternal(ObjectOutput out) throws IOException {
0N/A out.writeInt(x);
0N/A out.writeInt(y);
0N/A out.writeObject(obj);
0N/A }
0N/A
0N/A public void readExternal(ObjectInput in)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A x = in.readInt();
0N/A y = in.readInt();
0N/A obj = in.readObject();
0N/A }
0N/A
0N/A public boolean equals(Object other) {
0N/A if (other instanceof Foo) {
0N/A Foo f = (Foo) other;
0N/A return ((x == f.x) && (y == f.y) &&
0N/A ((obj != null) ? obj.equals(f.obj) : (f.obj == null)));
0N/A }
0N/A return false;
0N/A }
0N/A}
0N/A
0N/Apublic class ExternalizableBlockData {
0N/A public static void main(String[] args) throws Exception {
0N/A byte[] oldExternalizableBytes = getFileBytes(
0N/A new File(System.getProperty("test.src", "."), "old.ser"));
0N/A Foo foo = new Foo(0xbad, 0xbeef, "burrito");
0N/A ByteArrayOutputStream bout = new ByteArrayOutputStream();
0N/A ObjectOutputStream oout = new ObjectOutputStream(bout);
0N/A oout.useProtocolVersion(ObjectStreamConstants.PROTOCOL_VERSION_1);
0N/A oout.writeObject(foo);
0N/A oout.close();
0N/A if (! Arrays.equals(bout.toByteArray(), oldExternalizableBytes)) {
0N/A throw new Error();
0N/A }
0N/A
0N/A ObjectInputStream oin = new ObjectInputStream(
0N/A new ByteArrayInputStream(oldExternalizableBytes));
0N/A if (! foo.equals(oin.readObject())) {
0N/A throw new Error();
0N/A }
0N/A
0N/A bout = new ByteArrayOutputStream();
0N/A oout = new ObjectOutputStream(bout);
0N/A oout.writeObject(foo);
0N/A oout.close();
0N/A if (Arrays.equals(bout.toByteArray(), oldExternalizableBytes)) {
0N/A throw new Error();
0N/A }
0N/A }
0N/A
0N/A static byte[] getFileBytes(File file) throws IOException {
0N/A FileInputStream fin = new FileInputStream(file);
0N/A ByteArrayOutputStream bout = new ByteArrayOutputStream();
0N/A byte[] buf = new byte[256];
0N/A int n;
0N/A
0N/A while ((n = fin.read(buf)) != -1) {
0N/A bout.write(buf, 0, n);
0N/A }
0N/A fin.close();
0N/A return bout.toByteArray();
0N/A }
0N/A}