make/jdk/src/classes/build/tools/generatecurrencydata/GenerateCurrencyData.java
author erikj
Wed, 02 Jan 2019 12:59:26 +0100
changeset 53110 50677f43ac3d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8215445: Enable building for Windows in WSL Reviewed-by: ihse Contributed-by: andrewluotechnologies@outlook.com, erik.joelsson@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
     2
 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package build.tools.generatecurrencydata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.DataOutputStream;
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    31
import java.io.FileInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.FileOutputStream;
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
    33
import java.io.InputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.text.SimpleDateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Locale;
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    38
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.TimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Reads currency data in properties format from the file specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * command line and generates a binary data file as specified in the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Output of this tool is a binary file that contains the data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     - magic number (int): always 0x43757244 ('CurD')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     - formatVersion (int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *     - dataVersion (int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     - mainTable (int[26*26])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *     - specialCaseCount (int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     - specialCaseCutOverTimes (long[specialCaseCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *     - specialCaseOldCurrencies (String[specialCaseCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *     - specialCaseNewCurrencies (String[specialCaseCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *     - specialCaseOldCurrenciesDefaultFractionDigits (int[specialCaseCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *     - specialCaseNewCurrenciesDefaultFractionDigits (int[specialCaseCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *     - specialCaseOldCurrenciesNumericCode (int[specialCaseCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     - specialCaseNewCurrenciesNumericCode (int[specialCaseCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *     - otherCurrenciesCount (int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *     - otherCurrencies (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *     - otherCurrenciesDefaultFractionDigits (int[otherCurrenciesCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *     - otherCurrenciesNumericCode (int[otherCurrenciesCount])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * See CurrencyData.properties for the input format description and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Currency.java for the format descriptions of the generated tables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public class GenerateCurrencyData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static DataOutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // input data: currency data obtained from properties on input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static Properties currencyData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static String formatVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static String dataVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static String validCurrencyCodes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // handy constants - must match definitions in java.util.Currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // magic number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final int MAGIC_NUMBER = 0x43757244;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // number of characters from A to Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final int A_TO_Z = ('Z' - 'A') + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // entry for invalid country codes
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    85
    private static final int INVALID_COUNTRY_ENTRY = 0x0000007F;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // entry for countries without currency
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    87
    private static final int COUNTRY_WITHOUT_CURRENCY_ENTRY = 0x00000200;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // mask for simple case country entries
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    89
    private static final int SIMPLE_CASE_COUNTRY_MASK = 0x00000000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // mask for simple case country entry final character
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    91
    private static final int SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK = 0x0000001F;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // mask for simple case country entry default currency digits
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    93
    private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK = 0x000001E0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // shift count for simple case country entry default currency digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT = 5;
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    96
    // maximum number for simple case country entry default currency digits
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    97
    private static final int SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS = 9;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // mask for special case country entries
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
    99
    private static final int SPECIAL_CASE_COUNTRY_MASK = 0x00000200;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // mask for special case country index
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   101
    private static final int SPECIAL_CASE_COUNTRY_INDEX_MASK = 0x0000001F;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // delta from entry index component in main table to index into special case tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static final int SPECIAL_CASE_COUNTRY_INDEX_DELTA = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // mask for distinguishing simple and special case countries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static final int COUNTRY_TYPE_MASK = SIMPLE_CASE_COUNTRY_MASK | SPECIAL_CASE_COUNTRY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // mask for the numeric code of the currency
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   107
    private static final int NUMERIC_CODE_MASK = 0x000FFC00;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // shift count for the numeric code of the currency
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   109
    private static final int NUMERIC_CODE_SHIFT = 10;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // generated data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static int[] mainTable = new int[A_TO_Z * A_TO_Z];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static final int maxSpecialCases = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static int specialCaseCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static long[] specialCaseCutOverTimes = new long[maxSpecialCases];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private static String[] specialCaseOldCurrencies = new String[maxSpecialCases];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static String[] specialCaseNewCurrencies = new String[maxSpecialCases];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static int[] specialCaseOldCurrenciesDefaultFractionDigits = new int[maxSpecialCases];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static int[] specialCaseNewCurrenciesDefaultFractionDigits = new int[maxSpecialCases];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static int[] specialCaseOldCurrenciesNumericCode = new int[maxSpecialCases];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static int[] specialCaseNewCurrenciesNumericCode = new int[maxSpecialCases];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   124
    private static final int maxOtherCurrencies = 128;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static int otherCurrenciesCount = 0;
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   126
    private static String[] otherCurrencies = new String[maxOtherCurrencies];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static int[] otherCurrenciesDefaultFractionDigits = new int[maxOtherCurrencies];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static int[] otherCurrenciesNumericCode= new int[maxOtherCurrencies];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    // date format for parsing cut-over times
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private static SimpleDateFormat format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   133
    // Minor Units
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   134
    private static String[] currenciesWithDefinedMinorUnitDecimals =
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   135
        new String[SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS + 1];
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   136
    private static String currenciesWithMinorUnitsUndefined;
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   137
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public static void main(String[] args) {
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   139
        InputStream in = System.in;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // Look for "-o outputfilename" option
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   141
        for (int n = 0; n < args.length; ++n) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   142
            if (args[n].equals("-o")) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   143
                ++n;
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   144
                if (n >= args.length) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   145
                    System.err.println("Error: Invalid argument format");
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   146
                    System.exit(1);
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   147
                }
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   148
                try {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   149
                    out = new DataOutputStream(new FileOutputStream(args[n]));
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   150
                } catch ( FileNotFoundException e ) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   151
                    System.err.println("Error: " + e.getMessage());
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   152
                    e.printStackTrace(System.err);
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   153
                    System.exit(1);
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   154
                }
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   155
            } else if (args[n].equals("-i")) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   156
                ++n;
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   157
                if (n >= args.length) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   158
                    System.err.println("Error: Invalid argument format");
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   159
                    System.exit(1);
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   160
                }
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   161
                try {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   162
                    in = new FileInputStream(args[n]);
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   163
                } catch ( FileNotFoundException e ) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   164
                    System.err.println("Error: " + e.getMessage());
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   165
                    e.printStackTrace(System.err);
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   166
                    System.exit(1);
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   167
                }
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   168
            } else {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   169
                System.err.println("Error: Invalid argument " + args[n]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   172
        }
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   173
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   174
        if (out == null) {
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   175
            System.err.println("Error: Invalid argument format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        format.setLenient(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        try {
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   184
            readInput(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            buildMainAndSpecialCaseTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            buildOtherTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            writeOutput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            System.err.println("Error: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            e.printStackTrace(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   197
    private static void readInput(InputStream in) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        currencyData = new Properties();
53110
50677f43ac3d 8215445: Enable building for Windows in WSL
erikj
parents: 47216
diff changeset
   199
        currencyData.load(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // initialize other lookup strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        formatVersion = (String) currencyData.get("formatVersion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        dataVersion = (String) currencyData.get("dataVersion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        validCurrencyCodes = (String) currencyData.get("all");
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   205
        for (int i = 0; i <= SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS; i++) {
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   206
            currenciesWithDefinedMinorUnitDecimals[i]
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   207
                = (String) currencyData.get("minor"+i);
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   208
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        currenciesWithMinorUnitsUndefined  = (String) currencyData.get("minorUndefined");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (formatVersion == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                dataVersion == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                validCurrencyCodes == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                currenciesWithMinorUnitsUndefined == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            throw new NullPointerException("not all required data is defined in input");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    private static void buildMainAndSpecialCaseTables() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        for (int first = 0; first < A_TO_Z; first++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            for (int second = 0; second < A_TO_Z; second++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                char firstChar = (char) ('A' + first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                char secondChar = (char) ('A' + second);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                String countryCode = (new StringBuffer()).append(firstChar).append(secondChar).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                String currencyInfo = (String) currencyData.get(countryCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                int tableEntry = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                if (currencyInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    // no entry -> must be invalid ISO 3166 country code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    tableEntry = INVALID_COUNTRY_ENTRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    int length = currencyInfo.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    if (length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        // special case: country without currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                       tableEntry = COUNTRY_WITHOUT_CURRENCY_ENTRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    } else if (length == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                        // valid currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        if (currencyInfo.charAt(0) == firstChar && currencyInfo.charAt(1) == secondChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                            checkCurrencyCode(currencyInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                            int digits = getDefaultFractionDigits(currencyInfo);
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   239
                            if (digits < 0 || digits > SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                throw new RuntimeException("fraction digits out of range for " + currencyInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                            int numericCode= getNumericCode(currencyInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                            if (numericCode < 0 || numericCode >= 1000 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                throw new RuntimeException("numeric code out of range for " + currencyInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            tableEntry = SIMPLE_CASE_COUNTRY_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                    | (currencyInfo.charAt(2) - 'A')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                    | (digits << SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                    | (numericCode << NUMERIC_CODE_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                            tableEntry = SPECIAL_CASE_COUNTRY_MASK | (makeSpecialCaseEntry(currencyInfo) + SPECIAL_CASE_COUNTRY_INDEX_DELTA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        tableEntry = SPECIAL_CASE_COUNTRY_MASK | (makeSpecialCaseEntry(currencyInfo) + SPECIAL_CASE_COUNTRY_INDEX_DELTA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                mainTable[first * A_TO_Z + second] = tableEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private static int getDefaultFractionDigits(String currencyCode) {
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   263
        for (int i = 0; i <= SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS; i++) {
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   264
            if (Objects.nonNull(currenciesWithDefinedMinorUnitDecimals[i]) &&
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   265
                currenciesWithDefinedMinorUnitDecimals[i].indexOf(currencyCode) != -1) {
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   266
                return i;
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   267
            }
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   268
        }
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   269
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 23010
diff changeset
   270
        if (currenciesWithMinorUnitsUndefined.indexOf(currencyCode) != -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static int getNumericCode(String currencyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        int index = validCurrencyCodes.indexOf(currencyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        String numericCode = validCurrencyCodes.substring(index + 3, index + 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return Integer.parseInt(numericCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   283
    static HashMap<String, Integer> specialCaseMap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private static int makeSpecialCaseEntry(String currencyInfo) throws Exception {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   286
        Integer oldEntry = specialCaseMap.get(currencyInfo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (oldEntry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            return oldEntry.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (specialCaseCount == maxSpecialCases) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            throw new RuntimeException("too many special cases");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (currencyInfo.length() == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            checkCurrencyCode(currencyInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            specialCaseCutOverTimes[specialCaseCount] = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            specialCaseOldCurrencies[specialCaseCount] = currencyInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            specialCaseOldCurrenciesDefaultFractionDigits[specialCaseCount] = getDefaultFractionDigits(currencyInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            specialCaseOldCurrenciesNumericCode[specialCaseCount] = getNumericCode(currencyInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            specialCaseNewCurrencies[specialCaseCount] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            specialCaseNewCurrenciesDefaultFractionDigits[specialCaseCount] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            specialCaseNewCurrenciesNumericCode[specialCaseCount] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            int length = currencyInfo.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (currencyInfo.charAt(3) != ';' ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    currencyInfo.charAt(length - 4) != ';') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                throw new RuntimeException("invalid currency info: " + currencyInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            String oldCurrency = currencyInfo.substring(0, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            String newCurrency = currencyInfo.substring(length - 3, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            checkCurrencyCode(oldCurrency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            checkCurrencyCode(newCurrency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            String timeString = currencyInfo.substring(4, length - 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            long time = format.parse(timeString).getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if (Math.abs(time - System.currentTimeMillis()) > ((long) 10) * 365 * 24 * 60 * 60 * 1000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                throw new RuntimeException("time is more than 10 years from present: " + time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            specialCaseCutOverTimes[specialCaseCount] = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            specialCaseOldCurrencies[specialCaseCount] = oldCurrency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            specialCaseOldCurrenciesDefaultFractionDigits[specialCaseCount] = getDefaultFractionDigits(oldCurrency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            specialCaseOldCurrenciesNumericCode[specialCaseCount] = getNumericCode(oldCurrency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            specialCaseNewCurrencies[specialCaseCount] = newCurrency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            specialCaseNewCurrenciesDefaultFractionDigits[specialCaseCount] = getDefaultFractionDigits(newCurrency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            specialCaseNewCurrenciesNumericCode[specialCaseCount] = getNumericCode(newCurrency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        specialCaseMap.put(currencyInfo, new Integer(specialCaseCount));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return specialCaseCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    private static void buildOtherTables() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (validCurrencyCodes.length() % 7 != 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            throw new RuntimeException("\"all\" entry has incorrect size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        for (int i = 0; i < (validCurrencyCodes.length() + 1) / 7; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (i > 0 && validCurrencyCodes.charAt(i * 7 - 1) != '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                throw new RuntimeException("incorrect separator in \"all\" entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            String currencyCode = validCurrencyCodes.substring(i * 7, i * 7 + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            int numericCode = Integer.parseInt(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                validCurrencyCodes.substring(i * 7 + 3, i * 7 + 6));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            checkCurrencyCode(currencyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            int tableEntry = mainTable[(currencyCode.charAt(0) - 'A') * A_TO_Z + (currencyCode.charAt(1) - 'A')];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            if (tableEntry == INVALID_COUNTRY_ENTRY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    (tableEntry & SPECIAL_CASE_COUNTRY_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    (tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) != (currencyCode.charAt(2) - 'A')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                if (otherCurrenciesCount == maxOtherCurrencies) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    throw new RuntimeException("too many other currencies");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                }
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   348
                otherCurrencies[otherCurrenciesCount] = currencyCode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                otherCurrenciesDefaultFractionDigits[otherCurrenciesCount] = getDefaultFractionDigits(currencyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                otherCurrenciesNumericCode[otherCurrenciesCount] = getNumericCode(currencyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                otherCurrenciesCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    private static void checkCurrencyCode(String currencyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (currencyCode.length() != 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            throw new RuntimeException("illegal length for currency code: " + currencyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            char aChar = currencyCode.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            if ((aChar < 'A' || aChar > 'Z') && !currencyCode.equals("XB5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                throw new RuntimeException("currency code contains illegal character: " + currencyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (validCurrencyCodes.indexOf(currencyCode) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            throw new RuntimeException("currency code not listed as valid: " + currencyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private static void writeOutput() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        out.writeInt(MAGIC_NUMBER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        out.writeInt(Integer.parseInt(formatVersion));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        out.writeInt(Integer.parseInt(dataVersion));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        writeIntArray(mainTable, mainTable.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        out.writeInt(specialCaseCount);
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   377
        writeSpecialCaseEntries();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        out.writeInt(otherCurrenciesCount);
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   379
        writeOtherCurrencies();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    private static void writeIntArray(int[] ia, int count) throws IOException {
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   383
        for (int i = 0; i < count; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            out.writeInt(ia[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   388
    private static void writeSpecialCaseEntries() throws IOException {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   389
        for (int index = 0; index < specialCaseCount; index++) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   390
            out.writeLong(specialCaseCutOverTimes[index]);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   391
            String str = (specialCaseOldCurrencies[index] != null)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   392
                    ? specialCaseOldCurrencies[index] : "";
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   393
            out.writeUTF(str);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   394
            str = (specialCaseNewCurrencies[index] != null)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   395
                    ? specialCaseNewCurrencies[index] : "";
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   396
            out.writeUTF(str);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   397
            out.writeInt(specialCaseOldCurrenciesDefaultFractionDigits[index]);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   398
            out.writeInt(specialCaseNewCurrenciesDefaultFractionDigits[index]);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   399
            out.writeInt(specialCaseOldCurrenciesNumericCode[index]);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   400
            out.writeInt(specialCaseNewCurrenciesNumericCode[index]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   404
    private static void writeOtherCurrencies() throws IOException {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   405
        for (int index = 0; index < otherCurrenciesCount; index++) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   406
            String str = (otherCurrencies[index] != null)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   407
                    ? otherCurrencies[index] : "";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            out.writeUTF(str);
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   409
            out.writeInt(otherCurrenciesDefaultFractionDigits[index]);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   410
            out.writeInt(otherCurrenciesNumericCode[index]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 29524
diff changeset
   413
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
}