0N/A/*
0N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @summary Unit test for ISR/OSW constructors that take coders
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.nio.*;
0N/Aimport java.nio.charset.*;
0N/A
0N/A
0N/Apublic class IOCoders {
0N/A
0N/A static Charset ascii = Charset.forName("US-ASCII");
0N/A
0N/A static void isrPositive() throws Exception {
0N/A ByteArrayInputStream bis
0N/A = new ByteArrayInputStream(new byte[] { (byte)'h', (byte)'i' });
0N/A InputStreamReader isr
0N/A = new InputStreamReader(bis,
0N/A ascii.newDecoder()
0N/A .onMalformedInput(CodingErrorAction.REPORT)
0N/A .onUnmappableCharacter(CodingErrorAction.REPORT));
0N/A BufferedReader br = new BufferedReader(isr);
0N/A if (!br.readLine().equals("hi"))
0N/A throw new Exception();
0N/A }
0N/A
0N/A static void isrNegative() throws Exception {
0N/A ByteArrayInputStream bis
0N/A = new ByteArrayInputStream(new byte[] { (byte)0xff, (byte)0xff });
0N/A InputStreamReader isr
0N/A = new InputStreamReader(bis,
0N/A ascii.newDecoder()
0N/A .onMalformedInput(CodingErrorAction.REPORT)
0N/A .onUnmappableCharacter(CodingErrorAction.REPORT));
0N/A BufferedReader br = new BufferedReader(isr);
0N/A try {
0N/A br.readLine();
0N/A } catch (MalformedInputException x) {
0N/A return;
0N/A }
0N/A throw new Exception();
0N/A }
0N/A
0N/A static void oswPositive() throws Exception {
0N/A ByteArrayOutputStream bos = new ByteArrayOutputStream();
0N/A OutputStreamWriter osw
0N/A = new OutputStreamWriter(bos,
0N/A ascii.newEncoder()
0N/A .onMalformedInput(CodingErrorAction.REPORT)
0N/A .onUnmappableCharacter(CodingErrorAction.REPORT));
0N/A osw.write("hi");
0N/A osw.close();
0N/A if (!ascii.decode(ByteBuffer.wrap(bos.toByteArray()))
0N/A .toString().equals("hi"))
0N/A throw new Exception();
0N/A }
0N/A
0N/A static void oswNegative() throws Exception {
0N/A ByteArrayOutputStream bos = new ByteArrayOutputStream();
0N/A OutputStreamWriter osw
0N/A = new OutputStreamWriter(bos,
0N/A ascii.newEncoder()
0N/A .onMalformedInput(CodingErrorAction.REPORT)
0N/A .onUnmappableCharacter(CodingErrorAction.REPORT));
0N/A try {
0N/A osw.write("\u00A0\u00A1");
0N/A } catch (UnmappableCharacterException x) {
0N/A return;
0N/A }
0N/A throw new Exception();
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A isrPositive();
0N/A isrNegative();
0N/A oswPositive();
0N/A oswNegative();
0N/A }
0N/A
0N/A}
0N/A