Path: blob/master/test/jdk/sun/nio/cs/BufferUnderflowEUCTWTest.java
41149 views
/*1* Copyright (c) 2008, 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/* @test24@bug 483415425@summary Decode a file using EUC-TW, test for decode errors26*/2728/*29* Tests for decode errors in NIO EUC-TW decoder. 4734607 details30* decoding errors which occur when the input file > 8k in size31* and contains numerous US-ASCII range chars32*/3334import java.io.*;3536public class BufferUnderflowEUCTWTest {37private static int BUFFERSIZE = 8194;3839public static void main (String[] args) throws Exception {40int i = 0;41byte[] b = new byte[BUFFERSIZE];4243for (; i < BUFFERSIZE - 4; i++) // pad with zeroes44b[i] = 0;4546// Overspill a valid EUC-TW 4 byte sequence between 247// successive input buffers.48b[i++] = (byte)0x8E;49b[i++] = (byte)0xA2;50b[i++] = (byte)0xA1;51b[i++] = (byte)0xA6;5253ByteArrayInputStream r = new ByteArrayInputStream(b);5455try {56InputStreamReader isr=new InputStreamReader(r, "EUC-TW");57char[] cc = new char[BUFFERSIZE];58int cx = isr.read(cc);59} catch (ArrayIndexOutOfBoundsException e) {60throw new Exception("Array Index error: bug 4834154");61}62}63}646566