Path: blob/master/test/jdk/java/text/Format/NumberFormat/SerializationSaveTest.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* No at-test for this test, because it needs to be run on JDK 1.1.4.25* Instead, the resulting serialized files DecimalFormat.114 and26* DecimalFormatSymbols.114 are archived.27*/2829import java.awt.*;30import java.text.*;31import java.util.*;32import java.io.*;3334public class SerializationSaveTest {3536public static void main(String[] args)37{38try {39CheckDecimalFormat it = new CheckDecimalFormat();40System.out.println(it.Update());41FileOutputStream ostream = new FileOutputStream("DecimalFormat.114");42ObjectOutputStream p = new ObjectOutputStream(ostream);43p.writeObject(it);44ostream.close();45System.out.println("DecimalFormat saved ok.");46CheckDecimalFormatSymbols it2 = new CheckDecimalFormatSymbols();47System.out.println("getDigit : " + it2.Update());48FileOutputStream ostream2 = new FileOutputStream("DecimalFormatSymbols.114");49ObjectOutputStream p2 = new ObjectOutputStream(ostream2);50p2.writeObject(it2);51ostream2.close();52System.out.println("DecimalFormatSymbols saved ok.");53} catch (Exception e) {54e.printStackTrace();55}56}57}5859@SuppressWarnings("serial")60class CheckDecimalFormat implements Serializable61{62DecimalFormat _decFormat = (DecimalFormat)NumberFormat.getInstance();6364public String Update()65{66Random r = new Random();67return _decFormat.format(r.nextDouble());68}69}7071@SuppressWarnings("serial")72class CheckDecimalFormatSymbols implements Serializable73{74DecimalFormatSymbols _decFormatSymbols = new DecimalFormatSymbols();7576public char Update()77{78return _decFormatSymbols.getDigit();79}80}818283