Path: blob/master/test/jdk/tools/launcher/DefaultLocaleTest.java
41144 views
/*1* Copyright (c) 2004, 2012, 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*/2223import java.io.BufferedReader;24import java.io.BufferedWriter;25import java.io.File;26import java.io.IOException;27import java.nio.charset.Charset;2829import static java.nio.file.Files.*;30import static java.nio.file.StandardOpenOption.*;3132public class DefaultLocaleTest {3334static final String setting =35"language:" + System.getProperty("user.language") + "_" +36"country:" + System.getProperty("user.country") + "_" +37"encoding:" + System.getProperty("file.encoding") + "_" +38"jnuEncoding:"+ System.getProperty("sun.jnu.encoding");3940public static void main(String[] args) throws IOException {41if (args != null && args.length > 1) {42File f = new File(args[1]);43switch (args[0]) {44case "-r":45System.out.println("reading file: " + args[1]);46String str = null;47try (BufferedReader in = newBufferedReader(f.toPath(),48Charset.defaultCharset())) {49str = in.readLine().trim();50}51if (setting.equals(str)) {52System.out.println("Compared ok");53} else {54System.out.println("Compare fails");55System.out.println("EXPECTED: " + setting);56System.out.println("OBTAINED: " + str);57throw new RuntimeException("Test fails: compare failed");58}59break;60case "-w":61System.out.println("writing file: " + args[1]);62try (BufferedWriter out = newBufferedWriter(f.toPath(),63Charset.defaultCharset(), CREATE_NEW)) {64out.write(setting);65}66break;67default:68throw new RuntimeException("ERROR: invalid arguments");69}70} else {71throw new RuntimeException("ERROR: invalid arguments");72}73}74}757677