1/* 2 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23/** 24 * 25 * 26 * Check the consistency between the regression tests and the currency data in the JRE 27 */ 28 29import java.io.*; 30import java.lang.reflect.*; 31import java.security.*; 32import java.util.Currency; 33 34class CheckDataVersion { 35 static final String datafile = "tablea1.txt"; 36 static final String FILEVERSIONKEY = "FILEVERSION="; 37 static final String DATAVERSIONKEY = "DATAVERSION="; 38 static String fileVersion; 39 static String dataVersion; 40 static boolean checked = false; 41 42 static void check() { 43 if (!checked) { 44 try { 45 FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile)); 46 BufferedReader in = new BufferedReader(fr); 47 String line; 48 49 while ((line = in.readLine()) != null) { 50 if (line.startsWith(FILEVERSIONKEY)) { 51 fileVersion = line.substring(FILEVERSIONKEY.length()); 52 } 53 if (line.startsWith(DATAVERSIONKEY)) { 54 dataVersion = line.substring(DATAVERSIONKEY.length()); 55 } 56 if (fileVersion != null && dataVersion != null) { 57 break; 58 } 59 } 60 } catch (IOException ioe) { 61 throw new RuntimeException(ioe); 62 } 63 64 AccessController.doPrivileged(new PrivilegedAction<Object>() { 65 public Object run() { 66 try { 67 InputStream in = Currency.class.getModule().getResourceAsStream("java/util/currency.data"); 68 String sep = File.separator; 69 DataInputStream dis = new DataInputStream(in); 70 int magic = dis.readInt(); 71 if (magic != 0x43757244) { 72 throw new RuntimeException("The magic number in the JRE's currency data is incorrect. Expected: 0x43757244, Got: 0x"+magic); 73 } 74 int fileVerNumber = dis.readInt(); 75 int dataVerNumber = dis.readInt(); 76 if (Integer.parseInt(fileVersion) != fileVerNumber || 77 Integer.parseInt(dataVersion) != dataVerNumber) { 78 throw new RuntimeException("Test data and JRE's currency data are inconsistent. test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")"); 79 } 80System.out.println("test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")"); 81 } catch (IOException ioe) { 82 throw new RuntimeException(ioe); 83 } 84 return null; 85 } 86 }); 87 checked = true; 88 } 89 } 90} 91