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