Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Currency/CheckDataVersion.java
47178 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.*;3132class CheckDataVersion {33static final String datafile = "tablea1.txt";34static final String FILEVERSIONKEY = "FILEVERSION=";35static final String DATAVERSIONKEY = "DATAVERSION=";36static String fileVersion;37static String dataVersion;38static boolean checked = false;3940static void check() {41if (!checked) {42try {43FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile));44BufferedReader in = new BufferedReader(fr);45String line;4647while ((line = in.readLine()) != null) {48if (line.startsWith(FILEVERSIONKEY)) {49fileVersion = line.substring(FILEVERSIONKEY.length());50}51if (line.startsWith(DATAVERSIONKEY)) {52dataVersion = line.substring(DATAVERSIONKEY.length());53}54if (fileVersion != null && dataVersion != null) {55break;56}57}58} catch (IOException ioe) {59throw new RuntimeException(ioe);60}6162AccessController.doPrivileged(new PrivilegedAction<Object>() {63public Object run() {64try {65String sep = File.separator;66DataInputStream dis = new DataInputStream(new FileInputStream(System.getProperty("java.home")+sep+"lib"+sep+"currency.data"));67int magic = dis.readInt();68if (magic != 0x43757244) {69throw new RuntimeException("The magic number in the JRE's currency data is incorrect. Expected: 0x43757244, Got: 0x"+magic);70}71int fileVerNumber = dis.readInt();72int dataVerNumber = dis.readInt();73if (Integer.parseInt(fileVersion) != fileVerNumber ||74Integer.parseInt(dataVersion) != dataVerNumber) {75throw new RuntimeException("Test data and JRE's currency data are inconsistent. test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")");76}77System.out.println("test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")");78} catch (IOException ioe) {79throw new RuntimeException(ioe);80}81return null;82}83});84checked = true;85}86}87}888990