jdk/src/share/classes/java/util/zip/GZIPInputStream.java
author sherman
Wed, 04 Mar 2009 09:26:41 -0800
changeset 2178 5a730fff4d0d
parent 2 90ce3da70b43
child 5506 202f599c92aa
child 5605 bba86030a87b
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 1996-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.SequenceInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.EOFException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class implements a stream filter for reading compressed data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * the GZIP file format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @see         InflaterInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author      David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
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 GZIPInputStream extends InflaterInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * CRC-32 for uncompressed data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    protected CRC32 crc = new CRC32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Indicates end of input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected boolean eos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private boolean closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Check to make sure that this stream has not been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        if (closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            throw new IOException("Stream closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Creates a new input stream with the specified buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param in the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param size the input buffer size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @exception IllegalArgumentException if size is <= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public GZIPInputStream(InputStream in, int size) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        super(in, new Inflater(true), size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        usesDefaultInflater = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        readHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        crc.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Creates a new input stream with a default buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param in the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public GZIPInputStream(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this(in, 512);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Reads uncompressed data into an array of bytes. If <code>len</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * zero, the method will block until some input can be decompressed; otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * no bytes are read and <code>0</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param buf the buffer into which the data is read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param off the start offset in the destination array <code>b</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param len the maximum number of bytes read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @return  the actual number of bytes read, or -1 if the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *          compressed input stream is reached
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @exception  NullPointerException If <code>buf</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <code>len</code> is negative, or <code>len</code> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * <code>buf.length - off</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @exception IOException if an I/O error has occurred or the compressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *                        input data is corrupt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public int read(byte[] buf, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (eos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        len = super.read(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            readTrailer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            eos = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            crc.update(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return len;
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 releases any system resources associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * with the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (!closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            eos = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            closed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * GZIP header magic number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public final static int GZIP_MAGIC = 0x8b1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * File header flags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private final static int FTEXT      = 1;    // Extra text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private final static int FHCRC      = 2;    // Header CRC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private final static int FEXTRA     = 4;    // Extra field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private final static int FNAME      = 8;    // File name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private final static int FCOMMENT   = 16;   // File comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Reads GZIP member header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private void readHeader() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        CheckedInputStream in = new CheckedInputStream(this.in, crc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        crc.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // Check header magic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (readUShort(in) != GZIP_MAGIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            throw new IOException("Not in GZIP format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // Check compression method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (readUByte(in) != 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new IOException("Unsupported compression method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // Read flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int flg = readUByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // Skip MTIME, XFL, and OS fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        skipBytes(in, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        // Skip optional extra field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if ((flg & FEXTRA) == FEXTRA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            skipBytes(in, readUShort(in));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        // Skip optional file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if ((flg & FNAME) == FNAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            while (readUByte(in) != 0) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        // Skip optional file comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if ((flg & FCOMMENT) == FCOMMENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            while (readUByte(in) != 0) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // Check optional header CRC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if ((flg & FHCRC) == FHCRC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            int v = (int)crc.getValue() & 0xffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (readUShort(in) != v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                throw new IOException("Corrupt GZIP header");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Reads GZIP member trailer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private void readTrailer() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        InputStream in = this.in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        int n = inf.getRemaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            in = new SequenceInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        new ByteArrayInputStream(buf, len - n, n), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // Uses left-to-right evaluation order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if ((readUInt(in) != crc.getValue()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // rfc1952; ISIZE is the input size modulo 2^32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            (readUInt(in) != (inf.getBytesWritten() & 0xffffffffL)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new IOException("Corrupt GZIP trailer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Reads unsigned integer in Intel byte order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private long readUInt(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        long s = readUShort(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return ((long)readUShort(in) << 16) | s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Reads unsigned short in Intel byte order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private int readUShort(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        int b = readUByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return ((int)readUByte(in) << 8) | b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Reads unsigned byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    private int readUByte(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        int b = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (b == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            throw new EOFException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (b < -1 || b > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            // Report on this.in, not argument in; see read{Header, Trailer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            throw new IOException(this.in.getClass().getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                + ".read() returned value out of range -1..255: " + b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private byte[] tmpbuf = new byte[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Skips bytes of input data blocking until all bytes are skipped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Does not assume that the input stream is capable of seeking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    private void skipBytes(InputStream in, int n) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        while (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            int len = in.read(tmpbuf, 0, n < tmpbuf.length ? n : tmpbuf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                throw new EOFException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            n -= 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
}