]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/format/WriteNumberFormatSerialTestData.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / core / src / com / ibm / icu / dev / test / format / WriteNumberFormatSerialTestData.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2001-2010, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7  
8 package com.ibm.icu.dev.test.format;
9
10 import java.io.ByteArrayOutputStream;
11 import java.io.FileOutputStream;
12 import java.io.ObjectOutputStream;
13 import java.util.Locale;
14
15 import com.ibm.icu.text.NumberFormat;
16
17 /**
18  * @version     1.0
19  * @author Ram Viswanadha
20  */
21 public class WriteNumberFormatSerialTestData {
22     static final String header="/*\n" +
23                                " *******************************************************************************\n"+
24                                " * Copyright (C) 2001, International Business Machines Corporation and         *\n"+
25                                " * others. All Rights Reserved.                                                *\n"+
26                                " *******************************************************************************\n"+
27                                " */\n\n"+
28                                "package com.ibm.icu.dev.test.format;\n\n"+
29                                 
30                                "public class NumberFormatSerialTestData {\n"+
31                                "    //get Content\n"+
32                                "    public static byte[][] getContent() {\n"+
33                                "            return content;\n"+
34                                "    }\n";
35                               
36     static final String footer ="\n    final static byte[][] content = {generalInstance, currencyInstance, percentInstance, scientificInstance};\n"+
37                                 "}\n";                           
38     public static void main(String[] args){
39         NumberFormat nf     = NumberFormat.getInstance(Locale.US);
40         NumberFormat nfc    = NumberFormat.getCurrencyInstance(Locale.US);
41         NumberFormat nfp     = NumberFormat.getPercentInstance(Locale.US);
42         NumberFormat nfsp     = NumberFormat.getScientificInstance(Locale.US);
43         
44         try{
45             FileOutputStream file = new FileOutputStream("NumberFormatSerialTestData.java");
46             file.write(header.getBytes());
47             write(file,(Object)nf,"generalInstance", "//NumberFormat.getInstance(Locale.US)");
48             write(file,(Object)nfc,"currencyInstance","//NumberFormat.getCurrencyInstance(Locale.US)");
49             write(file,(Object)nfp,"percentInstance","//NumberFormat.getPercentInstance(Locale.US)");
50             write(file,(Object)nfsp,"scientificInstance","//NumberFormat.getScientificInstance(Locale.US)");
51             file.write(footer.getBytes());            
52             file.close();
53         }catch( Exception e){
54             System.out.println(e.getMessage());
55             e.printStackTrace();
56         }
57     }
58     private static void write(FileOutputStream file,Object o ,String name,String comment){
59         try{
60             ByteArrayOutputStream bts =  new ByteArrayOutputStream();
61             ObjectOutputStream os = new ObjectOutputStream(bts);    
62             os.writeObject((Object)o);
63             os.flush();
64             os.close();
65             byte[] myArr = bts.toByteArray();
66             //String temp = new String(myArr);
67             System.out.println("    "+comment+ " :");
68             /*System.out.println("minimumIntegerDigits : "  + (temp.indexOf("minimumIntegerDigits")+"minimumIntegerDigits".length()));
69             System.out.println("maximumIntegerDigits : "  + (temp.indexOf("maximumIntegerDigits")+"maximumIntegerDigits".length()));
70             System.out.println("minimumFractionDigits : " + (temp.indexOf("minimumFractionDigits")+"minimumFractionDigits".length()));
71             System.out.println("maximumFractionDigits : " + (temp.indexOf("maximumFractionDigits")+"maximumFractionDigits".length()));
72             */
73             //file.write(myArr);
74             file.write(("\n    "+comment).getBytes());
75             file.write(new String("\n    static byte[] "+name+" = new byte[]{ \n").getBytes("UTF-8"));
76             file.write( "        ".getBytes());
77             for(int i=0; i<myArr.length; i++){
78                 file.write(String.valueOf((int)myArr[i]).getBytes());
79                 file.write( ", ".getBytes());
80                 if((i+1)%20 == 0){
81                     file.write("\n".getBytes());
82                     file.write( "        ".getBytes());
83                 }
84             }
85             file.write(new String("\n    };\n").getBytes("UTF-8"));
86         }catch( Exception e){
87             System.out.println(e.getMessage());
88             e.printStackTrace();
89         }
90     
91     }
92 }