Constructors.java revision 0
70N/A/*
70N/A * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
70N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
70N/A *
911N/A * This code is free software; you can redistribute it and/or modify it
851N/A * under the terms of the GNU General Public License version 2 only, as
70N/A * published by the Free Software Foundation.
70N/A *
919N/A * This code is distributed in the hope that it will be useful, but WITHOUT
919N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
919N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
919N/A * version 2 for more details (a copy is included in the LICENSE file that
919N/A * accompanied this code).
919N/A *
919N/A * You should have received a copy of the GNU General Public License version
919N/A * 2 along with this work; if not, write to the Free Software Foundation,
919N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
919N/A *
919N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
919N/A * CA 95054 USA or visit www.sun.com if you need additional information or
919N/A * have any questions.
919N/A */
919N/A
919N/A/**
919N/A * @test
70N/A * @bug 4028462
70N/A * @summary Test for new constructors that set the pipe size
70N/A */
70N/A
493N/Aimport java.io.*;
70N/Apublic class Constructors extends Thread {
70N/A
851N/A static PipedOutputStream out;
70N/A static PipedInputStream in;
911N/A static int totalToWrite = (8 * 1024);
911N/A static int pipeSize = totalToWrite;
911N/A
911N/A public void run() {
70N/A try {
70N/A for (int times = (totalToWrite / pipeSize); times > 0; times--) {
70N/A System.out.println("Pipe Input stream reading...");
70N/A int read = in.read(new byte[pipeSize]);
70N/A System.out.println("read: " + read);
70N/A if (read < pipeSize) {
70N/A throw new Exception("Pipe Size is not set to:" + pipeSize);
70N/A }
70N/A }
493N/A } catch (Throwable e) {
70N/A System.out.println("Pipe Input stream exception:");
70N/A e.printStackTrace();
493N/A } finally {
70N/A System.out.println("Pipe Input stream done.");
70N/A }
70N/A }
70N/A
70N/A public static void main(String args[]) throws Exception {
in = new PipedInputStream(pipeSize);
out = new PipedOutputStream(in);
testPipe();
out = new PipedOutputStream();
in = new PipedInputStream(out, pipeSize);
testPipe();
}
private static void testPipe() throws Exception {
Constructors reader = new Constructors();
reader.start();
try {
System.out.println("Pipe Output stream started.");
out.write(new byte[totalToWrite]);
} catch (Throwable e) {
System.out.println("Pipe Output stream exception:");
e.printStackTrace();
} finally {
out.close();
System.out.println("Waiting for Pipe Input stream...");
reader.join();
in.close();
System.out.println("Done.");
}
}
}