2 *******************************************************************************
\r
3 * Copyright (C) 2001-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.dev.test.format;
\r
10 import java.io.ByteArrayOutputStream;
\r
11 import java.io.FileOutputStream;
\r
12 import java.io.ObjectOutputStream;
\r
13 import java.util.Locale;
\r
15 import com.ibm.icu.text.NumberFormat;
\r
19 * @author Ram Viswanadha
\r
21 public class WriteNumberFormatSerialTestData {
\r
22 static final String header="/*\n" +
\r
23 " *******************************************************************************\n"+
\r
24 " * Copyright (C) 2001, International Business Machines Corporation and *\n"+
\r
25 " * others. All Rights Reserved. *\n"+
\r
26 " *******************************************************************************\n"+
\r
28 "package com.ibm.icu.dev.test.format;\n\n"+
\r
30 "public class NumberFormatSerialTestData {\n"+
\r
32 " public static byte[][] getContent() {\n"+
\r
33 " return content;\n"+
\r
36 static final String footer ="\n final static byte[][] content = {generalInstance, currencyInstance, percentInstance, scientificInstance};\n"+
\r
38 public static void main(String[] args){
\r
39 NumberFormat nf = NumberFormat.getInstance(Locale.US);
\r
40 NumberFormat nfc = NumberFormat.getCurrencyInstance(Locale.US);
\r
41 NumberFormat nfp = NumberFormat.getPercentInstance(Locale.US);
\r
42 NumberFormat nfsp = NumberFormat.getScientificInstance(Locale.US);
\r
45 FileOutputStream file = new FileOutputStream("NumberFormatSerialTestData.java");
\r
46 file.write(header.getBytes());
\r
47 write(file,(Object)nf,"generalInstance", "//NumberFormat.getInstance(Locale.US)");
\r
48 write(file,(Object)nfc,"currencyInstance","//NumberFormat.getCurrencyInstance(Locale.US)");
\r
49 write(file,(Object)nfp,"percentInstance","//NumberFormat.getPercentInstance(Locale.US)");
\r
50 write(file,(Object)nfsp,"scientificInstance","//NumberFormat.getScientificInstance(Locale.US)");
\r
51 file.write(footer.getBytes());
\r
53 }catch( Exception e){
\r
54 System.out.println(e.getMessage());
\r
55 e.printStackTrace();
\r
58 private static void write(FileOutputStream file,Object o ,String name,String comment){
\r
60 ByteArrayOutputStream bts = new ByteArrayOutputStream();
\r
61 ObjectOutputStream os = new ObjectOutputStream(bts);
\r
62 os.writeObject((Object)o);
\r
65 byte[] myArr = bts.toByteArray();
\r
66 //String temp = new String(myArr);
\r
67 System.out.println(" "+comment+ " :");
\r
68 /*System.out.println("minimumIntegerDigits : " + (temp.indexOf("minimumIntegerDigits")+"minimumIntegerDigits".length()));
\r
69 System.out.println("maximumIntegerDigits : " + (temp.indexOf("maximumIntegerDigits")+"maximumIntegerDigits".length()));
\r
70 System.out.println("minimumFractionDigits : " + (temp.indexOf("minimumFractionDigits")+"minimumFractionDigits".length()));
\r
71 System.out.println("maximumFractionDigits : " + (temp.indexOf("maximumFractionDigits")+"maximumFractionDigits".length()));
\r
73 //file.write(myArr);
\r
74 file.write(("\n "+comment).getBytes());
\r
75 file.write(new String("\n static byte[] "+name+" = new byte[]{ \n").getBytes("UTF-8"));
\r
76 file.write( " ".getBytes());
\r
77 for(int i=0; i<myArr.length; i++){
\r
78 file.write(String.valueOf((int)myArr[i]).getBytes());
\r
79 file.write( ", ".getBytes());
\r
81 file.write("\n".getBytes());
\r
82 file.write( " ".getBytes());
\r
85 file.write(new String("\n };\n").getBytes("UTF-8"));
\r
86 }catch( Exception e){
\r
87 System.out.println(e.getMessage());
\r
88 e.printStackTrace();
\r