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