1 /* 2 * Copyright (c) 2006, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 4028462 27 * @summary Test for new constructors that set the pipe size 28 */ 29 30 import java.io.*; 31 public class Constructors extends Thread { 32 33 static PipedWriter out; 34 static PipedReader in; 35 static int totalToWrite = (8 * 1024); 36 static int pipeSize = totalToWrite; 37 run()38 public void run() { 39 try { 40 for (int times = (totalToWrite / pipeSize); times > 0; times--) { 41 System.out.println("Reader reading..."); 42 int read = in.read(new char[pipeSize]); 43 System.out.println("read: " + read); 44 if (read < pipeSize) { 45 throw new Exception("Pipe Size is not set to:" + pipeSize); 46 } 47 } 48 } catch (Throwable e) { 49 System.out.println("Reader exception:"); 50 e.printStackTrace(); 51 } finally { 52 System.out.println("Reader done."); 53 } 54 } 55 main(String args[])56 public static void main(String args[]) throws Exception { 57 58 in = new PipedReader(pipeSize); 59 out = new PipedWriter(in); 60 testPipe(); 61 62 out = new PipedWriter(); 63 in = new PipedReader(out, pipeSize); 64 testPipe(); 65 } 66 67 testPipe()68 private static void testPipe() throws Exception { 69 Constructors reader = new Constructors(); 70 reader.start(); 71 72 try { 73 System.out.println("Writer started."); 74 out.write(new char[totalToWrite]); 75 } catch (Throwable e) { 76 System.out.println("Writer exception:"); 77 e.printStackTrace(); 78 } finally { 79 out.close(); 80 System.out.println("Waiting for reader..."); 81 reader.join(); 82 in.close(); 83 System.out.println("Done."); 84 } 85 } 86 } 87