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 / PipedWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.2 KB  |  71 lines

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