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 / GZIPOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  1.8 KB  |  68 lines

  1. package java.util.zip;
  2.  
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5.  
  6. public class GZIPOutputStream extends DeflaterOutputStream {
  7.    protected CRC32 crc;
  8.    private static final int GZIP_MAGIC = 35615;
  9.  
  10.    public GZIPOutputStream(OutputStream var1, int var2) throws IOException {
  11.       super(var1, new Deflater(-1, true), var2);
  12.       this.crc = new CRC32();
  13.       this.writeHeader();
  14.       this.crc.reset();
  15.    }
  16.  
  17.    public GZIPOutputStream(OutputStream var1) throws IOException {
  18.       this(var1, 512);
  19.    }
  20.  
  21.    public synchronized void write(byte[] var1, int var2, int var3) throws IOException {
  22.       super.write(var1, var2, var3);
  23.       this.crc.update(var1, var2, var3);
  24.    }
  25.  
  26.    public void finish() throws IOException {
  27.       if (!super.def.finished()) {
  28.          super.def.finish();
  29.  
  30.          while(!super.def.finished()) {
  31.             ((DeflaterOutputStream)this).deflate();
  32.          }
  33.  
  34.          this.writeTrailer();
  35.       }
  36.  
  37.    }
  38.  
  39.    public void close() throws IOException {
  40.       this.finish();
  41.       super.out.close();
  42.    }
  43.  
  44.    private void writeHeader() throws IOException {
  45.       this.writeShort(35615);
  46.       super.out.write(8);
  47.       super.out.write(0);
  48.       this.writeInt(0);
  49.       super.out.write(0);
  50.       super.out.write(0);
  51.    }
  52.  
  53.    private void writeTrailer() throws IOException {
  54.       this.writeInt((int)this.crc.getValue());
  55.       this.writeInt(super.def.getTotalIn());
  56.    }
  57.  
  58.    private void writeInt(int var1) throws IOException {
  59.       this.writeShort(var1 & '\uffff');
  60.       this.writeShort(var1 >> 16 & '\uffff');
  61.    }
  62.  
  63.    private void writeShort(int var1) throws IOException {
  64.       super.out.write(var1 & 255);
  65.       super.out.write(var1 >> 8 & 255);
  66.    }
  67. }
  68.