summaryrefslogtreecommitdiffstats
path: root/libjava/java/util/zip/GZIPOutputStream.java
diff options
context:
space:
mode:
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-09 15:22:19 +0000
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-09 15:22:19 +0000
commit9e0c5d3a620e2c00fef805aace78d909b6ed2f33 (patch)
treeda8856033bd84b9270468089c3a2f34c2c565b0a /libjava/java/util/zip/GZIPOutputStream.java
parent45495fdc0d2ad726ddbafc790713f980fec4a97c (diff)
downloadppe42-gcc-9e0c5d3a620e2c00fef805aace78d909b6ed2f33.tar.gz
ppe42-gcc-9e0c5d3a620e2c00fef805aace78d909b6ed2f33.zip
2004-07-09 Michael Koch <konqueror@gmx.de>
* java/util/zip/DeflaterOutputStream.java, java/util/zip/GZIPInputStream.java, java/util/zip/GZIPOutputStream.java, java/util/zip/InflaterInputStream.java: Reformatted. Added javadocs. Reordered all stuff. Renamed variables to be more clear. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84380 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/util/zip/GZIPOutputStream.java')
-rw-r--r--libjava/java/util/zip/GZIPOutputStream.java106
1 files changed, 63 insertions, 43 deletions
diff --git a/libjava/java/util/zip/GZIPOutputStream.java b/libjava/java/util/zip/GZIPOutputStream.java
index 939097ed7bb..70339a022d0 100644
--- a/libjava/java/util/zip/GZIPOutputStream.java
+++ b/libjava/java/util/zip/GZIPOutputStream.java
@@ -41,8 +41,12 @@ import java.io.IOException;
import java.io.OutputStream;
/**
+ * This filter stream is used to compress a stream into a "GZIP" stream.
+ * The "GZIP" format is described in RFC 1952.
+ *
+ * @author John Leuner
* @author Tom Tromey
- * @date May 17, 1999
+ * @since JDK 1.1
*/
/* Written using on-line Java Platform 1.2 API Specification
@@ -52,75 +56,91 @@ import java.io.OutputStream;
public class GZIPOutputStream extends DeflaterOutputStream
{
- public void close () throws IOException
- {
- finish ();
- out.close ();
- }
-
- public void finish () throws IOException
- {
- super.finish();
- put4 ((int) crc.getValue());
- put4 (def.getTotalIn());
- }
+ /**
+ * CRC-32 value for uncompressed data
+ */
+ protected CRC32 crc;
- public GZIPOutputStream (OutputStream out) throws IOException
+ /**
+ * Creates a GZIPOutputStream with the default buffer size
+ *
+ * @param out The stream to read data (to be compressed) from
+ *
+ */
+ public GZIPOutputStream(OutputStream out) throws IOException
{
- this (out, 512);
+ this(out, 512);
}
- public GZIPOutputStream (OutputStream out, int readsize) throws IOException
+ /**
+ * Creates a GZIPOutputStream with the specified buffer size
+ *
+ * @param out The stream to read compressed data from
+ * @param size Size of the buffer to use
+ */
+ public GZIPOutputStream(OutputStream out, int size) throws IOException
{
- super (out, new Deflater (Deflater.DEFAULT_COMPRESSION, true), readsize);
-
- put2 (GZIPInputStream.GZIP_MAGIC);
- out.write (GZIPInputStream.Z_DEFLATED);
+ super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size);
+ crc = new CRC32();
+ put2(GZIPInputStream.GZIP_MAGIC);
+ out.write(GZIPInputStream.Z_DEFLATED);
// No flags for now.
- out.write (0);
+ out.write(0);
// No time either.
- put2 (0);
- put2 (0);
+ put2(0);
+ put2(0);
// No xflags either.
- out.write (0);
+ out.write(0);
// FIXME: unknown OS.
- out.write (255);
-
- crc = new CRC32 ();
+ out.write(255);
}
- public synchronized void write (int bval) throws IOException
+ public synchronized void write(int bval) throws IOException
{
- super.write (bval);
- crc.update (bval);
+ super.write(bval);
+ crc.update(bval);
}
- public synchronized void write (byte[] buf) throws IOException
+ public synchronized void write(byte[] buf) throws IOException
{
- write (buf, 0, buf.length);
+ write(buf, 0, buf.length);
}
- public synchronized void write (byte[] buf, int off, int len)
+ public synchronized void write(byte[] buf, int off, int len)
throws IOException
{
super.write(buf, off, len);
crc.update(buf, off, len);
}
- private final void put2 (int i) throws IOException
+ /**
+ * Writes remaining compressed output data to the output stream
+ * and closes it.
+ */
+ public void close() throws IOException
{
- out.write (i);
- out.write (i >> 8);
+ finish();
+ out.close();
}
- private final void put4 (int i) throws IOException
+ public void finish() throws IOException
{
- out.write (i);
- out.write (i >> 8);
- out.write (i >> 16);
- out.write (i >> 24);
+ super.finish();
+ put4((int) crc.getValue());
+ put4(def.getTotalIn());
}
- // Checksum used by this stream.
- protected CRC32 crc;
+ private final void put2(int i) throws IOException
+ {
+ out.write(i);
+ out.write(i >> 8);
+ }
+
+ private final void put4 (int i) throws IOException
+ {
+ out.write(i);
+ out.write(i >> 8);
+ out.write(i >> 16);
+ out.write(i >> 24);
+ }
}
OpenPOWER on IntegriCloud