--- /dev/null 2011-11-08 10:18:28.885878122 -0800 +++ new/test/java/io/OutputStreamWriter/Flush.java 2012-02-08 17:38:47.000000000 -0800 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6995537 + * @summary check OutputStreamWriter and PrintStream flush the underlying + * charset encoder correctly + */ + +import java.io.*; +import java.util.*; + +public class Flush { + public static void main(String args[]) throws Exception { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + String str = "\u6700"; + byte[] bytes = new byte[] { (byte)0x1b, (byte)0x24, (byte)0x42, + (byte)0x3a, (byte)0x47, + (byte)0x1b, (byte)0x28, (byte)0x42 }; + + OutputStreamWriter osw = new OutputStreamWriter(bos, "iso-2022-jp"); + osw.write(str, 0, str.length()); + osw.flush(); + check(bos.toByteArray(), bytes); + + bos.reset(); + PrintStream ps = new PrintStream(bos, false, "iso-2022-jp"); + ps.print(str); + check(bos.toByteArray(), bytes); + + } + + private static void check(byte[] result, byte[] expected) + throws Exception + { + if (!Arrays.equals(result, expected)) { + System.out.println("Expected:"); + for (int i = 0; i < expected.length; i++) + System.out.printf("0x%x ", expected[i] & 0xff); + System.out.println(); + System.out.println("Result::"); + for (int i = 0; i < result.length; i++) + System.out.printf("0x%x ", result[i] & 0xff); + System.out.println(); + throw new RuntimeException("Test failed"); + } + + } + + +}