1 /* 2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4101150 27 * @library /java/text/testlib 28 * @build SerializationLoadTest HexDumpReader 29 * @run main SerializationLoadTest 30 * @summary test serialization compatibility of DecimalFormat and DecimalFormatSymbols 31 * @key randomness 32 */ 33 34 package test.java.text.Format.NumberFormat.SerializationLoadTest; 35 36 import java.io.InputStream; 37 import java.io.ObjectInputStream; 38 import java.io.Serializable; 39 import java.text.DecimalFormat; 40 import java.text.DecimalFormatSymbols; 41 import java.text.NumberFormat; 42 import java.util.Random; 43 44 import test.java.text.testlib.HexDumpReader; 45 46 public class SerializationLoadTest { 47 main(String[] args)48 public static void main(String[] args) 49 { 50 try { 51 InputStream istream1 = HexDumpReader.getStreamFromHexDump("DecimalFormat.114.txt"); 52 ObjectInputStream p = new ObjectInputStream(istream1); 53 CheckDecimalFormat it = (CheckDecimalFormat)p.readObject(); 54 System.out.println("1.1.4 DecimalFormat Loaded ok."); 55 System.out.println(it.Update()); 56 System.out.println("Called Update successfully."); 57 istream1.close(); 58 59 InputStream istream2 = HexDumpReader.getStreamFromHexDump("DecimalFormatSymbols.114.txt"); 60 ObjectInputStream p2 = new ObjectInputStream(istream2); 61 CheckDecimalFormatSymbols it2 = (CheckDecimalFormatSymbols)p2.readObject(); 62 System.out.println("1.1.4 DecimalFormatSymbols Loaded ok."); 63 System.out.println("getDigit : " + it2.Update()); 64 System.out.println("Called Update successfully."); 65 istream2.close(); 66 } catch (Exception e) { 67 e.printStackTrace(); 68 } 69 } 70 } 71 72 @SuppressWarnings("serial") 73 class CheckDecimalFormat implements Serializable 74 { 75 DecimalFormat _decFormat = (DecimalFormat)NumberFormat.getInstance(); 76 Update()77 public String Update() 78 { 79 Random r = new Random(); 80 return _decFormat.format(r.nextDouble()); 81 } 82 } 83 84 @SuppressWarnings("serial") 85 class CheckDecimalFormatSymbols implements Serializable 86 { 87 DecimalFormatSymbols _decFormatSymbols = new DecimalFormatSymbols(); 88 Update()89 public char Update() 90 { 91 return _decFormatSymbols.getDigit(); 92 } 93 } 94