jdk/src/share/classes/java/util/zip/GZIPOutputStream.java
author alanb
Mon, 10 Jun 2013 12:58:32 +0100
changeset 18156 edb590d448c5
parent 5627 e636ac7a63a4
child 23010 6dadb192ad81
permissions -rw-r--r--
8016217: More javadoc warnings Reviewed-by: lancea, chegar, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5627
lana
parents: 5608 5506
diff changeset
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.zip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This class implements a stream filter for writing compressed data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * the GZIP file format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @author      David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class GZIPOutputStream extends DeflaterOutputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * CRC-32 of uncompressed data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    protected CRC32 crc = new CRC32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * GZIP header magic number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private final static int GZIP_MAGIC = 0x8b1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Trailer size in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final static int TRAILER_SIZE = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Creates a new output stream with the specified buffer size.
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    57
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    58
     * <p>The new output stream instance is created as if by invoking
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    59
     * the 3-argument constructor GZIPOutputStream(out, size, false).
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    60
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param out the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @param size the output buffer size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @exception IOException If an I/O error has occurred.
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5627
diff changeset
    64
     * @exception IllegalArgumentException if {@code size <= 0}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public GZIPOutputStream(OutputStream out, int size) throws IOException {
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    67
        this(out, size, false);
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    68
    }
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    69
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    70
    /**
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    71
     * Creates a new output stream with the specified buffer size and
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    72
     * flush mode.
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    73
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    74
     * @param out the output stream
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    75
     * @param size the output buffer size
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    76
     * @param syncFlush
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    77
     *        if {@code true} invocation of the inherited
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    78
     *        {@link DeflaterOutputStream#flush() flush()} method of
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    79
     *        this instance flushes the compressor with flush mode
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    80
     *        {@link Deflater#SYNC_FLUSH} before flushing the output
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    81
     *        stream, otherwise only flushes the output stream
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    82
     * @exception IOException If an I/O error has occurred.
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5627
diff changeset
    83
     * @exception IllegalArgumentException if {@code size <= 0}
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    84
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    85
     * @since 1.7
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    86
     */
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    87
    public GZIPOutputStream(OutputStream out, int size, boolean syncFlush)
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    88
        throws IOException
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    89
    {
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    90
        super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true),
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    91
              size,
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    92
              syncFlush);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        usesDefaultDeflater = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        writeHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        crc.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    98
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Creates a new output stream with a default buffer size.
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   101
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   102
     * <p>The new output stream instance is created as if by invoking
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   103
     * the 2-argument constructor GZIPOutputStream(out, false).
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   104
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param out the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @exception IOException If an I/O error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public GZIPOutputStream(OutputStream out) throws IOException {
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   109
        this(out, 512, false);
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   110
    }
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   111
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   112
    /**
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   113
     * Creates a new output stream with a default buffer size and
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   114
     * the specified flush mode.
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   115
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   116
     * @param out the output stream
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   117
     * @param syncFlush
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   118
     *        if {@code true} invocation of the inherited
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   119
     *        {@link DeflaterOutputStream#flush() flush()} method of
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   120
     *        this instance flushes the compressor with flush mode
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   121
     *        {@link Deflater#SYNC_FLUSH} before flushing the output
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   122
     *        stream, otherwise only flushes the output stream
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   123
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   124
     * @exception IOException If an I/O error has occurred.
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   125
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   126
     * @since 1.7
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   127
     */
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   128
    public GZIPOutputStream(OutputStream out, boolean syncFlush)
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   129
        throws IOException
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   130
    {
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   131
        this(out, 512, syncFlush);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Writes array of bytes to the compressed output stream. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * will block until all the bytes are written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param buf the data to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param off the start offset of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param len the length of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @exception IOException If an I/O error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public synchronized void write(byte[] buf, int off, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        super.write(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        crc.update(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Finishes writing compressed data to the output stream without closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * the underlying stream. Use this method when applying multiple filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * in succession to the same output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public void finish() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (!def.finished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            def.finish();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            while (!def.finished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                int len = def.deflate(buf, 0, buf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                if (def.finished() && len <= buf.length - TRAILER_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    // last deflater buffer. Fit trailer at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    writeTrailer(buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    len = len + TRAILER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    out.write(buf, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                if (len > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    out.write(buf, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            // if we can't fit the trailer at the end of the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            // deflater buffer, we write it separately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            byte[] trailer = new byte[TRAILER_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            writeTrailer(trailer, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            out.write(trailer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Writes GZIP member header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private void writeHeader() throws IOException {
5608
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   182
        out.write(new byte[] {
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   183
                      (byte) GZIP_MAGIC,        // Magic number (short)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   184
                      (byte)(GZIP_MAGIC >> 8),  // Magic number (short)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   185
                      Deflater.DEFLATED,        // Compression method (CM)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   186
                      0,                        // Flags (FLG)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   187
                      0,                        // Modification time MTIME (int)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   188
                      0,                        // Modification time MTIME (int)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   189
                      0,                        // Modification time MTIME (int)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   190
                      0,                        // Modification time MTIME (int)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   191
                      0,                        // Extra flags (XFLG)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   192
                      0                         // Operating system (OS)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   193
                  });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Writes GZIP member trailer to a byte array, starting at a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private void writeTrailer(byte[] buf, int offset) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        writeInt((int)crc.getValue(), buf, offset); // CRC-32 of uncompr. data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        writeInt(def.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Writes integer in Intel byte order to a byte array, starting at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * given offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    private void writeInt(int i, byte[] buf, int offset) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        writeShort(i & 0xffff, buf, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        writeShort((i >> 16) & 0xffff, buf, offset + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Writes short integer in Intel byte order to a byte array, starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * at a given offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    private void writeShort(int s, byte[] buf, int offset) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        buf[offset] = (byte)(s & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        buf[offset + 1] = (byte)((s >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
}