1/* 2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 6350021 27 * @summary Consistency checks when input buffer contains JISX0212 characters 28 * @author Martin Buchholz 29 */ 30 31import java.io.*; 32import java.util.*; 33import java.nio.*; 34import java.nio.charset.*; 35 36public class EucJpLinux0212 { 37 private static void equal(CharBuffer b1, CharBuffer b2) { 38 equal(b1.position(), b2.position()); 39 equal(b1.limit(), b2.limit()); 40 System.out.printf("positions=%d %d%n", b1.position(), b2.position()); 41 System.out.printf("limits=%d %d%n", b1.limit(), b2.limit()); 42 for (int i = b1.position(); i < b1.limit(); i++) 43 equal((int)b1.get(i), (int)b2.get(i)); 44 } 45 46 private static void realMain(String[] args) throws Throwable { 47 List<ByteBuffer> bbs = Arrays.asList( 48 ByteBuffer.allocate(10), 49 ByteBuffer.allocateDirect(10)); 50 List<CharBuffer> cbs = new ArrayList<CharBuffer>(); 51 52 for (ByteBuffer bb : bbs) { 53 bb.put(new byte[]{ (byte)0x8f, 0x01, 0x02, 54 (byte)0xa1, (byte)0xc0, 55 0x02, 0x03}); 56 bb.flip(); 57 CharsetDecoder decoder = Charset.forName("EUC_JP_LINUX").newDecoder(); 58 decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); 59 CharBuffer cb = decoder.decode(bb); 60 cbs.add(cb); 61 } 62 equal(cbs.get(0), cbs.get(1)); 63 } 64 65 //--------------------- Infrastructure --------------------------- 66 static volatile int passed = 0, failed = 0; 67 static void pass() {passed++;} 68 static void fail() {failed++; Thread.dumpStack();} 69 static void fail(String msg) {System.out.println(msg); fail();} 70 static void unexpected(Throwable t) {failed++; t.printStackTrace();} 71 static void check(boolean cond) {if (cond) pass(); else fail();} 72 static void equal(Object x, Object y) { 73 if (x == null ? y == null : x.equals(y)) pass(); 74 else fail(x + " not equal to " + y);} 75 public static void main(String[] args) throws Throwable { 76 try {realMain(args);} catch (Throwable t) {unexpected(t);} 77 System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); 78 if (failed > 0) throw new AssertionError("Some tests failed");} 79} 80