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

  1. package java.util.zip;
  2.  
  3. import java.io.FilterOutputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6.  
  7. public class DeflaterOutputStream extends FilterOutputStream {
  8.    protected Deflater def;
  9.    protected byte[] buf;
  10.  
  11.    public DeflaterOutputStream(OutputStream var1, Deflater var2, int var3) {
  12.       super(var1);
  13.       this.def = var2;
  14.       this.buf = new byte[var3];
  15.    }
  16.  
  17.    public DeflaterOutputStream(OutputStream var1, Deflater var2) {
  18.       this(var1, var2, 512);
  19.    }
  20.  
  21.    public DeflaterOutputStream(OutputStream var1) {
  22.       this(var1, new Deflater());
  23.    }
  24.  
  25.    public void write(int var1) throws IOException {
  26.       byte[] var2 = new byte[]{(byte)(var1 & 255)};
  27.       this.write(var2, 0, 1);
  28.    }
  29.  
  30.    public void write(byte[] var1, int var2, int var3) throws IOException {
  31.       if (this.def.finished()) {
  32.          throw new IOException("write beyond end of stream");
  33.       } else {
  34.          if (!this.def.finished()) {
  35.             this.def.setInput(var1, var2, var3);
  36.  
  37.             while(!this.def.needsInput()) {
  38.                this.deflate();
  39.             }
  40.          }
  41.  
  42.       }
  43.    }
  44.  
  45.    public void finish() throws IOException {
  46.       if (!this.def.finished()) {
  47.          this.def.finish();
  48.  
  49.          while(!this.def.finished()) {
  50.             this.deflate();
  51.          }
  52.       }
  53.  
  54.    }
  55.  
  56.    public void close() throws IOException {
  57.       this.finish();
  58.       super.out.close();
  59.    }
  60.  
  61.    protected void deflate() throws IOException {
  62.       int var1 = this.def.deflate(this.buf, 0, this.buf.length);
  63.       if (var1 > 0) {
  64.          super.out.write(this.buf, 0, var1);
  65.       }
  66.  
  67.    }
  68. }
  69.