Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/charset/coders/ResetISO2022JP.java
38828 views
/*1* Copyright (c) 2010, 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 622651025@summary Check that ISO-2022-JP's encoder correctly resets to ASCII mode26@author Martin Buchholz27*/2829import java.nio.*;30import java.nio.charset.*;3132public class ResetISO2022JP {3334public static void main(String[] args) throws Exception {35if (! (encode(true).equals(encode(false))))36throw new Exception("Mismatch!");37}3839static String encode(boolean reuseEncoder) {40String s = "\u3042\u3043\u3044";4142CharsetEncoder e = Charset.forName("ISO-2022-JP").newEncoder();4344if (reuseEncoder) {45// I'm turning japanese. Yes I'm turning japanese. Yes I think so!46e.encode(CharBuffer.wrap(s), ByteBuffer.allocate(64), true);4748// Should put encoder back into ASCII mode49e.reset();50}5152ByteBuffer bb = ByteBuffer.allocate(64);53e.encode(CharBuffer.wrap(s), bb, true);54e.flush(bb);55bb.flip();56StringBuilder sb = new StringBuilder();57for (int i = 0; i < bb.limit(); i++)58sb.append(String.format("%02x ", bb.get(i)));59System.out.println(sb);60return sb.toString();61}62}636465