Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/BreakIterator/NewVSOld_th_TH.java
38813 views
/*1* Copyright (c) 2000, 2016, 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*/2223/*24@test25@summary test Comparison of New Collators against Old Collators in the en_US locale26*/2728import java.io.*;29import java.util.Enumeration;30import java.util.Vector;31import java.util.Locale;32import java.text.BreakIterator;33import java.lang.Math;3435public class NewVSOld_th_TH {36public static void main(String args[]) throws FileNotFoundException,37UnsupportedEncodingException,38IOException {39final String ENCODING = "UTF-8";40final Locale THAI_LOCALE = new Locale("th", "TH");4142String rawFileName = "test_th_TH.txt";43String oldFileName = "broken_th_TH.txt";44StringBuilder rawText = new StringBuilder();45StringBuilder oldText = new StringBuilder();46StringBuilder cookedText = new StringBuilder();4748File f;49f = new File(System.getProperty("test.src", "."), rawFileName);5051try (InputStreamReader rawReader =52new InputStreamReader(new FileInputStream(f), ENCODING)) {53int c;54while ((c = rawReader.read()) != -1) {55rawText.append((char) c);56}57}5859f = new File(System.getProperty("test.src", "."), oldFileName);60try (InputStreamReader oldReader =61new InputStreamReader(new FileInputStream(f), ENCODING)) {62int c;63while ((c = oldReader.read()) != -1) {64oldText.append((char) c);65}66}6768BreakIterator breakIterator = BreakIterator.getWordInstance(THAI_LOCALE);69breakIterator.setText(rawText.toString());7071int start = breakIterator.first();72for (int end = breakIterator.next();73end != BreakIterator.DONE;74start = end, end = breakIterator.next()) {75cookedText.append(rawText.substring(start, end));76cookedText.append("\n");77}7879String cooked = cookedText.toString();80String old = oldText.toString();81if (cooked.compareTo(old) != 0) {82throw new RuntimeException("Text not broken the same as with the old BreakIterators");83}84}85}868788