Path: blob/master/test/jdk/java/text/Format/NumberFormat/SerializationLoadTest.java
41152 views
/*1* Copyright (c) 1998, 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* @test25* @bug 410115026* @library /java/text/testlib27* @build SerializationLoadTest HexDumpReader28* @run main SerializationLoadTest29* @summary test serialization compatibility of DecimalFormat and DecimalFormatSymbols30* @key randomness31*/3233import java.io.InputStream;34import java.io.ObjectInputStream;35import java.io.Serializable;36import java.text.DecimalFormat;37import java.text.DecimalFormatSymbols;38import java.text.NumberFormat;39import java.util.Random;4041public class SerializationLoadTest {4243public static void main(String[] args)44{45try {46InputStream istream1 = HexDumpReader.getStreamFromHexDump("DecimalFormat.114.txt");47ObjectInputStream p = new ObjectInputStream(istream1);48CheckDecimalFormat it = (CheckDecimalFormat)p.readObject();49System.out.println("1.1.4 DecimalFormat Loaded ok.");50System.out.println(it.Update());51System.out.println("Called Update successfully.");52istream1.close();5354InputStream istream2 = HexDumpReader.getStreamFromHexDump("DecimalFormatSymbols.114.txt");55ObjectInputStream p2 = new ObjectInputStream(istream2);56CheckDecimalFormatSymbols it2 = (CheckDecimalFormatSymbols)p2.readObject();57System.out.println("1.1.4 DecimalFormatSymbols Loaded ok.");58System.out.println("getDigit : " + it2.Update());59System.out.println("Called Update successfully.");60istream2.close();61} catch (Exception e) {62e.printStackTrace();63}64}65}6667@SuppressWarnings("serial")68class CheckDecimalFormat implements Serializable69{70DecimalFormat _decFormat = (DecimalFormat)NumberFormat.getInstance();7172public String Update()73{74Random r = new Random();75return _decFormat.format(r.nextDouble());76}77}7879@SuppressWarnings("serial")80class CheckDecimalFormatSymbols implements Serializable81{82DecimalFormatSymbols _decFormatSymbols = new DecimalFormatSymbols();8384public char Update()85{86return _decFormatSymbols.getDigit();87}88}899091