Dead
[official-gcc.git] / gomp-20050608-branch / libjava / java / util / zip / GZIPOutputStream.java
blob260911a22154762178b6a4699973aad15a7cdb85
1 /* GZIPOutputStream.java - Create a file in gzip format
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.util.zip;
40 import java.io.IOException;
41 import java.io.OutputStream;
43 /**
44 * This filter stream is used to compress a stream into a "GZIP" stream.
45 * The "GZIP" format is described in RFC 1952.
47 * @author John Leuner
48 * @author Tom Tromey
49 * @since JDK 1.1
52 /* Written using on-line Java Platform 1.2 API Specification
53 * and JCL book.
54 * Believed complete and correct.
57 public class GZIPOutputStream extends DeflaterOutputStream
59 /**
60 * CRC-32 value for uncompressed data
62 protected CRC32 crc;
64 /**
65 * Creates a GZIPOutputStream with the default buffer size
67 * @param out The stream to read data (to be compressed) from
70 public GZIPOutputStream(OutputStream out) throws IOException
72 this(out, 4096);
75 /**
76 * Creates a GZIPOutputStream with the specified buffer size
78 * @param out The stream to read compressed data from
79 * @param size Size of the buffer to use
81 public GZIPOutputStream(OutputStream out, int size) throws IOException
83 super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size);
84 crc = new CRC32();
85 put2(GZIPInputStream.GZIP_MAGIC);
86 out.write(GZIPInputStream.Z_DEFLATED);
87 // No flags for now.
88 out.write(0);
89 // No time either.
90 put2(0);
91 put2(0);
92 // No xflags either.
93 out.write(0);
94 // FIXME: unknown OS.
95 out.write(255);
98 public synchronized void write(int bval) throws IOException
100 super.write(bval);
101 crc.update(bval);
104 public synchronized void write(byte[] buf) throws IOException
106 write(buf, 0, buf.length);
109 public synchronized void write(byte[] buf, int off, int len)
110 throws IOException
112 super.write(buf, off, len);
113 crc.update(buf, off, len);
117 * Writes remaining compressed output data to the output stream
118 * and closes it.
120 public void close() throws IOException
122 finish();
123 out.close();
126 public void finish() throws IOException
128 super.finish();
129 put4((int) crc.getValue());
130 put4(def.getTotalIn());
133 private final void put2(int i) throws IOException
135 out.write(i);
136 out.write(i >> 8);
139 private final void put4 (int i) throws IOException
141 out.write(i);
142 out.write(i >> 8);
143 out.write(i >> 16);
144 out.write(i >> 24);