Path: blob/master/test/jdk/sun/nio/cs/EUCTWBufferBoundaryDecodeTest.java
41149 views
/*1* Copyright (c) 2018, 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* @bug 4734607 4767225 486361326* @summary Decode a file using EUC-TW, test for decode errors27* @modules jdk.charsets28* @run main EUCTWBufferBoundaryDecodeTest29*/30import java.io.BufferedReader;31import java.io.BufferedWriter;32import java.io.ByteArrayOutputStream;33import java.io.File;34import java.io.FileInputStream;35import java.io.InputStreamReader;36import java.io.OutputStreamWriter;3738/*39* Tests for decode errors in NIO EUC-TW decoder. 4734607 details40* decoding errors which occur when the input file > 8k in size41* and contains numerous US-ASCII range chars42*/43public class EUCTWBufferBoundaryDecodeTest {4445public static void main(String[] args) throws Exception {46final String inputFileName47= System.getProperty("os.name").startsWith("Windows")48? "tradChinese.win.po"49: "tradChinese.po";5051ByteArrayOutputStream bos = new ByteArrayOutputStream(1024 * 120);5253File inputFile = new File(System.getProperty("test.src"), inputFileName);54FileInputStream fis = new FileInputStream(inputFile);5556// Decode the EUC_TW source file, re-encode it -- (roundtrip)57// input and output files ought to be byte for byte identical58BufferedReader bin59= new BufferedReader(new InputStreamReader(fis, "EUC_TW"));60BufferedWriter bout61= new BufferedWriter(new OutputStreamWriter(bos, "EUC-TW"));6263String line = bin.readLine();6465while (line != null) {66bout.write(line);67bout.newLine();68line = bin.readLine();69}7071bout.close();72bin.close();7374// Compare the output with the expected output byte by byte75byte[] outputBytes = bos.toByteArray();76int i = 0;77FileInputStream fi = new FileInputStream(inputFile);7879while (i < outputBytes.length) {80byte b = (byte) fi.read();81if (b != outputBytes[i++]) {82throw new Exception("bug 4734607: test failed");83}84}85fi.close();86}87}888990