File: helper.java

package info (click to toggle)
mauve 20120103-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 28,504 kB
  • sloc: java: 250,155; sh: 2,834; xml: 208; makefile: 66
file content (49 lines) | stat: -rw-r--r-- 934 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
// Helper for 

// Copyright (c) 2001  Free Software Foundation

// This file is part of Mauve.

// Tags: not-a-test

package gnu.testlet.java.io.BufferedOutputStream;

import java.io.*;

public class helper extends OutputStream
{
  // Number of bytes we've read.
  int count;
  // When we should stop.
  int stop;

  public helper (int size)
  {
    stop = size;
  }

  private void update (int howmuch) throws InterruptedIOException
  {
    if (count + howmuch > stop)
      {
	InterruptedIOException ioe = new InterruptedIOException ();
	ioe.bytesTransferred = stop - count;
	count = stop;
	throw ioe;
      }

    count += howmuch;
  }

  public void write (int b) throws InterruptedIOException
  {
    update (1);
  }

  public void write (byte[] b, int off, int len) throws InterruptedIOException
  {
    if (off < 0 || len < 0 || off + len > b.length)
      throw new ArrayIndexOutOfBoundsException ();
    update (len);
  }
}