|
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 PipedOutputStream out; |
|
34 static PipedInputStream in; |
|
35 static int totalToWrite = (8 * 1024); |
|
36 static int pipeSize = totalToWrite; |
|
37 |
|
38 public void run() { |
|
39 try { |
|
40 for (int times = (totalToWrite / pipeSize); times > 0; times--) { |
|
41 System.out.println("Pipe Input stream reading..."); |
|
42 int read = in.read(new byte[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("Pipe Input stream exception:"); |
|
50 e.printStackTrace(); |
|
51 } finally { |
|
52 System.out.println("Pipe Input stream done."); |
|
53 } |
|
54 } |
|
55 |
|
56 public static void main(String args[]) throws Exception { |
|
57 |
|
58 in = new PipedInputStream(pipeSize); |
|
59 out = new PipedOutputStream(in); |
|
60 testPipe(); |
|
61 |
|
62 out = new PipedOutputStream(); |
|
63 in = new PipedInputStream(out, pipeSize); |
|
64 testPipe(); |
|
65 } |
|
66 |
|
67 |
|
68 private static void testPipe() throws Exception { |
|
69 Constructors reader = new Constructors(); |
|
70 reader.start(); |
|
71 |
|
72 try { |
|
73 System.out.println("Pipe Output stream started."); |
|
74 out.write(new byte[totalToWrite]); |
|
75 } catch (Throwable e) { |
|
76 System.out.println("Pipe Output stream exception:"); |
|
77 e.printStackTrace(); |
|
78 } finally { |
|
79 out.close(); |
|
80 System.out.println("Waiting for Pipe Input stream..."); |
|
81 reader.join(); |
|
82 in.close(); |
|
83 System.out.println("Done."); |
|
84 } |
|
85 } |
|
86 } |