jdk/test/java/io/charStreams/BufferSizes.java
changeset 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 1997 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /* @test
       
    25    @summary Test interaction of buffer sizes in buffered char and byte streams
       
    26  */
       
    27 
       
    28 import java.io.*;
       
    29 
       
    30 public class BufferSizes {
       
    31 
       
    32     static int min = 90;
       
    33     static int max = 110;
       
    34     static int chunk = 100;
       
    35     static int count = 1000;
       
    36 
       
    37     static void runBytes() throws IOException {
       
    38         for (int sz = min; sz <= max; sz++) {
       
    39             System.err.println(sz);
       
    40             InputStream in
       
    41                 = new BufferedInputStream(new ABCInputStream(count, chunk), sz);
       
    42             OutputStream out
       
    43                 = new BufferedOutputStream(new ABCOutputStream(count), sz);
       
    44             int n;
       
    45             byte[] buf = new byte[sz];
       
    46             while ((n = in.read(buf, 0, sz)) != -1)
       
    47                 out.write(buf, 0, n);
       
    48             in.close();
       
    49             out.close();
       
    50         }
       
    51     }
       
    52 
       
    53 
       
    54     static void runChars() throws IOException {
       
    55         for (int sz = min; sz <= max; sz++) {
       
    56             System.err.println(sz);
       
    57             Reader in
       
    58                 = new BufferedReader(new InputStreamReader(new ABCInputStream(count, chunk)), sz);
       
    59             Writer out
       
    60                 = new BufferedWriter(new OutputStreamWriter(new ABCOutputStream(count)), sz);
       
    61             int n;
       
    62             char[] cbuf = new char[sz];
       
    63 
       
    64             while ((n = in.read(cbuf, 0, sz)) != -1)
       
    65                 out.write(cbuf, 0, n);
       
    66             in.close();
       
    67             out.close();
       
    68         }
       
    69     }
       
    70 
       
    71     public static void main(String[] args) throws IOException {
       
    72         runBytes();
       
    73         runChars();
       
    74     }
       
    75 
       
    76 }