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