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 * No at-test for this test, because it needs to be run on JDK 1.1.4. 26 * Instead, the resulting serialized files DecimalFormat.114 and 27 * DecimalFormatSymbols.114 are archived. 28 */ 29 30 package test.java.text.Format.NumberFormat.SerializationSaveTest; 31 32 import java.text.*; 33 import java.util.*; 34 import java.io.*; 35 36 public class SerializationSaveTest { 37 main(String[] args)38 public static void main(String[] args) 39 { 40 try { 41 CheckDecimalFormat it = new CheckDecimalFormat(); 42 System.out.println(it.Update()); 43 FileOutputStream ostream = new FileOutputStream("DecimalFormat.114"); 44 ObjectOutputStream p = new ObjectOutputStream(ostream); 45 p.writeObject(it); 46 ostream.close(); 47 System.out.println("DecimalFormat saved ok."); 48 CheckDecimalFormatSymbols it2 = new CheckDecimalFormatSymbols(); 49 System.out.println("getDigit : " + it2.Update()); 50 FileOutputStream ostream2 = new FileOutputStream("DecimalFormatSymbols.114"); 51 ObjectOutputStream p2 = new ObjectOutputStream(ostream2); 52 p2.writeObject(it2); 53 ostream2.close(); 54 System.out.println("DecimalFormatSymbols saved ok."); 55 } catch (Exception e) { 56 e.printStackTrace(); 57 } 58 } 59 } 60 61 @SuppressWarnings("serial") 62 class CheckDecimalFormat implements Serializable 63 { 64 DecimalFormat _decFormat = (DecimalFormat)NumberFormat.getInstance(); 65 Update()66 public String Update() 67 { 68 Random r = new Random(); 69 return _decFormat.format(r.nextDouble()); 70 } 71 } 72 73 @SuppressWarnings("serial") 74 class CheckDecimalFormatSymbols implements Serializable 75 { 76 DecimalFormatSymbols _decFormatSymbols = new DecimalFormatSymbols(); 77 Update()78 public char Update() 79 { 80 return _decFormatSymbols.getDigit(); 81 } 82 } 83