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 import java.awt.*;
  31 import java.text.*;
  32 import java.util.*;
  33 import java.io.*;
  34 
  35 public class SerializationSaveTest {
  36 
  37     public static void main(String[] args)
  38     {
  39         try {
  40             CheckDecimalFormat it = new CheckDecimalFormat();
  41             System.out.println(it.Update());
  42             FileOutputStream ostream = new FileOutputStream("DecimalFormat.114");
  43             ObjectOutputStream p = new ObjectOutputStream(ostream);
  44             p.writeObject(it);
  45             ostream.close();
  46             System.out.println("DecimalFormat saved ok.");
  47             CheckDecimalFormatSymbols it2 = new CheckDecimalFormatSymbols();
  48             System.out.println("getDigit : "  + it2.Update());
  49             FileOutputStream ostream2 = new FileOutputStream("DecimalFormatSymbols.114");
  50             ObjectOutputStream p2 = new ObjectOutputStream(ostream2);
  51             p2.writeObject(it2);
  52             ostream2.close();
  53             System.out.println("DecimalFormatSymbols saved ok.");
  54         } catch (Exception e) {
  55             e.printStackTrace();
  56         }
  57     }
  58 }
  59 
  60 class CheckDecimalFormat implements Serializable
  61 {
  62     DecimalFormat _decFormat = (DecimalFormat)NumberFormat.getInstance();
  63 
  64     public String Update()
  65     {
  66         Random r = new Random();
  67         return _decFormat.format(r.nextDouble());
  68     }
  69 }
  70 
  71 class CheckDecimalFormatSymbols implements Serializable
  72 {
  73     DecimalFormatSymbols _decFormatSymbols = new DecimalFormatSymbols();
  74 
  75     public char Update()
  76     {
  77         return  _decFormatSymbols.getDigit();
  78     }
  79 }