summaryrefslogtreecommitdiff
path: root/libjava/java/util/zip
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2006-03-10 23:09:23 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2006-03-10 23:09:23 +0000
commitb3c9e878a88866f035822406f53ae9f5b165ce96 (patch)
tree61a09663191772cb2d0e99154b48b8c6269350fa /libjava/java/util/zip
parentd217355ec70102e776f09159d3831277b729affd (diff)
downloadgcc-b3c9e878a88866f035822406f53ae9f5b165ce96.tar.gz
libjava
PR libgcj/25713: * java/util/zip/Deflater.java (flush): New method. * sources.am, Makefile.in: Rebuilt. * java/util/zip/DeflaterOutputStream.java: Removed. * java/util/zip/InflaterInputStream.java: Likewise. * java/util/zip/GZIPInputStream.java: Likewise. * java/util/zip/GZIPOutputStream.java: Likewise. libjava/classpath For PR libgcj/25713: * java/util/zip/InflaterInputStream.java (read): Replaced with libgcj implementation. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111949 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/util/zip')
-rw-r--r--libjava/java/util/zip/Deflater.java8
-rw-r--r--libjava/java/util/zip/DeflaterOutputStream.java194
-rw-r--r--libjava/java/util/zip/GZIPInputStream.java252
-rw-r--r--libjava/java/util/zip/GZIPOutputStream.java146
-rw-r--r--libjava/java/util/zip/InflaterInputStream.java264
5 files changed, 7 insertions, 857 deletions
diff --git a/libjava/java/util/zip/Deflater.java b/libjava/java/util/zip/Deflater.java
index 78af729637a..8ac8a34a6ae 100644
--- a/libjava/java/util/zip/Deflater.java
+++ b/libjava/java/util/zip/Deflater.java
@@ -1,5 +1,5 @@
/* Deflater.java - Compress a data stream
- Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -325,4 +325,10 @@ public class Deflater
* already called or another dictionary was already set.
*/
public native void setDictionary(byte[] buf, int off, int len);
+
+ // Classpath's compression library supports flushing, but we
+ // don't. So this is a no-op here.
+ void flush()
+ {
+ }
}
diff --git a/libjava/java/util/zip/DeflaterOutputStream.java b/libjava/java/util/zip/DeflaterOutputStream.java
deleted file mode 100644
index 37a3f9896ff..00000000000
--- a/libjava/java/util/zip/DeflaterOutputStream.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/* DeflaterOutputStream.java - Output filter for compressing.
- Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.util.zip;
-
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-/* Written using on-line Java Platform 1.2 API Specification
- * and JCL book.
- * Believed complete and correct.
- */
-
-/**
- * This is a special FilterOutputStream deflating the bytes that are
- * written through it. It uses the Deflater for deflating.
- *
- * A special thing to be noted is that flush() doesn't flush
- * everything in Sun's JDK, but it does so in jazzlib. This is because
- * Sun's Deflater doesn't have a way to flush() everything, without
- * finishing the stream.
- *
- * @author Tom Tromey, Jochen Hoenicke
- * @date Jan 11, 2001
- */
-public class DeflaterOutputStream extends FilterOutputStream
-{
- /**
- * This buffer is used temporarily to retrieve the bytes from the
- * deflater and write them to the underlying output stream.
- */
- protected byte[] buf;
-
- /**
- * The deflater which is used to deflate the stream.
- */
- protected Deflater def;
-
- /**
- * Deflates everything in the def's input buffers. This will call
- * <code>def.deflate()</code> until all bytes from the input buffers
- * are processed.
- */
- protected void deflate() throws IOException
- {
- while (! def.needsInput())
- {
- int len = def.deflate(buf, 0, buf.length);
- if (len > 0)
- out.write(buf, 0, len);
- }
- }
-
- /**
- * Creates a new DeflaterOutputStream with a default Deflater and
- * default buffer size.
- * @param out the output stream where deflated output should be written.
- */
- public DeflaterOutputStream(OutputStream out)
- {
- this(out, new Deflater(), 512);
- }
-
- /**
- * Creates a new DeflaterOutputStream with the given Deflater and
- * default buffer size.
- * @param out the output stream where deflated output should be written.
- * @param defl the underlying deflater.
- */
- public DeflaterOutputStream(OutputStream out, Deflater defl)
- {
- this(out, defl, 512);
- }
-
- /**
- * Creates a new DeflaterOutputStream with the given Deflater and
- * buffer size.
- * @param out the output stream where deflated output should be written.
- * @param defl the underlying deflater.
- * @param bufsize the buffer size.
- * @exception IllegalArgumentException if bufsize isn't positive.
- */
- public DeflaterOutputStream(OutputStream out, Deflater defl, int bufsize)
- {
- super(out);
- if (bufsize <= 0)
- throw new IllegalArgumentException("bufsize <= 0");
- buf = new byte[bufsize];
- def = defl;
- }
-
- /**
- * Finishes the stream by calling finish() on the deflater. This
- * was the only way to ensure that all bytes are flushed in Sun's
- * JDK.
- */
- public void finish() throws IOException
- {
- inbufWrite();
- def.finish();
- while (! def.finished())
- {
- int len = def.deflate(buf, 0, buf.length);
- if (len > 0)
- out.write(buf, 0, len);
- }
- }
-
- /**
- * Calls finish() and closes the stream.
- */
- public void close() throws IOException
- {
- finish();
- out.close();
- }
-
- /**
- * Writes a single byte to the compressed output stream.
- * @param bval the byte value.
- */
- public void write(int bval) throws IOException
- {
- if (inbuf == null)
- inbuf = new byte[128];
- else if (inbufLength == inbuf.length)
- inbufWrite();
- inbuf[inbufLength++] = (byte) bval;
- }
-
- /**
- * Writes a len bytes from an array to the compressed stream.
- * @param buf the byte array.
- * @param off the offset into the byte array where to start.
- * @param len the number of bytes to write.
- */
- public void write(byte[] buf, int off, int len) throws IOException
- {
- inbufWrite();
- def.setInput(buf, off, len);
- deflate();
- }
-
- private void inbufWrite() throws IOException
- {
- if (inbufLength > 0)
- {
- int size = inbufLength;
- inbufLength = 0;
- write(inbuf, 0, size);
- }
- }
-
- // Used, if needed, for write(int).
- private byte[] inbuf;
- // Used length of inbuf.
- private int inbufLength;
-}
diff --git a/libjava/java/util/zip/GZIPInputStream.java b/libjava/java/util/zip/GZIPInputStream.java
deleted file mode 100644
index d0a053a2a4a..00000000000
--- a/libjava/java/util/zip/GZIPInputStream.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/* GZIPInputStream.java - Input filter for reading gzip file
- Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.util.zip;
-
-import java.io.InputStream;
-import java.io.IOException;
-
-/**
- * This filter stream is used to decompress a "GZIP" format stream.
- * The "GZIP" format is described in RFC 1952.
- *
- * @author John Leuner
- * @author Tom Tromey
- * @since JDK 1.1
- */
-public class GZIPInputStream
- extends InflaterInputStream
-{
- /**
- * The magic number found at the start of a GZIP stream.
- */
- public static final int GZIP_MAGIC = 0x8b1f;
-
- static final int Z_DEFLATED = 8;
-
- /**
- * The mask for bit 1 of the flag byte.
- */
- static final int HEAD_CRC = 0x02;
-
- /**
- * The mask for bit 2 of the flag byte.
- */
- static final int EXTRA_FIELD = 0x04;
-
- /**
- * The mask for bit 3 of the flag byte.
- */
- static final int ORIG_NAME = 0x08;
-
- /**
- * The mask for bit 4 of the flag byte.
- */
- static final int COMMENT = 0x10;
-
- /**
- * The mask for all reserved bits of the flag byte.
- */
- static final int RESERVED = 0xe0;
-
- /**
- * The CRC-32 checksum value for uncompressed data.
- */
- protected CRC32 crc;
-
- /**
- * Indicates whether or not the end of the stream has been reached.
- */
- protected boolean eos;
-
- /**
- * Creates a GZIPInputStream with the default buffer size.
- *
- * @param in The stream to read compressed data from
- * (in GZIP format).
- *
- * @throws IOException if an error occurs during an I/O operation.
- */
- public GZIPInputStream(InputStream in)
- throws IOException
- {
- this(in, 4096);
- }
-
- /**
- * Creates a GZIPInputStream with the specified buffer size.
- *
- * @param in The stream to read compressed data from
- * (in GZIP format).
- * @param size The size of the buffer to use.
- *
- * @throws IOException if an error occurs during an I/O operation.
- * @throws IllegalArgumentException if <code>size</code>
- * is less than or equal to 0.
- */
- public GZIPInputStream(InputStream in, int size)
- throws IOException
- {
- super(in, new Inflater(true), size);
-
- // NOTE: header reading code taken from zlib's gzio.c.
-
- // Read the magic number.
- int magic = eof_read() | (eof_read() << 8);
- if (magic != GZIP_MAGIC)
- throw new ZipException("gzip header corrupted");
-
- int method = eof_read();
- int flags = eof_read();
- // Test from zlib.
- if (method != Z_DEFLATED || (flags & RESERVED) != 0)
- throw new ZipException("gzip header corrupted");
-
- // Discard time, xflags, OS code.
- for (int i = 0; i < 6; ++i)
- eof_read();
-
- // Skip the extra field.
- if ((flags & EXTRA_FIELD) != 0)
- {
- int len = eof_read() | (eof_read() << 8);
- while (len-- != 0)
- eof_read();
- }
-
- if ((flags & ORIG_NAME) != 0)
- {
- while (true)
- {
- int c = eof_read();
- if (c == 0)
- break;
- }
- }
-
- if ((flags & COMMENT) != 0)
- {
- while (true)
- {
- int c = eof_read();
- if (c == 0)
- break;
- }
- }
-
- if ((flags & HEAD_CRC) != 0)
- {
- // FIXME: consider checking CRC of the header.
- eof_read();
- eof_read();
- }
-
- crc = new CRC32();
- }
-
- /**
- * Closes the input stream.
- *
- * @throws IOException if an error occurs during an I/O operation.
- */
- public void close()
- throws IOException
- {
- // Nothing to do here.
- super.close();
- }
-
- private final int eof_read() throws IOException
- {
- int r = in.read();
- if (r == -1)
- throw new ZipException("gzip header corrupted");
- return r & 0xff;
- }
-
- /**
- * Reads in GZIP-compressed data and stores it in uncompressed form
- * into an array of bytes. The method will block until either
- * enough input data becomes available or the compressed stream
- * reaches its end.
- *
- * @param buf the buffer into which the uncompressed data will
- * be stored.
- * @param offset the offset indicating where in <code>buf</code>
- * the uncompressed data should be placed.
- * @param len the number of uncompressed bytes to be read.
- */
- public int read(byte[] buf, int offset, int len) throws IOException
- {
- if (eos)
- return -1;
- int r = super.read(buf, offset, len);
- if (r == -1)
- {
- eos = true;
-
- byte[] tmp = new byte[8];
- // First copy remaining bytes from inflater input buffer.
- int avail = inf.getRemaining();
- System.arraycopy(this.buf, this.len - avail, tmp, 0, avail);
-
- // Now read remaining bytes from wrapped input stream.
- for (int i = avail; i < 8; ++i)
- {
- tmp[i] = (byte) eof_read();
- }
-
- // Be careful to avoid sign extension here; CRC32.getValue()
- // returns a long.
- long header_crc = read4(tmp, 0) & 0xffffffffL;
- if (crc.getValue() != header_crc)
- throw new ZipException("corrupted gzip file - crc mismatch");
- int isize = read4(tmp, 4);
- if (inf.getTotalOut() != isize)
- throw new ZipException("corrupted gzip file - size mismatch");
- return -1;
- }
- crc.update(buf, offset, r);
- return r;
- }
-
- private final int read4(byte[] buf, int offset) throws IOException
- {
- return (((buf[offset + 3] & 0xFF) << 24) + ((buf[offset + 2] & 0xFF) << 16)
- + ((buf[offset + 1] & 0xFF) << 8) + (buf[offset] & 0xFF));
- }
-}
diff --git a/libjava/java/util/zip/GZIPOutputStream.java b/libjava/java/util/zip/GZIPOutputStream.java
deleted file mode 100644
index 260911a2215..00000000000
--- a/libjava/java/util/zip/GZIPOutputStream.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/* GZIPOutputStream.java - Create a file in gzip format
- Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.util.zip;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * This filter stream is used to compress a stream into a "GZIP" stream.
- * The "GZIP" format is described in RFC 1952.
- *
- * @author John Leuner
- * @author Tom Tromey
- * @since JDK 1.1
- */
-
-/* Written using on-line Java Platform 1.2 API Specification
- * and JCL book.
- * Believed complete and correct.
- */
-
-public class GZIPOutputStream extends DeflaterOutputStream
-{
- /**
- * CRC-32 value for uncompressed data
- */
- protected CRC32 crc;
-
- /**
- * Creates a GZIPOutputStream with the default buffer size
- *
- * @param out The stream to read data (to be compressed) from
- *
- */
- public GZIPOutputStream(OutputStream out) throws IOException
- {
- this(out, 4096);
- }
-
- /**
- * Creates a GZIPOutputStream with the specified buffer size
- *
- * @param out The stream to read compressed data from
- * @param size Size of the buffer to use
- */
- public GZIPOutputStream(OutputStream out, int size) throws IOException
- {
- super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size);
- crc = new CRC32();
- put2(GZIPInputStream.GZIP_MAGIC);
- out.write(GZIPInputStream.Z_DEFLATED);
- // No flags for now.
- out.write(0);
- // No time either.
- put2(0);
- put2(0);
- // No xflags either.
- out.write(0);
- // FIXME: unknown OS.
- out.write(255);
- }
-
- public synchronized void write(int bval) throws IOException
- {
- super.write(bval);
- crc.update(bval);
- }
-
- public synchronized void write(byte[] buf) throws IOException
- {
- write(buf, 0, buf.length);
- }
-
- public synchronized void write(byte[] buf, int off, int len)
- throws IOException
- {
- super.write(buf, off, len);
- crc.update(buf, off, len);
- }
-
- /**
- * Writes remaining compressed output data to the output stream
- * and closes it.
- */
- public void close() throws IOException
- {
- finish();
- out.close();
- }
-
- public void finish() throws IOException
- {
- super.finish();
- put4((int) crc.getValue());
- put4(def.getTotalIn());
- }
-
- private final void put2(int i) throws IOException
- {
- out.write(i);
- out.write(i >> 8);
- }
-
- private final void put4 (int i) throws IOException
- {
- out.write(i);
- out.write(i >> 8);
- out.write(i >> 16);
- out.write(i >> 24);
- }
-}
diff --git a/libjava/java/util/zip/InflaterInputStream.java b/libjava/java/util/zip/InflaterInputStream.java
deleted file mode 100644
index 11b06d24a28..00000000000
--- a/libjava/java/util/zip/InflaterInputStream.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/* InflaterInputStream.java - Input stream filter for decompressing
- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
- Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.util.zip;
-
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * This filter stream is used to decompress data compressed in the "deflate"
- * format. The "deflate" format is described in RFC 1951.
- *
- * This stream may form the basis for other decompression filters, such
- * as the <code>GZIPInputStream</code>.
- *
- * @author John Leuner
- * @author Tom Tromey
- * @since 1.1
- */
-public class InflaterInputStream extends FilterInputStream
-{
- /**
- * Decompressor for this filter
- */
- protected Inflater inf;
-
- /**
- * Byte array used as a buffer
- */
- protected byte[] buf;
-
- /**
- * Size of buffer
- */
- protected int len;
-
- // We just use this if we are decoding one byte at a time with the
- // read() call.
- private byte[] onebytebuffer = new byte[1];
-
- /**
- * Create an InflaterInputStream with the default decompresseor
- * and a default buffer size.
- *
- * @param in the InputStream to read bytes from
- */
- public InflaterInputStream(InputStream in)
- {
- this(in, new Inflater(), 4096);
- }
-
- /**
- * Create an InflaterInputStream with the specified decompresseor
- * and a default buffer size.
- *
- * @param in the InputStream to read bytes from
- * @param inf the decompressor used to decompress data read from in
- */
- public InflaterInputStream(InputStream in, Inflater inf)
- {
- this(in, inf, 4096);
- }
-
- /**
- * Create an InflaterInputStream with the specified decompresseor
- * and a specified buffer size.
- *
- * @param in the InputStream to read bytes from
- * @param inf the decompressor used to decompress data read from in
- * @param size size of the buffer to use
- */
- public InflaterInputStream(InputStream in, Inflater inf, int size)
- {
- super(in);
-
- if (in == null)
- throw new NullPointerException("in may not be null");
- if (inf == null)
- throw new NullPointerException("inf may not be null");
- if (size < 0)
- throw new IllegalArgumentException("size may not be negative");
-
- this.inf = inf;
- this.buf = new byte [size];
- }
-
- /**
- * Returns 0 once the end of the stream (EOF) has been reached.
- * Otherwise returns 1.
- */
- public int available() throws IOException
- {
- // According to the JDK 1.2 docs, this should only ever return 0
- // or 1 and should not be relied upon by Java programs.
- if (inf == null)
- throw new IOException("stream closed");
- return inf.finished() ? 0 : 1;
- }
-
- /**
- * Closes the input stream
- */
- public synchronized void close() throws IOException
- {
- inf = null;
- super.close();
- }
-
- /**
- * Fills the buffer with more data to decompress.
- */
- protected void fill() throws IOException
- {
- if (in == null)
- throw new ZipException ("InflaterInputStream is closed");
-
- len = in.read(buf, 0, buf.length);
-
- if (len < 0)
- throw new ZipException("Deflated stream ends early.");
-
- inf.setInput(buf, 0, len);
- }
-
- /**
- * Reads one byte of decompressed data.
- *
- * The byte is in the lower 8 bits of the int.
- */
- public int read() throws IOException
- {
- int nread = read(onebytebuffer, 0, 1);
- if (nread > 0)
- return onebytebuffer[0] & 0xff;
- return -1;
- }
-
- /**
- * Decompresses data into the byte array
- *
- * @param b the array to read and decompress data into
- * @param off the offset indicating where the data should be placed
- * @param len the number of bytes to decompress
- */
- public int read(byte[] b, int off, int len) throws IOException
- {
- if (inf == null)
- throw new IOException("stream closed");
- if (len == 0)
- return 0;
- if (inf.finished())
- return -1;
-
- int count = 0;
- while (count == 0)
- {
- if (inf.needsInput())
- fill();
-
- try
- {
- count = inf.inflate(b, off, len);
- if (count == 0)
- {
- if (this.len == -1)
- {
- // Couldn't get any more data to feed to the Inflater
- return -1;
- }
- if (inf.needsDictionary())
- throw new ZipException("Inflater needs Dictionary");
- }
- }
- catch (DataFormatException dfe)
- {
- throw new ZipException(dfe.getMessage());
- }
- }
- return count;
- }
-
- /**
- * Skip specified number of bytes of uncompressed data
- *
- * @param n number of bytes to skip
- */
- public long skip(long n) throws IOException
- {
- if (inf == null)
- throw new IOException("stream closed");
- if (n < 0)
- throw new IllegalArgumentException();
-
- if (n == 0)
- return 0;
-
- int buflen = (int) Math.min(n, 2048);
- byte[] tmpbuf = new byte[buflen];
-
- long skipped = 0L;
- while (n > 0L)
- {
- int numread = read(tmpbuf, 0, buflen);
- if (numread <= 0)
- break;
- n -= numread;
- skipped += numread;
- buflen = (int) Math.min(n, 2048);
- }
-
- return skipped;
- }
-
- public boolean markSupported()
- {
- return false;
- }
-
- public void mark(int readLimit)
- {
- }
-
- public void reset() throws IOException
- {
- throw new IOException("reset not supported");
- }
-}