Path: blob/master/test/jdk/java/text/BreakIterator/NewVSOld_th_TH.java
41152 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* @modules jdk.localedata27*/2829import java.io.*;30import java.util.Enumeration;31import java.util.Vector;32import java.util.Locale;33import java.text.BreakIterator;34import java.lang.Math;3536public class NewVSOld_th_TH {37public static void main(String args[]) throws FileNotFoundException,38UnsupportedEncodingException,39IOException {40final String ENCODING = "UTF-8";41final Locale THAI_LOCALE = new Locale("th", "TH");4243String rawFileName = "test_th_TH.txt";44String oldFileName = "broken_th_TH.txt";45StringBuilder rawText = new StringBuilder();46StringBuilder oldText = new StringBuilder();47StringBuilder cookedText = new StringBuilder();4849File f;50f = new File(System.getProperty("test.src", "."), rawFileName);5152try (InputStreamReader rawReader =53new InputStreamReader(new FileInputStream(f), ENCODING)) {54int c;55while ((c = rawReader.read()) != -1) {56rawText.append((char) c);57}58}5960f = new File(System.getProperty("test.src", "."), oldFileName);61try (InputStreamReader oldReader =62new InputStreamReader(new FileInputStream(f), ENCODING)) {63int c;64while ((c = oldReader.read()) != -1) {65oldText.append((char) c);66}67}6869BreakIterator breakIterator = BreakIterator.getWordInstance(THAI_LOCALE);70breakIterator.setText(rawText.toString());7172int start = breakIterator.first();73for (int end = breakIterator.next();74end != BreakIterator.DONE;75start = end, end = breakIterator.next()) {76cookedText.append(rawText.substring(start, end));77cookedText.append("\n");78}7980String cooked = cookedText.toString();81String old = oldText.toString();82if (cooked.compareTo(old) != 0) {83throw new RuntimeException("Text not broken the same as with the old BreakIterators");84}85}86}878889