src/java.base/share/classes/java/util/zip/GZIPOutputStream.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45434 jdk/src/java.base/share/classes/java/util/zip/GZIPOutputStream.java@4582657c7260
child 58242 94bb65cb37d3
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18156
diff changeset
     2
 * Copyright (c) 1996, 2013, 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
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 32649
diff changeset
    35
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
class GZIPOutputStream extends DeflaterOutputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * CRC-32 of uncompressed data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    protected CRC32 crc = new CRC32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * GZIP header magic number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
    48
    private static final int GZIP_MAGIC = 0x8b1f;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Trailer size in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
    54
    private static final int TRAILER_SIZE = 8;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * 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
    58
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    59
     * <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
    60
     * the 3-argument constructor GZIPOutputStream(out, size, false).
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    61
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @param out the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param size the output buffer size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @exception IOException If an I/O error has occurred.
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5627
diff changeset
    65
     * @exception IllegalArgumentException if {@code size <= 0}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    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
    68
        this(out, size, false);
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
    /**
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    72
     * 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
    73
     * flush mode.
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    74
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    75
     * @param out the output stream
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    76
     * @param size the output buffer size
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    77
     * @param syncFlush
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    78
     *        if {@code true} invocation of the inherited
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    79
     *        {@link DeflaterOutputStream#flush() flush()} method of
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    80
     *        this instance flushes the compressor with flush mode
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    81
     *        {@link Deflater#SYNC_FLUSH} before flushing the output
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    82
     *        stream, otherwise only flushes the output stream
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    83
     * @exception IOException If an I/O error has occurred.
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5627
diff changeset
    84
     * @exception IllegalArgumentException if {@code size <= 0}
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    85
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    86
     * @since 1.7
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    87
     */
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    88
    public GZIPOutputStream(OutputStream out, int size, boolean syncFlush)
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    89
        throws IOException
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    90
    {
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    91
        super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true),
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    92
              size,
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    93
              syncFlush);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        usesDefaultDeflater = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        writeHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        crc.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
    99
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * 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
   102
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   103
     * <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
   104
     * the 2-argument constructor GZIPOutputStream(out, false).
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   105
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param out the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @exception IOException If an I/O error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public GZIPOutputStream(OutputStream out) throws IOException {
5607
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   110
        this(out, 512, false);
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
    /**
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   114
     * 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
   115
     * the specified flush mode.
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   116
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   117
     * @param out the output stream
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   118
     * @param syncFlush
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   119
     *        if {@code true} invocation of the inherited
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   120
     *        {@link DeflaterOutputStream#flush() flush()} method of
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   121
     *        this instance flushes the compressor with flush mode
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   122
     *        {@link Deflater#SYNC_FLUSH} before flushing the output
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   123
     *        stream, otherwise only flushes the output stream
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   124
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   125
     * @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
   126
     *
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   127
     * @since 1.7
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   128
     */
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   129
    public GZIPOutputStream(OutputStream out, boolean syncFlush)
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   130
        throws IOException
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   131
    {
f01eda72e178 4813885: RFE: GZIPOutputStream should implement flush using Z_SYNC_FLUSH
sherman
parents: 2
diff changeset
   132
        this(out, 512, syncFlush);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Writes array of bytes to the compressed output stream. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * will block until all the bytes are written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param buf the data to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param off the start offset of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param len the length of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @exception IOException If an I/O error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public synchronized void write(byte[] buf, int off, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        super.write(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        crc.update(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Finishes writing compressed data to the output stream without closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * the underlying stream. Use this method when applying multiple filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * in succession to the same output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void finish() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (!def.finished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            def.finish();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            while (!def.finished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                int len = def.deflate(buf, 0, buf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                if (def.finished() && len <= buf.length - TRAILER_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    // last deflater buffer. Fit trailer at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    writeTrailer(buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    len = len + TRAILER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    out.write(buf, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (len > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    out.write(buf, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            // if we can't fit the trailer at the end of the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            // deflater buffer, we write it separately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            byte[] trailer = new byte[TRAILER_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            writeTrailer(trailer, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            out.write(trailer);
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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Writes GZIP member header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    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
   183
        out.write(new byte[] {
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   184
                      (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
   185
                      (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
   186
                      Deflater.DEFLATED,        // Compression method (CM)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   187
                      0,                        // Flags (FLG)
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,                        // Modification time MTIME (int)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   192
                      0,                        // Extra flags (XFLG)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   193
                      0                         // Operating system (OS)
6771207f52b4 4853493: GZIPOutputStream passes a reference to a private array into an untrusted method
sherman
parents: 5607
diff changeset
   194
                  });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Writes GZIP member trailer to a byte array, starting at a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private void writeTrailer(byte[] buf, int offset) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        writeInt((int)crc.getValue(), buf, offset); // CRC-32 of uncompr. data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        writeInt(def.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Writes integer in Intel byte order to a byte array, starting at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * given offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    private void writeInt(int i, byte[] buf, int offset) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        writeShort(i & 0xffff, buf, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        writeShort((i >> 16) & 0xffff, buf, offset + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Writes short integer in Intel byte order to a byte array, starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * at a given offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private void writeShort(int s, byte[] buf, int offset) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        buf[offset] = (byte)(s & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        buf[offset + 1] = (byte)((s >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
}