Path: blob/master/test/jdk/java/text/Format/common/Bug4769840.java
41152 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test 1.1 03/10/2725* @bug 476984026* @library /java/text/testlib27* @build Bug4769840 HexDumpReader28* @run main Bug476984029* @summary Confirm serialization compatibility30*/3132import java.io.*;33import java.text.*;3435public class Bug4769840 {3637public static void main(String[] args) throws Exception {38if (args.length == 1 && args[0].equals("-ser")) {39serialize();40} else {41deserialize();42}43}4445/* Serialization */46private static void serialize() throws Exception {47/* Serialize with JDK 1.1 */48serialize("ChoiceFormat.ser", new ChoiceFormat("0# foo|1# bar"));4950/*51* Serialize with JDK1.4.0 because the Field class was added in the52* version.53*/54serialize("DateFormat.Field.ser", DateFormat.Field.TIME_ZONE);55serialize("MessageFormat.Field.ser", MessageFormat.Field.ARGUMENT);56serialize("NumberFormat.Field.ser", NumberFormat.Field.INTEGER);57}5859private static void serialize(String filename, Object o) throws Exception {60FileOutputStream fos = new FileOutputStream(filename);61ObjectOutputStream out = new ObjectOutputStream(fos);62out.writeObject(o);63out.close();64}6566/* Deserialization */67private static void deserialize() throws Exception {68deserialize("ChoiceFormat.ser");69deserialize("DateFormat.Field.ser");70deserialize("MessageFormat.Field.ser");71deserialize("NumberFormat.Field.ser");72}7374private static void deserialize(String filename) throws Exception {75InputStream is = HexDumpReader.getStreamFromHexDump(filename + ".txt");76ObjectInputStream in = new ObjectInputStream(is);77Object obj = in.readObject();78in.close();79System.out.println("Deserialization of <" + filename + "> succeeded.");80}81}828384