Path: blob/master/test/jdk/java/nio/charset/coders/FullRead.java
41153 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* @summary Ensure that InputStreamReader reads as many characters as possible25*/2627// InputStreamReader is not required by its spec to read as many characters as28// possible upon each invocation of read(char[], int, int), but many programs29// (e.g., javac) depend upon this behavior.3031import java.io.*;323334public class FullRead {3536static int MAX_LEN = 1 << 16;3738static void test(File f, int len) throws Exception {39FileOutputStream fo = new FileOutputStream(f);40for (int i = 0; i < len; i++)41fo.write('x');42fo.close();4344FileInputStream fi = new FileInputStream(f);45Reader rd = new InputStreamReader(fi, "US-ASCII");46char[] cb = new char[MAX_LEN + 100];47int n = rd.read(cb, 0, cb.length);48System.out.println(len + " : " + n);49if (len != n)50throw new Exception("Expected " + len + ", read " + n);51}5253public static void main(String[] args) throws Exception {54File f = File.createTempFile("foo", "bar");55f.deleteOnExit();56System.out.println(f);5758for (int i = 4; i <= MAX_LEN; i <<= 1)59test(f, i);60}6162}636465