Path: blob/master/test/jdk/java/io/PipedReader/Constructors.java
41149 views
/*1* Copyright (c) 2006, 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/**24* @test25* @bug 402846226* @summary Test for new constructors that set the pipe size27*/2829import java.io.*;30public class Constructors extends Thread {3132static PipedWriter out;33static PipedReader in;34static int totalToWrite = (8 * 1024);35static int pipeSize = totalToWrite;3637public void run() {38try {39for (int times = (totalToWrite / pipeSize); times > 0; times--) {40System.out.println("Reader reading...");41int read = in.read(new char[pipeSize]);42System.out.println("read: " + read);43if (read < pipeSize) {44throw new Exception("Pipe Size is not set to:" + pipeSize);45}46}47} catch (Throwable e) {48System.out.println("Reader exception:");49e.printStackTrace();50} finally {51System.out.println("Reader done.");52}53}5455public static void main(String args[]) throws Exception {5657in = new PipedReader(pipeSize);58out = new PipedWriter(in);59testPipe();6061out = new PipedWriter();62in = new PipedReader(out, pipeSize);63testPipe();64}656667private static void testPipe() throws Exception {68Constructors reader = new Constructors();69reader.start();7071try {72System.out.println("Writer started.");73out.write(new char[totalToWrite]);74} catch (Throwable e) {75System.out.println("Writer exception:");76e.printStackTrace();77} finally {78out.close();79System.out.println("Waiting for reader...");80reader.join();81in.close();82System.out.println("Done.");83}84}85}868788