Path: blob/master/test/jdk/java/io/charStreams/BufferSizes.java
41152 views
/*1* Copyright (c) 1997, 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 Test interaction of buffer sizes in buffered char and byte streams25*/2627import java.io.*;2829public class BufferSizes {3031static int min = 90;32static int max = 110;33static int chunk = 100;34static int count = 1000;3536static void runBytes() throws IOException {37for (int sz = min; sz <= max; sz++) {38System.err.println(sz);39InputStream in40= new BufferedInputStream(new ABCInputStream(count, chunk), sz);41OutputStream out42= new BufferedOutputStream(new ABCOutputStream(count), sz);43int n;44byte[] buf = new byte[sz];45while ((n = in.read(buf, 0, sz)) != -1)46out.write(buf, 0, n);47in.close();48out.close();49}50}515253static void runChars() throws IOException {54for (int sz = min; sz <= max; sz++) {55System.err.println(sz);56Reader in57= new BufferedReader(new InputStreamReader(new ABCInputStream(count, chunk)), sz);58Writer out59= new BufferedWriter(new OutputStreamWriter(new ABCOutputStream(count)), sz);60int n;61char[] cbuf = new char[sz];6263while ((n = in.read(cbuf, 0, sz)) != -1)64out.write(cbuf, 0, n);65in.close();66out.close();67}68}6970public static void main(String[] args) throws IOException {71runBytes();72runChars();73}7475}767778