jdk/src/share/classes/java/util/zip/DeflaterInputStream.java
author sherman
Wed, 04 Mar 2009 09:26:41 -0800
changeset 2178 5a730fff4d0d
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6812879: Excess code line in ArrayList method Summary: Removed the line of "oldData" which is no longer used. Reviewed-by: martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Implements an input stream filter for compressing data in the "deflate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * compression format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @since       1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author      David R Tribble (david@tribble.com)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @see DeflaterOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see InflaterOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see InflaterInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class DeflaterInputStream extends FilterInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /** Compressor for this stream. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    protected final Deflater def;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /** Input buffer for reading compressed data. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected final byte[] buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /** Temporary read buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private byte[] rbuf = new byte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /** Default compressor is used. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private boolean usesDefaultDeflater = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /** End of the underlying input stream has been reached. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private boolean reachEOF = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Check to make sure that this stream has not been closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (in == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            throw new IOException("Stream closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Creates a new input stream with a default compressor and buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param in input stream to read the uncompressed data to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @throws NullPointerException if {@code in} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public DeflaterInputStream(InputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this(in, new Deflater());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        usesDefaultDeflater = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Creates a new input stream with the specified compressor and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * default buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param in input stream to read the uncompressed data to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param defl compressor ("deflater") for this stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @throws NullPointerException if {@code in} or {@code defl} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public DeflaterInputStream(InputStream in, Deflater defl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this(in, defl, 512);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Creates a new input stream with the specified compressor and buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param in input stream to read the uncompressed data to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param defl compressor ("deflater") for this stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param bufLen compression buffer size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @throws IllegalArgumentException if {@code bufLen} is <= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @throws NullPointerException if {@code in} or {@code defl} is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public DeflaterInputStream(InputStream in, Deflater defl, int bufLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        super(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // Sanity checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (in == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            throw new NullPointerException("Null input");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (defl == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            throw new NullPointerException("Null deflater");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (bufLen < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throw new IllegalArgumentException("Buffer size < 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // Initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        def = defl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        buf = new byte[bufLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Closes this input stream and its underlying input stream, discarding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * any pending uncompressed data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @throws IOException if an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (in != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                // Clean up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                if (usesDefaultDeflater) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    def.end();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Reads a single byte of compressed data from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * This method will block until some input can be read and compressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return a single byte of compressed data, or -1 if the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * uncompressed input stream is reached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @throws IOException if an I/O error occurs or if this stream is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * already closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // Read a single byte of compressed data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        int len = read(rbuf, 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (len <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return (rbuf[0] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Reads compressed data into a byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * This method will block until some input can be read and compressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param b buffer into which the data is read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param off starting offset of the data within {@code b}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param len maximum number of compressed bytes to read into {@code b}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return the actual number of bytes read, or -1 if the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * uncompressed input stream is reached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws IndexOutOfBoundsException  if {@code len} > {@code b.length -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * off}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @throws IOException if an I/O error occurs or if this input stream is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * already closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public int read(byte[] b, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        // Sanity checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            throw new NullPointerException("Null buffer for read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        } else if (off < 0 || len < 0 || len > b.length - off) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        } else if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // Read and compress (deflate) input data bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        int cnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        while (len > 0 && !def.finished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            int n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            // Read data from the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (def.needsInput()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                n = in.read(buf, 0, buf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                if (n < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    // End of the input stream reached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    def.finish();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                } else if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    def.setInput(buf, 0, n);
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
            // Compress the input data, filling the read buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            n = def.deflate(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            cnt += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            off += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            len -= n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (cnt == 0 && def.finished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            reachEOF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            cnt = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Skips over and discards data from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * This method may block until the specified number of bytes are read and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * skipped. <em>Note:</em> While {@code n} is given as a {@code long},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * the maximum number of bytes which can be skipped is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * {@code Integer.MAX_VALUE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param n number of bytes to be skipped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return the actual number of bytes skipped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @throws IOException if an I/O error occurs or if this stream is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * already closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public long skip(long n) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (n < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            throw new IllegalArgumentException("negative skip length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // Skip bytes by repeatedly decompressing small blocks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (rbuf.length < 512)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            rbuf = new byte[512];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        int total = (int)Math.min(n, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        long cnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        while (total > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            // Read a small block of uncompressed bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            int len = read(rbuf, 0, (total <= rbuf.length ? total : rbuf.length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (len < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            cnt += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            total -= len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Returns 0 after EOF has been reached, otherwise always return 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Programs should not count on this method to return the actual number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * of bytes that could be read without blocking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return zero after the end of the underlying input stream has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * reached, otherwise always returns 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @throws IOException if an I/O error occurs or if this stream is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * already closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public int available() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (reachEOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Always returns {@code false} because this input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * the {@link #mark mark()} and {@link #reset reset()} methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return false, always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public boolean markSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <i>This operation is not supported</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param limit maximum bytes that can be read before invalidating the position marker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public void mark(int limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // Operation not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <i>This operation is not supported</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @throws IOException always thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public void reset() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        throw new IOException("mark/reset not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
}