src/java.base/share/classes/java/util/zip/InflaterInputStream.java
author jboes
Tue, 24 Sep 2019 09:43:43 +0100
changeset 58288 48e480e56aad
parent 58242 94bb65cb37d3
child 58679 9c3209ff7550
child 59201 b24f4caa1411
permissions -rw-r--r--
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: bchristi, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 1996, 2019, 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.FilterInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.EOFException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class implements a stream filter for uncompressing data in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * "deflate" compression format. It is also used as the basis for other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * decompression filters, such as GZIPInputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @see         Inflater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author      David Connelly
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 39642
diff changeset
    40
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class InflaterInputStream extends FilterInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Decompressor for this stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    protected Inflater inf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Input buffer for decompression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected byte[] buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Length of input buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private boolean closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // this flag is set to true after EOF has reached
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private boolean reachEOF = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Check to make sure that this stream has not been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            throw new IOException("Stream closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Creates a new input stream with the specified decompressor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param in the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param inf the decompressor ("inflater")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param size the input buffer size
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
    79
     * @throws    IllegalArgumentException if {@code size <= 0}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public InflaterInputStream(InputStream in, Inflater inf, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        super(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (in == null || inf == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        } else if (size <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            throw new IllegalArgumentException("buffer size <= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        this.inf = inf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        buf = new byte[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Creates a new input stream with the specified decompressor and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * default buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param in the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param inf the decompressor ("inflater")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public InflaterInputStream(InputStream in, Inflater inf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this(in, inf, 512);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    boolean usesDefaultInflater = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Creates a new input stream with a default decompressor and buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param in the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public InflaterInputStream(InputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this(in, new Inflater());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        usesDefaultInflater = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private byte[] singleByteBuf = new byte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Reads a byte of uncompressed data. This method will block until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * enough input is available for decompression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return the byte read, or -1 if end of compressed input is reached
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   119
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        ensureOpen();
11828
590711df7828 7143629: JDK jar/zip code should use unsigned library support
darcy
parents: 5506
diff changeset
   123
        return read(singleByteBuf, 0, 1) == -1 ? -1 : Byte.toUnsignedInt(singleByteBuf[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   127
     * Reads uncompressed data into an array of bytes. If {@code len} is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * zero, the method will block until some input can be decompressed; otherwise,
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   129
     * no bytes are read and {@code 0} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param b the buffer into which the data is read
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   131
     * @param off the start offset in the destination array {@code b}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param len the maximum number of bytes read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the actual number of bytes read, or -1 if the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *         compressed input is reached or a preset dictionary is needed
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   135
     * @throws     NullPointerException If {@code b} is {@code null}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   136
     * @throws     IndexOutOfBoundsException If {@code off} is negative,
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   137
     * {@code len} is negative, or {@code len} is greater than
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   138
     * {@code b.length - off}
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   139
     * @throws    ZipException if a ZIP format error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   140
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public int read(byte[] b, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else if (off < 0 || len < 0 || len > b.length - off) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        } else if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            int n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            while ((n = inf.inflate(b, off, len)) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                if (inf.finished() || inf.needsDictionary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    reachEOF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                if (inf.needsInput()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    fill();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } catch (DataFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            String s = e.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new ZipException(s != null ? s : "Invalid ZLIB data format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Returns 0 after EOF has been reached, otherwise always return 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Programs should not count on this method to return the actual number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * of bytes that could be read without blocking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @return     1 before EOF and 0 after EOF.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   176
     * @throws     IOException  if an I/O error occurs.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public int available() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (reachEOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            return 0;
39642
cac81257c657 7031075: GZIPInputStream's available() reports 1, but read() gives -1.
sherman
parents: 25859
diff changeset
   183
        } else if (inf.finished()) {
cac81257c657 7031075: GZIPInputStream's available() reports 1, but read() gives -1.
sherman
parents: 25859
diff changeset
   184
            // the end of the compressed data stream has been reached
cac81257c657 7031075: GZIPInputStream's available() reports 1, but read() gives -1.
sherman
parents: 25859
diff changeset
   185
            reachEOF = true;
cac81257c657 7031075: GZIPInputStream's available() reports 1, but read() gives -1.
sherman
parents: 25859
diff changeset
   186
            return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private byte[] b = new byte[512];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Skips specified number of bytes of uncompressed data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param n the number of bytes to skip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return the actual number of bytes skipped.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   198
     * @throws    IOException if an I/O error has occurred
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   199
     * @throws    IllegalArgumentException if {@code n < 0}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public long skip(long n) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (n < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            throw new IllegalArgumentException("negative skip length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        int max = (int)Math.min(n, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        int total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        while (total < max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            int len = max - total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (len > b.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                len = b.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            len = read(b, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                reachEOF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            total += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Closes this input stream and releases any system resources associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * with the stream.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   226
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (!closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if (usesDefaultInflater)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                inf.end();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            closed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Fills input buffer with more data to decompress.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   239
     * @throws    IOException if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    protected void fill() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        len = in.read(buf, 0, buf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            throw new EOFException("Unexpected end of ZLIB input stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        inf.setInput(buf, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   251
     * Tests if this input stream supports the {@code mark} and
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   252
     * {@code reset} methods. The {@code markSupported}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   253
     * method of {@code InflaterInputStream} returns
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   254
     * {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   256
     * @return  a {@code boolean} indicating if this stream type supports
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   257
     *          the {@code mark} and {@code reset} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see     java.io.InputStream#mark(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see     java.io.InputStream#reset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public boolean markSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Marks the current position in this input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   268
     * <p> The {@code mark} method of {@code InflaterInputStream}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @param   readlimit   the maximum limit of bytes that can be read before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *                      the mark position becomes invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @see     java.io.InputStream#reset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public synchronized void mark(int readlimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Repositions this stream to the position at the time the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   280
     * {@code mark} method was last called on this input stream.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   282
     * <p> The method {@code reset} for class
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   283
     * {@code InflaterInputStream} does nothing except throw an
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   284
     * {@code IOException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   286
     * @throws     IOException  if this method is invoked.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see     java.io.InputStream#mark(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @see     java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public synchronized void reset() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        throw new IOException("mark/reset not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}