home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / browser / nc32lyc / comm.z / java40.jar / java / lang / ProcessInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-15  |  2.1 KB  |  114 lines

  1. package java.lang;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.io.PipedInputStream;
  7. import java.io.PipedOutputStream;
  8. import java.util.Vector;
  9.  
  10. class ProcessInputStream extends PipedInputStream implements Runnable {
  11.    InputStream ins;
  12.    OutputStream outs;
  13.    // $FF: renamed from: p java.lang.UNIXProcess
  14.    UNIXProcess field_0;
  15.    byte[] writeBuf;
  16.    boolean chaining;
  17.    int inPos;
  18.    Vector chain;
  19.  
  20.    ProcessInputStream(UNIXProcess var1, PipedOutputStream var2, InputStream var3) throws IOException {
  21.       super(var2);
  22.       this.field_0 = var1;
  23.       this.outs = var2;
  24.       this.ins = var3;
  25.       this.writeBuf = null;
  26.       this.chaining = false;
  27.       this.inPos = 0;
  28.       this.chain = new Vector();
  29.    }
  30.  
  31.    protected synchronized void receive(int var1) throws IOException {
  32.       if (this.chaining) {
  33.          if (this.inPos == 1024) {
  34.             this.writeBuf = new byte[1024];
  35.             this.chain.addElement(this.writeBuf);
  36.             this.inPos = 0;
  37.          }
  38.  
  39.          this.writeBuf[this.inPos++] = (byte)var1;
  40.       } else {
  41.          super.receive(var1);
  42.          if (super.in == super.out) {
  43.             this.inPos = 0;
  44.             this.chaining = true;
  45.             this.writeBuf = new byte[1024];
  46.             this.chain.addElement(this.writeBuf);
  47.          }
  48.  
  49.       }
  50.    }
  51.  
  52.    public synchronized int read() throws IOException {
  53.       if (!this.chaining) {
  54.          return super.read();
  55.       } else {
  56.          if (super.in == -1 && this.chain.size() != 0) {
  57.             super.buffer = (byte[])this.chain.elementAt(0);
  58.             this.chain.removeElementAt(0);
  59.             super.in = super.out = 0;
  60.             if (this.chain.size() == 0) {
  61.                if (this.inPos == 0) {
  62.                   super.in = -1;
  63.                } else if (this.inPos == 1024) {
  64.                   super.in = 0;
  65.                } else {
  66.                   super.in = this.inPos;
  67.                }
  68.  
  69.                this.chaining = false;
  70.             }
  71.          }
  72.  
  73.          return super.read();
  74.       }
  75.    }
  76.  
  77.    public int available() throws IOException {
  78.       return super.available() + 1024 * this.chain.size();
  79.    }
  80.  
  81.    public void run() {
  82.       byte[] var1 = new byte[512];
  83.  
  84.       while(true) {
  85.          try {
  86.             int var2 = this.ins.available();
  87.             if (var2 != 0) {
  88.                if ((var2 = this.ins.read(var1)) < 0) {
  89.                   break;
  90.                }
  91.  
  92.                this.outs.write(var1, 0, var2);
  93.             } else {
  94.                try {
  95.                   Thread.sleep(500L);
  96.                } catch (InterruptedException var8) {
  97.                } finally {
  98.                   ;
  99.                }
  100.             }
  101.          } catch (IOException var10) {
  102.             break;
  103.          }
  104.       }
  105.  
  106.       try {
  107.          this.outs.close();
  108.       } catch (IOException var7) {
  109.       }
  110.  
  111.       this.field_0.decrNumReaders();
  112.    }
  113. }
  114.