home *** CD-ROM | disk | FTP | other *** search
- package java.util.zip;
-
- import java.io.IOException;
- import java.io.OutputStream;
-
- public class GZIPOutputStream extends DeflaterOutputStream {
- protected CRC32 crc;
- private static final int GZIP_MAGIC = 35615;
-
- public GZIPOutputStream(OutputStream var1, int var2) throws IOException {
- super(var1, new Deflater(-1, true), var2);
- this.crc = new CRC32();
- this.writeHeader();
- this.crc.reset();
- }
-
- public GZIPOutputStream(OutputStream var1) throws IOException {
- this(var1, 512);
- }
-
- public synchronized void write(byte[] var1, int var2, int var3) throws IOException {
- super.write(var1, var2, var3);
- this.crc.update(var1, var2, var3);
- }
-
- public void finish() throws IOException {
- if (!super.def.finished()) {
- super.def.finish();
-
- while(!super.def.finished()) {
- ((DeflaterOutputStream)this).deflate();
- }
-
- this.writeTrailer();
- }
-
- }
-
- public void close() throws IOException {
- this.finish();
- super.out.close();
- }
-
- private void writeHeader() throws IOException {
- this.writeShort(35615);
- super.out.write(8);
- super.out.write(0);
- this.writeInt(0);
- super.out.write(0);
- super.out.write(0);
- }
-
- private void writeTrailer() throws IOException {
- this.writeInt((int)this.crc.getValue());
- this.writeInt(super.def.getTotalIn());
- }
-
- private void writeInt(int var1) throws IOException {
- this.writeShort(var1 & '\uffff');
- this.writeShort(var1 >> 16 & '\uffff');
- }
-
- private void writeShort(int var1) throws IOException {
- super.out.write(var1 & 255);
- super.out.write(var1 >> 8 & 255);
- }
- }
-