26 package build.tools.generatecurrencydata; |
26 package build.tools.generatecurrencydata; |
27 |
27 |
28 import java.io.IOException; |
28 import java.io.IOException; |
29 import java.io.FileNotFoundException; |
29 import java.io.FileNotFoundException; |
30 import java.io.DataOutputStream; |
30 import java.io.DataOutputStream; |
|
31 import java.io.FileInputStream; |
31 import java.io.FileOutputStream; |
32 import java.io.FileOutputStream; |
|
33 import java.io.InputStream; |
32 import java.text.SimpleDateFormat; |
34 import java.text.SimpleDateFormat; |
33 import java.util.Date; |
35 import java.util.Date; |
34 import java.util.HashMap; |
36 import java.util.HashMap; |
35 import java.util.Locale; |
37 import java.util.Locale; |
36 import java.util.Objects; |
38 import java.util.Objects; |
132 private static String[] currenciesWithDefinedMinorUnitDecimals = |
134 private static String[] currenciesWithDefinedMinorUnitDecimals = |
133 new String[SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS + 1]; |
135 new String[SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS + 1]; |
134 private static String currenciesWithMinorUnitsUndefined; |
136 private static String currenciesWithMinorUnitsUndefined; |
135 |
137 |
136 public static void main(String[] args) { |
138 public static void main(String[] args) { |
137 |
139 InputStream in = System.in; |
138 // Look for "-o outputfilename" option |
140 // Look for "-o outputfilename" option |
139 if ( args.length == 2 && args[0].equals("-o") ) { |
141 for (int n = 0; n < args.length; ++n) { |
140 try { |
142 if (args[n].equals("-o")) { |
141 out = new DataOutputStream(new FileOutputStream(args[1])); |
143 ++n; |
142 } catch ( FileNotFoundException e ) { |
144 if (n >= args.length) { |
143 System.err.println("Error: " + e.getMessage()); |
145 System.err.println("Error: Invalid argument format"); |
144 e.printStackTrace(System.err); |
146 System.exit(1); |
|
147 } |
|
148 try { |
|
149 out = new DataOutputStream(new FileOutputStream(args[n])); |
|
150 } catch ( FileNotFoundException e ) { |
|
151 System.err.println("Error: " + e.getMessage()); |
|
152 e.printStackTrace(System.err); |
|
153 System.exit(1); |
|
154 } |
|
155 } else if (args[n].equals("-i")) { |
|
156 ++n; |
|
157 if (n >= args.length) { |
|
158 System.err.println("Error: Invalid argument format"); |
|
159 System.exit(1); |
|
160 } |
|
161 try { |
|
162 in = new FileInputStream(args[n]); |
|
163 } catch ( FileNotFoundException e ) { |
|
164 System.err.println("Error: " + e.getMessage()); |
|
165 e.printStackTrace(System.err); |
|
166 System.exit(1); |
|
167 } |
|
168 } else { |
|
169 System.err.println("Error: Invalid argument " + args[n]); |
145 System.exit(1); |
170 System.exit(1); |
146 } |
171 } |
147 } else { |
172 } |
148 System.err.println("Error: Illegal arg count"); |
173 |
|
174 if (out == null) { |
|
175 System.err.println("Error: Invalid argument format"); |
149 System.exit(1); |
176 System.exit(1); |
150 } |
177 } |
151 |
178 |
152 format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US); |
179 format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US); |
153 format.setTimeZone(TimeZone.getTimeZone("GMT")); |
180 format.setTimeZone(TimeZone.getTimeZone("GMT")); |
154 format.setLenient(false); |
181 format.setLenient(false); |
155 |
182 |
156 try { |
183 try { |
157 readInput(); |
184 readInput(in); |
158 buildMainAndSpecialCaseTables(); |
185 buildMainAndSpecialCaseTables(); |
159 buildOtherTables(); |
186 buildOtherTables(); |
160 writeOutput(); |
187 writeOutput(); |
161 out.flush(); |
188 out.flush(); |
162 out.close(); |
189 out.close(); |
165 e.printStackTrace(System.err); |
192 e.printStackTrace(System.err); |
166 System.exit(1); |
193 System.exit(1); |
167 } |
194 } |
168 } |
195 } |
169 |
196 |
170 private static void readInput() throws IOException { |
197 private static void readInput(InputStream in) throws IOException { |
171 currencyData = new Properties(); |
198 currencyData = new Properties(); |
172 currencyData.load(System.in); |
199 currencyData.load(in); |
173 |
200 |
174 // initialize other lookup strings |
201 // initialize other lookup strings |
175 formatVersion = (String) currencyData.get("formatVersion"); |
202 formatVersion = (String) currencyData.get("formatVersion"); |
176 dataVersion = (String) currencyData.get("dataVersion"); |
203 dataVersion = (String) currencyData.get("dataVersion"); |
177 validCurrencyCodes = (String) currencyData.get("all"); |
204 validCurrencyCodes = (String) currencyData.get("all"); |