1 // Test to see if InterruptedIOException affects output streams |
|
2 |
|
3 // Copyright (c) 2001 Free Software Foundation |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 // Tags: JDK1.1 |
|
8 // Uses: helper |
|
9 |
|
10 package gnu.testlet.java.io.BufferedOutputStream; |
|
11 |
|
12 import gnu.testlet.Testlet; |
|
13 import gnu.testlet.TestHarness; |
|
14 import java.io.*; |
|
15 |
|
16 public class interrupt extends BufferedOutputStream implements Testlet |
|
17 { |
|
18 public interrupt (OutputStream out, int size) |
|
19 { |
|
20 super (out, size); |
|
21 } |
|
22 |
|
23 public interrupt () |
|
24 { |
|
25 super (null); |
|
26 } |
|
27 |
|
28 private int getCount() |
|
29 { |
|
30 return this.count; |
|
31 } |
|
32 |
|
33 public void test (TestHarness harness) |
|
34 { |
|
35 // We create an output stream that will throw an |
|
36 // InterruptedIOException after 10 bytes are written. Then we |
|
37 // wrap it in a buffered output stream with a buffer that is a bit |
|
38 // smaller than that -- but not a nice multiple. Finally we write |
|
39 // bytes until we get the interrupt. |
|
40 |
|
41 int BUFFER = 7; |
|
42 |
|
43 helper h = new helper (10); |
|
44 interrupt out = new interrupt (h, BUFFER); |
|
45 |
|
46 boolean ok = false; |
|
47 int i = -1; |
|
48 int xfer = -1; |
|
49 try |
|
50 { |
|
51 for (i = 0; i < BUFFER * 2; ++i) |
|
52 out.write (i); |
|
53 out.flush (); |
|
54 } |
|
55 catch (InterruptedIOException ioe) |
|
56 { |
|
57 xfer = ioe.bytesTransferred; |
|
58 ok = true; |
|
59 } |
|
60 catch (IOException _) |
|
61 { |
|
62 } |
|
63 harness.check (ok, "single-byte writes"); |
|
64 // The flush() will cause the second buffer to be written. This |
|
65 // will only write 3 bytes, though. |
|
66 harness.check (xfer, 3); |
|
67 harness.check (i, BUFFER * 2); |
|
68 // In theory the BufferedOutputStream should notice the |
|
69 // InterruptedIOException and update its internal data structure |
|
70 // accordingly. |
|
71 // harness.check (out.getCount(), 4); |
|
72 |
|
73 h = new helper (10); |
|
74 out = new interrupt (h, BUFFER); |
|
75 byte[] b = new byte[7]; |
|
76 |
|
77 ok = false; |
|
78 xfer = 0; |
|
79 try |
|
80 { |
|
81 for (i = 0; i < 5; ++i) |
|
82 out.write (b); |
|
83 } |
|
84 catch (InterruptedIOException ioe) |
|
85 { |
|
86 xfer = ioe.bytesTransferred; |
|
87 ok = true; |
|
88 } |
|
89 catch (IOException _) |
|
90 { |
|
91 } |
|
92 harness.check (ok, "byte array writes"); |
|
93 harness.check (xfer, 3); |
|
94 harness.check (i, 1); |
|
95 } |
|
96 } |
|