2115N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2115N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2115N/A *
2115N/A * This code is free software; you can redistribute it and/or modify it
2115N/A * under the terms of the GNU General Public License version 2 only, as
2115N/A * published by the Free Software Foundation.
2115N/A *
2115N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2115N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2115N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2115N/A * version 2 for more details (a copy is included in the LICENSE file that
2115N/A * accompanied this code).
2115N/A *
2115N/A * You should have received a copy of the GNU General Public License version
2115N/A * 2 along with this work; if not, write to the Free Software Foundation,
2115N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2115N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2115N/A */
2115N/A
2115N/A/* @test
2115N/A * @summary Ensure that InputStreamReader reads as many characters as possible
2115N/A */
2115N/A
2115N/A// InputStreamReader is not required by its spec to read as many characters as
2115N/A// possible upon each invocation of read(char[], int, int), but many programs
2115N/A// (e.g., javac) depend upon this behavior.
2115N/A
2115N/Aimport java.io.*;
2115N/A
2115N/A
2115N/Apublic class FullRead {
2115N/A
2115N/A static int MAX_LEN = 1 << 16;
2115N/A
2115N/A static void test(File f, int len) throws Exception {
2115N/A FileOutputStream fo = new FileOutputStream(f);
2115N/A for (int i = 0; i < len; i++)
2115N/A fo.write('x');
2115N/A fo.close();
2115N/A
2115N/A FileInputStream fi = new FileInputStream(f);
2115N/A Reader rd = new InputStreamReader(fi, "US-ASCII");
2115N/A char[] cb = new char[MAX_LEN + 100];
2115N/A int n = rd.read(cb, 0, cb.length);
2115N/A System.out.println(len + " : " + n);
2115N/A if (len != n)
2115N/A throw new Exception("Expected " + len + ", read " + n);
2115N/A }
2115N/A
2115N/A public static void main(String[] args) throws Exception {
2115N/A File f = File.createTempFile("foo", "bar");
2115N/A f.deleteOnExit();
2115N/A System.out.println(f);
2115N/A
2115N/A for (int i = 4; i <= MAX_LEN; i <<= 1)
2115N/A test(f, i);
2115N/A }
2115N/A
2115N/A}