File: interrupt.java

package info (click to toggle)
mauve 20080616-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 26,856 kB
  • ctags: 21,952
  • sloc: java: 234,107; sh: 2,834; xml: 208; makefile: 59
file content (96 lines) | stat: -rw-r--r-- 2,151 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Test to see if InterruptedIOException affects output streams

// Copyright (c) 2001  Free Software Foundation

// This file is part of Mauve.

// Tags: JDK1.1
// Uses: helper

package gnu.testlet.java.io.BufferedOutputStream;

import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.io.*;

public class interrupt extends BufferedOutputStream implements Testlet
{
  public interrupt (OutputStream out, int size)
  {
    super (out, size);
  }

  public interrupt ()
  {
    super (null);
  }

  private int getCount()
  {
    return this.count;
  }

  public void test (TestHarness harness)
  {
    // We create an output stream that will throw an
    // InterruptedIOException after 10 bytes are written.  Then we
    // wrap it in a buffered output stream with a buffer that is a bit
    // smaller than that -- but not a nice multiple.  Finally we write
    // bytes until we get the interrupt.

    int BUFFER = 7;

    helper h = new helper (10);
    interrupt out = new interrupt (h, BUFFER);

    boolean ok = false;
    int i = -1;
    int xfer = -1;
    try
      {
	for (i = 0; i < BUFFER * 2; ++i)
	  out.write (i);
	out.flush ();
      }
    catch (InterruptedIOException ioe)
      {
	xfer = ioe.bytesTransferred;
	ok = true;
      }
    catch (IOException _)
      {
      }
    harness.check (ok, "single-byte writes");
    // The flush() will cause the second buffer to be written.  This
    // will only write 3 bytes, though.
    harness.check (xfer, 3);
    harness.check (i, BUFFER * 2);
    // In theory the BufferedOutputStream should notice the
    // InterruptedIOException and update its internal data structure
    // accordingly.
    // harness.check (out.getCount(), 4);

    h = new helper (10);
    out = new interrupt (h, BUFFER);
    byte[] b = new byte[7];

    ok = false;
    xfer = 0;
    try
      {
	for (i = 0; i < 5; ++i)
	  out.write (b);
      }
    catch (InterruptedIOException ioe)
      {
	xfer = ioe.bytesTransferred;
	ok = true;
      }
    catch (IOException _)
      {
      }
    harness.check (ok, "byte array writes");
    harness.check (xfer, 3);
    harness.check (i, 1);
  }
}