home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / io / PipedOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.1 KB  |  65 lines

  1. package java.io;
  2.  
  3. public class PipedOutputStream extends OutputStream {
  4.    private PipedInputStream sink;
  5.  
  6.    public PipedOutputStream(PipedInputStream var1) throws IOException {
  7.       this.connect(var1);
  8.    }
  9.  
  10.    public PipedOutputStream() {
  11.    }
  12.  
  13.    public synchronized void connect(PipedInputStream var1) throws IOException {
  14.       if (var1 == null) {
  15.          throw new NullPointerException();
  16.       } else if (this.sink == null && !var1.connected) {
  17.          this.sink = var1;
  18.          var1.in = -1;
  19.          var1.out = 0;
  20.          var1.connected = true;
  21.       } else {
  22.          throw new IOException("Already connected");
  23.       }
  24.    }
  25.  
  26.    public void write(int var1) throws IOException {
  27.       if (this.sink == null) {
  28.          throw new IOException("Pipe not connected");
  29.       } else {
  30.          this.sink.receive(var1);
  31.       }
  32.    }
  33.  
  34.    public void write(byte[] var1, int var2, int var3) throws IOException {
  35.       if (this.sink == null) {
  36.          throw new IOException("Pipe not connected");
  37.       } else if (var1 == null) {
  38.          throw new NullPointerException();
  39.       } else if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
  40.          if (var3 != 0) {
  41.             this.sink.receive(var1, var2, var3);
  42.          }
  43.       } else {
  44.          throw new IndexOutOfBoundsException();
  45.       }
  46.    }
  47.  
  48.    public synchronized void flush() throws IOException {
  49.       if (this.sink != null) {
  50.          PipedInputStream var1 = this.sink;
  51.          synchronized(var1) {
  52.             this.sink.notifyAll();
  53.          }
  54.       }
  55.  
  56.    }
  57.  
  58.    public void close() throws IOException {
  59.       if (this.sink != null) {
  60.          this.sink.receivedLast();
  61.       }
  62.  
  63.    }
  64. }
  65.