API Overview API Index Package Overview Direct link to this page
JDK 1.6
  java.util. Formatter View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388

/*
 * @(#)Formatter.java	1.26 06/06/28
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package java.util;

import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.Flushable;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.nio.charset.Charset;
import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
import sun.misc.FormattedFloatingDecimal;

/**
 * An interpreter for printf-style format strings.  This class provides support
 * for layout justification and alignment, common formats for numeric, string,
 * and date/time data, and locale-specific output.  Common Java types such as
 * <tt>byte</tt>, {@link java.math.BigDecimal BigDecimal}, and {@link Calendar}
 * are supported.  Limited formatting customization for arbitrary user types is
 * provided through the {@link Formattable} interface.
 *
 * <p> Formatters are not necessarily safe for multithreaded access.  Thread
 * safety is optional and is the responsibility of users of methods in this
 * class.
 *
 * <p> Formatted printing for the Java language is heavily inspired by C's
 * <tt>printf</tt>.  Although the format strings are similar to C, some
 * customizations have been made to accommodate the Java language and exploit
 * some of its features.  Also, Java formatting is more strict than C's; for
 * example, if a conversion is incompatible with a flag, an exception will be
 * thrown.  In C inapplicable flags are silently ignored.  The format strings
 * are thus intended to be recognizable to C programmers but not necessarily
 * completely compatible with those in C.
 *
 * <p> Examples of expected usage:
 *
 * <blockquote><pre>
 *   StringBuilder sb = new StringBuilder();
 *   // Send all output to the Appendable object sb
 *   Formatter formatter = new Formatter(sb, Locale.US);
 *
 *   // Explicit argument indices may be used to re-order output.
 *   formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d")
 *   // -&gt; " d  c  b  a"
 *
 *   // Optional locale as the first argument can be used to get
 *   // locale-specific formatting of numbers.  The precision and width can be
 *   // given to round and align the value.
 *   formatter.format(Locale.FRANCE, "e = %+10.4f", Math.E);
 *   // -&gt; "e =    +2,7183"
 *
 *   // The '(' numeric flag may be used to format negative numbers with
 *   // parentheses rather than a minus sign.  Group separators are
 *   // automatically inserted.
 *   formatter.format("Amount gained or lost since last statement: $ %(,.2f",
 *                    balanceDelta);
 *   // -&gt; "Amount gained or lost since last statement: $ (6,217.58)"
 * </pre></blockquote>
 *
 * <p> Convenience methods for common formatting requests exist as illustrated
 * by the following invocations:
 *
 * <blockquote><pre>
 *   // Writes a formatted string to System.out.
 *   System.out.format("Local time: %tT", Calendar.getInstance());
 *   // -&gt; "Local time: 13:34:18"
 *
 *   // Writes formatted output to System.err.
 *   System.err.printf("Unable to open file '%1$s': %2$s",
 *                     fileName, exception.getMessage());
 *   // -&gt; "Unable to open file 'food': No such file or directory"
 * </pre></blockquote>
 *
 * <p> Like C's <tt>sprintf(3)</tt>, Strings may be formatted using the static
 * method {@link String#format(String,Object...) String.format}:
 *
 * <blockquote><pre>
 *   // Format a string containing a date.
 *   import java.util.Calendar;
 *   import java.util.GregorianCalendar;
 *   import static java.util.Calendar.*;
 *
 *   Calendar c = new GregorianCalendar(1995, MAY, 23);
 *   String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
 *   // -&gt; s == "Duke's Birthday: May 23, 1995"
 * </pre></blockquote>
 *
 * <h3><a name="org">Organization</a></h3>
 *
 * <p> This specification is divided into two sections.  The first section, <a
 * href="#summary">Summary</a>, covers the basic formatting concepts.  This
 * section is intended for users who want to get started quickly and are
 * familiar with formatted printing in other programming languages.  The second
 * section, <a href="#detail">Details</a>, covers the specific implementation
 * details.  It is intended for users who want more precise specification of
 * formatting behavior.
 *
 * <h3><a name="summary">Summary</a></h3>
 *
 * <p> This section is intended to provide a brief overview of formatting
 * concepts.  For precise behavioral details, refer to the <a
 * href="#detail">Details</a> section.
 *
 * <h4><a name="syntax">Format String Syntax</a></h4>
 *
 * <p> Every method which produces formatted output requires a <i>format
 * string</i> and an <i>argument list</i>.  The format string is a {@link
 * String} which may contain fixed text and one or more embedded <i>format
 * specifiers</i>.  Consider the following example:
 *
 * <blockquote><pre>
 *   Calendar c = ...;
 *   String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
 * </pre></blockquote>
 *
 * This format string is the first argument to the <tt>format</tt> method.  It
 * contains three format specifiers "<tt>%1$tm</tt>", "<tt>%1$te</tt>", and
 * "<tt>%1$tY</tt>" which indicate how the arguments should be processed and
 * where they should be inserted in the text.  The remaining portions of the
 * format string are fixed text including <tt>"Dukes Birthday: "</tt> and any
 * other spaces or punctuation.
 *
 * The argument list consists of all arguments passed to the method after the
 * format string.  In the above example, the argument list is of size one and
 * consists of the {@link java.util.Calendar Calendar} object <tt>c</tt>.
 *
 * <ul>
 *
 * <li> The format specifiers for general, character, and numeric types have
 * the following syntax:
 *
 * <blockquote><pre>
 *   %[argument_index$][flags][width][.precision]conversion
 * </pre></blockquote>
 *
 * <p> The optional <i>argument_index</i> is a decimal integer indicating the
 * position of the argument in the argument list.  The first argument is
 * referenced by "<tt>1$</tt>", the second by "<tt>2$</tt>", etc.
 *
 * <p> The optional <i>flags</i> is a set of characters that modify the output
 * format.  The set of valid flags depends on the conversion.
 *
 * <p> The optional <i>width</i> is a non-negative decimal integer indicating
 * the minimum number of characters to be written to the output.
 *
 * <p> The optional <i>precision</i> is a non-negative decimal integer usually
 * used to restrict the number of characters.  The specific behavior depends on
 * the conversion.
 *
 * <p> The required <i>conversion</i> is a character indicating how the
 * argument should be formatted.  The set of valid conversions for a given
 * argument depends on the argument's data type.
 *
 * <li> The format specifiers for types which are used to represents dates and
 * times have the following syntax:
 *
 * <blockquote><pre>
 *   %[argument_index$][flags][width]conversion
 * </pre></blockquote>
 *
 * <p> The optional <i>argument_index</i>, <i>flags</i> and <i>width</i> are
 * defined as above.
 *
 * <p> The required <i>conversion</i> is a two character sequence.  The first
 * character is <tt>'t'</tt> or <tt>'T'</tt>.  The second character indicates
 * the format to be used.  These characters are similar to but not completely
 * identical to those defined by GNU <tt>date</tt> and POSIX
 * <tt>strftime(3c)</tt>.
 *
 * <li> The format specifiers which do not correspond to arguments have the
 * following syntax:
 *
 * <blockquote><pre>
 *   %[flags][width]conversion
 * </pre></blockquote>
 *
 * <p> The optional <i>flags</i> and <i>width</i> is defined as above.
 *
 * <p> The required <i>conversion</i> is a character indicating content to be
 * inserted in the output.
 *
 * </ul>
 *
 * <h4> Conversions </h4>
 *
 * <p> Conversions are divided into the following categories:
 *
 * <ol>
 *
 * <li> <b>General</b> - may be applied to any argument
 * type
 *
 * <li> <b>Character</b> - may be applied to basic types which represent
 * Unicode characters: <tt>char</tt>, {@link Character}, <tt>byte</tt>, {@link
 * Byte}, <tt>short</tt>, and {@link Short}. This conversion may also be
 * applied to the types <tt>int</tt> and {@link Integer} when {@link
 * Character#isValidCodePoint} returns <tt>true</tt>
 *
 * <li> <b>Numeric</b>
 *
 * <ol>
 *
 * <li> <b>Integral</b> - may be applied to Java integral types: <tt>byte</tt>,
 * {@link Byte}, <tt>short</tt>, {@link Short}, <tt>int</tt> and {@link
 * Integer}, <tt>long</tt>, {@link Long}, and {@link java.math.BigInteger
 * BigInteger}
 *
 * <li><b>Floating Point</b> - may be applied to Java floating-point types:
 * <tt>float</tt>, {@link Float}, <tt>double</tt>, {@link Double}, and {@link
 * java.math.BigDecimal BigDecimal}
 *
 * </ol>
 *
 * <li> <b>Date/Time</b> - may be applied to Java types which are capable of
 * encoding a date or time: <tt>long</tt>, {@link Long}, {@link Calendar}, and
 * {@link Date}.
 *
 * <li> <b>Percent</b> - produces a literal <tt>'%'</tt>
 * (<tt>'&#92;u0025'</tt>)
 *
 * <li> <b>Line Separator</b> - produces the platform-specific line separator
 *
 * </ol>
 *
 * <p> The following table summarizes the supported conversions.  Conversions
 * denoted by an upper-case character (i.e. <tt>'B'</tt>, <tt>'H'</tt>,
 * <tt>'S'</tt>, <tt>'C'</tt>, <tt>'X'</tt>, <tt>'E'</tt>, <tt>'G'</tt>,
 * <tt>'A'</tt>, and <tt>'T'</tt>) are the same as those for the corresponding
 * lower-case conversion characters except that the result is converted to
 * upper case according to the rules of the prevailing {@link java.util.Locale
 * Locale}.  The result is equivalent to the following invocation of {@link
 * String#toUpperCase()}
 *
 * <pre>
 *    out.toUpperCase() </pre>
 *
 * <table cellpadding=5 summary="genConv">
 *
 * <tr><th valign="bottom"> Conversion
 *     <th valign="bottom"> Argument Category
 *     <th valign="bottom"> Description
 *
 * <tr><td valign="top"> <tt>'b'</tt>, <tt>'B'</tt>
 *     <td valign="top"> general
 *     <td> If the argument <i>arg</i> is <tt>null</tt>, then the result is
 *     "<tt>false</tt>".  If <i>arg</i> is a <tt>boolean</tt> or {@link
 *     Boolean}, then the result is the string returned by {@link
 *     String#valueOf(boolean) String.valueOf()}.  Otherwise, the result is
 *     "true".
 *
 * <tr><td valign="top"> <tt>'h'</tt>, <tt>'H'</tt>
 *     <td valign="top"> general
 *     <td> If the argument <i>arg</i> is <tt>null</tt>, then the result is
 *     "<tt>null</tt>".  Otherwise, the result is obtained by invoking
 *     <tt>Integer.toHexString(arg.hashCode())</tt>.
 *
 * <tr><td valign="top"> <tt>'s'</tt>, <tt>'S'</tt>
 *     <td valign="top"> general
 *     <td> If the argument <i>arg</i> is <tt>null</tt>, then the result is
 *     "<tt>null</tt>".  If <i>arg</i> implements {@link Formattable}, then
 *     {@link Formattable#formatTo arg.formatTo} is invoked. Otherwise, the
 *     result is obtained by invoking <tt>arg.toString()</tt>.
 *
 * <tr><td valign="top"><tt>'c'</tt>, <tt>'C'</tt>
 *     <td valign="top"> character
 *     <td> The result is a Unicode character
 *
 * <tr><td valign="top"><tt>'d'</tt>
 *     <td valign="top"> integral
 *     <td> The result is formatted as a decimal integer
 *
 * <tr><td valign="top"><tt>'o'</tt>
 *     <td valign="top"> integral
 *     <td> The result is formatted as an octal integer
 *
 * <tr><td valign="top"><tt>'x'</tt>, <tt>'X'</tt>
 *     <td valign="top"> integral
 *     <td> The result is formatted as a hexadecimal integer
 *
 * <tr><td valign="top"><tt>'e'</tt>, <tt>'E'</tt>
 *     <td valign="top"> floating point
 *     <td> The result is formatted as a decimal number in computerized
 *     scientific notation
 *
 * <tr><td valign="top"><tt>'f'</tt>
 *     <td valign="top"> floating point
 *     <td> The result is formatted as a decimal number
 *
 * <tr><td valign="top"><tt>'g'</tt>, <tt>'G'</tt>
 *     <td valign="top"> floating point
 *     <td> The result is formatted using computerized scientific notation or
 *     decimal format, depending on the precision and the value after rounding.
 *
 * <tr><td valign="top"><tt>'a'</tt>, <tt>'A'</tt>
 *     <td valign="top"> floating point
 *     <td> The result is formatted as a hexadecimal floating-point number with
 *     a significand and an exponent
 *
 * <tr><td valign="top"><tt>'t'</tt>, <tt>'T'</tt>
 *     <td valign="top"> date/time
 *     <td> Prefix for date and time conversion characters.  See <a
 *     href="#dt">Date/Time Conversions</a>.
 *
 * <tr><td valign="top"><tt>'%'</tt>
 *     <td valign="top"> percent
 *     <td> The result is a literal <tt>'%'</tt> (<tt>'&#92;u0025'</tt>)
 *
 * <tr><td valign="top"><tt>'n'</tt>
 *     <td valign="top"> line separator
 *     <td> The result is the platform-specific line separator
 *
 * </table>
 *
 * <p> Any characters not explicitly defined as conversions are illegal and are
 * reserved for future extensions.
 *
 * <h4><a name="dt">Date/Time Conversions</a></h4>
 *
 * <p> The following date and time conversion suffix characters are defined for
 * the <tt>'t'</tt> and <tt>'T'</tt> conversions.  The types are similar to but
 * not completely identical to those defined by GNU <tt>date</tt> and POSIX
 * <tt>strftime(3c)</tt>.  Additional conversion types are provided to access
 * Java-specific functionality (e.g. <tt>'L'</tt> for milliseconds within the
 * second).
 *
 * <p> The following conversion characters are used for formatting times:
 *
 * <table cellpadding=5 summary="time">
 *
 * <tr><td valign="top"> <tt>'H'</tt>
 *     <td> Hour of the day for the 24-hour clock, formatted as two digits with
 *     a leading zero as necessary i.e. <tt>00 - 23</tt>.
 *
 * <tr><td valign="top"><tt>'I'</tt>
 *     <td> Hour for the 12-hour clock, formatted as two digits with a leading
 *     zero as necessary, i.e.  <tt>01 - 12</tt>.
 *
 * <tr><td valign="top"><tt>'k'</tt>
 *     <td> Hour of the day for the 24-hour clock, i.e. <tt>0 - 23</tt>.
 *
 * <tr><td valign="top"><tt>'l'</tt>
 *     <td> Hour for the 12-hour clock, i.e. <tt>1 - 12</tt>.
 *
 * <tr><td valign="top"><tt>'M'</tt>
 *     <td> Minute within the hour formatted as two digits with a leading zero
 *     as necessary, i.e.  <tt>00 - 59</tt>.
 *
 * <tr><td valign="top"><tt>'S'</tt>
 *     <td> Seconds within the minute, formatted as two digits with a leading
 *     zero as necessary, i.e. <tt>00 - 60</tt> ("<tt>60</tt>" is a special
 *     value required to support leap seconds).
 *
 * <tr><td valign="top"><tt>'L'</tt>
 *     <td> Millisecond within the second formatted as three digits with
 *     leading zeros as necessary, i.e. <tt>000 - 999</tt>.
 *
 * <tr><td valign="top"><tt>'N'</tt>
 *     <td> Nanosecond within the second, formatted as nine digits with leading
 *     zeros as necessary, i.e. <tt>000000000 - 999999999</tt>.
 *
 * <tr><td valign="top"><tt>'p'</tt>
 *     <td> Locale-specific {@linkplain
 *     java.text.DateFormatSymbols#getAmPmStrings morning or afternoon} marker
 *     in lower case, e.g."<tt>am</tt>" or "<tt>pm</tt>". Use of the conversion
 *     prefix <tt>'T'</tt> forces this output to upper case.
 *
 * <tr><td valign="top"><tt>'z'</tt>
 *     <td> <a href="http://www.ietf.org/rfc/rfc0822.txt">RFC&nbsp;822</a>
 *     style numeric time zone offset from GMT, e.g. <tt>-0800</tt>.
 *
 * <tr><td valign="top"><tt>'Z'</tt>
 *     <td> A string representing the abbreviation for the time zone.  The
 *     Formatter's locale will supersede the locale of the argument (if any).
 *
 * <tr><td valign="top"><tt>'s'</tt>
 *     <td> Seconds since the beginning of the epoch starting at 1 January 1970
 *     <tt>00:00:00</tt> UTC, i.e. <tt>Long.MIN_VALUE/1000</tt> to
 *     <tt>Long.MAX_VALUE/1000</tt>.
 *
 * <tr><td valign="top"><tt>'Q'</tt>
 *     <td> Milliseconds since the beginning of the epoch starting at 1 January
 *     1970 <tt>00:00:00</tt> UTC, i.e. <tt>Long.MIN_VALUE</tt> to
 *     <tt>Long.MAX_VALUE</tt>.
 *
 * </table>
 *
 * <p> The following conversion characters are used for formatting dates:
 *
 * <table cellpadding=5 summary="date">
 *
 * <tr><td valign="top"><tt>'B'</tt>
 *     <td> Locale-specific {@linkplain java.text.DateFormatSymbols#getMonths
 *     full month name}, e.g. <tt>"January"</tt>, <tt>"February"</tt>.
 *
 * <tr><td valign="top"><tt>'b'</tt>
 *     <td> Locale-specific {@linkplain
 *     java.text.DateFormatSymbols#getShortMonths abbreviated month name},
 *     e.g. <tt>"Jan"</tt>, <tt>"Feb"</tt>.
 *
 * <tr><td valign="top"><tt>'h'</tt>
 *     <td> Same as <tt>'b'</tt>.
 *
 * <tr><td valign="top"><tt>'A'</tt>
 *     <td> Locale-specific full name of the {@linkplain
 *     java.text.DateFormatSymbols#getWeekdays day of the week},
 *     e.g. <tt>"Sunday"</tt>, <tt>"Monday"</tt>
 *
 * <tr><td valign="top"><tt>'a'</tt>
 *     <td> Locale-specific short name of the {@linkplain
 *     java.text.DateFormatSymbols#getShortWeekdays day of the week},
 *     e.g. <tt>"Sun"</tt>, <tt>"Mon"</tt>
 *
 * <tr><td valign="top"><tt>'C'</tt>
 *     <td> Four-digit year divided by <tt>100</tt>, formatted as two digits
 *     with leading zero as necessary, i.e. <tt>00 - 99</tt>
 *
 * <tr><td valign="top"><tt>'Y'</tt>
 *     <td> Year, formatted as at least four digits with leading zeros as
 *     necessary, e.g. <tt>0092</tt> equals <tt>92</tt> CE for the Gregorian
 *     calendar.
 *
 * <tr><td valign="top"><tt>'y'</tt>
 *     <td> Last two digits of the year, formatted with leading zeros as
 *     necessary, i.e. <tt>00 - 99</tt>.
 *
 * <tr><td valign="top"><tt>'j'</tt>
 *     <td> Day of year, formatted as three digits with leading zeros as
 *     necessary, e.g. <tt>001 - 366</tt> for the Gregorian calendar.
 *
 * <tr><td valign="top"><tt>'m'</tt>
 *     <td> Month, formatted as two digits with leading zeros as necessary,
 *     i.e. <tt>01 - 13</tt>.
 *
 * <tr><td valign="top"><tt>'d'</tt>
 *     <td> Day of month, formatted as two digits with leading zeros as
 *     necessary, i.e. <tt>01 - 31</tt>
 *
 * <tr><td valign="top"><tt>'e'</tt>
 *     <td> Day of month, formatted as two digits, i.e. <tt>1 - 31</tt>.
 *
 * </table>
 *
 * <p> The following conversion characters are used for formatting common
 * date/time compositions.
 *
 * <table cellpadding=5 summary="composites">
 *
 * <tr><td valign="top"><tt>'R'</tt>
 *     <td> Time formatted for the 24-hour clock as <tt>"%tH:%tM"</tt>
 *
 * <tr><td valign="top"><tt>'T'</tt>
 *     <td> Time formatted for the 24-hour clock as <tt>"%tH:%tM:%tS"</tt>.
 *
 * <tr><td valign="top"><tt>'r'</tt>
 *     <td> Time formatted for the 12-hour clock as <tt>"%tI:%tM:%tS %Tp"</tt>.
 *     The location of the morning or afternoon marker (<tt>'%Tp'</tt>) may be
 *     locale-dependent.
 *
 * <tr><td valign="top"><tt>'D'</tt>
 *     <td> Date formatted as <tt>"%tm/%td/%ty"</tt>.
 *
 * <tr><td valign="top"><tt>'F'</tt>
 *     <td> <a href="http://www.w3.org/TR/NOTE-datetime">ISO&nbsp;8601</a>
 *     complete date formatted as <tt>"%tY-%tm-%td"</tt>.
 *
 * <tr><td valign="top"><tt>'c'</tt>
 *     <td> Date and time formatted as <tt>"%ta %tb %td %tT %tZ %tY"</tt>,
 *     e.g. <tt>"Sun Jul 20 16:17:00 EDT 1969"</tt>.
 *
 * </table>
 *
 * <p> Any characters not explicitly defined as date/time conversion suffixes
 * are illegal and are reserved for future extensions.
 *
 * <h4> Flags </h4>
 *
 * <p> The following table summarizes the supported flags.  <i>y</i> means the
 * flag is supported for the indicated argument types.
 *
 * <table cellpadding=5 summary="genConv">
 *
 * <tr><th valign="bottom"> Flag <th valign="bottom"> General
 *     <th valign="bottom"> Character <th valign="bottom"> Integral
 *     <th valign="bottom"> Floating Point
 *     <th valign="bottom"> Date/Time
 *     <th valign="bottom"> Description
 *
 * <tr><td> '-' <td align="center" valign="top"> y
 *     <td align="center" valign="top"> y
 *     <td align="center" valign="top"> y
 *     <td align="center" valign="top"> y
 *     <td align="center" valign="top"> y
 *     <td> The result will be left-justified.
 *
 * <tr><td> '#' <td align="center" valign="top"> y<sup>1</sup>
 *     <td align="center" valign="top"> -
 *     <td align="center" valign="top"> y<sup>3</sup>
 *     <td align="center" valign="top"> y
 *     <td align="center" valign="top"> -
 *     <td> The result should use a conversion-dependent alternate form
 *
 * <tr><td> '+' <td align="center" valign="top"> -
 *     <td align="center" valign="top"> -
 *     <td align="center" valign="top"> y<sup>4</sup>
 *     <td align="center" valign="top"> y
 *     <td align="center" valign="top"> -
 *     <td> The result will always include a sign
 *
 * <tr><td> '&nbsp;&nbsp;' <td align="center" valign="top"> -
 *     <td align="center" valign="top"> -
 *     <td align="center" valign="top"> y<sup>4</sup>
 *     <td align="center" valign="top"> y
 *     <td align="center" valign="top"> -
 *     <td> The result will include a leading space for positive values
 *
 * <tr><td> '0' <td align="center" valign="top"> -
 *     <td align="center" valign="top"> -
 *     <td align="center" valign="top"> y
 *     <td align="center" valign="top"> y
 *     <td align="center" valign="top"> -
 *     <td> The result will be zero-padded
 *
 * <tr><td> ',' <td align="center" valign="top"> -
 *     <td align="center" valign="top"> -
 *     <td align="center" valign="top"> y<sup>2</sup>
 *     <td align="center" valign="top"> y<sup>5</sup>
 *     <td align="center" valign="top"> -
 *     <td> The result will include locale-specific {@linkplain
 *     java.text.DecimalFormatSymbols#getGroupingSeparator grouping separators}
 *
 * <tr><td> '(' <td align="center" valign="top"> -
 *     <td align="center" valign="top"> -
 *     <td align="center" valign="top"> y<sup>4</sup>
 *     <td align="center" valign="top"> y<sup>5</sup>
 *     <td align="center"> -
 *     <td> The result will enclose negative numbers in parentheses
 *
 * </table>
 *
 * <p> <sup>1</sup> Depends on the definition of {@link Formattable}.
 *
 * <p> <sup>2</sup> For <tt>'d'</tt> conversion only.
 *
 * <p> <sup>3</sup> For <tt>'o'</tt>, <tt>'x'</tt>, and <tt>'X'</tt>
 * conversions only.
 *
 * <p> <sup>4</sup> For <tt>'d'</tt>, <tt>'o'</tt>, <tt>'x'</tt>, and
 * <tt>'X'</tt> conversions applied to {@link java.math.BigInteger BigInteger}
 * or <tt>'d'</tt> applied to <tt>byte</tt>, {@link Byte}, <tt>short</tt>, {@link
 * Short}, <tt>int</tt> and {@link Integer}, <tt>long</tt>, and {@link Long}.
 *
 * <p> <sup>5</sup> For <tt>'e'</tt>, <tt>'E'</tt>, <tt>'f'</tt>,
 * <tt>'g'</tt>, and <tt>'G'</tt> conversions only.
 *
 * <p> Any characters not explicitly defined as flags are illegal and are
 * reserved for future extensions.
 *
 * <h4> Width </h4>
 *
 * <p> The width is the minimum number of characters to be written to the
 * output.  For the line separator conversion, width is not applicable; if it
 * is provided, an exception will be thrown.
 *
 * <h4> Precision </h4>
 *
 * <p> For general argument types, the precision is the maximum number of
 * characters to be written to the output.
 *
 * <p> For the floating-point conversions <tt>'e'</tt>, <tt>'E'</tt>, and
 * <tt>'f'</tt> the precision is the number of digits after the decimal
 * separator.  If the conversion is <tt>'g'</tt> or <tt>'G'</tt>, then the
 * precision is the total number of digits in the resulting magnitude after
 * rounding.  If the conversion is <tt>'a'</tt> or <tt>'A'</tt>, then the
 * precision must not be specified.
 *
 * <p> For character, integral, and date/time argument types and the percent
 * and line separator conversions, the precision is not applicable; if a
 * precision is provided, an exception will be thrown.
 *
 * <h4> Argument Index </h4>
 *
 * <p> The argument index is a decimal integer indicating the position of the
 * argument in the argument list.  The first argument is referenced by
 * "<tt>1$</tt>", the second by "<tt>2$</tt>", etc.
 *
 * <p> Another way to reference arguments by position is to use the
 * <tt>'&lt;'</tt> (<tt>'&#92;u003c'</tt>) flag, which causes the argument for
 * the previous format specifier to be re-used.  For example, the following two
 * statements would produce identical strings:
 *
 * <blockquote><pre>
 *   Calendar c = ...;
 *   String s1 = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
 *
 *   String s2 = String.format("Duke's Birthday: %1$tm %&lt;te,%&lt;tY", c);
 * </pre></blockquote>
 *
 * <hr>
 * <h3><a name="detail">Details</a></h3>
 *
 * <p> This section is intended to provide behavioral details for formatting,
 * including conditions and exceptions, supported data types, localization, and
 * interactions between flags, conversions, and data types.  For an overview of
 * formatting concepts, refer to the <a href="#summary">Summary</a>
 *
 * <p> Any characters not explicitly defined as conversions, date/time
 * conversion suffixes, or flags are illegal and are reserved for
 * future extensions.  Use of such a character in a format string will
 * cause an {@link UnknownFormatConversionException} or {@link
 * UnknownFormatFlagsException} to be thrown.
 *
 * <p> If the format specifier contains a width or precision with an invalid
 * value or which is otherwise unsupported, then a {@link
 * IllegalFormatWidthException} or {@link IllegalFormatPrecisionException}
 * respectively will be thrown.
 *
 * <p> If a format specifier contains a conversion character that is not
 * applicable to the corresponding argument, then an {@link
 * IllegalFormatConversionException} will be thrown.
 *
 * <p> All specified exceptions may be thrown by any of the <tt>format</tt>
 * methods of <tt>Formatter</tt> as well as by any <tt>format</tt> convenience
 * methods such as {@link String#format(String,Object...) String.format} and
 * {@link java.io.PrintStream#printf(String,Object...) PrintStream.printf}.
 *
 * <p> Conversions denoted by an upper-case character (i.e. <tt>'B'</tt>,
 * <tt>'H'</tt>, <tt>'S'</tt>, <tt>'C'</tt>, <tt>'X'</tt>, <tt>'E'</tt>,
 * <tt>'G'</tt>, <tt>'A'</tt>, and <tt>'T'</tt>) are the same as those for the
 * corresponding lower-case conversion characters except that the result is
 * converted to upper case according to the rules of the prevailing {@link
 * java.util.Locale Locale}.  The result is equivalent to the following
 * invocation of {@link String#toUpperCase()}
 *
 * <pre>
 *    out.toUpperCase() </pre>
 *
 * <h4><a name="dgen">General</a></h4>
 *
 * <p> The following general conversions may be applied to any argument type:
 *
 * <table cellpadding=5 summary="dgConv">
 *
 * <tr><td valign="top"> <tt>'b'</tt>
 *     <td valign="top"> <tt>'&#92;u0062'</tt>
 *     <td> Produces either "<tt>true</tt>" or "<tt>false</tt>" as returned by
 *     {@link Boolean#toString(boolean)}.
 *
 *     <p> If the argument is <tt>null</tt>, then the result is
 *     "<tt>false</tt>".  If the argument is a <tt>boolean</tt> or {@link
 *     Boolean}, then the result is the string returned by {@link
 *     String#valueOf(boolean) String.valueOf()}.  Otherwise, the result is
 *     "<tt>true</tt>".
 *
 *     <p> If the <tt>'#'</tt> flag is given, then a {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'B'</tt>
 *     <td valign="top"> <tt>'&#92;u0042'</tt>
 *     <td> The upper-case variant of <tt>'b'</tt>.
 *
 * <tr><td valign="top"> <tt>'h'</tt>
 *     <td valign="top"> <tt>'&#92;u0068'</tt>
 *     <td> Produces a string representing the hash code value of the object.
 *
 *     <p> If the argument, <i>arg</i> is <tt>null</tt>, then the
 *     result is "<tt>null</tt>".  Otherwise, the result is obtained
 *     by invoking <tt>Integer.toHexString(arg.hashCode())</tt>.
 *
 *     <p> If the <tt>'#'</tt> flag is given, then a {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'H'</tt>
 *     <td valign="top"> <tt>'&#92;u0048'</tt>
 *     <td> The upper-case variant of <tt>'h'</tt>.
 *
 * <tr><td valign="top"> <tt>'s'</tt>
 *     <td valign="top"> <tt>'&#92;u0073'</tt>
 *     <td> Produces a string.
 *
 *     <p> If the argument is <tt>null</tt>, then the result is
 *     "<tt>null</tt>".  If the argument implements {@link Formattable}, then
 *     its {@link Formattable#formatTo formatTo} method is invoked.
 *     Otherwise, the result is obtained by invoking the argument's
 *     <tt>toString()</tt> method.
 *
 *     <p> If the <tt>'#'</tt> flag is given and the argument is not a {@link
 *     Formattable} , then a {@link FormatFlagsConversionMismatchException}
 *     will be thrown.
 *
 * <tr><td valign="top"> <tt>'S'</tt>
 *     <td valign="top"> <tt>'&#92;u0053'</tt>
 *     <td> The upper-case variant of <tt>'s'</tt>.
 *
 * </table>
 *
 * <p> The following <a name="dFlags">flags</a> apply to general conversions:
 *
 * <table cellpadding=5 summary="dFlags">
 *
 * <tr><td valign="top"> <tt>'-'</tt>
 *     <td valign="top"> <tt>'&#92;u002d'</tt>
 *     <td> Left justifies the output.  Spaces (<tt>'&#92;u0020'</tt>) will be
 *     added at the end of the converted value as required to fill the minimum
 *     width of the field.  If the width is not provided, then a {@link
 *     MissingFormatWidthException} will be thrown.  If this flag is not given
 *     then the output will be right-justified.
 *
 * <tr><td valign="top"> <tt>'#'</tt>
 *     <td valign="top"> <tt>'&#92;u0023'</tt>
 *     <td> Requires the output use an alternate form.  The definition of the
 *     form is specified by the conversion.
 *
 * </table>
 *
 * <p> The <a name="genWidth">width</a> is the minimum number of characters to
 * be written to the
 * output.  If the length of the converted value is less than the width then
 * the output will be padded by <tt>'&nbsp;&nbsp;'</tt> (<tt>&#92;u0020'</tt>)
 * until the total number of characters equals the width.  The padding is on
 * the left by default.  If the <tt>'-'</tt> flag is given, then the padding
 * will be on the right.  If the width is not specified then there is no
 * minimum.
 *
 * <p> The precision is the maximum number of characters to be written to the
 * output.  The precision is applied before the width, thus the output will be
 * truncated to <tt>precision</tt> characters even if the width is greater than
 * the precision.  If the precision is not specified then there is no explicit
 * limit on the number of characters.
 *
 * <h4><a name="dchar">Character</a></h4>
 *
 * This conversion may be applied to <tt>char</tt> and {@link Character}.  It
 * may also be applied to the types <tt>byte</tt>, {@link Byte},
 * <tt>short</tt>, and {@link Short}, <tt>int</tt> and {@link Integer} when
 * {@link Character#isValidCodePoint} returns <tt>true</tt>.  If it returns
 * <tt>false</tt> then an {@link IllegalFormatCodePointException} will be
 * thrown.
 *
 * <table cellpadding=5 summary="charConv">
 *
 * <tr><td valign="top"> <tt>'c'</tt>
 *     <td valign="top"> <tt>'&#92;u0063'</tt>
 *     <td> Formats the argument as a Unicode character as described in <a
 *     href="../lang/Character.html#unicode">Unicode Character
 *     Representation</a>.  This may be more than one 16-bit <tt>char</tt> in
 *     the case where the argument represents a supplementary character.
 *
 *     <p> If the <tt>'#'</tt> flag is given, then a {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'C'</tt>
 *     <td valign="top"> <tt>'&#92;u0043'</tt>
 *     <td> The upper-case variant of <tt>'c'</tt>.
 *
 * </table>
 *
 * <p> The <tt>'-'</tt> flag defined for <a href="#dFlags">General
 * conversions</a> applies.  If the <tt>'#'</tt> flag is given, then a {@link
 * FormatFlagsConversionMismatchException} will be thrown.
 *
 * <p> The width is defined as for <a href="#genWidth">General conversions</a>.
 *
 * <p> The precision is not applicable.  If the precision is specified then an
 * {@link IllegalFormatPrecisionException} will be thrown.
 *
 * <h4><a name="dnum">Numeric</a></h4>
 *
 * <p> Numeric conversions are divided into the following categories:
 *
 * <ol>
 *
 * <li> <a href="#dnint"><b>Byte, Short, Integer, and Long</b></a>
 *
 * <li> <a href="#dnbint"><b>BigInteger</b></a>
 *
 * <li> <a href="#dndec"><b>Float and Double</b></a>
 *
 * <li> <a href="#dndec"><b>BigDecimal</b></a>
 *
 * </ol>
 *
 * <p> Numeric types will be formatted according to the following algorithm:
 *
 * <p><b><a name="l10n algorithm"> Number Localization Algorithm</a></b>
 *
 * <p> After digits are obtained for the integer part, fractional part, and
 * exponent (as appropriate for the data type), the following transformation
 * is applied:
 *
 * <ol>
 *
 * <li> Each digit character <i>d</i> in the string is replaced by a
 * locale-specific digit computed relative to the current locale's
 * {@linkplain java.text.DecimalFormatSymbols#getZeroDigit() zero digit}
 * <i>z</i>; that is <i>d&nbsp;-&nbsp;</i> <tt>'0'</tt>
 * <i>&nbsp;+&nbsp;z</i>.
 *
 * <li> If a decimal separator is present, a locale-specific {@linkplain
 * java.text.DecimalFormatSymbols#getDecimalSeparator decimal separator} is
 * substituted.
 *
 * <li> If the <tt>','</tt> (<tt>'&#92;u002c'</tt>)
 * <a name="l10n group">flag</a> is given, then the locale-specific {@linkplain
 * java.text.DecimalFormatSymbols#getGroupingSeparator grouping separator} is
 * inserted by scanning the integer part of the string from least significant
 * to most significant digits and inserting a separator at intervals defined by
 * the locale's {@linkplain java.text.DecimalFormat#getGroupingSize() grouping
 * size}.
 *
 * <li> If the <tt>'0'</tt> flag is given, then the locale-specific {@linkplain
 * java.text.DecimalFormatSymbols#getZeroDigit() zero digits} are inserted
 * after the sign character, if any, and before the first non-zero digit, until
 * the length of the string is equal to the requested field width.
 *
 * <li> If the value is negative and the <tt>'('</tt> flag is given, then a
 * <tt>'('</tt> (<tt>'&#92;u0028'</tt>) is prepended and a <tt>')'</tt>
 * (<tt>'&#92;u0029'</tt>) is appended.
 *
 * <li> If the value is negative (or floating-point negative zero) and
 * <tt>'('</tt> flag is not given, then a <tt>'-'</tt> (<tt>'&#92;u002d'</tt>)
 * is prepended.
 *
 * <li> If the <tt>'+'</tt> flag is given and the value is positive or zero (or
 * floating-point positive zero), then a <tt>'+'</tt> (<tt>'&#92;u002b'</tt>)
 * will be prepended.
 *
 * </ol>
 *
 * <p> If the value is NaN or positive infinity the literal strings "NaN" or
 * "Infinity" respectively, will be output.  If the value is negative infinity,
 * then the output will be "(Infinity)" if the <tt>'('</tt> flag is given
 * otherwise the output will be "-Infinity".  These values are not localized.
 *
 * <p><a name="dnint"><b> Byte, Short, Integer, and Long </b></a>
 *
 * <p> The following conversions may be applied to <tt>byte</tt>, {@link Byte},
 * <tt>short</tt>, {@link Short}, <tt>int</tt> and {@link Integer},
 * <tt>long</tt>, and {@link Long}.
 *
 * <table cellpadding=5 summary="IntConv">
 *
 * <tr><td valign="top"> <tt>'d'</tt>
 *     <td valign="top"> <tt>'&#92;u0054'</tt>
 *     <td> Formats the argument as a decimal integer. The <a
 *     href="#l10n algorithm">localization algorithm</a> is applied.
 *
 *     <p> If the <tt>'0'</tt> flag is given and the value is negative, then
 *     the zero padding will occur after the sign.
 *
 *     <p> If the <tt>'#'</tt> flag is given then a {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'o'</tt>
 *     <td valign="top"> <tt>'&#92;u006f'</tt>
 *     <td> Formats the argument as an integer in base eight.  No localization
 *     is applied.
 *
 *     <p> If <i>x</i> is negative then the result will be an unsigned value
 *     generated by adding 2<sup>n</sup> to the value where <tt>n</tt> is the
 *     number of bits in the type as returned by the static <tt>SIZE</tt> field
 *     in the {@linkplain Byte#SIZE Byte}, {@linkplain Short#SIZE Short},
 *     {@linkplain Integer#SIZE Integer}, or {@linkplain Long#SIZE Long}
 *     classes as appropriate.
 *
 *     <p> If the <tt>'#'</tt> flag is given then the output will always begin
 *     with the radix indicator <tt>'0'</tt>.
 *
 *     <p> If the <tt>'0'</tt> flag is given then the output will be padded
 *     with leading zeros to the field width following any indication of sign.
 *
 *     <p> If <tt>'('</tt>, <tt>'+'</tt>, '&nbsp&nbsp;', or <tt>','</tt> flags
 *     are given then a {@link FormatFlagsConversionMismatchException} will be
 *     thrown.
 *
 * <tr><td valign="top"> <tt>'x'</tt>
 *     <td valign="top"> <tt>'&#92;u0078'</tt>
 *     <td> Formats the argument as an integer in base sixteen. No
 *     localization is applied.
 *
 *     <p> If <i>x</i> is negative then the result will be an unsigned value
 *     generated by adding 2<sup>n</sup> to the value where <tt>n</tt> is the
 *     number of bits in the type as returned by the static <tt>SIZE</tt> field
 *     in the {@linkplain Byte#SIZE Byte}, {@linkplain Short#SIZE Short},
 *     {@linkplain Integer#SIZE Integer}, or {@linkplain Long#SIZE Long}
 *     classes as appropriate.
 *
 *     <p> If the <tt>'#'</tt> flag is given then the output will always begin
 *     with the radix indicator <tt>"0x"</tt>.
 *
 *     <p> If the <tt>'0'</tt> flag is given then the output will be padded to
 *     the field width with leading zeros after the radix indicator or sign (if
 *     present).
 *
 *     <p> If <tt>'('</tt>, <tt>'&nbsp;&nbsp;'</tt>, <tt>'+'</tt>, or
 *     <tt>','</tt> flags are given then a {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'X'</tt>
 *     <td valign="top"> <tt>'&#92;u0058'</tt>
 *     <td> The upper-case variant of <tt>'x'</tt>.  The entire string
 *     representing the number will be converted to {@linkplain
 *     String#toUpperCase upper case} including the <tt>'x'</tt> (if any) and
 *     all hexadecimal digits <tt>'a'</tt> - <tt>'f'</tt>
 *     (<tt>'&#92;u0061'</tt> -  <tt>'&#92;u0066'</tt>).
 *
 * </table>
 *
 * <p> If the conversion is <tt>'o'</tt>, <tt>'x'</tt>, or <tt>'X'</tt> and
 * both the <tt>'#'</tt> and the <tt>'0'</tt> flags are given, then result will
 * contain the radix indicator (<tt>'0'</tt> for octal and <tt>"0x"</tt> or
 * <tt>"0X"</tt> for hexadecimal), some number of zeros (based on the width),
 * and the value.
 *
 * <p> If the <tt>'-'</tt> flag is not given, then the space padding will occur
 * before the sign.
 *
 * <p> The following <a name="intFlags">flags</a> apply to numeric integral
 * conversions:
 *
 * <table cellpadding=5 summary="intFlags">
 *
 * <tr><td valign="top"> <tt>'+'</tt>
 *     <td valign="top"> <tt>'&#92;u002b'</tt>
 *     <td> Requires the output to include a positive sign for all positive
 *     numbers.  If this flag is not given then only negative values will
 *     include a sign.
 *
 *     <p> If both the <tt>'+'</tt> and <tt>'&nbsp;&nbsp;'</tt> flags are given
 *     then an {@link IllegalFormatFlagsException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'&nbsp;&nbsp;'</tt>
 *     <td valign="top"> <tt>'&#92;u0020'</tt>
 *     <td> Requires the output to include a single extra space
 *     (<tt>'&#92;u0020'</tt>) for non-negative values.
 *
 *     <p> If both the <tt>'+'</tt> and <tt>'&nbsp;&nbsp;'</tt> flags are given
 *     then an {@link IllegalFormatFlagsException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'0'</tt>
 *     <td valign="top"> <tt>'&#92;u0030'</tt>
 *     <td> Requires the output to be padded with leading {@linkplain
 *     java.text.DecimalFormatSymbols#getZeroDigit zeros} to the minimum field
 *     width following any sign or radix indicator except when converting NaN
 *     or infinity.  If the width is not provided, then a {@link
 *     MissingFormatWidthException} will be thrown.
 *
 *     <p> If both the <tt>'-'</tt> and <tt>'0'</tt> flags are given then an
 *     {@link IllegalFormatFlagsException} will be thrown.
 *
 * <tr><td valign="top"> <tt>','</tt>
 *     <td valign="top"> <tt>'&#92;u002c'</tt>
 *     <td> Requires the output to include the locale-specific {@linkplain
 *     java.text.DecimalFormatSymbols#getGroupingSeparator group separators} as
 *     described in the <a href="#l10n group">"group" section</a> of the
 *     localization algorithm.
 *
 * <tr><td valign="top"> <tt>'('</tt>
 *     <td valign="top"> <tt>'&#92;u0028'</tt>
 *     <td> Requires the output to prepend a <tt>'('</tt>
 *     (<tt>'&#92;u0028'</tt>) and append a <tt>')'</tt>
 *     (<tt>'&#92;u0029'</tt>) to negative values.
 *
 * </table>
 *
 * <p> If no <a name="intdFlags">flags</a> are given the default formatting is
 * as follows:
 *
 * <ul>
 *
 * <li> The output is right-justified within the <tt>width</tt>
 *
 * <li> Negative numbers begin with a <tt>'-'</tt> (<tt>'&#92;u002d'</tt>)
 *
 * <li> Positive numbers and zero do not include a sign or extra leading
 * space
 *
 * <li> No grouping separators are included
 *
 * </ul>
 *
 * <p> The <a name="intWidth">width</a> is the minimum number of characters to
 * be written to the output.  This includes any signs, digits, grouping
 * separators, radix indicator, and parentheses.  If the length of the
 * converted value is less than the width then the output will be padded by
 * spaces (<tt>'&#92;u0020'</tt>) until the total number of characters equals
 * width.  The padding is on the left by default.  If <tt>'-'</tt> flag is
 * given then the padding will be on the right.  If width is not specified then
 * there is no minimum.
 *
 * <p> The precision is not applicable.  If precision is specified then an
 * {@link IllegalFormatPrecisionException} will be thrown.
 *
 * <p><a name="dnbint"><b> BigInteger </b></a>
 *
 * <p> The following conversions may be applied to {@link
 * java.math.BigInteger}.
 *
 * <table cellpadding=5 summary="BIntConv">
 *
 * <tr><td valign="top"> <tt>'d'</tt>
 *     <td valign="top"> <tt>'&#92;u0054'</tt>
 *     <td> Requires the output to be formatted as a decimal integer. The <a
 *     href="#l10n algorithm">localization algorithm</a> is applied.
 *
 *     <p> If the <tt>'#'</tt> flag is given {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'o'</tt>
 *     <td valign="top"> <tt>'&#92;u006f'</tt>
 *     <td> Requires the output to be formatted as an integer in base eight.
 *     No localization is applied.
 *
 *     <p> If <i>x</i> is negative then the result will be a signed value
 *     beginning with <tt>'-'</tt> (<tt>'&#92;u002d'</tt>).  Signed output is
 *     allowed for this type because unlike the primitive types it is not
 *     possible to create an unsigned equivalent without assuming an explicit
 *     data-type size.
 *
 *     <p> If <i>x</i> is positive or zero and the <tt>'+'</tt> flag is given
 *     then the result will begin with <tt>'+'</tt> (<tt>'&#92;u002b'</tt>).
 *
 *     <p> If the <tt>'#'</tt> flag is given then the output will always begin
 *     with <tt>'0'</tt> prefix.
 *
 *     <p> If the <tt>'0'</tt> flag is given then the output will be padded
 *     with leading zeros to the field width following any indication of sign.
 *
 *     <p> If the <tt>','</tt> flag is given then a {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'x'</tt>
 *     <td valign="top"> <tt>'&#92;u0078'</tt>
 *     <td> Requires the output to be formatted as an integer in base
 *     sixteen.  No localization is applied.
 *
 *     <p> If <i>x</i> is negative then the result will be a signed value
 *     beginning with <tt>'-'</tt> (<tt>'&#92;u002d'</tt>).  Signed output is
 *     allowed for this type because unlike the primitive types it is not
 *     possible to create an unsigned equivalent without assuming an explicit
 *     data-type size.
 *
 *     <p> If <i>x</i> is positive or zero and the <tt>'+'</tt> flag is given
 *     then the result will begin with <tt>'+'</tt> (<tt>'&#92;u002b'</tt>).
 *
 *     <p> If the <tt>'#'</tt> flag is given then the output will always begin
 *     with the radix indicator <tt>"0x"</tt>.
 *
 *     <p> If the <tt>'0'</tt> flag is given then the output will be padded to
 *     the field width with leading zeros after the radix indicator or sign (if
 *     present).
 *
 *     <p> If the <tt>','</tt> flag is given then a {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'X'</tt>
 *     <td valign="top"> <tt>'&#92;u0058'</tt>
 *     <td> The upper-case variant of <tt>'x'</tt>.  The entire string
 *     representing the number will be converted to {@linkplain
 *     String#toUpperCase upper case} including the <tt>'x'</tt> (if any) and
 *     all hexadecimal digits <tt>'a'</tt> - <tt>'f'</tt>
 *     (<tt>'&#92;u0061'</tt> - <tt>'&#92;u0066'</tt>).
 *
 * </table>
 *
 * <p> If the conversion is <tt>'o'</tt>, <tt>'x'</tt>, or <tt>'X'</tt> and
 * both the <tt>'#'</tt> and the <tt>'0'</tt> flags are given, then result will
 * contain the base indicator (<tt>'0'</tt> for octal and <tt>"0x"</tt> or
 * <tt>"0X"</tt> for hexadecimal), some number of zeros (based on the width),
 * and the value.
 *
 * <p> If the <tt>'0'</tt> flag is given and the value is negative, then the
 * zero padding will occur after the sign.
 *
 * <p> If the <tt>'-'</tt> flag is not given, then the space padding will occur
 * before the sign.
 *
 * <p> All <a href="#intFlags">flags</a> defined for Byte, Short, Integer, and
 * Long apply.  The <a href="#intdFlags">default behavior</a> when no flags are
 * given is the same as for Byte, Short, Integer, and Long.
 *
 * <p> The specification of <a href="#intWidth">width</a> is the same as
 * defined for Byte, Short, Integer, and Long.
 *
 * <p> The precision is not applicable.  If precision is specified then an
 * {@link IllegalFormatPrecisionException} will be thrown.
 *
 * <p><a name="dndec"><b> Float and Double</b></a>
 *
 * <p> The following conversions may be applied to <tt>float</tt>, {@link
 * Float}, <tt>double</tt> and {@link Double}.
 *
 * <table cellpadding=5 summary="floatConv">
 *
 * <tr><td valign="top"> <tt>'e'</tt>
 *     <td valign="top"> <tt>'&#92;u0065'</tt>
 *     <td> Requires the output to be formatted using <a
 *     name="scientific">computerized scientific notation</a>.  The <a
 *     href="#l10n algorithm">localization algorithm</a> is applied.
 *
 *     <p> The formatting of the magnitude <i>m</i> depends upon its value.
 *
 *     <p> If <i>m</i> is NaN or infinite, the literal strings "NaN" or
 *     "Infinity", respectively, will be output.  These values are not
 *     localized.
 *
 *     <p> If <i>m</i> is positive-zero or negative-zero, then the exponent
 *     will be <tt>"+00"</tt>.
 *
 *     <p> Otherwise, the result is a string that represents the sign and
 *     magnitude (absolute value) of the argument.  The formatting of the sign
 *     is described in the <a href="#l10n algorithm">localization
 *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
 *     value.
 *
 *     <p> Let <i>n</i> be the unique integer such that 10<sup><i>n</i></sup>
 *     &lt;= <i>m</i> &lt; 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
 *     mathematically exact quotient of <i>m</i> and 10<sup><i>n</i></sup> so
 *     that 1 &lt;= <i>a</i> &lt; 10. The magnitude is then represented as the
 *     integer part of <i>a</i>, as a single decimal digit, followed by the
 *     decimal separator followed by decimal digits representing the fractional
 *     part of <i>a</i>, followed by the exponent symbol <tt>'e'</tt>
 *     (<tt>'&#92;u0065'</tt>), followed by the sign of the exponent, followed
 *     by a representation of <i>n</i> as a decimal integer, as produced by the
 *     method {@link Long#toString(long, int)}, and zero-padded to include at
 *     least two digits.
 *
 *     <p> The number of digits in the result for the fractional part of
 *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
 *     specified then the default value is <tt>6</tt>. If the precision is less
 *     than the number of digits which would appear after the decimal point in
 *     the string returned by {@link Float#toString(float)} or {@link
 *     Double#toString(double)} respectively, then the value will be rounded
 *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
 *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
 *     For a canonical representation of the value, use {@link
 *     Float#toString(float)} or {@link Double#toString(double)} as
 *     appropriate.
 *
 *     <p>If the <tt>','</tt> flag is given, then an {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'E'</tt>
 *     <td valign="top"> <tt>'&#92;u0045'</tt>
 *     <td> The upper-case variant of <tt>'e'</tt>.  The exponent symbol
 *     will be <tt>'E'</tt> (<tt>'&#92;u0045'</tt>).
 *
 * <tr><td valign="top"> <tt>'g'</tt>
 *     <td valign="top"> <tt>'&#92;u0067'</tt>
 *     <td> Requires the output to be formatted in general scientific notation
 *     as described below. The <a href="#l10n algorithm">localization
 *     algorithm</a> is applied.
 *
 *     <p> After rounding for the precision, the formatting of the resulting
 *     magnitude <i>m</i> depends on its value.
 *
 *     <p> If <i>m</i> is greater than or equal to 10<sup>-4</sup> but less
 *     than 10<sup>precision</sup> then it is represented in <i><a
 *     href="#decimal">decimal format</a></i>.
 *
 *     <p> If <i>m</i> is less than 10<sup>-4</sup> or greater than or equal to
 *     10<sup>precision</sup>, then it is represented in <i><a
 *     href="#scientific">computerized scientific notation</a></i>.
 *
 *     <p> The total number of significant digits in <i>m</i> is equal to the
 *     precision.  If the precision is not specified, then the default value is
 *     <tt>6</tt>.  If the precision is <tt>0</tt>, then it is taken to be
 *     <tt>1</tt>.
 *
 *     <p> If the <tt>'#'</tt> flag is given then an {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'G'</tt>
 *     <td valign="top"> <tt>'&#92;u0047'</tt>
 *     <td> The upper-case variant of <tt>'g'</tt>.
 *
 * <tr><td valign="top"> <tt>'f'</tt>
 *     <td valign="top"> <tt>'&#92;u0066'</tt>
 *     <td> Requires the output to be formatted using <a name="decimal">decimal
 *     format</a>.  The <a href="#l10n algorithm">localization algorithm</a> is
 *     applied.
 *
 *     <p> The result is a string that represents the sign and magnitude
 *     (absolute value) of the argument.  The formatting of the sign is
 *     described in the <a href="#l10n algorithm">localization
 *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
 *     value.
 *
 *     <p> If <i>m</i> NaN or infinite, the literal strings "NaN" or
 *     "Infinity", respectively, will be output.  These values are not
 *     localized.
 *
 *     <p> The magnitude is formatted as the integer part of <i>m</i>, with no
 *     leading zeroes, followed by the decimal separator followed by one or
 *     more decimal digits representing the fractional part of <i>m</i>.
 *
 *     <p> The number of digits in the result for the fractional part of
 *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
 *     specified then the default value is <tt>6</tt>. If the precision is less
 *     than the number of digits which would appear after the decimal point in
 *     the string returned by {@link Float#toString(float)} or {@link
 *     Double#toString(double)} respectively, then the value will be rounded
 *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
 *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
 *     For a canonical representation of the value,use {@link
 *     Float#toString(float)} or {@link Double#toString(double)} as
 *     appropriate.
 *
 * <tr><td valign="top"> <tt>'a'</tt>
 *     <td valign="top"> <tt>'&#92;u0061'</tt>
 *     <td> Requires the output to be formatted in hexadecimal exponential
 *     form.  No localization is applied.
 *
 *     <p> The result is a string that represents the sign and magnitude
 *     (absolute value) of the argument <i>x</i>.
 *
 *     <p> If <i>x</i> is negative or a negative-zero value then the result
 *     will begin with <tt>'-'</tt> (<tt>'&#92;u002d'</tt>).
 *
 *     <p> If <i>x</i> is positive or a positive-zero value and the
 *     <tt>'+'</tt> flag is given then the result will begin with <tt>'+'</tt>
 *     (<tt>'&#92;u002b'</tt>).
 *
 *     <p> The formatting of the magnitude <i>m</i> depends upon its value.
 *
 *     <ul>
 *
 *     <li> If the value is NaN or infinite, the literal strings "NaN" or
 *     "Infinity", respectively, will be output.
 *
 *     <li> If <i>m</i> is zero then it is represented by the string
 *     <tt>"0x0.0p0"</tt>.
 *
 *     <li> If <i>m</i> is a <tt>double</tt> value with a normalized
 *     representation then substrings are used to represent the significand and
 *     exponent fields.  The significand is represented by the characters
 *     <tt>"0x1."</tt> followed by the hexadecimal representation of the rest
 *     of the significand as a fraction.  The exponent is represented by
 *     <tt>'p'</tt> (<tt>'&#92;u0070'</tt>) followed by a decimal string of the
 *     unbiased exponent as if produced by invoking {@link
 *     Integer#toString(int) Integer.toString} on the exponent value.
 *
 *     <li> If <i>m</i> is a <tt>double</tt> value with a subnormal
 *     representation then the significand is represented by the characters
 *     <tt>'0x0.'</tt> followed by the hexadecimal representation of the rest
 *     of the significand as a fraction.  The exponent is represented by
 *     <tt>'p-1022'</tt>.  Note that there must be at least one nonzero digit
 *     in a subnormal significand.
 *
 *     </ul>
 *
 *     <p> If the <tt>'('</tt> or <tt>','</tt> flags are given, then a {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'A'</tt>
 *     <td valign="top"> <tt>'&#92;u0041'</tt>
 *     <td> The upper-case variant of <tt>'a'</tt>.  The entire string
 *     representing the number will be converted to upper case including the
 *     <tt>'x'</tt> (<tt>'&#92;u0078'</tt>) and <tt>'p'</tt>
 *     (<tt>'&#92;u0070'</tt> and all hexadecimal digits <tt>'a'</tt> -
 *     <tt>'f'</tt> (<tt>'&#92;u0061'</tt> - <tt>'&#92;u0066'</tt>).
 *
 * </table>
 *
 * <p> All <a href="#intFlags">flags</a> defined for Byte, Short, Integer, and
 * Long apply.
 *
 * <p> If the <tt>'#'</tt> flag is given, then the decimal separator will
 * always be present.
 *
 * <p> If no <a name="floatdFlags">flags</a> are given the default formatting
 * is as follows:
 *
 * <ul>
 *
 * <li> The output is right-justified within the <tt>width</tt>
 *
 * <li> Negative numbers begin with a <tt>'-'</tt>
 *
 * <li> Positive numbers and positive zero do not include a sign or extra
 * leading space
 *
 * <li> No grouping separators are included
 *
 * <li> The decimal separator will only appear if a digit follows it
 *
 * </ul>
 *
 * <p> The <a name="floatDWidth">width</a> is the minimum number of characters
 * to be written to the output.  This includes any signs, digits, grouping
 * separators, decimal separators, exponential symbol, radix indicator,
 * parentheses, and strings representing infinity and NaN as applicable.  If
 * the length of the converted value is less than the width then the output
 * will be padded by spaces (<tt>'&#92;u0020'</tt>) until the total number of
 * characters equals width.  The padding is on the left by default.  If the
 * <tt>'-'</tt> flag is given then the padding will be on the right.  If width
 * is not specified then there is no minimum.
 *
 * <p> If the <a name="floatDPrec">conversion</a> is <tt>'e'</tt>,
 * <tt>'E'</tt> or <tt>'f'</tt>, then the precision is the number of digits
 * after the decimal separator.  If the precision is not specified, then it is
 * assumed to be <tt>6</tt>.
 *
 * <p> If the conversion is <tt>'g'</tt> or <tt>'G'</tt>, then the precision is
 * the total number of significant digits in the resulting magnitude after
 * rounding.  If the precision is not specified, then the default value is
 * <tt>6</tt>.  If the precision is <tt>0</tt>, then it is taken to be
 * <tt>1</tt>.
 *
 * <p> If the conversion is <tt>'a'</tt> or <tt>'A'</tt>, then the precision
 * is the number of hexadecimal digits after the decimal separator.  If the
 * precision is not provided, then all of the digits as returned by {@link
 * Double#toHexString(double)} will be output.
 *
 * <p><a name="dndec"><b> BigDecimal </b></a>
 *
 * <p> The following conversions may be applied {@link java.math.BigDecimal
 * BigDecimal}.
 *
 * <table cellpadding=5 summary="floatConv">
 *
 * <tr><td valign="top"> <tt>'e'</tt>
 *     <td valign="top"> <tt>'&#92;u0065'</tt>
 *     <td> Requires the output to be formatted using <a
 *     name="scientific">computerized scientific notation</a>.  The <a
 *     href="#l10n algorithm">localization algorithm</a> is applied.
 *
 *     <p> The formatting of the magnitude <i>m</i> depends upon its value.
 *
 *     <p> If <i>m</i> is positive-zero or negative-zero, then the exponent
 *     will be <tt>"+00"</tt>.
 *
 *     <p> Otherwise, the result is a string that represents the sign and
 *     magnitude (absolute value) of the argument.  The formatting of the sign
 *     is described in the <a href="#l10n algorithm">localization
 *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
 *     value.
 *
 *     <p> Let <i>n</i> be the unique integer such that 10<sup><i>n</i></sup>
 *     &lt;= <i>m</i> &lt; 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
 *     mathematically exact quotient of <i>m</i> and 10<sup><i>n</i></sup> so
 *     that 1 &lt;= <i>a</i> &lt; 10. The magnitude is then represented as the
 *     integer part of <i>a</i>, as a single decimal digit, followed by the
 *     decimal separator followed by decimal digits representing the fractional
 *     part of <i>a</i>, followed by the exponent symbol <tt>'e'</tt>
 *     (<tt>'&#92;u0065'</tt>), followed by the sign of the exponent, followed
 *     by a representation of <i>n</i> as a decimal integer, as produced by the
 *     method {@link Long#toString(long, int)}, and zero-padded to include at
 *     least two digits.
 *
 *     <p> The number of digits in the result for the fractional part of
 *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
 *     specified then the default value is <tt>6</tt>.  If the precision is
 *     less than the number of digits which would appear after the decimal
 *     point in the string returned by {@link Float#toString(float)} or {@link
 *     Double#toString(double)} respectively, then the value will be rounded
 *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
 *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
 *     For a canonical representation of the value, use {@link
 *     BigDecimal#toString()}.
 *
 *     <p> If the <tt>','</tt> flag is given, then an {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'E'</tt>
 *     <td valign="top"> <tt>'&#92;u0045'</tt>
 *     <td> The upper-case variant of <tt>'e'</tt>.  The exponent symbol
 *     will be <tt>'E'</tt> (<tt>'&#92;u0045'</tt>).
 *
 * <tr><td valign="top"> <tt>'g'</tt>
 *     <td valign="top"> <tt>'&#92;u0067'</tt>
 *     <td> Requires the output to be formatted in general scientific notation
 *     as described below. The <a href="#l10n algorithm">localization
 *     algorithm</a> is applied.
 *
 *     <p> After rounding for the precision, the formatting of the resulting
 *     magnitude <i>m</i> depends on its value.
 *
 *     <p> If <i>m</i> is greater than or equal to 10<sup>-4</sup> but less
 *     than 10<sup>precision</sup> then it is represented in <i><a
 *     href="#decimal">decimal format</a></i>.
 *
 *     <p> If <i>m</i> is less than 10<sup>-4</sup> or greater than or equal to
 *     10<sup>precision</sup>, then it is represented in <i><a
 *     href="#scientific">computerized scientific notation</a></i>.
 *
 *     <p> The total number of significant digits in <i>m</i> is equal to the
 *     precision.  If the precision is not specified, then the default value is
 *     <tt>6</tt>.  If the precision is <tt>0</tt>, then it is taken to be
 *     <tt>1</tt>.
 *
 *     <p> If the <tt>'#'</tt> flag is given then an {@link
 *     FormatFlagsConversionMismatchException} will be thrown.
 *
 * <tr><td valign="top"> <tt>'G'</tt>
 *     <td valign="top"> <tt>'&#92;u0047'</tt>
 *     <td> The upper-case variant of <tt>'g'</tt>.
 *
 * <tr><td valign="top"> <tt>'f'</tt>
 *     <td valign="top"> <tt>'&#92;u0066'</tt>
 *     <td> Requires the output to be formatted using <a name="decimal">decimal
 *     format</a>.  The <a href="#l10n algorithm">localization algorithm</a> is
 *     applied.
 *
 *     <p> The result is a string that represents the sign and magnitude
 *     (absolute value) of the argument.  The formatting of the sign is
 *     described in the <a href="#l10n algorithm">localization
 *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
 *     value.
 *
 *     <p> The magnitude is formatted as the integer part of <i>m</i>, with no
 *     leading zeroes, followed by the decimal separator followed by one or
 *     more decimal digits representing the fractional part of <i>m</i>.
 *
 *     <p> The number of digits in the result for the fractional part of
 *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
 *     specified then the default value is <tt>6</tt>.  If the precision is
 *     less than the number of digits which would appear after the decimal
 *     point in the string returned by {@link Float#toString(float)} or {@link
 *     Double#toString(double)} respectively, then the value will be rounded
 *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
 *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
 *     For a canonical representation of the value, use {@link
 *     BigDecimal#toString()}.
 *
 * </table>
 *
 * <p> All <a href="#intFlags">flags</a> defined for Byte, Short, Integer, and
 * Long apply.
 *
 * <p> If the <tt>'#'</tt> flag is given, then the decimal separator will
 * always be present.
 *
 * <p> The <a href="#floatdFlags">default behavior</a> when no flags are
 * given is the same as for Float and Double.
 *
 * <p> The specification of <a href="#floatDWidth">width</a> and <a
 * href="#floatDPrec">precision</a> is the same as defined for Float and
 * Double.
 *
 * <h4><a name="ddt">Date/Time</a></h4>
 *
 * <p> This conversion may be applied to <tt>long</tt>, {@link Long}, {@link
 * Calendar}, and {@link Date}.
 *
 * <table cellpadding=5 summary="DTConv">
 *
 * <tr><td valign="top"> <tt>'t'</tt>
 *     <td valign="top"> <tt>'&#92;u0074'</tt>
 *     <td> Prefix for date and time conversion characters.
 * <tr><td valign="top"> <tt>'T'</tt>
 *     <td valign="top"> <tt>'&#92;u0054'</tt>
 *     <td> The upper-case variant of <tt>'t'</tt>.
 *
 * </table>
 *
 * <p> The following date and time conversion character suffixes are defined
 * for the <tt>'t'</tt> and <tt>'T'</tt> conversions.  The types are similar to
 * but not completely identical to those defined by GNU <tt>date</tt> and
 * POSIX <tt>strftime(3c)</tt>.  Additional conversion types are provided to
 * access Java-specific functionality (e.g. <tt>'L'</tt> for milliseconds
 * within the second).
 *
 * <p> The following conversion characters are used for formatting times:
 *
 * <table cellpadding=5 summary="time">
 *
 * <tr><td valign="top"> <tt>'H'</tt>
 *     <td valign="top"> <tt>'&#92;u0048'</tt>
 *     <td> Hour of the day for the 24-hour clock, formatted as two digits with
 *     a leading zero as necessary i.e. <tt>00 - 23</tt>. <tt>00</tt>
 *     corresponds to midnight.
 *
 * <tr><td valign="top"><tt>'I'</tt>
 *     <td valign="top"> <tt>'&#92;u0049'</tt>
 *     <td> Hour for the 12-hour clock, formatted as two digits with a leading
 *     zero as necessary, i.e.  <tt>01 - 12</tt>.  <tt>01</tt> corresponds to
 *     one o'clock (either morning or afternoon).
 *
 * <tr><td valign="top"><tt>'k'</tt>
 *     <td valign="top"> <tt>'&#92;u006b'</tt>
 *     <td> Hour of the day for the 24-hour clock, i.e. <tt>0 - 23</tt>.
 *     <tt>0</tt> corresponds to midnight.
 *
 * <tr><td valign="top"><tt>'l'</tt>
 *     <td valign="top"> <tt>'&#92;u006c'</tt>
 *     <td> Hour for the 12-hour clock, i.e. <tt>1 - 12</tt>.  <tt>1</tt>
 *     corresponds to one o'clock (either morning or afternoon).
 *
 * <tr><td valign="top"><tt>'M'</tt>
 *     <td valign="top"> <tt>'&#92;u004d'</tt>
 *     <td> Minute within the hour formatted as two digits with a leading zero
 *     as necessary, i.e.  <tt>00 - 59</tt>.
 *
 * <tr><td valign="top"><tt>'S'</tt>
 *     <td valign="top"> <tt>'&#92;u0053'</tt>
 *     <td> Seconds within the minute, formatted as two digits with a leading
 *     zero as necessary, i.e. <tt>00 - 60</tt> ("<tt>60</tt>" is a special
 *     value required to support leap seconds).
 *
 * <tr><td valign="top"><tt>'L'</tt>
 *     <td valign="top"> <tt>'&#92;u004c'</tt>
 *     <td> Millisecond within the second formatted as three digits with
 *     leading zeros as necessary, i.e. <tt>000 - 999</tt>.
 *
 * <tr><td valign="top"><tt>'N'</tt>
 *     <td valign="top"> <tt>'&#92;u004e'</tt>
 *     <td> Nanosecond within the second, formatted as nine digits with leading
 *     zeros as necessary, i.e. <tt>000000000 - 999999999</tt>.  The precision
 *     of this value is limited by the resolution of the underlying operating
 *     system or hardware.
 *
 * <tr><td valign="top"><tt>'p'</tt>
 *     <td valign="top"> <tt>'&#92;u0070'</tt>
 *     <td> Locale-specific {@linkplain
 *     java.text.DateFormatSymbols#getAmPmStrings morning or afternoon} marker
 *     in lower case, e.g."<tt>am</tt>" or "<tt>pm</tt>".  Use of the
 *     conversion prefix <tt>'T'</tt> forces this output to upper case.  (Note
 *     that <tt>'p'</tt> produces lower-case output.  This is different from
 *     GNU <tt>date</tt> and POSIX <tt>strftime(3c)</tt> which produce
 *     upper-case output.)
 *
 * <tr><td valign="top"><tt>'z'</tt>
 *     <td valign="top"> <tt>'&#92;u007a'</tt>
 *     <td> <a href="http://www.ietf.org/rfc/rfc0822.txt">RFC&nbsp;822</a>
 *     style numeric time zone offset from GMT, e.g. <tt>-0800</tt>.
 *
 * <tr><td valign="top"><tt>'Z'</tt>
 *     <td valign="top"> <tt>'&#92;u005a'</tt>
 *     <td> A string representing the abbreviation for the time zone.
 *
 * <tr><td valign="top"><tt>'s'</tt>
 *     <td valign="top"> <tt>'&#92;u0073'</tt>
 *     <td> Seconds since the beginning of the epoch starting at 1 January 1970
 *     <tt>00:00:00</tt> UTC, i.e. <tt>Long.MIN_VALUE/1000</tt> to
 *     <tt>Long.MAX_VALUE/1000</tt>.
 *
 * <tr><td valign="top"><tt>'Q'</tt>
 *     <td valign="top"> <tt>'&#92;u004f'</tt>
 *     <td> Milliseconds since the beginning of the epoch starting at 1 January
 *     1970 <tt>00:00:00</tt> UTC, i.e. <tt>Long.MIN_VALUE</tt> to
 *     <tt>Long.MAX_VALUE</tt>. The precision of this value is limited by
 *     the resolution of the underlying operating system or hardware.
 *
 * </table>
 *
 * <p> The following conversion characters are used for formatting dates:
 *
 * <table cellpadding=5 summary="date">
 *
 * <tr><td valign="top"><tt>'B'</tt>
 *     <td valign="top"> <tt>'&#92;u0042'</tt>
 *     <td> Locale-specific {@linkplain java.text.DateFormatSymbols#getMonths
 *     full month name}, e.g. <tt>"January"</tt>, <tt>"February"</tt>.
 *
 * <tr><td valign="top"><tt>'b'</tt>
 *     <td valign="top"> <tt>'&#92;u0062'</tt>
 *     <td> Locale-specific {@linkplain
 *     java.text.DateFormatSymbols#getShortMonths abbreviated month name},
 *     e.g. <tt>"Jan"</tt>, <tt>"Feb"</tt>.
 *
 * <tr><td valign="top"><tt>'h'</tt>
 *     <td valign="top"> <tt>'&#92;u0068'</tt>
 *     <td> Same as <tt>'b'</tt>.
 *
 * <tr><td valign="top"><tt>'A'</tt>
 *     <td valign="top"> <tt>'&#92;u0041'</tt>
 *     <td> Locale-specific full name of the {@linkplain
 *     java.text.DateFormatSymbols#getWeekdays day of the week},
 *     e.g. <tt>"Sunday"</tt>, <tt>"Monday"</tt>
 *
 * <tr><td valign="top"><tt>'a'</tt>
 *     <td valign="top"> <tt>'&#92;u0061'</tt>
 *     <td> Locale-specific short name of the {@linkplain
 *     java.text.DateFormatSymbols#getShortWeekdays day of the week},
 *     e.g. <tt>"Sun"</tt>, <tt>"Mon"</tt>
 *
 * <tr><td valign="top"><tt>'C'</tt>
 *     <td valign="top"> <tt>'&#92;u0043'</tt>
 *     <td> Four-digit year divided by <tt>100</tt>, formatted as two digits
 *     with leading zero as necessary, i.e. <tt>00 - 99</tt>
 *
 * <tr><td valign="top"><tt>'Y'</tt>
 *     <td valign="top"> <tt>'&#92;u0059'</tt> <td> Year, formatted to at least
 *     four digits with leading zeros as necessary, e.g. <tt>0092</tt> equals
 *     <tt>92</tt> CE for the Gregorian calendar.
 *
 * <tr><td valign="top"><tt>'y'</tt>
 *     <td valign="top"> <tt>'&#92;u0079'</tt>
 *     <td> Last two digits of the year, formatted with leading zeros as
 *     necessary, i.e. <tt>00 - 99</tt>.
 *
 * <tr><td valign="top"><tt>'j'</tt>
 *     <td valign="top"> <tt>'&#92;u006a'</tt>
 *     <td> Day of year, formatted as three digits with leading zeros as
 *     necessary, e.g. <tt>001 - 366</tt> for the Gregorian calendar.
 *     <tt>001</tt> corresponds to the first day of the year.
 *
 * <tr><td valign="top"><tt>'m'</tt>
 *     <td valign="top"> <tt>'&#92;u006d'</tt>
 *     <td> Month, formatted as two digits with leading zeros as necessary,
 *     i.e. <tt>01 - 13</tt>, where "<tt>01</tt>" is the first month of the
 *     year and ("<tt>13</tt>" is a special value required to support lunar
 *     calendars).
 *
 * <tr><td valign="top"><tt>'d'</tt>
 *     <td valign="top"> <tt>'&#92;u0064'</tt>
 *     <td> Day of month, formatted as two digits with leading zeros as
 *     necessary, i.e. <tt>01 - 31</tt>, where "<tt>01</tt>" is the first day
 *     of the month.
 *
 * <tr><td valign="top"><tt>'e'</tt>
 *     <td valign="top"> <tt>'&#92;u0065'</tt>
 *     <td> Day of month, formatted as two digits, i.e. <tt>1 - 31</tt> where
 *     "<tt>1</tt>" is the first day of the month.
 *
 * </table>
 *
 * <p> The following conversion characters are used for formatting common
 * date/time compositions.
 *
 * <table cellpadding=5 summary="composites">
 *
 * <tr><td valign="top"><tt>'R'</tt>
 *     <td valign="top"> <tt>'&#92;u0052'</tt>
 *     <td> Time formatted for the 24-hour clock as <tt>"%tH:%tM"</tt>
 *
 * <tr><td valign="top"><tt>'T'</tt>
 *     <td valign="top"> <tt>'&#92;u0054'</tt>
 *     <td> Time formatted for the 24-hour clock as <tt>"%tH:%tM:%tS"</tt>.
 *
 * <tr><td valign="top"><tt>'r'</tt>
 *     <td valign="top"> <tt>'&#92;u0072'</tt>
 *     <td> Time formatted for the 12-hour clock as <tt>"%tI:%tM:%tS
 *     %Tp"</tt>.  The location of the morning or afternoon marker
 *     (<tt>'%Tp'</tt>) may be locale-dependent.
 *
 * <tr><td valign="top"><tt>'D'</tt>
 *     <td valign="top"> <tt>'&#92;u0044'</tt>
 *     <td> Date formatted as <tt>"%tm/%td/%ty"</tt>.
 *
 * <tr><td valign="top"><tt>'F'</tt>
 *     <td valign="top"> <tt>'&#92;u0046'</tt>
 *     <td> <a href="http://www.w3.org/TR/NOTE-datetime">ISO&nbsp;8601</a>
 *     complete date formatted as <tt>"%tY-%tm-%td"</tt>.
 *
 * <tr><td valign="top"><tt>'c'</tt>
 *     <td valign="top"> <tt>'&#92;u0063'</tt>
 *     <td> Date and time formatted as <tt>"%ta %tb %td %tT %tZ %tY"</tt>,
 *     e.g. <tt>"Sun Jul 20 16:17:00 EDT 1969"</tt>.
 *
 * </table>
 *
 * <p> The <tt>'-'</tt> flag defined for <a href="#dFlags">General
 * conversions</a> applies.  If the <tt>'#'</tt> flag is given, then a {@link
 * FormatFlagsConversionMismatchException} will be thrown.
 *
 * <p> The <a name="dtWidth">width</a> is the minimum number of characters to
 * be written to the output.  If the length of the converted value is less than
 * the <tt>width</tt> then the output will be padded by spaces
 * (<tt>'&#92;u0020'</tt>) until the total number of characters equals width.
 * The padding is on the left by default.  If the <tt>'-'</tt> flag is given
 * then the padding will be on the right.  If width is not specified then there
 * is no minimum.
 *
 * <p> The precision is not applicable.  If the precision is specified then an
 * {@link IllegalFormatPrecisionException} will be thrown.
 *
 * <h4><a name="dper">Percent</a></h4>
 *
 * <p> The conversion does not correspond to any argument.
 *
 * <table cellpadding=5 summary="DTConv">
 *
 * <tr><td valign="top"><tt>'%'</tt>
 *     <td> The result is a literal <tt>'%'</tt> (<tt>'&#92;u0025'</tt>)
 *
 * <p> The <a name="dtWidth">width</a> is the minimum number of characters to
 * be written to the output including the <tt>'%'</tt>.  If the length of the
 * converted value is less than the <tt>width</tt> then the output will be
 * padded by spaces (<tt>'&#92;u0020'</tt>) until the total number of
 * characters equals width.  The padding is on the left.  If width is not
 * specified then just the <tt>'%'</tt> is output.
 *
 * <p> The <tt>'-'</tt> flag defined for <a href="#dFlags">General
 * conversions</a> applies.  If any other flags are provided, then a
 * {@link FormatFlagsConversionMismatchException} will be thrown.
 *
 * <p> The precision is not applicable.  If the precision is specified an
 * {@link IllegalFormatPrecisionException} will be thrown.
 *
 * </table>
 *
 * <h4><a name="dls">Line Separator</a></h4>
 *
 * <p> The conversion does not correspond to any argument.
 *
 * <table cellpadding=5 summary="DTConv">
 *
 * <tr><td valign="top"><tt>'n'</tt>
 *     <td> the platform-specific line separator as returned by {@link
 *     System#getProperty System.getProperty("line.separator")}.
 *
 * </table>
 *
 * <p> Flags, width, and precision are not applicable.  If any are provided an
 * {@link IllegalFormatFlagsException}, {@link IllegalFormatWidthException},
 * and {@link IllegalFormatPrecisionException}, respectively will be thrown.
 *
 * <h4><a name="dpos">Argument Index</a></h4>
 *
 * <p> Format specifiers can reference arguments in three ways:
 *
 * <ul>
 *
 * <li> <i>Explicit indexing</i> is used when the format specifier contains an
 * argument index.  The argument index is a decimal integer indicating the
 * position of the argument in the argument list.  The first argument is
 * referenced by "<tt>1$</tt>", the second by "<tt>2$</tt>", etc.  An argument
 * may be referenced more than once.
 *
 * <p> For example:
 *
 * <blockquote><pre>
 *   formatter.format("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s",
 *                    "a", "b", "c", "d")
 *   // -&gt; "d c b a d c b a"
 * </pre></blockquote>
 *
 * <li> <i>Relative indexing</i> is used when the format specifier contains a
 * <tt>'&lt;'</tt> (<tt>'&#92;u003c'</tt>) flag which causes the argument for
 * the previous format specifier to be re-used.  If there is no previous
 * argument, then a {@link MissingFormatArgumentException} is thrown.
 *
 * <blockquote><pre>
 *    formatter.format("%s %s %&lt;s %&lt;s", "a", "b", "c", "d")
 *    // -&gt; "a b b b"
 *    // "c" and "d" are ignored because they are not referenced
 * </pre></blockquote>
 *
 * <li> <i>Ordinary indexing</i> is used when the format specifier contains
 * neither an argument index nor a <tt>'&lt;'</tt> flag.  Each format specifier
 * which uses ordinary indexing is assigned a sequential implicit index into
 * argument list which is independent of the indices used by explicit or
 * relative indexing.
 *
 * <blockquote><pre>
 *   formatter.format("%s %s %s %s", "a", "b", "c", "d")
 *   // -&gt; "a b c d"
 * </pre></blockquote>
 *
 * </ul>
 *
 * <p> It is possible to have a format string which uses all forms of indexing,
 * for example:
 *
 * <blockquote><pre>
 *   formatter.format("%2$s %s %&lt;s %s", "a", "b", "c", "d")
 *   // -&gt; "b a a b"
 *   // "c" and "d" are ignored because they are not referenced
 * </pre></blockquote>
 *
 * <p> The maximum number of arguments is limited by the maximum dimension of a
 * Java array as defined by the <a
 * href="http://java.sun.com/docs/books/vmspec/">Java Virtual Machine
 * Specification</a>.  If the argument index is does not correspond to an
 * available argument, then a {@link MissingFormatArgumentException} is thrown.
 *
 * <p> If there are more arguments than format specifiers, the extra arguments
 * are ignored.
 *
 * <p> Unless otherwise specified, passing a <tt>null</tt> argument to any
 * method or constructor in this class will cause a {@link
 * NullPointerException} to be thrown.
 *
 * @author  Iris Clark
 * @version 	1.26, 06/28/06
 * @since 1.5
 */
public final class Formatter implements Closeable, Flushable {
    private Appendable a;
    private Locale l;

    private IOException lastException;

    private char zero = '0';
    private static double scaleUp;

    // 1 (sign) + 19 (max # sig digits) + 1 ('.') + 1 ('e') + 1 (sign)
    // + 3 (max # exp digits) + 4 (error) = 30
    private static final int MAX_FD_CHARS = 30;

    // Initialize internal data.
    private void init(Appendable a, Locale l) {
	this.a = a;
	this.l = l;
	setZero();
    }

    /**
     * Constructs a new formatter.
     *
     * <p> The destination of the formatted output is a {@link StringBuilder}
     * which may be retrieved by invoking {@link #out out()} and whose
     * current content may be converted into a string by invoking {@link
     * #toString toString()}.  The locale used is the {@linkplain
     * Locale#getDefault() default locale} for this instance of the Java
     * virtual machine.
     */
    public Formatter() {
	init(new StringBuilder(), Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified destination.
     *
     * <p> The locale used is the {@linkplain Locale#getDefault() default
     * locale} for this instance of the Java virtual machine.
     *
     * @param  a
     *         Destination for the formatted output.  If <tt>a</tt> is
     *         <tt>null</tt> then a {@link StringBuilder} will be created.
     */
    public Formatter(Appendable a) {
	if (a == null)
	    a = new StringBuilder();
	init(a, Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified locale.
     *
     * <p> The destination of the formatted output is a {@link StringBuilder}
     * which may be retrieved by invoking {@link #out out()} and whose current
     * content may be converted into a string by invoking {@link #toString
     * toString()}.
     *
     * @param  l
     *         The {@linkplain java.util.Locale locale} to apply during
     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
     *         is applied.
     */
    public Formatter(Locale l) {
	init(new StringBuilder(), l);
    }

    /**
     * Constructs a new formatter with the specified destination and locale.
     *
     * @param  a
     *         Destination for the formatted output.  If <tt>a</tt> is
     *         <tt>null</tt> then a {@link StringBuilder} will be created.
     *
     * @param  l
     *         The {@linkplain java.util.Locale locale} to apply during
     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
     *         is applied.
     */
    public Formatter(Appendable a, Locale l) {
	if (a == null)
	    a = new StringBuilder();
	init(a, l);
    }

    /**
     * Constructs a new formatter with the specified file name.
     *
     * <p> The charset used is the {@linkplain
     * java.nio.charset.Charset#defaultCharset() default charset} for this
     * instance of the Java virtual machine.
     *
     * <p> The locale used is the {@linkplain Locale#getDefault() default
     * locale} for this instance of the Java virtual machine.
     *
     * @param  fileName
     *         The name of the file to use as the destination of this
     *         formatter.  If the file exists then it will be truncated to
     *         zero size; otherwise, a new file will be created.  The output
     *         will be written to the file and is buffered.
     *
     * @throws  SecurityException
     *          If a security manager is present and {@link
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
     *          access to the file
     *
     * @throws  FileNotFoundException
     *          If the given file name does not denote an existing, writable
     *          regular file and a new regular file of that name cannot be
     *          created, or if some other error occurs while opening or
     *          creating the file
     */
    public Formatter(String fileName) throws FileNotFoundException {
	init(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))),
	     Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified file name and charset.
     *
     * <p> The locale used is the {@linkplain Locale#getDefault default
     * locale} for this instance of the Java virtual machine.
     *
     * @param  fileName
     *         The name of the file to use as the destination of this
     *         formatter.  If the file exists then it will be truncated to
     *         zero size; otherwise, a new file will be created.  The output
     *         will be written to the file and is buffered.
     *
     * @param  csn
     *         The name of a supported {@linkplain java.nio.charset.Charset
     *         charset}
     *
     * @throws  FileNotFoundException
     *          If the given file name does not denote an existing, writable
     *          regular file and a new regular file of that name cannot be
     *          created, or if some other error occurs while opening or
     *          creating the file
     *
     * @throws  SecurityException
     *          If a security manager is present and {@link
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
     *          access to the file
     *
     * @throws  UnsupportedEncodingException
     *          If the named charset is not supported
     */
    public Formatter(String fileName, String csn)
	throws FileNotFoundException, UnsupportedEncodingException
    {
	this(fileName, csn, Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified file name, charset, and
     * locale.
     *
     * @param  fileName
     *         The name of the file to use as the destination of this
     *         formatter.  If the file exists then it will be truncated to
     *         zero size; otherwise, a new file will be created.  The output
     *         will be written to the file and is buffered.
     *
     * @param  csn
     *         The name of a supported {@linkplain java.nio.charset.Charset
     *         charset}
     *
     * @param  l
     *         The {@linkplain java.util.Locale locale} to apply during
     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
     *         is applied.
     *
     * @throws  FileNotFoundException
     *          If the given file name does not denote an existing, writable
     *          regular file and a new regular file of that name cannot be
     *          created, or if some other error occurs while opening or
     *          creating the file
     *
     * @throws  SecurityException
     *          If a security manager is present and {@link
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
     *          access to the file
     *
     * @throws  UnsupportedEncodingException
     *          If the named charset is not supported
     */
    public Formatter(String fileName, String csn, Locale l)
	throws FileNotFoundException, UnsupportedEncodingException
    {
	init(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), csn)),
	     l);
    }

    /**
     * Constructs a new formatter with the specified file.
     *
     * <p> The charset used is the {@linkplain
     * java.nio.charset.Charset#defaultCharset() default charset} for this
     * instance of the Java virtual machine.
     *
     * <p> The locale used is the {@linkplain Locale#getDefault() default
     * locale} for this instance of the Java virtual machine.
     *
     * @param  file
     *         The file to use as the destination of this formatter.  If the
     *         file exists then it will be truncated to zero size; otherwise,
     *         a new file will be created.  The output will be written to the
     *         file and is buffered.
     *
     * @throws  SecurityException
     *          If a security manager is present and {@link
     *          SecurityManager#checkWrite checkWrite(file.getPath())} denies
     *          write access to the file
     *
     * @throws  FileNotFoundException
     *          If the given file object does not denote an existing, writable
     *          regular file and a new regular file of that name cannot be
     *          created, or if some other error occurs while opening or
     *          creating the file
     */
    public Formatter(File file) throws FileNotFoundException {
	init(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))),
	     Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified file and charset.
     *
     * <p> The locale used is the {@linkplain Locale#getDefault default
     * locale} for this instance of the Java virtual machine.
     *
     * @param  file
     *         The file to use as the destination of this formatter.  If the
     *         file exists then it will be truncated to zero size; otherwise,
     *         a new file will be created.  The output will be written to the
     *         file and is buffered.
     *
     * @param  csn
     *         The name of a supported {@linkplain java.nio.charset.Charset
     *         charset}
     *
     * @throws  FileNotFoundException
     *          If the given file object does not denote an existing, writable
     *          regular file and a new regular file of that name cannot be
     *          created, or if some other error occurs while opening or
     *          creating the file
     *
     * @throws  SecurityException
     *          If a security manager is present and {@link
     *          SecurityManager#checkWrite checkWrite(file.getPath())} denies
     *          write access to the file
     *
     * @throws  UnsupportedEncodingException
     *          If the named charset is not supported
     */
    public Formatter(File file, String csn)
	throws FileNotFoundException, UnsupportedEncodingException
    {
	this(file, csn, Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified file, charset, and
     * locale.
     *
     * @param  file
     *         The file to use as the destination of this formatter.  If the
     *         file exists then it will be truncated to zero size; otherwise,
     *         a new file will be created.  The output will be written to the
     *         file and is buffered.
     *
     * @param  csn
     *         The name of a supported {@linkplain java.nio.charset.Charset
     *         charset}
     *
     * @param  l
     *         The {@linkplain java.util.Locale locale} to apply during
     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
     *         is applied.
     *
     * @throws  FileNotFoundException
     *          If the given file object does not denote an existing, writable
     *          regular file and a new regular file of that name cannot be
     *          created, or if some other error occurs while opening or
     *          creating the file
     *
     * @throws  SecurityException
     *          If a security manager is present and {@link
     *          SecurityManager#checkWrite checkWrite(file.getPath())} denies
     *          write access to the file
     *
     * @throws  UnsupportedEncodingException
     *          If the named charset is not supported
     */
    public Formatter(File file, String csn, Locale l)
	throws FileNotFoundException, UnsupportedEncodingException
    {
	init(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), csn)),
	     l);
    }

    /**
     * Constructs a new formatter with the specified print stream.
     *
     * <p> The locale used is the {@linkplain Locale#getDefault() default
     * locale} for this instance of the Java virtual machine.
     *
     * <p> Characters are written to the given {@link java.io.PrintStream
     * PrintStream} object and are therefore encoded using that object's
     * charset.
     *
     * @param  ps
     *         The stream to use as the destination of this formatter.
     */
    public Formatter(PrintStream ps) {
	if (ps == null)
	    throw new NullPointerException();
	init((Appendable)ps, Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified output stream.
     *
     * <p> The charset used is the {@linkplain
     * java.nio.charset.Charset#defaultCharset() default charset} for this
     * instance of the Java virtual machine.
     *
     * <p> The locale used is the {@linkplain Locale#getDefault() default
     * locale} for this instance of the Java virtual machine.
     *
     * @param  os
     *         The output stream to use as the destination of this formatter.
     *         The output will be buffered.
     */
    public Formatter(OutputStream os) {
	init(new BufferedWriter(new OutputStreamWriter(os)),
	     Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified output stream and
     * charset.
     *
     * <p> The locale used is the {@linkplain Locale#getDefault default
     * locale} for this instance of the Java virtual machine.
     *
     * @param  os
     *         The output stream to use as the destination of this formatter.
     *         The output will be buffered.
     *
     * @param  csn
     *         The name of a supported {@linkplain java.nio.charset.Charset
     *         charset}
     *
     * @throws  UnsupportedEncodingException
     *          If the named charset is not supported
     */
    public Formatter(OutputStream os, String csn)
	throws UnsupportedEncodingException
    {
	this(os, csn, Locale.getDefault());
    }

    /**
     * Constructs a new formatter with the specified output stream, charset,
     * and locale.
     *
     * @param  os
     *         The output stream to use as the destination of this formatter.
     *         The output will be buffered.
     *
     * @param  csn
     *         The name of a supported {@linkplain java.nio.charset.Charset
     *         charset}
     *
     * @param  l
     *         The {@linkplain java.util.Locale locale} to apply during
     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
     *         is applied.
     *
     * @throws  UnsupportedEncodingException
     *          If the named charset is not supported
     */
    public Formatter(OutputStream os, String csn, Locale l)
	throws UnsupportedEncodingException
    {
	init(new BufferedWriter(new OutputStreamWriter(os, csn)), l);
    }

    private void setZero() {
	if ((l != null) && !l.equals(Locale.US)) {
	    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
	    zero = dfs.getZeroDigit();
	}
    }

    /**
     * Returns the locale set by the construction of this formatter.
     *
     * <p> The {@link #format(java.util.Locale,String,Object...) format} method
     * for this object which has a locale argument does not change this value.
     *
     * @return  <tt>null</tt> if no localization is applied, otherwise a
     *          locale
     *
     * @throws  FormatterClosedException
     *          If this formatter has been closed by invoking its {@link
     *          #close()} method
     */
    public Locale locale() {
	ensureOpen();
	return l;
    }

    /**
     * Returns the destination for the output.
     *
     * @return  The destination for the output
     *
     * @throws  FormatterClosedException
     *          If this formatter has been closed by invoking its {@link
     *          #close()} method
     */
    public Appendable out() {
	ensureOpen();
	return a;
    }

    /**
     * Returns the result of invoking <tt>toString()</tt> on the destination
     * for the output.  For example, the following code formats text into a
     * {@link StringBuilder} then retrieves the resultant string:
     *
     * <blockquote><pre>
     *   Formatter f = new Formatter();
     *   f.format("Last reboot at %tc", lastRebootDate);
     *   String s = f.toString();
     *   // -&gt; s == "Last reboot at Sat Jan 01 00:00:00 PST 2000"
     * </pre></blockquote>
     *
     * <p> An invocation of this method behaves in exactly the same way as the
     * invocation
     *
     * <pre>
     *     out().toString() </pre>
     *
     * <p> Depending on the specification of <tt>toString</tt> for the {@link
     * Appendable}, the returned string may or may not contain the characters
     * written to the destination.  For instance, buffers typically return
     * their contents in <tt>toString()</tt>, but streams cannot since the
     * data is discarded.
     *
     * @return  The result of invoking <tt>toString()</tt> on the destination
     *          for the output
     *
     * @throws  FormatterClosedException
     *          If this formatter has been closed by invoking its {@link
     *          #close()} method
     */
    public String toString() {
	ensureOpen();
	return a.toString();
    }

    /**
     * Flushes this formatter.  If the destination implements the {@link
     * java.io.Flushable} interface, its <tt>flush</tt> method will be invoked.
     *
     * <p> Flushing a formatter writes any buffered output in the destination
     * to the underlying stream.
     *
     * @throws  FormatterClosedException
     *          If this formatter has been closed by invoking its {@link
     *          #close()} method
     */
    public void flush() {
	ensureOpen();
	if (a instanceof Flushable) {
	    try {
                ((Flushable)a).flush();
            } catch (IOException ioe) {
                lastException = ioe;
            }
        }
    }

    /**
     * Closes this formatter.  If the destination implements the {@link
     * java.io.Closeable} interface, its <tt>close</tt> method will be invoked.
     *
     * <p> Closing a formatter allows it to release resources it may be holding
     * (such as open files).  If the formatter is already closed, then invoking
     * this method has no effect.
     *
     * <p> Attempting to invoke any methods except {@link #ioException()} in
     * this formatter after it has been closed will result in a {@link
     * FormatterClosedException}.
     */
    public void close() {
	if (a == null)
	    return;
	try {
	    if (a instanceof Closeable)
                ((Closeable)a).close();
	} catch (IOException ioe) {
	    lastException = ioe;
	} finally {
	    a = null;
        }
    }

    private void ensureOpen() {
	if (a == null)
	    throw new FormatterClosedException();
    }

    /**
     * Returns the <tt>IOException</tt> last thrown by this formatter's {@link
     * Appendable}.
     *
     * <p> If the destination's <tt>append()</tt> method never throws
     * <tt>IOException</tt>, then this method will always return <tt>null</tt>.
     *
     * @return  The last exception thrown by the Appendable or <tt>null</tt> if
     *          no such exception exists.
     */
    public IOException ioException() {
        return lastException;
    }

    /**
     * Writes a formatted string to this object's destination using the
     * specified format string and arguments.  The locale used is the one
     * defined during the construction of this formatter.
     *
     * @param  format
     *         A format string as described in <a href="#syntax">Format string
     *         syntax</a>.
     *
     * @param  args
     *         Arguments referenced by the format specifiers in the format
     *         string.  If there are more arguments than format specifiers, the
     *         extra arguments are ignored.  The maximum number of arguments is
     *         limited by the maximum dimension of a Java array as defined by
     *         the <a href="http://java.sun.com/docs/books/vmspec/">Java
     *         Virtual Machine Specification</a>.
     *
     * @throws  IllegalFormatException
     *          If a format string contains an illegal syntax, a format
     *          specifier that is incompatible with the given arguments,
     *          insufficient arguments given the format string, or other
     *          illegal conditions.  For specification of all possible
     *          formatting errors, see the <a href="#detail">Details</a>
     *          section of the formatter class specification.
     *
     * @throws  FormatterClosedException
     *          If this formatter has been closed by invoking its {@link
     *          #close()} method
     *
     * @return  This formatter
     */
    public Formatter format(String format, Object ... args) {
	return format(l, format, args);
    }

    /**
     * Writes a formatted string to this object's destination using the
     * specified locale, format string, and arguments.
     *
     * @param  l
     *         The {@linkplain java.util.Locale locale} to apply during
     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
     *         is applied.  This does not change this object's locale that was
     *         set during construction.
     *
     * @param  format
     *         A format string as described in <a href="#syntax">Format string
     *         syntax</a>
     *
     * @param  args
     *         Arguments referenced by the format specifiers in the format
     *         string.  If there are more arguments than format specifiers, the
     *         extra arguments are ignored.  The maximum number of arguments is
     *         limited by the maximum dimension of a Java array as defined by
     *         the <a href="http://java.sun.com/docs/books/vmspec/">Java
     *         Virtual Machine Specification</a>
     *
     * @throws  IllegalFormatException
     *          If a format string contains an illegal syntax, a format
     *          specifier that is incompatible with the given arguments,
     *          insufficient arguments given the format string, or other
     *          illegal conditions.  For specification of all possible
     *          formatting errors, see the <a href="#detail">Details</a>
     *          section of the formatter class specification.
     *
     * @throws  FormatterClosedException
     *          If this formatter has been closed by invoking its {@link
     *          #close()} method
     *
     * @return  This formatter
     */
    public Formatter format(Locale l, String format, Object ... args) {
	ensureOpen();

	// index of last argument referenced
	int last = -1;
	// last ordinary index
	int lasto = -1;

	FormatString[] fsa = parse(format);
	for (int i = 0; i < fsa.length; i++) {
	    FormatString fs = fsa[i];
	    int index = fs.index();
	    try {
		switch (index) {
		case -2:  // fixed string, "%n", or "%%"
		    fs.print(null, l);
		    break;
		case -1:  // relative index
		    if (last < 0 || (args != null && last > args.length - 1))
			throw new MissingFormatArgumentException(fs.toString());
		    fs.print((args == null ? null : args[last]), l);
		    break;
		case 0:  // ordinary index
		    lasto++;
 		    last = lasto;
		    if (args != null && lasto > args.length - 1)
			throw new MissingFormatArgumentException(fs.toString());
 		    fs.print((args == null ? null : args[lasto]), l);
		    break;
		default:  // explicit index
		    last = index - 1;
		    if (args != null && last > args.length - 1)
			throw new MissingFormatArgumentException(fs.toString());
 		    fs.print((args == null ? null : args[last]), l);
		    break;
		}
	    } catch (IOException x) {
		lastException = x;
	    }
	}
	return this;
    }

    // %[argument_index$][flags][width][.precision][t]conversion
    private static final String formatSpecifier
	= "%(\\d+\\$)?([-#+ 0,(\\<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])";

    private static Pattern fsPattern = Pattern.compile(formatSpecifier);

    // Look for format specifiers in the format string.
    private FormatString[] parse(String s) {
	ArrayList al = new ArrayList();
	Matcher m = fsPattern.matcher(s);
	int i = 0;
	while (i < s.length()) {
	    if (m.find(i)) {
		// Anything between the start of the string and the beginning
		// of the format specifier is either fixed text or contains
		// an invalid format string.
		if (m.start() != i) {
		    // Make sure we didn't miss any invalid format specifiers
		    checkText(s.substring(i, m.start()));
		    // Assume previous characters were fixed text
		    al.add(new FixedString(s.substring(i, m.start())));
		}

		// Expect 6 groups in regular expression
		String[] sa = new String[6];
		for (int j = 0; j < m.groupCount(); j++)
		    {
		    sa[j] = m.group(j + 1);
// 		    System.out.print(sa[j] + " ");
		    }
// 		System.out.println();
		al.add(new FormatSpecifier(this, sa));
		i = m.end();
	    } else {
		// No more valid format specifiers.  Check for possible invalid
		// format specifiers.
		checkText(s.substring(i));
		// The rest of the string is fixed text
		al.add(new FixedString(s.substring(i)));
		break;
	    }
	}
//   	FormatString[] fs = new FormatString[al.size()];
//   	for (int j = 0; j < al.size(); j++)
//   	    System.out.println(((FormatString) al.get(j)).toString());
 	return (FormatString[]) al.toArray(new FormatString[0]);
    }

    private void checkText(String s) {
	int idx;
	// If there are any '%' in the given string, we got a bad format
	// specifier.
	if ((idx = s.indexOf('%')) != -1) {
	    char c = (idx > s.length() - 2 ? '%' : s.charAt(idx + 1));
	    throw new UnknownFormatConversionException(String.valueOf(c));
	}
    }

    private interface FormatString {
	int index();
	void print(Object arg, Locale l) throws IOException;
	String toString();
    }

    private class FixedString implements FormatString {
	private String s;
	FixedString(String s) { this.s = s; }
	public int index() { return -2; }
 	public void print(Object arg, Locale l)
	    throws IOException { a.append(s); }
	public String toString() { return s; }
    }

    public enum BigDecimalLayoutForm { SCIENTIFIC, DECIMAL_FLOAT };

    private class FormatSpecifier implements FormatString {
	private int index = -1;
	private Flags f = Flags.NONE;
	private int width;
	private int precision;
	private boolean dt = false;
	private char c;

	private Formatter formatter;

	// cache the line separator
	private String ls;

	private int index(String s) {
	    if (s != null) {
		try {
		    index = Integer.parseInt(s.substring(0, s.length() - 1));
		} catch (NumberFormatException x) {
		    assert(false);
		}
	    } else {
		index = 0;
	    }
	    return index;
	}

	public int index() {
	    return index;
	}

	private Flags flags(String s) {
	    f = Flags.parse(s);
	    if (f.contains(Flags.PREVIOUS))
		index = -1;
	    return f;
	}

	Flags flags() {
	    return f;
	}

	private int width(String s) {
	    width = -1;
	    if (s != null) {
		try {
		    width  = Integer.parseInt(s);
		    if (width < 0)
			throw new IllegalFormatWidthException(width);
		} catch (NumberFormatException x) {
		    assert(false);
		}
	    }
	    return width;
	}

	int width() {
	    return width;
	}

	private int precision(String s) {
	    precision = -1;
	    if (s != null) {
		try {
		    // remove the '.'
		    precision = Integer.parseInt(s.substring(1));
		    if (precision < 0)
			throw new IllegalFormatPrecisionException(precision);
		} catch (NumberFormatException x) {
		    assert(false);
		}
	    }
	    return precision;
	}

	int precision() {
	    return precision;
	}

	private char conversion(String s) {
	    c = s.charAt(0);
	    if (!dt) {
		if (!Conversion.isValid(c))
		    throw new UnknownFormatConversionException(String.valueOf(c));
		if (Character.isUpperCase(c))
		    f.add(Flags.UPPERCASE);
		c = Character.toLowerCase(c);
		if (Conversion.isText(c))
		    index = -2;
	    }
	    return c;
	}

	private char conversion() {
	    return c;
	}

	FormatSpecifier(Formatter formatter, String[] sa) {
	    this.formatter = formatter;
	    int idx = 0;

	    index(sa[idx++]);
	    flags(sa[idx++]);
	    width(sa[idx++]);
	    precision(sa[idx++]);

	    if (sa[idx] != null) {
		dt = true;
		if (sa[idx].equals("T"))
		    f.add(Flags.UPPERCASE);
	    }
	    conversion(sa[++idx]);

	    if (dt)
		checkDateTime();
	    else if (Conversion.isGeneral(c))
		checkGeneral();
	    else if (Conversion.isCharacter(c))
		checkCharacter();
	    else if (Conversion.isInteger(c))
		checkInteger();
	    else if (Conversion.isFloat(c))
		checkFloat();
            else if (Conversion.isText(c))
		checkText();
	    else
		throw new UnknownFormatConversionException(String.valueOf(c));
	}

	public void print(Object arg, Locale l) throws IOException {
	    if (dt) {
		printDateTime(arg, l);
		return;
	    }
	    switch(c) {
	    case Conversion.DECIMAL_INTEGER:
	    case Conversion.OCTAL_INTEGER:
	    case Conversion.HEXADECIMAL_INTEGER:
		printInteger(arg, l);
		break;
	    case Conversion.SCIENTIFIC:
	    case Conversion.GENERAL:
	    case Conversion.DECIMAL_FLOAT:
	    case Conversion.HEXADECIMAL_FLOAT:
		printFloat(arg, l);
		break;
	    case Conversion.CHARACTER:
	    case Conversion.CHARACTER_UPPER:
		printCharacter(arg);
		break;
	    case Conversion.BOOLEAN:
		printBoolean(arg);
		break;
	    case Conversion.STRING:
		printString(arg, l);
		break;
	    case Conversion.HASHCODE:
		printHashCode(arg);
		break;
	    case Conversion.LINE_SEPARATOR:
		if (ls == null)
		    ls = System.getProperty("line.separator");
 		a.append(ls);
		break;
	    case Conversion.PERCENT_SIGN:
		a.append('%');
		break;
	    default:
		assert false;
	    }
	}

	private void printInteger(Object arg, Locale l) throws IOException {
	    if (arg == null)
		print("null");
	    else if (arg instanceof Byte)
		print(((Byte)arg).byteValue(), l);
	    else if (arg instanceof Short)
		print(((Short)arg).shortValue(), l);
	    else if (arg instanceof Integer)
		print(((Integer)arg).intValue(), l);
	    else if (arg instanceof Long)
		print(((Long)arg).longValue(), l);
	    else if (arg instanceof BigInteger)
		print(((BigInteger)arg), l);
	    else
		failConversion(c, arg);
	}

	private void printFloat(Object arg, Locale l) throws IOException {
	    if (arg == null)
		print("null");
	    else if (arg instanceof Float)
		print(((Float)arg).floatValue(), l);
	    else if (arg instanceof Double)
		print(((Double)arg).doubleValue(), l);
	    else if (arg instanceof BigDecimal)
		print(((BigDecimal)arg), l);
	    else
		failConversion(c, arg);
	}

	private void printDateTime(Object arg, Locale l) throws IOException {
	    if (arg == null) {
		print("null");
		return;
	    }
	    Calendar cal = null;

	    // Instead of Calendar.setLenient(true), perhaps we should
	    // wrap the IllegalArgumentException that might be thrown?
	    if (arg instanceof Long) {
		// Note that the following method uses an instance of the
		// default time zone (TimeZone.getDefaultRef().
		cal = Calendar.getInstance(l);
		cal.setTimeInMillis((Long)arg);
	    } else if (arg instanceof Date) {
		// Note that the following method uses an instance of the
		// default time zone (TimeZone.getDefaultRef().
		cal = Calendar.getInstance(l);
		cal.setTime((Date)arg);
	    } else if (arg instanceof Calendar) {
		cal = (Calendar) ((Calendar)arg).clone();
		cal.setLenient(true);
	    } else {
		failConversion(c, arg);
	    }
	    print(cal, c, l);
	}

	private void printCharacter(Object arg) throws IOException {
	    if (arg == null) {
		print("null");
		return;
	    }
	    String s = null;
 	    if (arg instanceof Character) {
		s = ((Character)arg).toString();
	    } else if (arg instanceof Byte) {
		byte i = ((Byte)arg).byteValue();
		if (Character.isValidCodePoint(i))
		    s = new String(Character.toChars(i));
		else
		    throw new IllegalFormatCodePointException(i);
	    } else if (arg instanceof Short) {
		short i = ((Short)arg).shortValue();
		if (Character.isValidCodePoint(i))
		    s = new String(Character.toChars(i));
		else
		    throw new IllegalFormatCodePointException(i);
	    } else if (arg instanceof Integer) {
		int i = ((Integer)arg).intValue();
		if (Character.isValidCodePoint(i))
		    s = new String(Character.toChars(i));
		else
		    throw new IllegalFormatCodePointException(i);
	    } else {
		failConversion(c, arg);
	    }
	    print(s);
	}

	private void printString(Object arg, Locale l) throws IOException {
	    if (arg == null) {
		print("null");
	    } else if (arg instanceof Formattable) {
		Formatter fmt = formatter;
		if (formatter.locale() != l)
		    fmt = new Formatter(formatter.out(), l);
		((Formattable)arg).formatTo(fmt, f.valueOf(), width, precision);
	    } else {
		print(arg.toString());
	    }
	}

	private void printBoolean(Object arg) throws IOException {
	    String s;
	    if (arg != null)
		s = ((arg instanceof Boolean)
		     ? ((Boolean)arg).toString()
		     : Boolean.toString(true));
	    else
		s = Boolean.toString(false);
	    print(s);
	}

	private void printHashCode(Object arg) throws IOException {
	    String s = (arg == null
			? "null"
			: Integer.toHexString(arg.hashCode()));
	    print(s);
	}

	private void print(String s) throws IOException {
	    if (precision != -1 && precision < s.length())
		s = s.substring(0, precision);
	    if (f.contains(Flags.UPPERCASE))
		s = s.toUpperCase();
	    a.append(justify(s));
	}

	private String justify(String s) {
	    if (width == -1)
		return s;
	    StringBuilder sb = new StringBuilder();
	    boolean pad = f.contains(Flags.LEFT_JUSTIFY);
	    int sp = width - s.length();
	    if (!pad)
		for (int i = 0; i < sp; i++) sb.append(' ');
	    sb.append(s);
	    if (pad)
		for (int i = 0; i < sp; i++) sb.append(' ');
	    return sb.toString();
	}

	public String toString() {
	    StringBuilder sb = new StringBuilder('%');
	    // Flags.UPPERCASE is set internally for legal conversions.
	    Flags dupf = f.dup().remove(Flags.UPPERCASE);
	    sb.append(dupf.toString());
	    if (index > 0)
		sb.append(index).append('$');
	    if (width != -1)
		sb.append(width);
	    if (precision != -1)
		sb.append('.').append(precision);
	    if (dt)
		sb.append(f.contains(Flags.UPPERCASE) ? 'T' : 't');
	    sb.append(f.contains(Flags.UPPERCASE)
		      ? Character.toUpperCase(c) : c);
	    return sb.toString();
	}

	private void checkGeneral() {
	    if ((c == Conversion.BOOLEAN || c == Conversion.HASHCODE)
		&& f.contains(Flags.ALTERNATE))
		failMismatch(Flags.ALTERNATE, c);
	    // '-' requires a width
	    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
		throw new MissingFormatWidthException(toString());
	    checkBadFlags(Flags.PLUS, Flags.LEADING_SPACE, Flags.ZERO_PAD,
			  Flags.GROUP, Flags.PARENTHESES);
	}

	private void checkDateTime() {
	    if (precision != -1)
		throw new IllegalFormatPrecisionException(precision);
	    if (!DateTime.isValid(c))
		throw new UnknownFormatConversionException("t" + c);
	    checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE,
			  Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES);
	    // '-' requires a width
	    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
		throw new MissingFormatWidthException(toString());
	}

	private void checkCharacter() {
	    if (precision != -1)
		throw new IllegalFormatPrecisionException(precision);
	    checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE,
			  Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES);
	    // '-' requires a width
	    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
		throw new MissingFormatWidthException(toString());
	}

	private void checkInteger() {
	    checkNumeric();
	    if (precision != -1)
		throw new IllegalFormatPrecisionException(precision);

	    if (c == Conversion.DECIMAL_INTEGER)
		checkBadFlags(Flags.ALTERNATE);
	    else if (c == Conversion.OCTAL_INTEGER)
		checkBadFlags(Flags.GROUP);
	    else
		checkBadFlags(Flags.GROUP);
	}

	private void checkBadFlags(Flags ... badFlags) {
	    for (int i = 0; i < badFlags.length; i++)
		if (f.contains(badFlags[i]))
		    failMismatch(badFlags[i], c);
	}

	private void checkFloat() {
	    checkNumeric();
	    if (c == Conversion.DECIMAL_FLOAT) {
	    } else if (c == Conversion.HEXADECIMAL_FLOAT) {
		checkBadFlags(Flags.PARENTHESES, Flags.GROUP);
	    } else if (c == Conversion.SCIENTIFIC) {
		checkBadFlags(Flags.GROUP);
	    } else if (c == Conversion.GENERAL) {
		checkBadFlags(Flags.ALTERNATE);
	    }
	}

	private void checkNumeric() {
	    if (width != -1 && width < 0)
		throw new IllegalFormatWidthException(width);

	    if (precision != -1 && precision < 0)
		throw new IllegalFormatPrecisionException(precision);

	    // '-' and '0' require a width
	    if (width == -1
		&& (f.contains(Flags.LEFT_JUSTIFY) || f.contains(Flags.ZERO_PAD)))
		throw new MissingFormatWidthException(toString());

	    // bad combination
	    if ((f.contains(Flags.PLUS) && f.contains(Flags.LEADING_SPACE))
		|| (f.contains(Flags.LEFT_JUSTIFY) && f.contains(Flags.ZERO_PAD)))
		throw new IllegalFormatFlagsException(f.toString());
	}

	private void checkText() {
	    if (precision != -1)
		throw new IllegalFormatPrecisionException(precision);
	    switch (c) {
	    case Conversion.PERCENT_SIGN:
		if (f.valueOf() != Flags.LEFT_JUSTIFY.valueOf()
		    && f.valueOf() != Flags.NONE.valueOf())
		    throw new IllegalFormatFlagsException(f.toString());
		// '-' requires a width
		if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
		    throw new MissingFormatWidthException(toString());
		break;
	    case Conversion.LINE_SEPARATOR:
		if (width != -1)
		    throw new IllegalFormatWidthException(width);
		if (f.valueOf() != Flags.NONE.valueOf())
		    throw new IllegalFormatFlagsException(f.toString());
		break;
	    default:
		assert false;
	    }
	}

	private void print(byte value, Locale l) throws IOException {
	    long v = value;
	    if (value < 0
		&& (c == Conversion.OCTAL_INTEGER
		    || c == Conversion.HEXADECIMAL_INTEGER)) {
		v += (1L << 8);
		assert v >= 0 : v;
	    }
	    print(v, l);
	}

	private void print(short value, Locale l) throws IOException {
	    long v = value;
	    if (value < 0
		&& (c == Conversion.OCTAL_INTEGER
		    || c == Conversion.HEXADECIMAL_INTEGER)) {
		v += (1L << 16);
		assert v >= 0 : v;
	    }
	    print(v, l);
	}

	private void print(int value, Locale l) throws IOException {
	    long v = value;
	    if (value < 0
		&& (c == Conversion.OCTAL_INTEGER
		    || c == Conversion.HEXADECIMAL_INTEGER)) {
		v += (1L << 32);
		assert v >= 0 : v;
	    }
	    print(v, l);
	}

	private void print(long value, Locale l) throws IOException {

	    StringBuilder sb = new StringBuilder();

	    if (c == Conversion.DECIMAL_INTEGER) {
		boolean neg = value < 0;
		char[] va;
		if (value < 0)
		    va = Long.toString(value, 10).substring(1).toCharArray();
		else
		    va = Long.toString(value, 10).toCharArray();

		// leading sign indicator
		leadingSign(sb, neg);

		// the value
		localizedMagnitude(sb, va, f, adjustWidth(width, f, neg), l);

		// trailing sign indicator
		trailingSign(sb, neg);
	    } else if (c == Conversion.OCTAL_INTEGER) {
		checkBadFlags(Flags.PARENTHESES, Flags.LEADING_SPACE,
			      Flags.PLUS);
		String s = Long.toOctalString(value);
		int len = (f.contains(Flags.ALTERNATE)
			   ? s.length() + 1
			   : s.length());

		// apply ALTERNATE (radix indicator for octal) before ZERO_PAD
		if (f.contains(Flags.ALTERNATE))
		    sb.append('0');
		if (f.contains(Flags.ZERO_PAD))
		    for (int i = 0; i < width - len; i++) sb.append('0');
		sb.append(s);
	    } else if (c == Conversion.HEXADECIMAL_INTEGER) {
		checkBadFlags(Flags.PARENTHESES, Flags.LEADING_SPACE,
			      Flags.PLUS);
		String s = Long.toHexString(value);
		int len = (f.contains(Flags.ALTERNATE)
			   ? s.length() + 2
			   : s.length());

		// apply ALTERNATE (radix indicator for hex) before ZERO_PAD
		if (f.contains(Flags.ALTERNATE))
		    sb.append(f.contains(Flags.UPPERCASE) ? "0X" : "0x");
		if (f.contains(Flags.ZERO_PAD))
		    for (int i = 0; i < width - len; i++) sb.append('0');
		if (f.contains(Flags.UPPERCASE))
		    s = s.toUpperCase();
		sb.append(s);
	    }

	    // justify based on width
	    a.append(justify(sb.toString()));
	}

	// neg := val < 0
	private StringBuilder leadingSign(StringBuilder sb, boolean neg) {
	    if (!neg) {
		if (f.contains(Flags.PLUS)) {
		    sb.append('+');
		} else if (f.contains(Flags.LEADING_SPACE)) {
		    sb.append(' ');
		}
	    } else {
		if (f.contains(Flags.PARENTHESES))
		    sb.append('(');
		else
		    sb.append('-');
	    }
	    return sb;
	}

	// neg := val < 0
	private StringBuilder trailingSign(StringBuilder sb, boolean neg) {
	    if (neg && f.contains(Flags.PARENTHESES))
		sb.append(')');
	    return sb;
	}

	private void print(BigInteger value, Locale l) throws IOException {
	    StringBuilder sb = new StringBuilder();
	    boolean neg = value.signum() == -1;
	    BigInteger v = value.abs();

	    // leading sign indicator
	    leadingSign(sb, neg);

	    // the value
	    if (c == Conversion.DECIMAL_INTEGER) {
		char[] va = v.toString().toCharArray();
 		localizedMagnitude(sb, va, f, adjustWidth(width, f, neg), l);
	    } else if (c == Conversion.OCTAL_INTEGER) {
		String s = v.toString(8);

		int len = s.length() + sb.length();
		if (neg && f.contains(Flags.PARENTHESES))
		    len++;

		// apply ALTERNATE (radix indicator for octal) before ZERO_PAD
		if (f.contains(Flags.ALTERNATE)) {
		    len++;
		    sb.append('0');
		}
		if (f.contains(Flags.ZERO_PAD)) {
		    for (int i = 0; i < width - len; i++)
			sb.append('0');
		}
		sb.append(s);
	    } else if (c == Conversion.HEXADECIMAL_INTEGER) {
		String s = v.toString(16);

		int len = s.length() + sb.length();
		if (neg && f.contains(Flags.PARENTHESES))
		    len++;

		// apply ALTERNATE (radix indicator for hex) before ZERO_PAD
		if (f.contains(Flags.ALTERNATE)) {
		    len += 2;
		    sb.append(f.contains(Flags.UPPERCASE) ? "0X" : "0x");
		}
		if (f.contains(Flags.ZERO_PAD))
		    for (int i = 0; i < width - len; i++)
			sb.append('0');
		if (f.contains(Flags.UPPERCASE))
		    s = s.toUpperCase();
		sb.append(s);
	    }

	    // trailing sign indicator
	    trailingSign(sb, (value.signum() == -1));

	    // justify based on width
	    a.append(justify(sb.toString()));
	}

	private void print(float value, Locale l) throws IOException {
	    print((double) value, l);
	}

	private void print(double value, Locale l) throws IOException {
	    StringBuilder sb = new StringBuilder();
	    boolean neg = Double.compare(value, 0.0) == -1;

	    if (!Double.isNaN(value)) {
		double v = Math.abs(value);

		// leading sign indicator
		leadingSign(sb, neg);

		// the value
		if (!Double.isInfinite(v))
		    print(sb, v, l, f, c, precision, neg);
		else
		    sb.append(f.contains(Flags.UPPERCASE)
			      ? "INFINITY" : "Infinity");

		// trailing sign indicator
		trailingSign(sb, neg);
	    } else {
		sb.append(f.contains(Flags.UPPERCASE) ? "NAN" : "NaN");
	    }

	    // justify based on width
	    a.append(justify(sb.toString()));
	}

	// !Double.isInfinite(value) && !Double.isNaN(value)
	private void print(StringBuilder sb, double value, Locale l,
			   Flags f, char c, int precision, boolean neg)
	    throws IOException
	{
	    if (c == Conversion.SCIENTIFIC) {
		// Create a new FormattedFloatingDecimal with the desired
		// precision.
		int prec = (precision == -1 ? 6 : precision);

		FormattedFloatingDecimal fd
		    = new FormattedFloatingDecimal(value, prec,
                        FormattedFloatingDecimal.Form.SCIENTIFIC);

		char[] v = new char[MAX_FD_CHARS];
		int len = fd.getChars(v);

		char[] mant = addZeros(mantissa(v, len), prec);

		// If the precision is zero and the '#' flag is set, add the
		// requested decimal point.
		if (f.contains(Flags.ALTERNATE) && (prec == 0))
		    mant = addDot(mant);

		char[] exp = (value == 0.0)
		    ? new char[] {'+','0','0'} : exponent(v, len);

		int newW = width;
		if (width != -1)
		    newW = adjustWidth(width - exp.length - 1, f, neg);
		localizedMagnitude(sb, mant, f, newW, null);

		sb.append(f.contains(Flags.UPPERCASE) ? 'E' : 'e');

		Flags flags = f.dup().remove(Flags.GROUP);
		char sign = exp[0];
		assert(sign == '+' || sign == '-');
		sb.append(sign);

		char[] tmp = new char[exp.length - 1];
		System.arraycopy(exp, 1, tmp, 0, exp.length - 1);
		sb.append(localizedMagnitude(null, tmp, flags, -1, null));
	    } else if (c == Conversion.DECIMAL_FLOAT) {
		// Create a new FormattedFloatingDecimal with the desired
		// precision.
		int prec = (precision == -1 ? 6 : precision);

		FormattedFloatingDecimal fd
		    = new FormattedFloatingDecimal(value, prec,
			FormattedFloatingDecimal.Form.DECIMAL_FLOAT);

		// MAX_FD_CHARS + 1 (round?)
		char[] v = new char[MAX_FD_CHARS + 1
				   + Math.abs(fd.getExponent())];
		int len = fd.getChars(v);

		char[] mant = addZeros(mantissa(v, len), prec);

		// If the precision is zero and the '#' flag is set, add the
		// requested decimal point.
		if (f.contains(Flags.ALTERNATE) && (prec == 0))
		    mant = addDot(mant);

		int newW = width;
		if (width != -1)
		    newW = adjustWidth(width, f, neg);
		localizedMagnitude(sb, mant, f, newW, l);
	    } else if (c == Conversion.GENERAL) {
		int prec = precision;
		if (precision == -1)
		    prec = 6;
		else if (precision == 0)
		    prec = 1;

		FormattedFloatingDecimal fd
		    = new FormattedFloatingDecimal(value, prec,
			FormattedFloatingDecimal.Form.GENERAL);

		// MAX_FD_CHARS + 1 (round?)
		char[] v = new char[MAX_FD_CHARS + 1
				   + Math.abs(fd.getExponent())];
		int len = fd.getChars(v);

		char[] exp = exponent(v, len);
		if (exp != null) {
		    prec -= 1;
		} else {
		    prec = prec - (value == 0 ? 0 : fd.getExponentRounded()) - 1;
		}

		char[] mant = addZeros(mantissa(v, len), prec);
		// If the precision is zero and the '#' flag is set, add the
		// requested decimal point.
		if (f.contains(Flags.ALTERNATE) && (prec == 0))
		    mant = addDot(mant);

		int newW = width;
		if (width != -1) {
		    if (exp != null)
			newW = adjustWidth(width - exp.length - 1, f, neg);
		    else
			newW = adjustWidth(width, f, neg);
		}
		localizedMagnitude(sb, mant, f, newW, null);

		if (exp != null) {
		    sb.append(f.contains(Flags.UPPERCASE) ? 'E' : 'e');

		    Flags flags = f.dup().remove(Flags.GROUP);
		    char sign = exp[0];
		    assert(sign == '+' || sign == '-');
		    sb.append(sign);

		    char[] tmp = new char[exp.length - 1];
		    System.arraycopy(exp, 1, tmp, 0, exp.length - 1);
		    sb.append(localizedMagnitude(null, tmp, flags, -1, null));
		}
	    } else if (c == Conversion.HEXADECIMAL_FLOAT) {
		int prec = precision;
		if (precision == -1)
		    // assume that we want all of the digits
		    prec = 0;
		else if (precision == 0)
		    prec = 1;

 		String s = hexDouble(value, prec);

		char[] va;
		boolean upper = f.contains(Flags.UPPERCASE);
		sb.append(upper ? "0X" : "0x");

		if (f.contains(Flags.ZERO_PAD))
		    for (int i = 0; i < width - s.length() - 2; i++)
			sb.append('0');

		int idx = s.indexOf('p');
		va = s.substring(0, idx).toCharArray();
		if (upper) {
		    String tmp = new String(va);
		    // don't localize hex
		    tmp = tmp.toUpperCase(Locale.US);
		    va = tmp.toCharArray();
		}
		sb.append(prec != 0 ? addZeros(va, prec) : va);
		sb.append(upper ? 'P' : 'p');
		sb.append(s.substring(idx+1));
	    }
	}

	private char[] mantissa(char[] v, int len) {
	    int i;
	    for (i = 0; i < len; i++) {
		if (v[i] == 'e')
		    break;
	    }
	    char[] tmp = new char[i];
	    System.arraycopy(v, 0, tmp, 0, i);
	    return tmp;
	}

	private char[] exponent(char[] v, int len) {
	    int i;
	    for (i = len - 1; i >= 0; i--) {
		if (v[i] == 'e')
		    break;
	    }
 	    if (i == -1)
 		return null;
	    char[] tmp = new char[len - i - 1];
	    System.arraycopy(v, i + 1, tmp, 0, len - i - 1);
	    return tmp;
	}

	// Add zeros to the requested precision.
	private char[] addZeros(char[] v, int prec) {
	    // Look for the dot.  If we don't find one, the we'll need to add
	    // it before we add the zeros.
	    int i;
	    for (i = 0; i < v.length; i++) {
		if (v[i] == '.')
		    break;
	    }
	    boolean needDot = false;
	    if (i == v.length) {
		needDot = true;
	    }

	    // Determine existing precision.
	    int outPrec = v.length - i - (needDot ? 0 : 1);
	    assert (outPrec <= prec);
	    if (outPrec == prec)
		return v;

	    // Create new array with existing contents.
	    char[] tmp
		= new char[v.length + prec - outPrec + (needDot ? 1 : 0)];
	    System.arraycopy(v, 0, tmp, 0, v.length);

	    // Add dot if previously determined to be necessary.
	    int start = v.length;
	    if (needDot) {
		tmp[v.length] = '.';
		start++;
	    }

	    // Add zeros.
	    for (int j = start; j < tmp.length; j++)
		tmp[j] = '0';

	    return tmp;
	}

	// Method assumes that d > 0.
	private String hexDouble(double d, int prec) {
	    // Let Double.toHexString handle simple cases
	    if(!FpUtils.isFinite(d) || d == 0.0 || prec == 0 || prec >= 13)
		// remove "0x"
		return Double.toHexString(d).substring(2);
	    else {
		assert(prec >= 1 && prec <= 12);

		int exponent  = FpUtils.getExponent(d);
		boolean subnormal
		    = (exponent == DoubleConsts.MIN_EXPONENT - 1);

		// If this is subnormal input so normalize (could be faster to
		// do as integer operation).
		if (subnormal) {
		    scaleUp = FpUtils.scalb(1.0, 54);
		    d *= scaleUp;
		    // Calculate the exponent.  This is not just exponent + 54
		    // since the former is not the normalized exponent.
		    exponent = FpUtils.getExponent(d);
		    assert exponent >= DoubleConsts.MIN_EXPONENT &&
			exponent <= DoubleConsts.MAX_EXPONENT: exponent;
		}

		int precision = 1 + prec*4;
		int shiftDistance
		    =  DoubleConsts.SIGNIFICAND_WIDTH - precision;
		assert(shiftDistance >= 1 && shiftDistance < DoubleConsts.SIGNIFICAND_WIDTH);

		long doppel = Double.doubleToLongBits(d);
		// Deterime the number of bits to keep.
		long newSignif
		    = (doppel & (DoubleConsts.EXP_BIT_MASK
				 | DoubleConsts.SIGNIF_BIT_MASK))
				     >> shiftDistance;
		// Bits to round away.
		long roundingBits = doppel & ~(~0L << shiftDistance);

		// To decide how to round, look at the low-order bit of the
		// working significand, the highest order discarded bit (the
		// round bit) and whether any of the lower order discarded bits
		// are nonzero (the sticky bit).

		boolean leastZero = (newSignif & 0x1L) == 0L;
		boolean round
		    = ((1L << (shiftDistance - 1) ) & roundingBits) != 0L;
		boolean sticky  = shiftDistance > 1 &&
		    (~(1L<< (shiftDistance - 1)) & roundingBits) != 0;
		if((leastZero && round && sticky) || (!leastZero && round)) {
		    newSignif++;
		}

		long signBit = doppel & DoubleConsts.SIGN_BIT_MASK;
		newSignif = signBit | (newSignif << shiftDistance);
		double result = Double.longBitsToDouble(newSignif);

		if (Double.isInfinite(result) ) {
		    // Infinite result generated by rounding
		    return "1.0p1024";
		} else {
		    String res = Double.toHexString(result).substring(2);
		    if (!subnormal)
			return res;
		    else {
			// Create a normalized subnormal string.
			int idx = res.indexOf('p');
			if (idx == -1) {
			    // No 'p' character in hex string.
			    assert false;
			    return null;
			} else {
			    // Get exponent and append at the end.
			    String exp = res.substring(idx + 1);
			    int iexp = Integer.parseInt(exp) -54;
			    return res.substring(0, idx) + "p"
				+ Integer.toString(iexp);
			}
		    }
		}
	    }
	}

	private void print(BigDecimal value, Locale l) throws IOException {
	    if (c == Conversion.HEXADECIMAL_FLOAT)
		failConversion(c, value);
	    StringBuilder sb = new StringBuilder();
	    boolean neg = value.signum() == -1;
	    BigDecimal v = value.abs();
	    // leading sign indicator
	    leadingSign(sb, neg);

	    // the value
	    print(sb, v, l, f, c, precision, neg);

	    // trailing sign indicator
	    trailingSign(sb, neg);

	    // justify based on width
	    a.append(justify(sb.toString()));
	}

	// value > 0
	private void print(StringBuilder sb, BigDecimal value, Locale l,
			   Flags f, char c, int precision, boolean neg)
	    throws IOException
	{
	    if (c == Conversion.SCIENTIFIC) {
		// Create a new BigDecimal with the desired precision.
		int prec = (precision == -1 ? 6 : precision);
		int scale = value.scale();
		int origPrec = value.precision();
		int nzeros = 0;
		int compPrec;

		if (prec > origPrec - 1) {
		    compPrec = origPrec;
		    nzeros = prec - (origPrec - 1);
		} else {
		    compPrec = prec + 1;
		}

		MathContext mc = new MathContext(compPrec);
		BigDecimal v
		    = new BigDecimal(value.unscaledValue(), scale, mc);

		BigDecimalLayout bdl
 		    = new BigDecimalLayout(v.unscaledValue(), v.scale(),
 					   BigDecimalLayoutForm.SCIENTIFIC);

		char[] mant = bdl.mantissa();

		// Add a decimal point if necessary.  The mantissa may not
		// contain a decimal point if the scale is zero (the internal
		// representation has no fractional part) or the original
		// precision is one. Append a decimal point if '#' is set or if
		// we require zero padding to get to the requested precision.
 		if ((origPrec == 1 || !bdl.hasDot())
 		    && (nzeros > 0 || (f.contains(Flags.ALTERNATE))))
 		    mant = addDot(mant);

		// Add trailing zeros in the case precision is greater than
		// the number of available digits after the decimal separator.
		mant = trailingZeros(mant, nzeros);

		char[] exp = bdl.exponent();
		int newW = width;
		if (width != -1)
		    newW = adjustWidth(width - exp.length - 1, f, neg);
		localizedMagnitude(sb, mant, f, newW, null);

		sb.append(f.contains(Flags.UPPERCASE) ? 'E' : 'e');

		Flags flags = f.dup().remove(Flags.GROUP);
		char sign = exp[0];
		assert(sign == '+' || sign == '-');
		sb.append(exp[0]);

		char[] tmp = new char[exp.length - 1];
		System.arraycopy(exp, 1, tmp, 0, exp.length - 1);
		sb.append(localizedMagnitude(null, tmp, flags, -1, null));
	    } else if (c == Conversion.DECIMAL_FLOAT) {
		// Create a new BigDecimal with the desired precision.
		int prec = (precision == -1 ? 6 : precision);
		int scale = value.scale();
  		int compPrec = value.precision();
 		if (scale > prec) 
 		    compPrec -= (scale - prec);
		MathContext mc = new MathContext(compPrec);
		BigDecimal v
		    = new BigDecimal(value.unscaledValue(), scale, mc);

		BigDecimalLayout bdl
		    = new BigDecimalLayout(v.unscaledValue(), v.scale(),
					   BigDecimalLayoutForm.DECIMAL_FLOAT);

		char mant[] = bdl.mantissa();
 		int nzeros = (bdl.scale() < prec ? prec - bdl.scale() : 0);

		// Add a decimal point if necessary.  The mantissa may not
		// contain a decimal point if the scale is zero (the internal
		// representation has no fractional part).  Append a decimal
		// point if '#' is set or we require zero padding to get to the
		// requested precision.
  		if (bdl.scale() == 0 && (f.contains(Flags.ALTERNATE) || nzeros > 0))
  		    mant = addDot(bdl.mantissa());

		// Add trailing zeros if the precision is greater than the
		// number of available digits after the decimal separator.
		mant = trailingZeros(mant, nzeros);

		localizedMagnitude(sb, mant, f, adjustWidth(width, f, neg), l);
	    } else if (c == Conversion.GENERAL) {
		int prec = precision;
		if (precision == -1)
		    prec = 6;
		else if (precision == 0)
		    prec = 1;

		BigDecimal tenToTheNegFour = BigDecimal.valueOf(1, 4);
		BigDecimal tenToThePrec = BigDecimal.valueOf(1, -prec);
		if ((value.equals(BigDecimal.ZERO))
		    || ((value.compareTo(tenToTheNegFour) != -1)
			&& (value.compareTo(tenToThePrec) == -1))) {

		    int e = - value.scale()
			+ (value.unscaledValue().toString().length() - 1);

		    // xxx.yyy
		    //   g precision (# sig digits) = #x + #y
		    //   f precision = #y
		    //   exponent = #x - 1
		    // => f precision = g precision - exponent - 1
		    // 0.000zzz
		    //   g precision (# sig digits) = #z
		    //   f precision = #0 (after '.') + #z
		    //   exponent = - #0 (after '.') - 1
		    // => f precision = g precision - exponent - 1
		    prec = prec - e - 1;

		    print(sb, value, l, f, Conversion.DECIMAL_FLOAT, prec,
			  neg);
		} else {
		    print(sb, value, l, f, Conversion.SCIENTIFIC, prec - 1, neg);
		}
	    } else if (c == Conversion.HEXADECIMAL_FLOAT) {
		// This conversion isn't supported.  The error should be
		// reported earlier.
		assert false;
	    }
	}

	private class BigDecimalLayout {
	    private StringBuilder mant;
	    private StringBuilder exp;
	    private boolean dot = false;
	    private int scale;

 	    public BigDecimalLayout(BigInteger intVal, int scale, BigDecimalLayoutForm form) {
 		layout(intVal, scale, form);
 	    }

	    public boolean hasDot() {
		return dot;
	    }

	    public int scale() {
		return scale;
	    }

	    // char[] with canonical string representation
	    public char[] layoutChars() {
		StringBuilder sb = new StringBuilder(mant);
		if (exp != null) {
		    sb.append('E');
		    sb.append(exp);
		}
		return toCharArray(sb);
	    }

	    public char[] mantissa() {
		return toCharArray(mant);
	    }

	    // The exponent will be formatted as a sign ('+' or '-') followed
	    // by the exponent zero-padded to include at least two digits.
	    public char[] exponent() {
		return toCharArray(exp);
	    }

	    private char[] toCharArray(StringBuilder sb) {
		if (sb == null)
		    return null;
		char[] result = new char[sb.length()];
		sb.getChars(0, result.length, result, 0);
		return result;
	    }

 	    private void layout(BigInteger intVal, int scale, BigDecimalLayoutForm form) {
 		char coeff[] = intVal.toString().toCharArray();
		this.scale = scale;

		// Construct a buffer, with sufficient capacity for all cases.
		// If E-notation is needed, length will be: +1 if negative, +1
		// if '.' needed, +2 for "E+", + up to 10 for adjusted
		// exponent.  Otherwise it could have +1 if negative, plus
		// leading "0.00000"
		mant = new StringBuilder(coeff.length + 14);

		if (scale == 0) {
		    int len = coeff.length;
		    if (len > 1) {
			mant.append(coeff[0]);
			if (form == BigDecimalLayoutForm.SCIENTIFIC) {
			    mant.append('.');
			    dot = true;
			    mant.append(coeff, 1, len - 1);
			    exp = new StringBuilder("+");
			    if (len < 10)
				exp.append("0").append(len - 1);
			    else
				exp.append(len - 1);
			} else {
			    mant.append(coeff, 1, len - 1);
			}
		    } else {
			mant.append(coeff);
			if (form == BigDecimalLayoutForm.SCIENTIFIC)
			    exp = new StringBuilder("+00");
		    }
		    return;
		}
		long adjusted = -(long) scale + (coeff.length - 1);
		if (form == BigDecimalLayoutForm.DECIMAL_FLOAT) {
		    // count of padding zeros
		    int pad = scale - coeff.length;
		    if (pad >= 0) {
			// 0.xxx form
			mant.append("0.");
			dot = true;
			for (; pad > 0 ; pad--) mant.append('0');
			mant.append(coeff);
		    } else {
 			if (-pad < coeff.length) {
			    // xx.xx form
 			    mant.append(coeff, 0, -pad);
 			    mant.append('.');
 			    dot = true;
 			    mant.append(coeff, -pad, scale);
 			} else {
 			    // xx form
 			    mant.append(coeff, 0, coeff.length);
  			    for (int i = 0; i < -scale; i++) 
  				mant.append('0');
			    this.scale = 0;
 			}
		    }
		} else {
		    // x.xxx form
		    mant.append(coeff[0]);
		    if (coeff.length > 1) {
			mant.append('.');
			dot = true;
			mant.append(coeff, 1, coeff.length-1);
		    }
		    exp = new StringBuilder();
		    if (adjusted != 0) {
			long abs = Math.abs(adjusted);
			// require sign
			exp.append(adjusted < 0 ? '-' : '+');
			if (abs < 10)
			    exp.append('0');
			exp.append(abs);
		    } else {
			exp.append("+00");
		    }
		}
	    }
	}

	private int adjustWidth(int width, Flags f, boolean neg) {
	    int newW = width;
	    if (newW != -1 && neg && f.contains(Flags.PARENTHESES))
		newW--;
	    return newW;
	}

	// Add a '.' to th mantissa if required
	private char[] addDot(char[] mant) {
	    char[] tmp = mant;
	    tmp = new char[mant.length + 1];
	    System.arraycopy(mant, 0, tmp, 0, mant.length);
	    tmp[tmp.length - 1] = '.';
	    return tmp;
	}

	// Add trailing zeros in the case precision is greater than the number
	// of available digits after the decimal separator.
	private char[] trailingZeros(char[] mant, int nzeros) {
	    char[] tmp = mant;
	    if (nzeros > 0) {
		tmp = new char[mant.length + nzeros];
		System.arraycopy(mant, 0, tmp, 0, mant.length);
		for (int i = mant.length; i < tmp.length; i++)
		    tmp[i] = '0';
	    }
	    return tmp;
	}

	private void print(Calendar t, char c, Locale l)  throws IOException
	{
	    StringBuilder sb = new StringBuilder();
	    print(sb, t, c, l);

	    // justify based on width
	    String s = justify(sb.toString());
	    if (f.contains(Flags.UPPERCASE))
		s = s.toUpperCase();

	    a.append(s);
	}

	private Appendable print(StringBuilder sb, Calendar t, char c,
				 Locale l)
	    throws IOException
	{
	    assert(width == -1);
	    if (sb == null)
		sb = new StringBuilder();
	    switch (c) {
	    case DateTime.HOUR_OF_DAY_0: // 'H' (00 - 23)
	    case DateTime.HOUR_0:        // 'I' (01 - 12)
	    case DateTime.HOUR_OF_DAY:   // 'k' (0 - 23) -- like H
	    case DateTime.HOUR:        { // 'l' (1 - 12) -- like I
		int i = t.get(Calendar.HOUR_OF_DAY);
		if (c == DateTime.HOUR_0 || c == DateTime.HOUR)
		    i = (i == 0 || i == 12 ? 12 : i % 12);
		Flags flags = (c == DateTime.HOUR_OF_DAY_0
			       || c == DateTime.HOUR_0
			       ? Flags.ZERO_PAD
			       : Flags.NONE);
		sb.append(localizedMagnitude(null, i, flags, 2, l));
		break;
	    }
	    case DateTime.MINUTE:      { // 'M' (00 - 59)
		int i = t.get(Calendar.MINUTE);
		Flags flags = Flags.ZERO_PAD;
		sb.append(localizedMagnitude(null, i, flags, 2, l));
		break;
	    }
	    case DateTime.NANOSECOND:  { // 'N' (000000000 - 999999999)
		int i = t.get(Calendar.MILLISECOND) * 1000000;
		Flags flags = Flags.ZERO_PAD;
		sb.append(localizedMagnitude(null, i, flags, 9, l));
		break;
	    }
	    case DateTime.MILLISECOND: { // 'L' (000 - 999)
		int i = t.get(Calendar.MILLISECOND);
		Flags flags = Flags.ZERO_PAD;
		sb.append(localizedMagnitude(null, i, flags, 3, l));
		break;
	    }
	    case DateTime.MILLISECOND_SINCE_EPOCH: { // 'Q' (0 - 99...?)
		long i = t.getTimeInMillis();
		Flags flags = Flags.NONE;
		sb.append(localizedMagnitude(null, i, flags, width, l));
		break;
	    }
	    case DateTime.AM_PM:       { // 'p' (am or pm)
		// Calendar.AM = 0, Calendar.PM = 1, LocaleElements defines upper
		String[] ampm = { "AM", "PM" };
		if (l != null && l != Locale.US) {
		    DateFormatSymbols dfs = DateFormatSymbols.getInstance(l);
		    ampm = dfs.getAmPmStrings();
		}
		String s = ampm[t.get(Calendar.AM_PM)];
		sb.append(s.toLowerCase(l != null ? l : Locale.US));
		break;
	    }
	    case DateTime.SECONDS_SINCE_EPOCH: { // 's' (0 - 99...?)
		long i = t.getTimeInMillis() / 1000;
		Flags flags = Flags.NONE;
		sb.append(localizedMagnitude(null, i, flags, width, l));
		break;
	    }
	    case DateTime.SECOND:      { // 'S' (00 - 60 - leap second)
		int i = t.get(Calendar.SECOND);
		Flags flags = Flags.ZERO_PAD;
		sb.append(localizedMagnitude(null, i, flags, 2, l));
		break;
	    }
	    case DateTime.ZONE_NUMERIC: { // 'z' ({-|+}####) - ls minus?
		int i = t.get(Calendar.ZONE_OFFSET);
		boolean neg = i < 0;
		sb.append(neg ? '-' : '+');
		if (neg)
		    i = -i;
		int min = i / 60000;
		// combine minute and hour into a single integer
		int offset = (min / 60) * 100 + (min % 60);
		Flags flags = Flags.ZERO_PAD;

		sb.append(localizedMagnitude(null, offset, flags, 4, l));
		break;
	    }
	    case DateTime.ZONE:        { // 'Z' (symbol)
		TimeZone tz = t.getTimeZone();
		sb.append(tz.getDisplayName((t.get(Calendar.DST_OFFSET) != 0),
					   TimeZone.SHORT,
					   l));
		break;
	    }

            // Date
	    case DateTime.NAME_OF_DAY_ABBREV:     // 'a'
	    case DateTime.NAME_OF_DAY:          { // 'A'
		int i = t.get(Calendar.DAY_OF_WEEK);
		Locale lt = ((l == null) ? Locale.US : l);
		DateFormatSymbols dfs = DateFormatSymbols.getInstance(lt);
		if (c == DateTime.NAME_OF_DAY)
		    sb.append(dfs.getWeekdays()[i]);
		else
		    sb.append(dfs.getShortWeekdays()[i]);
		break;
	    }
	    case DateTime.NAME_OF_MONTH_ABBREV:   // 'b'
	    case DateTime.NAME_OF_MONTH_ABBREV_X: // 'h' -- same b
	    case DateTime.NAME_OF_MONTH:        { // 'B'
		int i = t.get(Calendar.MONTH);
		Locale lt = ((l == null) ? Locale.US : l);
		DateFormatSymbols dfs = DateFormatSymbols.getInstance(lt);
		if (c == DateTime.NAME_OF_MONTH)
		    sb.append(dfs.getMonths()[i]);
		else
		    sb.append(dfs.getShortMonths()[i]);
		break;
	    }
	    case DateTime.CENTURY:                // 'C' (00 - 99)
	    case DateTime.YEAR_2:                 // 'y' (00 - 99)
	    case DateTime.YEAR_4:               { // 'Y' (0000 - 9999)
		int i = t.get(Calendar.YEAR);
		int size = 2;
		switch (c) {
		case DateTime.CENTURY:
		    i /= 100;
		    break;
		case DateTime.YEAR_2:
		    i %= 100;
		    break;
		case DateTime.YEAR_4:
		    size = 4;
		    break;
		}
		Flags flags = Flags.ZERO_PAD;
		sb.append(localizedMagnitude(null, i, flags, size, l));
		break;
	    }
	    case DateTime.DAY_OF_MONTH_0:         // 'd' (01 - 31)
	    case DateTime.DAY_OF_MONTH:         { // 'e' (1 - 31) -- like d
		int i = t.get(Calendar.DATE);
		Flags flags = (c == DateTime.DAY_OF_MONTH_0
			       ? Flags.ZERO_PAD
			       : Flags.NONE);
		sb.append(localizedMagnitude(null, i, flags, 2, l));
		break;
	    }
	    case DateTime.DAY_OF_YEAR:          { // 'j' (001 - 366)
		int i = t.get(Calendar.DAY_OF_YEAR);
		Flags flags = Flags.ZERO_PAD;
		sb.append(localizedMagnitude(null, i, flags, 3, l));
		break;
	    }
	    case DateTime.MONTH:                { // 'm' (01 - 12)
		int i = t.get(Calendar.MONTH) + 1;
		Flags flags = Flags.ZERO_PAD;
		sb.append(localizedMagnitude(null, i, flags, 2, l));
		break;
	    }

            // Composites
	    case DateTime.TIME:         // 'T' (24 hour hh:mm:ss - %tH:%tM:%tS)
	    case DateTime.TIME_24_HOUR:    { // 'R' (hh:mm same as %H:%M)
		char sep = ':';
		print(sb, t, DateTime.HOUR_OF_DAY_0, l).append(sep);
		print(sb, t, DateTime.MINUTE, l);
		if (c == DateTime.TIME) {
		    sb.append(sep);
		    print(sb, t, DateTime.SECOND, l);
		}
		break;
	    }
	    case DateTime.TIME_12_HOUR:    { // 'r' (hh:mm:ss [AP]M)
		char sep = ':';
		print(sb, t, DateTime.HOUR_0, l).append(sep);
		print(sb, t, DateTime.MINUTE, l).append(sep);
		print(sb, t, DateTime.SECOND, l).append(' ');
		// this may be in wrong place for some locales
		StringBuilder tsb = new StringBuilder();
		print(tsb, t, DateTime.AM_PM, l);
		sb.append(tsb.toString().toUpperCase(l != null ? l : Locale.US));
		break;
	    }
	    case DateTime.DATE_TIME:    { // 'c' (Sat Nov 04 12:02:33 EST 1999)
		char sep = ' ';
		print(sb, t, DateTime.NAME_OF_DAY_ABBREV, l).append(sep);
		print(sb, t, DateTime.NAME_OF_MONTH_ABBREV, l).append(sep);
		print(sb, t, DateTime.DAY_OF_MONTH_0, l).append(sep);
		print(sb, t, DateTime.TIME, l).append(sep);
		print(sb, t, DateTime.ZONE, l).append(sep);
		print(sb, t, DateTime.YEAR_4, l);
		break;
	    }
	    case DateTime.DATE:            { // 'D' (mm/dd/yy)
		char sep = '/';
		print(sb, t, DateTime.MONTH, l).append(sep);
		print(sb, t, DateTime.DAY_OF_MONTH_0, l).append(sep);
		print(sb, t, DateTime.YEAR_2, l);
		break;
	    }
	    case DateTime.ISO_STANDARD_DATE: { // 'F' (%Y-%m-%d)
		char sep = '-';
		print(sb, t, DateTime.YEAR_4, l).append(sep);
		print(sb, t, DateTime.MONTH, l).append(sep);
		print(sb, t, DateTime.DAY_OF_MONTH_0, l);
		break;
	    }
	    default:
		assert false;
	    }
	    return sb;
	}

	// -- Methods to support throwing exceptions --

	private void failMismatch(Flags f, char c) {
	    String fs = f.toString();
	    throw new FormatFlagsConversionMismatchException(fs, c);
	}

	private void failConversion(char c, Object arg) {
	    throw new IllegalFormatConversionException(c, arg.getClass());
	}

	private char getZero(Locale l) {
	    if ((l != null) &&  !l.equals(locale())) {
		DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
		return dfs.getZeroDigit();
	    }
	    return zero;
	}

	private StringBuilder
	    localizedMagnitude(StringBuilder sb, long value, Flags f,
			       int width, Locale l)
	{
	    char[] va = Long.toString(value, 10).toCharArray();
	    return localizedMagnitude(sb, va, f, width, l);
	}

	private StringBuilder
	    localizedMagnitude(StringBuilder sb, char[] value, Flags f,
			       int width, Locale l)
	{
	    if (sb == null)
		sb = new StringBuilder();
	    int begin = sb.length();

	    char zero = getZero(l);

	    // determine localized grouping separator and size
	    char grpSep = '\0';
	    int  grpSize = -1;
	    char decSep = '\0';

	    int len = value.length;
	    int dot = len;
	    for (int j = 0; j < len; j++) {
		if (value[j] == '.') {
		    dot = j;
		    break;
		}
	    }

	    if (dot < len) {
		if (l == null || l.equals(Locale.US)) {
		    decSep  = '.';
		} else {
		    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
		    decSep  = dfs.getDecimalSeparator();
		}
	    }

	    if (f.contains(Flags.GROUP)) {
		if (l == null || l.equals(Locale.US)) {
		    grpSep = ',';
		    grpSize = 3;
		} else {
		    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
		    grpSep = dfs.getGroupingSeparator();
		    DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(l);
		    grpSize = df.getGroupingSize();
		}
	    }

	    // localize the digits inserting group separators as necessary
	    for (int j = 0; j < len; j++) {
		if (j == dot) {
		    sb.append(decSep);
		    // no more group separators after the decimal separator
		    grpSep = '\0';
		    continue;
		}

		char c = value[j];
		sb.append((char) ((c - '0') + zero));
		if (grpSep != '\0' && j != dot - 1 && ((dot - j) % grpSize == 1))
		    sb.append(grpSep);
	    }

	    // apply zero padding
	    len = sb.length();
	    if (width != -1 && f.contains(Flags.ZERO_PAD))
		for (int k = 0; k < width - len; k++)
		    sb.insert(begin, zero);

	    return sb;
	}
    }

    private static class Flags {
	private int flags;

	static final Flags NONE          = new Flags(0);      // ''

	// duplicate declarations from Formattable.java
	static final Flags LEFT_JUSTIFY  = new Flags(1<<0);   // '-'
	static final Flags UPPERCASE     = new Flags(1<<1);   // '^'
	static final Flags ALTERNATE     = new Flags(1<<2);   // '#'

	// numerics
        static final Flags PLUS          = new Flags(1<<3);   // '+'
        static final Flags LEADING_SPACE = new Flags(1<<4);   // ' '
        static final Flags ZERO_PAD      = new Flags(1<<5);   // '0'
        static final Flags GROUP         = new Flags(1<<6);   // ','
        static final Flags PARENTHESES   = new Flags(1<<7);   // '('

	// indexing
	static final Flags PREVIOUS      = new Flags(1<<8);   // '<'

	private Flags(int f) {
	    flags = f;
	}

	public int valueOf() {
	    return flags;
	}

 	public boolean contains(Flags f) {
	    return (flags & f.valueOf()) == f.valueOf();
	}

	public Flags dup() {
	    return new Flags(flags);
	}

	private Flags add(Flags f) {
	    flags |= f.valueOf();
	    return this;
 	}

	public Flags remove(Flags f) {
	    flags &= ~f.valueOf();
	    return this;
	}

	public static Flags parse(String s) {
 	    char[] ca = s.toCharArray();
	    Flags f = new Flags(0);
 	    for (int i = 0; i < ca.length; i++) {
 		Flags v = parse(ca[i]);
		if (f.contains(v))
 		    throw new DuplicateFormatFlagsException(v.toString());
		f.add(v);
 	    }
	    return f;
	}

	// parse those flags which may be provided by users
 	private static Flags parse(char c) {
	    switch (c) {
	    case '-': return LEFT_JUSTIFY;
	    case '#': return ALTERNATE;
	    case '+': return PLUS;
	    case ' ': return LEADING_SPACE;
	    case '0': return ZERO_PAD;
	    case ',': return GROUP;
	    case '(': return PARENTHESES;
	    case '<': return PREVIOUS;
	    default:
		throw new UnknownFormatFlagsException(String.valueOf(c));
	    }
	}

	// Returns a string representation of the current <tt>Flags</tt>.
  	public static String toString(Flags f) {
	    return f.toString();
	}

	public String toString() {
  	    StringBuilder sb = new StringBuilder();
	    if (contains(LEFT_JUSTIFY))  sb.append('-');
	    if (contains(UPPERCASE))     sb.append('^');
	    if (contains(ALTERNATE))     sb.append('#');
	    if (contains(PLUS))          sb.append('+');
	    if (contains(LEADING_SPACE)) sb.append(' ');
	    if (contains(ZERO_PAD))      sb.append('0');
	    if (contains(GROUP))         sb.append(',');
	    if (contains(PARENTHESES))   sb.append('(');
	    if (contains(PREVIOUS))      sb.append('<');
	    return sb.toString();
 	}
    }

    private static class Conversion {
        // Byte, Short, Integer, Long, BigInteger
        // (and associated primitives due to autoboxing)
	static final char DECIMAL_INTEGER     = 'd';
	static final char OCTAL_INTEGER       = 'o';
	static final char HEXADECIMAL_INTEGER = 'x';
	static final char HEXADECIMAL_INTEGER_UPPER = 'X';

        // Float, Double, BigDecimal
        // (and associated primitives due to autoboxing)
	static final char SCIENTIFIC          = 'e';
	static final char SCIENTIFIC_UPPER    = 'E';
	static final char GENERAL             = 'g';
	static final char GENERAL_UPPER       = 'G';
	static final char DECIMAL_FLOAT       = 'f';
	static final char HEXADECIMAL_FLOAT   = 'a';
	static final char HEXADECIMAL_FLOAT_UPPER = 'A';

        // Character, Byte, Short, Integer
        // (and associated primitives due to autoboxing)
	static final char CHARACTER           = 'c';
	static final char CHARACTER_UPPER     = 'C';

        // java.util.Date, java.util.Calendar, long
	static final char DATE_TIME           = 't';
	static final char DATE_TIME_UPPER     = 'T';

        // if (arg.TYPE != boolean) return boolean
        // if (arg != null) return true; else return false;
	static final char BOOLEAN             = 'b';
	static final char BOOLEAN_UPPER       = 'B';
        // if (arg instanceof Formattable) arg.formatTo()
        // else arg.toString();
	static final char STRING              = 's';
	static final char STRING_UPPER        = 'S';
        // arg.hashCode()
	static final char HASHCODE            = 'h';
	static final char HASHCODE_UPPER      = 'H';

	static final char LINE_SEPARATOR      = 'n';
	static final char PERCENT_SIGN        = '%';

	static boolean isValid(char c) {
	    return (isGeneral(c) || isInteger(c) || isFloat(c) || isText(c)
		    || c == 't' || isCharacter(c));
	}

	// Returns true iff the Conversion is applicable to all objects.
 	static boolean isGeneral(char c) {
 	    switch (c) {
 	    case BOOLEAN:
 	    case BOOLEAN_UPPER:
 	    case STRING:
 	    case STRING_UPPER:
 	    case HASHCODE:
 	    case HASHCODE_UPPER:
 		return true;
 	    default:
 		return false;
 	    }
 	}

	// Returns true iff the Conversion is applicable to character.
	static boolean isCharacter(char c) {
	    switch (c) {
	    case CHARACTER:
	    case CHARACTER_UPPER:
		return true;
	    default:
		return false;
	    }
	}

	// Returns true iff the Conversion is an integer type.
 	static boolean isInteger(char c) {
 	    switch (c) {
 	    case DECIMAL_INTEGER:
 	    case OCTAL_INTEGER:
 	    case HEXADECIMAL_INTEGER:
 	    case HEXADECIMAL_INTEGER_UPPER:
 		return true;
 	    default:
 		return false;
 	    }
 	}

	// Returns true iff the Conversion is a floating-point type.
 	static boolean isFloat(char c) {
 	    switch (c) {
 	    case SCIENTIFIC:
 	    case SCIENTIFIC_UPPER:
 	    case GENERAL:
 	    case GENERAL_UPPER:
 	    case DECIMAL_FLOAT:
 	    case HEXADECIMAL_FLOAT:
 	    case HEXADECIMAL_FLOAT_UPPER:
 		return true;
 	    default:
 		return false;
 	    }
 	}

	// Returns true iff the Conversion does not require an argument
	static boolean isText(char c) {
	    switch (c) {
	    case LINE_SEPARATOR:
	    case PERCENT_SIGN:
		return true;
	    default:
		return false;
	    }
	}
    }

    private static class DateTime {
        static final char HOUR_OF_DAY_0 = 'H'; // (00 - 23)
        static final char HOUR_0        = 'I'; // (01 - 12)
        static final char HOUR_OF_DAY   = 'k'; // (0 - 23) -- like H
        static final char HOUR          = 'l'; // (1 - 12) -- like I
        static final char MINUTE        = 'M'; // (00 - 59)
        static final char NANOSECOND    = 'N'; // (000000000 - 999999999)
        static final char MILLISECOND   = 'L'; // jdk, not in gnu (000 - 999)
        static final char MILLISECOND_SINCE_EPOCH = 'Q'; // (0 - 99...?)
        static final char AM_PM         = 'p'; // (am or pm)
        static final char SECONDS_SINCE_EPOCH = 's'; // (0 - 99...?)
        static final char SECOND        = 'S'; // (00 - 60 - leap second)
        static final char TIME          = 'T'; // (24 hour hh:mm:ss)
        static final char ZONE_NUMERIC  = 'z'; // (-1200 - +1200) - ls minus?
        static final char ZONE          = 'Z'; // (symbol)

        // Date
        static final char NAME_OF_DAY_ABBREV    = 'a'; // 'a'
        static final char NAME_OF_DAY           = 'A'; // 'A'
        static final char NAME_OF_MONTH_ABBREV  = 'b'; // 'b'
        static final char NAME_OF_MONTH         = 'B'; // 'B'
        static final char CENTURY               = 'C'; // (00 - 99)
        static final char DAY_OF_MONTH_0        = 'd'; // (01 - 31)
        static final char DAY_OF_MONTH          = 'e'; // (1 - 31) -- like d
// *    static final char ISO_WEEK_OF_YEAR_2    = 'g'; // cross %y %V
// *    static final char ISO_WEEK_OF_YEAR_4    = 'G'; // cross %Y %V
        static final char NAME_OF_MONTH_ABBREV_X  = 'h'; // -- same b
        static final char DAY_OF_YEAR           = 'j'; // (001 - 366)
	static final char MONTH                 = 'm'; // (01 - 12)
// *    static final char DAY_OF_WEEK_1         = 'u'; // (1 - 7) Monday
// *    static final char WEEK_OF_YEAR_SUNDAY   = 'U'; // (0 - 53) Sunday+
// *    static final char WEEK_OF_YEAR_MONDAY_01 = 'V'; // (01 - 53) Monday+
// *    static final char DAY_OF_WEEK_0         = 'w'; // (0 - 6) Sunday
// *    static final char WEEK_OF_YEAR_MONDAY   = 'W'; // (00 - 53) Monday
        static final char YEAR_2                = 'y'; // (00 - 99)
        static final char YEAR_4                = 'Y'; // (0000 - 9999)

	// Composites
        static final char TIME_12_HOUR  = 'r'; // (hh:mm:ss [AP]M)
        static final char TIME_24_HOUR  = 'R'; // (hh:mm same as %H:%M)
// *    static final char LOCALE_TIME   = 'X'; // (%H:%M:%S) - parse format?
        static final char DATE_TIME             = 'c';
                                            // (Sat Nov 04 12:02:33 EST 1999)
        static final char DATE                  = 'D'; // (mm/dd/yy)
       	static final char ISO_STANDARD_DATE     = 'F'; // (%Y-%m-%d)
// *    static final char LOCALE_DATE           = 'x'; // (mm/dd/yy)

	static boolean isValid(char c) {
	    switch (c) {
	    case HOUR_OF_DAY_0:
	    case HOUR_0:
	    case HOUR_OF_DAY:
	    case HOUR:
	    case MINUTE:
	    case NANOSECOND:
	    case MILLISECOND:
	    case MILLISECOND_SINCE_EPOCH:
	    case AM_PM:
	    case SECONDS_SINCE_EPOCH:
	    case SECOND:
	    case TIME:
	    case ZONE_NUMERIC:
	    case ZONE:

            // Date
	    case NAME_OF_DAY_ABBREV:
	    case NAME_OF_DAY:
	    case NAME_OF_MONTH_ABBREV:
	    case NAME_OF_MONTH:
	    case CENTURY:
	    case DAY_OF_MONTH_0:
	    case DAY_OF_MONTH:
// *        case ISO_WEEK_OF_YEAR_2:
// *        case ISO_WEEK_OF_YEAR_4:
	    case NAME_OF_MONTH_ABBREV_X:
	    case DAY_OF_YEAR:
	    case MONTH:
// *        case DAY_OF_WEEK_1:
// *        case WEEK_OF_YEAR_SUNDAY:
// *        case WEEK_OF_YEAR_MONDAY_01:
// *        case DAY_OF_WEEK_0:
// *        case WEEK_OF_YEAR_MONDAY:
	    case YEAR_2:
	    case YEAR_4:

	    // Composites
	    case TIME_12_HOUR:
	    case TIME_24_HOUR:
// *        case LOCALE_TIME:
	    case DATE_TIME:
	    case DATE:
	    case ISO_STANDARD_DATE:
// *        case LOCALE_DATE:
		return true;
	    default:
		return false;
	    }
	}
    }
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar