home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / io / PipedWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  1.4 KB  |  88 lines

  1. package java.io;
  2.  
  3. public class PipedWriter extends Writer {
  4.    PipedOutputStream byteSource;
  5.    private byte[] buf;
  6.  
  7.    public PipedWriter() {
  8.       this.byteSource = new PipedOutputStream();
  9.    }
  10.  
  11.    public PipedWriter(PipedReader var1) throws IOException {
  12.       this();
  13.       this.connect(var1);
  14.    }
  15.  
  16.    private void ensureOpen() throws IOException {
  17.       if (this.byteSource == null) {
  18.          throw new IOException("Stream closed");
  19.       }
  20.    }
  21.  
  22.    public void connect(PipedReader var1) throws IOException {
  23.       Object var2 = super.lock;
  24.       synchronized(var2){}
  25.  
  26.       try {
  27.          this.ensureOpen();
  28.          this.byteSource.connect(var1.byteSink);
  29.       } catch (Throwable var4) {
  30.          throw var4;
  31.       }
  32.  
  33.    }
  34.  
  35.    public void write(char[] var1, int var2, int var3) throws IOException {
  36.       Object var4 = super.lock;
  37.       synchronized(var4){}
  38.  
  39.       try {
  40.          this.ensureOpen();
  41.          int var6 = var3 * 2;
  42.          if (this.buf == null || this.buf.length < var6) {
  43.             this.buf = new byte[var6];
  44.          }
  45.  
  46.          for(int var7 = 0; var7 < var6; var7 += 2) {
  47.             char var8 = var1[var2 + (var7 >> 1)];
  48.             this.buf[var7] = (byte)(var8 >> 8);
  49.             this.buf[var7 + 1] = (byte)var8;
  50.          }
  51.  
  52.          this.byteSource.write(this.buf, 0, var6);
  53.       } catch (Throwable var10) {
  54.          throw var10;
  55.       }
  56.  
  57.    }
  58.  
  59.    public void flush() throws IOException {
  60.       Object var1 = super.lock;
  61.       synchronized(var1){}
  62.  
  63.       try {
  64.          this.ensureOpen();
  65.          this.byteSource.flush();
  66.       } catch (Throwable var3) {
  67.          throw var3;
  68.       }
  69.  
  70.    }
  71.  
  72.    public void close() throws IOException {
  73.       Object var1 = super.lock;
  74.       synchronized(var1){}
  75.  
  76.       try {
  77.          if (this.byteSource != null) {
  78.             this.byteSource.close();
  79.             this.byteSource = null;
  80.             return;
  81.          }
  82.       } catch (Throwable var4) {
  83.          throw var4;
  84.       }
  85.  
  86.    }
  87. }
  88.