# HG changeset patch
# User Jaroslav Tulach
- * The specification for Adler32 may be found in RFC 1950.
- * (ZLIB Compressed Data Format Specification version 3.3)
- *
- *
- * From that document:
- *
- * "ADLER32 (Adler-32 checksum)
- * This contains a checksum value of the uncompressed data
- * (excluding any dictionary data) computed according to Adler-32
- * algorithm. This algorithm is a 32-bit extension and improvement
- * of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
- * standard.
- *
- * Adler-32 is composed of two sums accumulated per byte: s1 is
- * the sum of all bytes, s2 is the sum of all s1 values. Both sums
- * are done modulo 65521. s1 is initialized to 1, s2 to zero. The
- * Adler-32 checksum is stored as s2*65536 + s1 in most-
- * significant-byte first (network) order."
- *
- * "8.2. The Adler-32 algorithm
- *
- * The Adler-32 algorithm is much faster than the CRC32 algorithm yet
- * still provides an extremely low probability of undetected errors.
- *
- * The modulo on unsigned long accumulators can be delayed for 5552
- * bytes, so the modulo operation time is negligible. If the bytes
- * are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
- * and order sensitive, unlike the first sum, which is just a
- * checksum. That 65521 is prime is important to avoid a possible
- * large class of two-byte errors that leave the check unchanged.
- * (The Fletcher checksum uses 255, which is not prime and which also
- * makes the Fletcher check insensitive to single byte changes 0 <->
- * 255.)
- *
- * The sum s1 is initialized to 1 instead of zero to make the length
- * of the sequence part of s2, so that the length does not have to be
- * checked separately. (Any sequence of zeroes has a Fletcher
- * checksum of zero.)"
- *
- * @author John Leuner, Per Bothner
- * @since JDK 1.1
- *
- * @see InflaterInputStream
- * @see DeflaterOutputStream
- */
-public class Adler32 implements Checksum
-{
-
- /** largest prime smaller than 65536 */
- private static final int BASE = 65521;
-
- private int checksum; //we do all in int.
-
- //Note that java doesn't have unsigned integers,
- //so we have to be careful with what arithmetic
- //we do. We return the checksum as a long to
- //avoid sign confusion.
-
- /**
- * Creates a new instance of the The following code fragment demonstrates a trivial compression
- * and decompression of a string using Deflater and
- * Inflater.
- *
- *
- * Note: When using the 'nowrap' option it is also necessary to provide
- * an extra "dummy" byte as input. This is required by the ZLIB native
- * library in order to support certain optimizations.
- *
- * @param nowrap if true then support GZIP compatible compression
- */
- public Inflater(boolean nowrap) {
- if (getClass() == org.apidesign.bck2brwsr.emul.zip.Inflater.class) {
- impl = null;
- } else {
- impl = new org.apidesign.bck2brwsr.emul.zip.Inflater(nowrap);
- }
- }
-
- /**
- * Creates a new decompressor.
- */
- public Inflater() {
- this(false);
- }
-
- /**
- * Sets input data for decompression. Should be called whenever
- * needsInput() returns true indicating that more input data is
- * required.
- * @param b the input data bytes
- * @param off the start offset of the input data
- * @param len the length of the input data
- * @see Inflater#needsInput
- */
- public void setInput(byte[] b, int off, int len) {
- impl.setInput(b, off, len);
- }
-
- /**
- * Sets input data for decompression. Should be called whenever
- * needsInput() returns true indicating that more input data is
- * required.
- * @param b the input data bytes
- * @see Inflater#needsInput
- */
- public void setInput(byte[] b) {
- impl.setInput(b);
- }
-
- /**
- * Sets the preset dictionary to the given array of bytes. Should be
- * called when inflate() returns 0 and needsDictionary() returns true
- * indicating that a preset dictionary is required. The method getAdler()
- * can be used to get the Adler-32 value of the dictionary needed.
- * @param b the dictionary data bytes
- * @param off the start offset of the data
- * @param len the length of the data
- * @see Inflater#needsDictionary
- * @see Inflater#getAdler
- */
- public void setDictionary(byte[] b, int off, int len) {
- impl.setDictionary(b, off, len);
- }
-
- /**
- * Sets the preset dictionary to the given array of bytes. Should be
- * called when inflate() returns 0 and needsDictionary() returns true
- * indicating that a preset dictionary is required. The method getAdler()
- * can be used to get the Adler-32 value of the dictionary needed.
- * @param b the dictionary data bytes
- * @see Inflater#needsDictionary
- * @see Inflater#getAdler
- */
- public void setDictionary(byte[] b) {
- impl.setDictionary(b);
- }
-
- /**
- * Returns the total number of bytes remaining in the input buffer.
- * This can be used to find out what bytes still remain in the input
- * buffer after decompression has finished.
- * @return the total number of bytes remaining in the input buffer
- */
- public int getRemaining() {
- return impl.getRemaining();
- }
-
- /**
- * Returns true if no data remains in the input buffer. This can
- * be used to determine if #setInput should be called in order
- * to provide more input.
- * @return true if no data remains in the input buffer
- */
- public boolean needsInput() {
- return impl.needsInput();
- }
-
- /**
- * Returns true if a preset dictionary is needed for decompression.
- * @return true if a preset dictionary is needed for decompression
- * @see Inflater#setDictionary
- */
- public boolean needsDictionary() {
- return impl.needsDictionary();
- }
-
- /**
- * Returns true if the end of the compressed data stream has been
- * reached.
- * @return true if the end of the compressed data stream has been
- * reached
- */
- public boolean finished() {
- return impl.finished();
- }
-
- /**
- * Uncompresses bytes into specified buffer. Returns actual number
- * of bytes uncompressed. A return value of 0 indicates that
- * needsInput() or needsDictionary() should be called in order to
- * determine if more input data or a preset dictionary is required.
- * In the latter case, getAdler() can be used to get the Adler-32
- * value of the dictionary required.
- * @param b the buffer for the uncompressed data
- * @param off the start offset of the data
- * @param len the maximum number of uncompressed bytes
- * @return the actual number of uncompressed bytes
- * @exception DataFormatException if the compressed data format is invalid
- * @see Inflater#needsInput
- * @see Inflater#needsDictionary
- */
- public int inflate(byte[] b, int off, int len)
- throws DataFormatException
- {
- return impl.inflate(b, off, len);
- }
-
- /**
- * Uncompresses bytes into specified buffer. Returns actual number
- * of bytes uncompressed. A return value of 0 indicates that
- * needsInput() or needsDictionary() should be called in order to
- * determine if more input data or a preset dictionary is required.
- * In the latter case, getAdler() can be used to get the Adler-32
- * value of the dictionary required.
- * @param b the buffer for the uncompressed data
- * @return the actual number of uncompressed bytes
- * @exception DataFormatException if the compressed data format is invalid
- * @see Inflater#needsInput
- * @see Inflater#needsDictionary
- */
- public int inflate(byte[] b) throws DataFormatException {
- return impl.inflate(b);
- }
-
- /**
- * Returns the ADLER-32 value of the uncompressed data.
- * @return the ADLER-32 value of the uncompressed data
- */
- public int getAdler() {
- return impl.getAdler();
- }
-
- /**
- * Returns the total number of compressed bytes input so far.
- *
- * Since the number of bytes may be greater than
- * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
- * the preferred means of obtaining this information.Adler32
class.
- * The checksum starts off with a value of 1.
- */
- public Adler32 ()
- {
- reset();
- }
-
- /**
- * Resets the Adler32 checksum to the initial value.
- */
- public void reset ()
- {
- checksum = 1; //Initialize to 1
- }
-
- /**
- * Updates the checksum with the byte b.
- *
- * @param bval the data value to add. The high byte of the int is ignored.
- */
- public void update (int bval)
- {
- //We could make a length 1 byte array and call update again, but I
- //would rather not have that overhead
- int s1 = checksum & 0xffff;
- int s2 = checksum >>> 16;
-
- s1 = (s1 + (bval & 0xFF)) % BASE;
- s2 = (s1 + s2) % BASE;
-
- checksum = (s2 << 16) + s1;
- }
-
- /**
- * Updates the checksum with the bytes taken from the array.
- *
- * @param buffer an array of bytes
- */
- public void update (byte[] buffer)
- {
- update(buffer, 0, buffer.length);
- }
-
- /**
- * Updates the checksum with the bytes taken from the array.
- *
- * @param buf an array of bytes
- * @param off the start of the data used for this update
- * @param len the number of bytes to use for this update
- */
- public void update (byte[] buf, int off, int len)
- {
- //(By Per Bothner)
- int s1 = checksum & 0xffff;
- int s2 = checksum >>> 16;
-
- while (len > 0)
- {
- // We can defer the modulo operation:
- // s1 maximally grows from 65521 to 65521 + 255 * 3800
- // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
- int n = 3800;
- if (n > len)
- n = len;
- len -= n;
- while (--n >= 0)
- {
- s1 = s1 + (buf[off++] & 0xFF);
- s2 = s2 + s1;
- }
- s1 %= BASE;
- s2 %= BASE;
- }
-
- /*Old implementation, borrowed from somewhere:
- int n;
-
- while (len-- > 0) {
-
- s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
- s2 = (s2 + s1) % BASE;
- }*/
-
- checksum = (s2 << 16) | s1;
- }
-
- /**
- * Returns the Adler32 data checksum computed so far.
- */
- public long getValue()
- {
- return (long) checksum & 0xffffffffL;
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/CRC32.java
--- a/rt/emul/mini/src/main/java/java/util/zip/CRC32.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-/* CRC32.java - Computes CRC32 data checksum of a data stream
- 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., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 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;
-
-/*
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * The actual CRC32 algorithm is taken from RFC 1952.
- * Status: Believed complete and correct.
- */
-
-/**
- * Computes CRC32 data checksum of a data stream.
- * The actual CRC32 algorithm is described in RFC 1952
- * (GZIP file format specification version 4.3).
- * Can be used to get the CRC32 over a stream if used with checked input/output
- * streams.
- *
- * @see InflaterInputStream
- * @see DeflaterOutputStream
- *
- * @author Per Bothner
- * @date April 1, 1999.
- */
-public class CRC32 implements Checksum
-{
- /** The crc data checksum so far. */
- private int crc = 0;
-
- /** The fast CRC table. Computed once when the CRC32 class is loaded. */
- private static int[] crc_table = make_crc_table();
-
- /** Make the table for a fast CRC. */
- private static int[] make_crc_table ()
- {
- int[] crc_table = new int[256];
- for (int n = 0; n < 256; n++)
- {
- int c = n;
- for (int k = 8; --k >= 0; )
- {
- if ((c & 1) != 0)
- c = 0xedb88320 ^ (c >>> 1);
- else
- c = c >>> 1;
- }
- crc_table[n] = c;
- }
- return crc_table;
- }
-
- /**
- * Returns the CRC32 data checksum computed so far.
- */
- public long getValue ()
- {
- return (long) crc & 0xffffffffL;
- }
-
- /**
- * Resets the CRC32 data checksum as if no update was ever called.
- */
- public void reset () { crc = 0; }
-
- /**
- * Updates the checksum with the int bval.
- *
- * @param bval (the byte is taken as the lower 8 bits of bval)
- */
-
- public void update (int bval)
- {
- int c = ~crc;
- c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
- crc = ~c;
- }
-
- /**
- * Adds the byte array to the data checksum.
- *
- * @param buf the buffer which contains the data
- * @param off the offset in the buffer where the data starts
- * @param len the length of the data
- */
- public void update (byte[] buf, int off, int len)
- {
- int c = ~crc;
- while (--len >= 0)
- c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
- crc = ~c;
- }
-
- /**
- * Adds the complete byte array to the data checksum.
- */
- public void update (byte[] buf) { update(buf, 0, buf.length); }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/Checksum.java
--- a/rt/emul/mini/src/main/java/java/util/zip/Checksum.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.util.zip;
-
-/**
- * An interface representing a data checksum.
- *
- * @author David Connelly
- */
-public
-interface Checksum {
- /**
- * Updates the current checksum with the specified byte.
- *
- * @param b the byte to update the checksum with
- */
- public void update(int b);
-
- /**
- * Updates the current checksum with the specified array of bytes.
- * @param b the byte array to update the checksum with
- * @param off the start offset of the data
- * @param len the number of bytes to use for the update
- */
- public void update(byte[] b, int off, int len);
-
- /**
- * Returns the current checksum value.
- * @return the current checksum value
- */
- public long getValue();
-
- /**
- * Resets the checksum to its initial value.
- */
- public void reset();
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/DataFormatException.java
--- a/rt/emul/mini/src/main/java/java/util/zip/DataFormatException.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.util.zip;
-
-/**
- * Signals that a data format error has occurred.
- *
- * @author David Connelly
- */
-public
-class DataFormatException extends Exception {
- private static final long serialVersionUID = 2219632870893641452L;
-
- /**
- * Constructs a DataFormatException with no detail message.
- */
- public DataFormatException() {
- super();
- }
-
- /**
- * Constructs a DataFormatException with the specified detail message.
- * A detail message is a String that describes this particular exception.
- * @param s the String containing a detail message
- */
- public DataFormatException(String s) {
- super(s);
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/Inflater.java
--- a/rt/emul/mini/src/main/java/java/util/zip/Inflater.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,310 +0,0 @@
-/*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.util.zip;
-
-/**
- * This class provides support for general purpose decompression using the
- * popular ZLIB compression library. The ZLIB compression library was
- * initially developed as part of the PNG graphics standard and is not
- * protected by patents. It is fully described in the specifications at
- * the java.util.zip
- * package description.
- *
- *
- *
- * @see Deflater
- * @author David Connelly
- *
- */
-public
-class Inflater {
- private final org.apidesign.bck2brwsr.emul.zip.Inflater impl;
-
- /**
- * Creates a new decompressor. If the parameter 'nowrap' is true then
- * the ZLIB header and checksum fields will not be used. This provides
- * compatibility with the compression format used by both GZIP and PKZIP.
- *
- * try {
- * // Encode a String into bytes
- * String inputString = "blahblahblah\u20AC\u20AC";
- * byte[] input = inputString.getBytes("UTF-8");
- *
- * // Compress the bytes
- * byte[] output = new byte[100];
- * Deflater compresser = new Deflater();
- * compresser.setInput(input);
- * compresser.finish();
- * int compressedDataLength = compresser.deflate(output);
- *
- * // Decompress the bytes
- * Inflater decompresser = new Inflater();
- * decompresser.setInput(output, 0, compressedDataLength);
- * byte[] result = new byte[100];
- * int resultLength = decompresser.inflate(result);
- * decompresser.end();
- *
- * // Decode the bytes into a String
- * String outputString = new String(result, 0, resultLength, "UTF-8");
- * } catch(java.io.UnsupportedEncodingException ex) {
- * // handle
- * } catch (java.util.zip.DataFormatException ex) {
- * // handle
- * }
- *
Since the number of bytes may be greater than - * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now - * the preferred means of obtaining this information.
- * - * @return the total number of uncompressed bytes output so far - */ - public int getTotalOut() { - return impl.getTotalOut(); - } - - /** - * Returns the total number of uncompressed bytes output so far. - * - * @return the total (non-negative) number of uncompressed bytes output so far - * @since 1.5 - */ - public long getBytesWritten() { - return impl.getBytesWritten(); - } - - /** - * Resets inflater so that a new set of input data can be processed. - */ - public void reset() { - impl.reset(); - } - - /** - * Closes the decompressor and discards any unprocessed input. - * This method should be called when the decompressor is no longer - * being used, but will also be called automatically by the finalize() - * method. Once this method is called, the behavior of the Inflater - * object is undefined. - */ - public void end() { - impl.end(); - } - - /** - * Closes the decompressor when garbage is collected. - */ - protected void finalize() { - end(); - } -} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/InflaterInputStream.java --- a/rt/emul/mini/src/main/java/java/util/zip/InflaterInputStream.java Tue May 06 17:46:47 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,288 +0,0 @@ -/* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package java.util.zip; - -import java.io.FilterInputStream; -import java.io.InputStream; -import java.io.IOException; -import java.io.EOFException; - -/** - * This class implements a stream filter for uncompressing data in the - * "deflate" compression format. It is also used as the basis for other - * decompression filters, such as GZIPInputStream. - * - * @see Inflater - * @author David Connelly - */ -public -class InflaterInputStream extends FilterInputStream { - /** - * Decompressor for this stream. - */ - protected Inflater inf; - - /** - * Input buffer for decompression. - */ - protected byte[] buf; - - /** - * Length of input buffer. - */ - protected int len; - - private boolean closed = false; - // this flag is set to true after EOF has reached - private boolean reachEOF = false; - - /** - * Check to make sure that this stream has not been closed - */ - private void ensureOpen() throws IOException { - if (closed) { - throw new IOException("Stream closed"); - } - } - - - /** - * Creates a new input stream with the specified decompressor and - * buffer size. - * @param in the input stream - * @param inf the decompressor ("inflater") - * @param size the input buffer size - * @exception IllegalArgumentException if size is <= 0 - */ - public InflaterInputStream(InputStream in, Inflater inf, int size) { - super(in); - if (in == null || inf == null) { - throw new NullPointerException(); - } else if (size <= 0) { - throw new IllegalArgumentException("buffer size <= 0"); - } - this.inf = inf; - buf = new byte[size]; - } - - /** - * Creates a new input stream with the specified decompressor and a - * default buffer size. - * @param in the input stream - * @param inf the decompressor ("inflater") - */ - public InflaterInputStream(InputStream in, Inflater inf) { - this(in, inf, 512); - } - - boolean usesDefaultInflater = false; - - /** - * Creates a new input stream with a default decompressor and buffer size. - * @param in the input stream - */ - public InflaterInputStream(InputStream in) { - this(in, new Inflater()); - usesDefaultInflater = true; - } - - private byte[] singleByteBuf = new byte[1]; - - /** - * Reads a byte of uncompressed data. This method will block until - * enough input is available for decompression. - * @return the byte read, or -1 if end of compressed input is reached - * @exception IOException if an I/O error has occurred - */ - public int read() throws IOException { - ensureOpen(); - return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff; - } - - /** - * Reads uncompressed data into an array of bytes. Iflen
is not
- * zero, the method will block until some input can be decompressed; otherwise,
- * no bytes are read and 0
is returned.
- * @param b the buffer into which the data is read
- * @param off the start offset in the destination array b
- * @param len the maximum number of bytes read
- * @return the actual number of bytes read, or -1 if the end of the
- * compressed input is reached or a preset dictionary is needed
- * @exception NullPointerException If b
is null
.
- * @exception IndexOutOfBoundsException If off
is negative,
- * len
is negative, or len
is greater than
- * b.length - off
- * @exception ZipException if a ZIP format error has occurred
- * @exception IOException if an I/O error has occurred
- */
- public int read(byte[] b, int off, int len) throws IOException {
- ensureOpen();
- if (b == null) {
- throw new NullPointerException();
- } else if (off < 0 || len < 0 || len > b.length - off) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return 0;
- }
- try {
- int n;
- while ((n = inf.inflate(b, off, len)) == 0) {
- if (inf.finished() || inf.needsDictionary()) {
- reachEOF = true;
- return -1;
- }
- if (inf.needsInput()) {
- fill();
- }
- }
- return n;
- } catch (DataFormatException e) {
- String s = e.getMessage();
- throw new ZipException(s != null ? s : "Invalid ZLIB data format");
- }
- }
-
- /**
- * Returns 0 after EOF has been reached, otherwise always return 1.
- *
- * Programs should not count on this method to return the actual number
- * of bytes that could be read without blocking.
- *
- * @return 1 before EOF and 0 after EOF.
- * @exception IOException if an I/O error occurs.
- *
- */
- public int available() throws IOException {
- ensureOpen();
- if (reachEOF) {
- return 0;
- } else {
- return 1;
- }
- }
-
- private byte[] b = new byte[512];
-
- /**
- * Skips specified number of bytes of uncompressed data.
- * @param n the number of bytes to skip
- * @return the actual number of bytes skipped.
- * @exception IOException if an I/O error has occurred
- * @exception IllegalArgumentException if n < 0
- */
- public long skip(long n) throws IOException {
- if (n < 0) {
- throw new IllegalArgumentException("negative skip length");
- }
- ensureOpen();
- int max = (int)Math.min(n, Integer.MAX_VALUE);
- int total = 0;
- while (total < max) {
- int len = max - total;
- if (len > b.length) {
- len = b.length;
- }
- len = read(b, 0, len);
- if (len == -1) {
- reachEOF = true;
- break;
- }
- total += len;
- }
- return total;
- }
-
- /**
- * Closes this input stream and releases any system resources associated
- * with the stream.
- * @exception IOException if an I/O error has occurred
- */
- public void close() throws IOException {
- if (!closed) {
- if (usesDefaultInflater)
- inf.end();
- in.close();
- closed = true;
- }
- }
-
- /**
- * Fills input buffer with more data to decompress.
- * @exception IOException if an I/O error has occurred
- */
- protected void fill() throws IOException {
- ensureOpen();
- len = in.read(buf, 0, buf.length);
- if (len == -1) {
- throw new EOFException("Unexpected end of ZLIB input stream");
- }
- inf.setInput(buf, 0, len);
- }
-
- /**
- * Tests if this input stream supports the mark
and
- * reset
methods. The markSupported
- * method of InflaterInputStream
returns
- * false
.
- *
- * @return a boolean
indicating if this stream type supports
- * the mark
and reset
methods.
- * @see java.io.InputStream#mark(int)
- * @see java.io.InputStream#reset()
- */
- public boolean markSupported() {
- return false;
- }
-
- /**
- * Marks the current position in this input stream.
- *
- *
The mark
method of InflaterInputStream
- * does nothing.
- *
- * @param readlimit the maximum limit of bytes that can be read before
- * the mark position becomes invalid.
- * @see java.io.InputStream#reset()
- */
- public synchronized void mark(int readlimit) {
- }
-
- /**
- * Repositions this stream to the position at the time the
- * mark
method was last called on this input stream.
- *
- *
The method reset
for class
- * InflaterInputStream
does nothing except throw an
- * IOException
.
- *
- * @exception IOException if this method is invoked.
- * @see java.io.InputStream#mark(int)
- * @see java.io.IOException
- */
- public synchronized void reset() throws IOException {
- throw new IOException("mark/reset not supported");
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/ZStreamRef.java
--- a/rt/emul/mini/src/main/java/java/util/zip/ZStreamRef.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.util.zip;
-
-/**
- * A reference to the native zlib's z_stream structure.
- */
-
-class ZStreamRef {
-
- private long address;
- ZStreamRef (long address) {
- this.address = address;
- }
-
- long address() {
- return address;
- }
-
- void clear() {
- address = 0;
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/ZipConstants.java
--- a/rt/emul/mini/src/main/java/java/util/zip/ZipConstants.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.util.zip;
-
-/*
- * This interface defines the constants that are used by the classes
- * which manipulate ZIP files.
- *
- * @author David Connelly
- */
-interface ZipConstants {
- /*
- * Header signatures
- */
- static long LOCSIG = 0x04034b50L; // "PK\003\004"
- static long EXTSIG = 0x08074b50L; // "PK\007\008"
- static long CENSIG = 0x02014b50L; // "PK\001\002"
- static long ENDSIG = 0x06054b50L; // "PK\005\006"
-
- /*
- * Header sizes in bytes (including signatures)
- */
- static final int LOCHDR = 30; // LOC header size
- static final int EXTHDR = 16; // EXT header size
- static final int CENHDR = 46; // CEN header size
- static final int ENDHDR = 22; // END header size
-
- /*
- * Local file (LOC) header field offsets
- */
- static final int LOCVER = 4; // version needed to extract
- static final int LOCFLG = 6; // general purpose bit flag
- static final int LOCHOW = 8; // compression method
- static final int LOCTIM = 10; // modification time
- static final int LOCCRC = 14; // uncompressed file crc-32 value
- static final int LOCSIZ = 18; // compressed size
- static final int LOCLEN = 22; // uncompressed size
- static final int LOCNAM = 26; // filename length
- static final int LOCEXT = 28; // extra field length
-
- /*
- * Extra local (EXT) header field offsets
- */
- static final int EXTCRC = 4; // uncompressed file crc-32 value
- static final int EXTSIZ = 8; // compressed size
- static final int EXTLEN = 12; // uncompressed size
-
- /*
- * Central directory (CEN) header field offsets
- */
- static final int CENVEM = 4; // version made by
- static final int CENVER = 6; // version needed to extract
- static final int CENFLG = 8; // encrypt, decrypt flags
- static final int CENHOW = 10; // compression method
- static final int CENTIM = 12; // modification time
- static final int CENCRC = 16; // uncompressed file crc-32 value
- static final int CENSIZ = 20; // compressed size
- static final int CENLEN = 24; // uncompressed size
- static final int CENNAM = 28; // filename length
- static final int CENEXT = 30; // extra field length
- static final int CENCOM = 32; // comment length
- static final int CENDSK = 34; // disk number start
- static final int CENATT = 36; // internal file attributes
- static final int CENATX = 38; // external file attributes
- static final int CENOFF = 42; // LOC header offset
-
- /*
- * End of central directory (END) header field offsets
- */
- static final int ENDSUB = 8; // number of entries on this disk
- static final int ENDTOT = 10; // total number of entries
- static final int ENDSIZ = 12; // central directory size in bytes
- static final int ENDOFF = 16; // offset of first CEN header
- static final int ENDCOM = 20; // zip file comment length
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/ZipEntry.java
--- a/rt/emul/mini/src/main/java/java/util/zip/ZipEntry.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,331 +0,0 @@
-/*
- * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.util.zip;
-
-/**
- * This class is used to represent a ZIP file entry.
- *
- * @author David Connelly
- */
-public
-class ZipEntry implements ZipConstants, Cloneable {
- String name; // entry name
- long time = -1; // modification time (in DOS time)
- long crc = -1; // crc-32 of entry data
- long size = -1; // uncompressed size of entry data
- long csize = -1; // compressed size of entry data
- int method = -1; // compression method
- int flag = 0; // general purpose flag
- byte[] extra; // optional extra field data for entry
- String comment; // optional comment string for entry
-
- /**
- * Compression method for uncompressed entries.
- */
- public static final int STORED = 0;
-
- /**
- * Compression method for compressed (deflated) entries.
- */
- public static final int DEFLATED = 8;
-
- /**
- * Creates a new zip entry with the specified name.
- *
- * @param name the entry name
- * @exception NullPointerException if the entry name is null
- * @exception IllegalArgumentException if the entry name is longer than
- * 0xFFFF bytes
- */
- public ZipEntry(String name) {
- if (name == null) {
- throw new NullPointerException();
- }
- if (name.length() > 0xFFFF) {
- throw new IllegalArgumentException("entry name too long");
- }
- this.name = name;
- }
-
- /**
- * Creates a new zip entry with fields taken from the specified
- * zip entry.
- * @param e a zip Entry object
- */
- public ZipEntry(ZipEntry e) {
- name = e.name;
- time = e.time;
- crc = e.crc;
- size = e.size;
- csize = e.csize;
- method = e.method;
- flag = e.flag;
- extra = e.extra;
- comment = e.comment;
- }
-
- /*
- * Creates a new un-initialized zip entry
- */
- ZipEntry() {}
-
- /**
- * Returns the name of the entry.
- * @return the name of the entry
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the modification time of the entry.
- * @param time the entry modification time in number of milliseconds
- * since the epoch
- * @see #getTime()
- */
- public void setTime(long time) {
- this.time = javaToDosTime(time);
- }
-
- /**
- * Returns the modification time of the entry, or -1 if not specified.
- * @return the modification time of the entry, or -1 if not specified
- * @see #setTime(long)
- */
- public long getTime() {
- return time != -1 ? dosToJavaTime(time) : -1;
- }
-
- /**
- * Sets the uncompressed size of the entry data.
- * @param size the uncompressed size in bytes
- * @exception IllegalArgumentException if the specified size is less
- * than 0, is greater than 0xFFFFFFFF when
- * ZIP64 format is not supported,
- * or is less than 0 when ZIP64 is supported
- * @see #getSize()
- */
- public void setSize(long size) {
- if (size < 0) {
- throw new IllegalArgumentException("invalid entry size");
- }
- this.size = size;
- }
-
- /**
- * Returns the uncompressed size of the entry data, or -1 if not known.
- * @return the uncompressed size of the entry data, or -1 if not known
- * @see #setSize(long)
- */
- public long getSize() {
- return size;
- }
-
- /**
- * Returns the size of the compressed entry data, or -1 if not known.
- * In the case of a stored entry, the compressed size will be the same
- * as the uncompressed size of the entry.
- * @return the size of the compressed entry data, or -1 if not known
- * @see #setCompressedSize(long)
- */
- public long getCompressedSize() {
- return csize;
- }
-
- /**
- * Sets the size of the compressed entry data.
- * @param csize the compressed size to set to
- * @see #getCompressedSize()
- */
- public void setCompressedSize(long csize) {
- this.csize = csize;
- }
-
- /**
- * Sets the CRC-32 checksum of the uncompressed entry data.
- * @param crc the CRC-32 value
- * @exception IllegalArgumentException if the specified CRC-32 value is
- * less than 0 or greater than 0xFFFFFFFF
- * @see #getCrc()
- */
- public void setCrc(long crc) {
- if (crc < 0 || crc > 0xFFFFFFFFL) {
- throw new IllegalArgumentException("invalid entry crc-32");
- }
- this.crc = crc;
- }
-
- /**
- * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
- * not known.
- * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
- * not known
- * @see #setCrc(long)
- */
- public long getCrc() {
- return crc;
- }
-
- /**
- * Sets the compression method for the entry.
- * @param method the compression method, either STORED or DEFLATED
- * @exception IllegalArgumentException if the specified compression
- * method is invalid
- * @see #getMethod()
- */
- public void setMethod(int method) {
- if (method != STORED && method != DEFLATED) {
- throw new IllegalArgumentException("invalid compression method");
- }
- this.method = method;
- }
-
- /**
- * Returns the compression method of the entry, or -1 if not specified.
- * @return the compression method of the entry, or -1 if not specified
- * @see #setMethod(int)
- */
- public int getMethod() {
- return method;
- }
-
- /**
- * Sets the optional extra field data for the entry.
- * @param extra the extra field data bytes
- * @exception IllegalArgumentException if the length of the specified
- * extra field data is greater than 0xFFFF bytes
- * @see #getExtra()
- */
- public void setExtra(byte[] extra) {
- if (extra != null && extra.length > 0xFFFF) {
- throw new IllegalArgumentException("invalid extra field length");
- }
- this.extra = extra;
- }
-
- /**
- * Returns the extra field data for the entry, or null if none.
- * @return the extra field data for the entry, or null if none
- * @see #setExtra(byte[])
- */
- public byte[] getExtra() {
- return extra;
- }
-
- /**
- * Sets the optional comment string for the entry.
- *
- *
ZIP entry comments have maximum length of 0xffff. If the length of the
- * specified comment string is greater than 0xFFFF bytes after encoding, only
- * the first 0xFFFF bytes are output to the ZIP file entry.
- *
- * @param comment the comment string
- *
- * @see #getComment()
- */
- public void setComment(String comment) {
- this.comment = comment;
- }
-
- /**
- * Returns the comment string for the entry, or null if none.
- * @return the comment string for the entry, or null if none
- * @see #setComment(String)
- */
- public String getComment() {
- return comment;
- }
-
- /**
- * Returns true if this is a directory entry. A directory entry is
- * defined to be one whose name ends with a '/'.
- * @return true if this is a directory entry
- */
- public boolean isDirectory() {
- return name.endsWith("/");
- }
-
- /**
- * Returns a string representation of the ZIP entry.
- */
- public String toString() {
- return getName();
- }
-
- /*
- * Converts DOS time to Java time (number of milliseconds since epoch).
- */
- private static long dosToJavaTime(long dtime) {
- return dtime;
- /* XXX:
- Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
- (int)(((dtime >> 21) & 0x0f) - 1),
- (int)((dtime >> 16) & 0x1f),
- (int)((dtime >> 11) & 0x1f),
- (int)((dtime >> 5) & 0x3f),
- (int)((dtime << 1) & 0x3e));
- return d.getTime();
- */
- }
-
- /*
- * Converts Java time to DOS time.
- */
- private static long javaToDosTime(long time) {
- return time;
- /* XXX:
- Date d = new Date(time);
- int year = d.getYear() + 1900;
- if (year < 1980) {
- return (1 << 21) | (1 << 16);
- }
- return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
- d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
- d.getSeconds() >> 1;
- */
- }
-
- /**
- * Returns the hash code value for this entry.
- */
- public int hashCode() {
- return name.hashCode();
- }
-
- /**
- * Returns a copy of this entry.
- */
- public Object clone() {
- try {
- ZipEntry e = (ZipEntry)super.clone();
- e.extra = (extra == null) ? null : extra.clone();
- return e;
- } catch (CloneNotSupportedException e) {
- // This should never happen, since we are Cloneable
- throw new IllegalStateException();
- }
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/ZipException.java
--- a/rt/emul/mini/src/main/java/java/util/zip/ZipException.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.util.zip;
-
-import java.io.IOException;
-
-/**
- * Signals that a Zip exception of some sort has occurred.
- *
- * @author unascribed
- * @see java.io.IOException
- * @since JDK1.0
- */
-
-public
-class ZipException extends IOException {
- private static final long serialVersionUID = 8000196834066748623L;
-
- /**
- * Constructs a ZipException
with null
- * as its error detail message.
- */
- public ZipException() {
- super();
- }
-
- /**
- * Constructs a ZipException
with the specified detail
- * message.
- *
- * @param s the detail message.
- */
-
- public ZipException(String s) {
- super(s);
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/ZipInputStream.java
--- a/rt/emul/mini/src/main/java/java/util/zip/ZipInputStream.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.util.zip;
-
-import java.io.InputStream;
-import java.io.IOException;
-
-/**
- * This class implements an input stream filter for reading files in the
- * ZIP file format. Includes support for both compressed and uncompressed
- * entries.
- *
- * @author David Connelly
- */
-public
-class ZipInputStream extends InflaterInputStream implements ZipConstants {
- private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
-
- /**
- * Creates a new ZIP input stream.
- *
- *
The UTF-8 {@link java.nio.charset.Charset charset} is used to - * decode the entry names. - * - * @param in the actual input stream - */ - public ZipInputStream(InputStream in) { - super(in); - impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in); - } - - /** - * Creates a new ZIP input stream. - * - * @param in the actual input stream - * - * @param charset - * The {@linkplain java.nio.charset.Charset charset} to be - * used to decode the ZIP entry name (ignored if the - * language - * encoding bit of the ZIP entry's general purpose bit - * flag is set). - * - * @since 1.7 - * - public ZipInputStream(InputStream in, Charset charset) { - super(new PushbackInputStream(in, 512), new Inflater(true), 512); - usesDefaultInflater = true; - if(in == null) { - throw new NullPointerException("in is null"); - } - if (charset == null) - throw new NullPointerException("charset is null"); - this.zc = ZipCoder.get(charset); - } - */ - - /** - * Reads the next ZIP file entry and positions the stream at the - * beginning of the entry data. - * @return the next ZIP file entry, or null if there are no more entries - * @exception ZipException if a ZIP file error has occurred - * @exception IOException if an I/O error has occurred - */ - public ZipEntry getNextEntry() throws IOException { - return impl.getNextEntry(); - } - - /** - * Closes the current ZIP entry and positions the stream for reading the - * next entry. - * @exception ZipException if a ZIP file error has occurred - * @exception IOException if an I/O error has occurred - */ - public void closeEntry() throws IOException { - impl.closeEntry(); - } - - /** - * Returns 0 after EOF has reached for the current entry data, - * otherwise always return 1. - *
- * Programs should not count on this method to return the actual number
- * of bytes that could be read without blocking.
- *
- * @return 1 before EOF and 0 after EOF has reached for current entry.
- * @exception IOException if an I/O error occurs.
- *
- */
- public int available() throws IOException {
- return impl.available();
- }
-
- /**
- * Reads from the current ZIP entry into an array of bytes.
- * If
-
-
-
-
-
-
-
-
- The following code fragment demonstrates a trivial compression
- * and decompression of a string using Deflater and
- * Inflater.
- *
- *
- * Note: When using the 'nowrap' option it is also necessary to provide
- * an extra "dummy" byte as input. This is required by the ZLIB native
- * library in order to support certain optimizations.
- *
- * @param nowrap if true then support GZIP compatible compression
- */
- public Inflater(boolean nowrap) {
- this.nowrap = nowrap;
- reset();
- }
-
- /**
- * Creates a new decompressor.
- */
- public Inflater() {
- this(false);
- }
-
- /**
- * Sets input data for decompression. Should be called whenever
- * needsInput() returns true indicating that more input data is
- * required.
- * @param b the input data bytes
- * @param off the start offset of the input data
- * @param len the length of the input data
- * @see Inflater#needsInput
- */
- public void setInput(byte[] b, int off, int len) {
- if (b == null) {
- throw new NullPointerException();
- }
- if (off < 0 || len < 0 || off > b.length - len) {
- throw new ArrayIndexOutOfBoundsException();
- }
- impl.setInput(b, off, len, false);
- }
-
- /**
- * Sets input data for decompression. Should be called whenever
- * needsInput() returns true indicating that more input data is
- * required.
- * @param b the input data bytes
- * @see Inflater#needsInput
- */
- public void setInput(byte[] b) {
- setInput(b, 0, b.length);
- }
-
- /**
- * Sets the preset dictionary to the given array of bytes. Should be
- * called when inflate() returns 0 and needsDictionary() returns true
- * indicating that a preset dictionary is required. The method getAdler()
- * can be used to get the Adler-32 value of the dictionary needed.
- * @param b the dictionary data bytes
- * @param off the start offset of the data
- * @param len the length of the data
- * @see Inflater#needsDictionary
- * @see Inflater#getAdler
- */
- public void setDictionary(byte[] b, int off, int len) {
- if (b == null) {
- throw new NullPointerException();
- }
- if (off < 0 || len < 0 || off > b.length - len) {
- throw new ArrayIndexOutOfBoundsException();
- }
- byte[] arr;
- if (off == 0) {
- arr = b;
- } else {
- arr = new byte[len];
- org.apidesign.bck2brwsr.emul.lang.System.arraycopy(b, off, arr, 0, len);
- }
- impl.setDictionary(arr, len);
- }
-
- /**
- * Sets the preset dictionary to the given array of bytes. Should be
- * called when inflate() returns 0 and needsDictionary() returns true
- * indicating that a preset dictionary is required. The method getAdler()
- * can be used to get the Adler-32 value of the dictionary needed.
- * @param b the dictionary data bytes
- * @see Inflater#needsDictionary
- * @see Inflater#getAdler
- */
- public void setDictionary(byte[] b) {
- impl.setDictionary(b, b.length);
- }
-
- /**
- * Returns the total number of bytes remaining in the input buffer.
- * This can be used to find out what bytes still remain in the input
- * buffer after decompression has finished.
- * @return the total number of bytes remaining in the input buffer
- */
- public int getRemaining() {
- return impl.getAvailIn();
- }
-
- /**
- * Returns true if no data remains in the input buffer. This can
- * be used to determine if #setInput should be called in order
- * to provide more input.
- * @return true if no data remains in the input buffer
- */
- public boolean needsInput() {
- return getRemaining() <= 0;
- }
-
- /**
- * Returns true if a preset dictionary is needed for decompression.
- * @return true if a preset dictionary is needed for decompression
- * @see Inflater#setDictionary
- */
- public boolean needsDictionary() {
- return impl.needDict();
- }
-
- /**
- * Returns true if the end of the compressed data stream has been
- * reached.
- * @return true if the end of the compressed data stream has been
- * reached
- */
- public boolean finished() {
- return impl.finished();
- }
-
- /**
- * Uncompresses bytes into specified buffer. Returns actual number
- * of bytes uncompressed. A return value of 0 indicates that
- * needsInput() or needsDictionary() should be called in order to
- * determine if more input data or a preset dictionary is required.
- * In the latter case, getAdler() can be used to get the Adler-32
- * value of the dictionary required.
- * @param b the buffer for the uncompressed data
- * @param off the start offset of the data
- * @param len the maximum number of uncompressed bytes
- * @return the actual number of uncompressed bytes
- * @exception DataFormatException if the compressed data format is invalid
- * @see Inflater#needsInput
- * @see Inflater#needsDictionary
- */
- public int inflate(byte[] b, int off, int len)
- throws DataFormatException
- {
- if (b == null) {
- throw new NullPointerException();
- }
- if (off < 0 || len < 0 || off > b.length - len) {
- throw new ArrayIndexOutOfBoundsException();
- }
- impl.setOutput(b, off, len);
- int err = impl.inflate(JzLibInflater.Z_NO_FLUSH);
- return impl.next_out_index - off;
- }
-
- /**
- * Uncompresses bytes into specified buffer. Returns actual number
- * of bytes uncompressed. A return value of 0 indicates that
- * needsInput() or needsDictionary() should be called in order to
- * determine if more input data or a preset dictionary is required.
- * In the latter case, getAdler() can be used to get the Adler-32
- * value of the dictionary required.
- * @param b the buffer for the uncompressed data
- * @return the actual number of uncompressed bytes
- * @exception DataFormatException if the compressed data format is invalid
- * @see Inflater#needsInput
- * @see Inflater#needsDictionary
- */
- public int inflate(byte[] b) throws DataFormatException {
- return inflate(b, 0, b.length);
- }
-
- /**
- * Returns the ADLER-32 value of the uncompressed data.
- * @return the ADLER-32 value of the uncompressed data
- */
- public int getAdler() {
- return (int) impl.getAdler();
- }
-
- /**
- * Returns the total number of compressed bytes input so far.
- *
- * Since the number of bytes may be greater than
- * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
- * the preferred means of obtaining this information.len
is not zero, the method
- * blocks until some input is available; otherwise, no
- * bytes are read and 0
is returned.
- * @param b the buffer into which the data is read
- * @param off the start offset in the destination array b
- * @param len the maximum number of bytes read
- * @return the actual number of bytes read, or -1 if the end of the
- * entry is reached
- * @exception NullPointerException if b
is null
.
- * @exception IndexOutOfBoundsException if off
is negative,
- * len
is negative, or len
is greater than
- * b.length - off
- * @exception ZipException if a ZIP file error has occurred
- * @exception IOException if an I/O error has occurred
- */
- public int read(byte[] b, int off, int len) throws IOException {
- return impl.read(b, off, len);
- }
-
- /**
- * Skips specified number of bytes in the current ZIP entry.
- * @param n the number of bytes to skip
- * @return the actual number of bytes skipped
- * @exception ZipException if a ZIP file error has occurred
- * @exception IOException if an I/O error has occurred
- * @exception IllegalArgumentException if n < 0
- */
- public long skip(long n) throws IOException {
- return impl.skip(n);
- }
-
- /**
- * Closes this input stream and releases any system resources associated
- * with the stream.
- * @exception IOException if an I/O error has occurred
- */
- public void close() throws IOException {
- impl.close();
- }
-
- /**
- * Creates a new ZipEntry
object for the specified
- * entry name.
- *
- * @param name the ZIP file entry name
- * @return the ZipEntry just created
- */
- protected ZipEntry createZipEntry(String name) {
- return new ZipEntry(name);
- }
-
- @Override
- public int read() throws IOException {
- return impl.read();
- }
-
- @Override
- public boolean markSupported() {
- return impl.markSupported();
- }
-
- @Override
- public void mark(int readlimit) {
- impl.mark(readlimit);
- }
-
- @Override
- public void reset() throws IOException {
- impl.reset();
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return impl.read(b);
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/java/util/zip/package-info.java
--- a/rt/emul/mini/src/main/java/java/util/zip/package-info.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-/**
- * Back 2 Browser Bytecode Translator
- * Copyright (C) 2012 Jaroslav Tulach Package Specification
-
-
-
-
-
-
-
-
-@since JDK1.1
-
-
-
-
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java
--- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/* -*-mode:java; c-basic-offset:2; -*- */
-/*
-Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the distribution.
-
- 3. The names of the authors may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
-INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/*
- * This program is based on zlib-1.1.3, so all credit should go authors
- * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
- * and contributors of zlib.
- */
-
-package org.apidesign.bck2brwsr.emul.zip;
-
-final class Adler32 implements Checksum {
-
- // largest prime smaller than 65536
- static final private int BASE=65521;
- // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
- static final private int NMAX=5552;
-
- private long s1=1L;
- private long s2=0L;
-
- public void reset(long init){
- s1=init&0xffff;
- s2=(init>>16)&0xffff;
- }
-
- public void reset(){
- s1=1L;
- s2=0L;
- }
-
- public long getValue(){
- return ((s2<<16)|s1);
- }
-
- public void update(byte[] buf, int index, int len){
-
- if(len==1){
- s1+=buf[index++]&0xff; s2+=s1;
- s1%=BASE;
- s2%=BASE;
- return;
- }
-
- int len1 = len/NMAX;
- int len2 = len%NMAX;
- while(len1-->0) {
- int k=NMAX;
- len-=k;
- while(k-->0){
- s1+=buf[index++]&0xff; s2+=s1;
- }
- s1%=BASE;
- s2%=BASE;
- }
-
- int k=len2;
- len-=k;
- while(k-->0){
- s1+=buf[index++]&0xff; s2+=s1;
- }
- s1%=BASE;
- s2%=BASE;
- }
-
- public Adler32 copy(){
- Adler32 foo = new Adler32();
- foo.s1 = this.s1;
- foo.s2 = this.s2;
- return foo;
- }
-
- // The following logic has come from zlib.1.2.
- static long combine(long adler1, long adler2, long len2){
- long BASEL = (long)BASE;
- long sum1;
- long sum2;
- long rem; // unsigned int
-
- rem = len2 % BASEL;
- sum1 = adler1 & 0xffffL;
- sum2 = rem * sum1;
- sum2 %= BASEL; // MOD(sum2);
- sum1 += (adler2 & 0xffffL) + BASEL - 1;
- sum2 += ((adler1 >> 16) & 0xffffL) + ((adler2 >> 16) & 0xffffL) + BASEL - rem;
- if (sum1 >= BASEL) sum1 -= BASEL;
- if (sum1 >= BASEL) sum1 -= BASEL;
- if (sum2 >= (BASEL << 1)) sum2 -= (BASEL << 1);
- if (sum2 >= BASEL) sum2 -= BASEL;
- return sum1 | (sum2 << 16);
- }
-
-/*
- private java.util.zip.Adler32 adler=new java.util.zip.Adler32();
- public void update(byte[] buf, int index, int len){
- if(buf==null) {adler.reset();}
- else{adler.update(buf, index, len);}
- }
- public void reset(){
- adler.reset();
- }
- public void reset(long init){
- if(init==1L){
- adler.reset();
- }
- else{
- System.err.println("unsupported operation");
- }
- }
- public long getValue(){
- return adler.getValue();
- }
-*/
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java
--- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,181 +0,0 @@
-/* -*-mode:java; c-basic-offset:2; -*- */
-/*
-Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the distribution.
-
- 3. The names of the authors may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
-INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/*
- * This program is based on zlib-1.1.3, so all credit should go authors
- * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
- * and contributors of zlib.
- */
-
-package org.apidesign.bck2brwsr.emul.zip;
-
-import org.apidesign.bck2brwsr.emul.lang.System;
-
-final class CRC32 implements Checksum {
-
- /*
- * The following logic has come from RFC1952.
- */
- private int v = 0;
- private static int[] crc_table = null;
- static {
- crc_table = new int[256];
- for (int n = 0; n < 256; n++) {
- int c = n;
- for (int k = 8; --k >= 0; ) {
- if ((c & 1) != 0)
- c = 0xedb88320 ^ (c >>> 1);
- else
- c = c >>> 1;
- }
- crc_table[n] = c;
- }
- }
-
- public void update (byte[] buf, int index, int len) {
- int c = ~v;
- while (--len >= 0)
- c = crc_table[(c^buf[index++])&0xff]^(c >>> 8);
- v = ~c;
- }
-
- public void reset(){
- v = 0;
- }
-
- public void reset(long vv){
- v = (int)(vv&0xffffffffL);
- }
-
- public long getValue(){
- return (long)(v&0xffffffffL);
- }
-
- // The following logic has come from zlib.1.2.
- private static final int GF2_DIM = 32;
- static long combine(long crc1, long crc2, long len2){
- long row;
- long[] even = new long[GF2_DIM];
- long[] odd = new long[GF2_DIM];
-
- // degenerate case (also disallow negative lengths)
- if (len2 <= 0)
- return crc1;
-
- // put operator for one zero bit in odd
- odd[0] = 0xedb88320L; // CRC-32 polynomial
- row = 1;
- for (int n = 1; n < GF2_DIM; n++) {
- odd[n] = row;
- row <<= 1;
- }
-
- // put operator for two zero bits in even
- gf2_matrix_square(even, odd);
-
- // put operator for four zero bits in odd
- gf2_matrix_square(odd, even);
-
- // apply len2 zeros to crc1 (first square will put the operator for one
- // zero byte, eight zero bits, in even)
- do {
- // apply zeros operator for this bit of len2
- gf2_matrix_square(even, odd);
- if ((len2 & 1)!=0)
- crc1 = gf2_matrix_times(even, crc1);
- len2 >>= 1;
-
- // if no more bits set, then done
- if (len2 == 0)
- break;
-
- // another iteration of the loop with odd and even swapped
- gf2_matrix_square(odd, even);
- if ((len2 & 1)!=0)
- crc1 = gf2_matrix_times(odd, crc1);
- len2 >>= 1;
-
- // if no more bits set, then done
- } while (len2 != 0);
-
- /* return combined crc */
- crc1 ^= crc2;
- return crc1;
- }
-
- private static long gf2_matrix_times(long[] mat, long vec){
- long sum = 0;
- int index = 0;
- while (vec!=0) {
- if ((vec & 1)!=0)
- sum ^= mat[index];
- vec >>= 1;
- index++;
- }
- return sum;
- }
-
- static final void gf2_matrix_square(long[] square, long[] mat) {
- for (int n = 0; n < GF2_DIM; n++)
- square[n] = gf2_matrix_times(mat, mat[n]);
- }
-
- /*
- private java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
-
- public void update(byte[] buf, int index, int len){
- if(buf==null) {crc32.reset();}
- else{crc32.update(buf, index, len);}
- }
- public void reset(){
- crc32.reset();
- }
- public void reset(long init){
- if(init==0L){
- crc32.reset();
- }
- else{
- System.err.println("unsupported operation");
- }
- }
- public long getValue(){
- return crc32.getValue();
- }
-*/
- public CRC32 copy(){
- CRC32 foo = new CRC32();
- foo.v = this.v;
- return foo;
- }
-
- public static int[] getCRC32Table(){
- int[] tmp = new int[crc_table.length];
- System.arraycopy(crc_table, 0, tmp, 0, tmp.length);
- return tmp;
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java
--- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-/* -*-mode:java; c-basic-offset:2; -*- */
-/*
-Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the distribution.
-
- 3. The names of the authors may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
-INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/*
- * This program is based on zlib-1.1.3, so all credit should go authors
- * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
- * and contributors of zlib.
- */
-
-package org.apidesign.bck2brwsr.emul.zip;
-
-interface Checksum {
- void update(byte[] buf, int index, int len);
- void reset();
- void reset(long init);
- long getValue();
- Checksum copy();
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java
--- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * Portions Copyrighted 2007 Sun Microsystems, Inc.
- */
-package org.apidesign.bck2brwsr.emul.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-/**
- *
- * @author Tomas Zezula
- */
-public final class FastJar {
- private final byte[] arr;
-
- public FastJar(byte[] arr) {
- this.arr = arr;
- }
-
-
- private static final int GIVE_UP = 1<<16;
-
- public static final class Entry {
-
- public final String name;
- final long offset;
- private final long dosTime;
-
- Entry (String name, long offset, long time) {
- assert name != null;
- this.name = name;
- this.offset = offset;
- this.dosTime = time;
- }
-/*
- public long getTime () {
- Date d = new Date((int)(((dosTime >> 25) & 0x7f) + 80),
- (int)(((dosTime >> 21) & 0x0f) - 1),
- (int)((dosTime >> 16) & 0x1f),
- (int)((dosTime >> 11) & 0x1f),
- (int)((dosTime >> 5) & 0x3f),
- (int)((dosTime << 1) & 0x3e));
- return d.getTime();
- }
- */
- }
-
- public InputStream getInputStream (final Entry e) throws IOException {
- return getInputStream(arr, e.offset);
- }
-
- private static InputStream getInputStream (byte[] arr, final long offset) throws IOException {
- ByteArrayInputStream is = new ByteArrayInputStream(arr);
- is.skip(offset);
- ZipInputStream in = new ZipInputStream (is);
- ZipEntry e = in.getNextEntry();
- if (e != null && e.getCrc() == 0L && e.getMethod() == ZipEntry.STORED) {
- int cp = arr.length - is.available();
- return new ByteArrayInputStream(arr, cp, (int)e.getSize());
- }
- return in;
- }
-
- public Entry[] list() throws IOException {
- final int size = arr.length;
-
- int at = size - ZipInputStream.ENDHDR;
-
- byte[] data = new byte[ZipInputStream.ENDHDR];
- int giveup = 0;
-
- do {
- org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
- at--;
- giveup++;
- if (giveup > GIVE_UP) {
- throw new IOException ();
- }
- } while (getsig(data) != ZipInputStream.ENDSIG);
-
-
- final long censize = endsiz(data);
- final long cenoff = endoff(data);
- at = (int) cenoff;
-
- Entry[] result = new Entry[0];
- int cenread = 0;
- data = new byte[ZipInputStream.CENHDR];
- while (cenread < censize) {
- org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
- at += data.length;
- if (getsig(data) != ZipInputStream.CENSIG) {
- throw new IOException("No central table"); //NOI18N
- }
- int cennam = cennam(data);
- int cenext = cenext(data);
- int cencom = cencom(data);
- long lhoff = cenoff(data);
- long centim = centim(data);
- String name = new String(arr, at, cennam, "UTF-8");
- at += cennam;
- int seekby = cenext+cencom;
- int cendatalen = ZipInputStream.CENHDR + cennam + seekby;
- cenread+=cendatalen;
- result = addEntry(result, new Entry(name,lhoff, centim));
- at += seekby;
- }
- return result;
- }
-
- private Entry[] addEntry(Entry[] result, Entry entry) {
- Entry[] e = new Entry[result.length + 1];
- e[result.length] = entry;
- org.apidesign.bck2brwsr.emul.lang.System.arraycopy(result, 0, e, 0, result.length);
- return e;
- }
-
- private static final long getsig(final byte[] b) throws IOException {return get32(b,0);}
- private static final long endsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDSIZ);}
- private static final long endoff(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDOFF);}
- private static final long cenlen(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENLEN);}
- private static final long censiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENSIZ);}
- private static final long centim(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENTIM);}
- private static final int cennam(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENNAM);}
- private static final int cenext(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENEXT);}
- private static final int cencom(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENCOM);}
- private static final long cenoff (final byte[] b) throws IOException {return get32(b,ZipInputStream.CENOFF);}
- private static final int lochow(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCHOW);}
- private static final int locname(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCNAM);}
- private static final int locext(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCEXT);}
- private static final long locsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.LOCSIZ);}
-
- private static final int get16(final byte[] b, int off) throws IOException {
- final int b1 = b[off];
- final int b2 = b[off+1];
- return (b1 & 0xff) | ((b2 & 0xff) << 8);
- }
-
- private static final long get32(final byte[] b, int off) throws IOException {
- final int s1 = get16(b, off);
- final int s2 = get16(b, off+2);
- return s1 | ((long)s2 << 16);
- }
-
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java
--- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,215 +0,0 @@
-/* -*-mode:java; c-basic-offset:2; -*- */
-/*
-Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the distribution.
-
- 3. The names of the authors may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
-INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/*
- * This program is based on zlib-1.1.3, so all credit should go authors
- * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
- * and contributors of zlib.
- */
-
-package org.apidesign.bck2brwsr.emul.zip;
-
-import org.apidesign.bck2brwsr.emul.lang.System;
-import java.io.UnsupportedEncodingException;
-
-/**
- * @see "http://www.ietf.org/rfc/rfc1952.txt"
- */
-final class GZIPHeader implements Cloneable {
-
- public static final byte OS_MSDOS = (byte) 0x00;
- public static final byte OS_AMIGA = (byte) 0x01;
- public static final byte OS_VMS = (byte) 0x02;
- public static final byte OS_UNIX = (byte) 0x03;
- public static final byte OS_ATARI = (byte) 0x05;
- public static final byte OS_OS2 = (byte) 0x06;
- public static final byte OS_MACOS = (byte) 0x07;
- public static final byte OS_TOPS20 = (byte) 0x0a;
- public static final byte OS_WIN32 = (byte) 0x0b;
- public static final byte OS_VMCMS = (byte) 0x04;
- public static final byte OS_ZSYSTEM = (byte) 0x08;
- public static final byte OS_CPM = (byte) 0x09;
- public static final byte OS_QDOS = (byte) 0x0c;
- public static final byte OS_RISCOS = (byte) 0x0d;
- public static final byte OS_UNKNOWN = (byte) 0xff;
-
- boolean text = false;
- private boolean fhcrc = false;
- long time;
- int xflags;
- int os = 255;
- byte[] extra;
- byte[] name;
- byte[] comment;
- int hcrc;
- long crc;
- boolean done = false;
- long mtime = 0;
-
- public void setModifiedTime(long mtime) {
- this.mtime = mtime;
- }
-
- public long getModifiedTime() {
- return mtime;
- }
-
- public void setOS(int os) {
- if((0<=os && os <=13) || os==255)
- this.os=os;
- else
- throw new IllegalArgumentException("os: "+os);
- }
-
- public int getOS(){
- return os;
- }
-
- public void setName(String name) {
- try{
- this.name=name.getBytes("ISO-8859-1");
- }
- catch(UnsupportedEncodingException e){
- throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
- }
- }
-
- public String getName(){
- if(name==null) return "";
- try {
- return new String(name, "ISO-8859-1");
- }
- catch (UnsupportedEncodingException e) {
- throw new IllegalArgumentException(e.toString());
- }
- }
-
- public void setComment(String comment) {
- try{
- this.comment=comment.getBytes("ISO-8859-1");
- }
- catch(UnsupportedEncodingException e){
- throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
- }
- }
-
- public String getComment(){
- if(comment==null) return "";
- try {
- return new String(comment, "ISO-8859-1");
- }
- catch (UnsupportedEncodingException e) {
- throw new IllegalArgumentException(e.toString());
- }
- }
-
- public void setCRC(long crc){
- this.crc = crc;
- }
-
- public long getCRC(){
- return crc;
- }
-/*
- void put(Deflate d){
- int flag = 0;
- if(text){
- flag |= 1; // FTEXT
- }
- if(fhcrc){
- flag |= 2; // FHCRC
- }
- if(extra!=null){
- flag |= 4; // FEXTRA
- }
- if(name!=null){
- flag |= 8; // FNAME
- }
- if(comment!=null){
- flag |= 16; // FCOMMENT
- }
- int xfl = 0;
- if(d.level == JZlib.Z_BEST_SPEED){
- xfl |= 4;
- }
- else if (d.level == JZlib.Z_BEST_COMPRESSION){
- xfl |= 2;
- }
-
- d.put_short((short)0x8b1f); // ID1 ID2
- d.put_byte((byte)8); // CM(Compression Method)
- d.put_byte((byte)flag);
- d.put_byte((byte)mtime);
- d.put_byte((byte)(mtime>>8));
- d.put_byte((byte)(mtime>>16));
- d.put_byte((byte)(mtime>>24));
- d.put_byte((byte)xfl);
- d.put_byte((byte)os);
-
- if(extra!=null){
- d.put_byte((byte)extra.length);
- d.put_byte((byte)(extra.length>>8));
- d.put_byte(extra, 0, extra.length);
- }
-
- if(name!=null){
- d.put_byte(name, 0, name.length);
- d.put_byte((byte)0);
- }
-
- if(comment!=null){
- d.put_byte(comment, 0, comment.length);
- d.put_byte((byte)0);
- }
- }
-*/
- @Override
- public Object clone() throws CloneNotSupportedException {
- GZIPHeader gheader = (GZIPHeader)super.clone();
- byte[] tmp;
- if(gheader.extra!=null){
- tmp=new byte[gheader.extra.length];
- System.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
- gheader.extra = tmp;
- }
-
- if(gheader.name!=null){
- tmp=new byte[gheader.name.length];
- System.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
- gheader.name = tmp;
- }
-
- if(gheader.comment!=null){
- tmp=new byte[gheader.comment.length];
- System.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
- gheader.comment = tmp;
- }
-
- return gheader;
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java
--- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java Tue May 06 17:46:47 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,616 +0,0 @@
-/* -*-mode:java; c-basic-offset:2; -*- */
-/*
-Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the distribution.
-
- 3. The names of the authors may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
-INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/*
- * This program is based on zlib-1.1.3, so all credit should go authors
- * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
- * and contributors of zlib.
- */
-
-package org.apidesign.bck2brwsr.emul.zip;
-
-import org.apidesign.bck2brwsr.emul.lang.System;
-
-final class InfBlocks{
- static final private int MANY=1440;
-
- // And'ing with mask[n] masks the lower n bits
- static final private int[] inflate_mask = {
- 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
- 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
- 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
- 0x00007fff, 0x0000ffff
- };
-
- // Table for deflate from PKZIP's appnote.txt.
- static final int[] border = { // Order of the bit length code lengths
- 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
- };
-
- static final private int Z_OK=0;
- static final private int Z_STREAM_END=1;
- static final private int Z_NEED_DICT=2;
- static final private int Z_ERRNO=-1;
- static final private int Z_STREAM_ERROR=-2;
- static final private int Z_DATA_ERROR=-3;
- static final private int Z_MEM_ERROR=-4;
- static final private int Z_BUF_ERROR=-5;
- static final private int Z_VERSION_ERROR=-6;
-
- static final private int TYPE=0; // get type bits (3, including end bit)
- static final private int LENS=1; // get lengths for stored
- static final private int STORED=2;// processing stored block
- static final private int TABLE=3; // get table lengths
- static final private int BTREE=4; // get bit lengths tree for a dynamic block
- static final private int DTREE=5; // get length, distance trees for a dynamic block
- static final private int CODES=6; // processing fixed or dynamic block
- static final private int DRY=7; // output remaining window bytes
- static final private int DONE=8; // finished last block, done
- static final private int BAD=9; // ot a data error--stuck here
-
- int mode; // current inflate_block mode
-
- int left; // if STORED, bytes left to copy
-
- int table; // table lengths (14 bits)
- int index; // index into blens (or border)
- int[] blens; // bit lengths of codes
- int[] bb=new int[1]; // bit length tree depth
- int[] tb=new int[1]; // bit length decoding tree
-
- int[] bl=new int[1];
- int[] bd=new int[1];
-
- int[][] tl=new int[1][];
- int[][] td=new int[1][];
- int[] tli=new int[1]; // tl_index
- int[] tdi=new int[1]; // td_index
-
- private final InfCodes codes; // if CODES, current state
-
- int last; // true if this block is the last block
-
- // mode independent information
- int bitk; // bits in bit buffer
- int bitb; // bit buffer
- int[] hufts; // single malloc for tree space
- byte[] window; // sliding window
- int end; // one byte after sliding window
- int read; // window read pointer
- int write; // window write pointer
- private boolean check;
-
- private final InfTree inftree=new InfTree();
-
- private final ZStream z;
-
- InfBlocks(ZStream z, int w){
- this.z=z;
- this.codes=new InfCodes(this.z, this);
- hufts=new int[MANY*3];
- window=new byte[w];
- end=w;
- this.check = (z.istate.wrap==0) ? false : true;
- mode = TYPE;
- reset();
- }
-
- void reset(){
- if(mode==BTREE || mode==DTREE){
- }
- if(mode==CODES){
- codes.free(z);
- }
- mode=TYPE;
- bitk=0;
- bitb=0;
- read=write=0;
- if(check){
- z.adler.reset();
- }
- }
-
- int proc(int r){
- int t; // temporary storage
- int b; // bit buffer
- int k; // bits in bit buffer
- int p; // input data pointer
- int n; // bytes available there
- int q; // output window write pointer
- int m; // bytes to end of window or read pointer
-
- // copy input/output information to locals (UPDATE macro restores)
- {p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;}
- {q=write;m=(int)(qjava.util.zip
classes are based.
-
- *
- * @see Deflater
- * @author David Connelly
- *
- */
-public
-class Inflater extends java.util.zip.Inflater {
- private final boolean nowrap;
- private JzLibInflater impl;
-
- /**
- * Creates a new decompressor. If the parameter 'nowrap' is true then
- * the ZLIB header and checksum fields will not be used. This provides
- * compatibility with the compression format used by both GZIP and PKZIP.
- *
- * try {
- * // Encode a String into bytes
- * String inputString = "blahblahblah\u20AC\u20AC";
- * byte[] input = inputString.getBytes("UTF-8");
- *
- * // Compress the bytes
- * byte[] output = new byte[100];
- * Deflater compresser = new Deflater();
- * compresser.setInput(input);
- * compresser.finish();
- * int compressedDataLength = compresser.deflate(output);
- *
- * // Decompress the bytes
- * Inflater decompresser = new Inflater();
- * decompresser.setInput(output, 0, compressedDataLength);
- * byte[] result = new byte[100];
- * int resultLength = decompresser.inflate(result);
- * decompresser.end();
- *
- * // Decode the bytes into a String
- * String outputString = new String(result, 0, resultLength, "UTF-8");
- * } catch(java.io.UnsupportedEncodingException ex) {
- * // handle
- * } catch (java.util.zip.DataFormatException ex) {
- * // handle
- * }
- *
Since the number of bytes may be greater than - * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now - * the preferred means of obtaining this information.
- * - * @return the total number of uncompressed bytes output so far - */ - public int getTotalOut() { - return (int) getBytesWritten(); - } - - /** - * Returns the total number of uncompressed bytes output so far. - * - * @return the total (non-negative) number of uncompressed bytes output so far - * @since 1.5 - */ - public long getBytesWritten() { - return impl.total_out; - } - - /** - * Resets inflater so that a new set of input data can be processed. - */ - public void reset() { - impl = new JzLibInflater(15, nowrap); - } - - /** - * Closes the decompressor and discards any unprocessed input. - * This method should be called when the decompressor is no longer - * being used, but will also be called automatically by the finalize() - * method. Once this method is called, the behavior of the Inflater - * object is undefined. - */ - public void end() { - impl.end(); - } - - /** - * Closes the decompressor when garbage is collected. - */ - protected void finalize() { - end(); - } -} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java Tue May 06 17:46:47 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ -/* -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the distribution. - - 3. The names of the authors may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/* - * This program is based on zlib-1.1.3, so all credit should go authors - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) - * and contributors of zlib. - */ - -package org.apidesign.bck2brwsr.emul.zip; - -final class JzLibInflater extends ZStream{ - - static final private int MAX_WBITS=15; // 32K LZ77 window - static final private int DEF_WBITS=MAX_WBITS; - - public static final int Z_NO_FLUSH=0; - static final private int Z_PARTIAL_FLUSH=1; - static final private int Z_SYNC_FLUSH=2; - static final private int Z_FULL_FLUSH=3; - static final private int Z_FINISH=4; - - static final private int MAX_MEM_LEVEL=9; - - static final private int Z_OK=0; - static final private int Z_STREAM_END=1; - static final private int Z_NEED_DICT=2; - static final private int Z_ERRNO=-1; - static final private int Z_STREAM_ERROR=-2; - static final private int Z_DATA_ERROR=-3; - static final private int Z_MEM_ERROR=-4; - static final private int Z_BUF_ERROR=-5; - static final private int Z_VERSION_ERROR=-6; - - public JzLibInflater() { - super(); - init(); - } - - public JzLibInflater(int w) { - this(w, false); - } - - public JzLibInflater(int w, boolean nowrap) { - super(); - int ret = init(w, nowrap); - if(ret!=Z_OK) - throw new IllegalStateException(ret+": "+msg); - } - - private boolean finished = false; - - public int init(){ - return init(DEF_WBITS); - } - - public int init(boolean nowrap){ - return init(DEF_WBITS, nowrap); - } - - public int init(int w){ - return init(w, false); - } - - public int init(int w, boolean nowrap){ - finished = false; - istate=new Inflate(this); - return istate.inflateInit(nowrap?-w:w); - } - - public int inflate(int f){ - if(istate==null) return Z_STREAM_ERROR; - int ret = istate.inflate(f); - if(ret == Z_STREAM_END) - finished = true; - return ret; - } - - public int end(){ - finished = true; - if(istate==null) return Z_STREAM_ERROR; - int ret=istate.inflateEnd(); -// istate = null; - return ret; - } - - public int sync(){ - if(istate == null) - return Z_STREAM_ERROR; - return istate.inflateSync(); - } - - public int syncPoint(){ - if(istate == null) - return Z_STREAM_ERROR; - return istate.inflateSyncPoint(); - } - - public int setDictionary(byte[] dictionary, int dictLength){ - if(istate == null) - return Z_STREAM_ERROR; - return istate.inflateSetDictionary(dictionary, dictLength); - } - - public boolean finished(){ - return istate.mode==12 /*DONE*/; - } - - public boolean needDict() { - return istate == null ? false : istate.mode == Inflate.DICT0; - } -} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java Tue May 06 17:46:47 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,253 +0,0 @@ -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ -/* -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the distribution. - - 3. The names of the authors may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/* - * This program is based on zlib-1.1.3, so all credit should go authors - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) - * and contributors of zlib. - */ - -package org.apidesign.bck2brwsr.emul.zip; - -import org.apidesign.bck2brwsr.emul.lang.System; - -/** - * ZStream - * - * @deprecated Not for public use in the future. - */ -@Deprecated -class ZStream{ - - static final private int MAX_WBITS=15; // 32K LZ77 window - static final private int DEF_WBITS=MAX_WBITS; - - static final private int Z_NO_FLUSH=0; - static final private int Z_PARTIAL_FLUSH=1; - static final private int Z_SYNC_FLUSH=2; - static final private int Z_FULL_FLUSH=3; - static final private int Z_FINISH=4; - - static final private int MAX_MEM_LEVEL=9; - - static final private int Z_OK=0; - static final private int Z_STREAM_END=1; - static final private int Z_NEED_DICT=2; - static final private int Z_ERRNO=-1; - static final private int Z_STREAM_ERROR=-2; - static final private int Z_DATA_ERROR=-3; - static final private int Z_MEM_ERROR=-4; - static final private int Z_BUF_ERROR=-5; - static final private int Z_VERSION_ERROR=-6; - - public byte[] next_in; // next input byte - public int next_in_index; - public int avail_in; // number of bytes available at next_in - public long total_in; // total nb of input bytes read so far - - public byte[] next_out; // next output byte should be put there - public int next_out_index; - public int avail_out; // remaining free space at next_out - public long total_out; // total nb of bytes output so far - - public String msg; - - Inflate istate; - - int data_type; // best guess about the data type: ascii or binary - - Checksum adler; - - public ZStream(){ - this(new Adler32()); - } - - public ZStream(Checksum adler){ - this.adler=adler; - } - - public int inflateInit(){ - return inflateInit(DEF_WBITS); - } - public int inflateInit(boolean nowrap){ - return inflateInit(DEF_WBITS, nowrap); - } - public int inflateInit(int w){ - return inflateInit(w, false); - } - - public int inflateInit(int w, boolean nowrap){ - istate=new Inflate(this); - return istate.inflateInit(nowrap?-w:w); - } - - public int inflate(int f){ - if(istate==null) return Z_STREAM_ERROR; - return istate.inflate(f); - } - public int inflateEnd(){ - if(istate==null) return Z_STREAM_ERROR; - int ret=istate.inflateEnd(); -// istate = null; - return ret; - } - - public int inflateSync(){ - if(istate == null) - return Z_STREAM_ERROR; - return istate.inflateSync(); - } - public int inflateSyncPoint(){ - if(istate == null) - return Z_STREAM_ERROR; - return istate.inflateSyncPoint(); - } - public int inflateSetDictionary(byte[] dictionary, int dictLength){ - if(istate == null) - return Z_STREAM_ERROR; - return istate.inflateSetDictionary(dictionary, dictLength); - } - public boolean inflateFinished(){ - return istate.mode==12 /*DONE*/; - } - - - public long getAdler(){ - return adler.getValue(); - } - - public void free(){ - next_in=null; - next_out=null; - msg=null; - } - - public void setOutput(byte[] buf){ - setOutput(buf, 0, buf.length); - } - - public void setOutput(byte[] buf, int off, int len){ - next_out = buf; - next_out_index = off; - avail_out = len; - } - - public void setInput(byte[] buf){ - setInput(buf, 0, buf.length, false); - } - - public void setInput(byte[] buf, boolean append){ - setInput(buf, 0, buf.length, append); - } - - public void setInput(byte[] buf, int off, int len, boolean append){ - if(len<=0 && append && next_in!=null) return; - - if(avail_in>0 && append){ - byte[] tmp = new byte[avail_in+len]; - System.arraycopy(next_in, next_in_index, tmp, 0, avail_in); - System.arraycopy(buf, off, tmp, avail_in, len); - next_in=tmp; - next_in_index=0; - avail_in+=len; - } - else{ - next_in=buf; - next_in_index=off; - avail_in=len; - } - } - - public byte[] getNextIn(){ - return next_in; - } - - public void setNextIn(byte[] next_in){ - this.next_in = next_in; - } - - public int getNextInIndex(){ - return next_in_index; - } - - public void setNextInIndex(int next_in_index){ - this.next_in_index = next_in_index; - } - - public int getAvailIn(){ - return avail_in; - } - - public void setAvailIn(int avail_in){ - this.avail_in = avail_in; - } - - public byte[] getNextOut(){ - return next_out; - } - - public void setNextOut(byte[] next_out){ - this.next_out = next_out; - } - - public int getNextOutIndex(){ - return next_out_index; - } - - public void setNextOutIndex(int next_out_index){ - this.next_out_index = next_out_index; - } - - public int getAvailOut(){ - return avail_out; - - } - - public void setAvailOut(int avail_out){ - this.avail_out = avail_out; - } - - public long getTotalOut(){ - return total_out; - } - - public long getTotalIn(){ - return total_in; - } - - public String getMessage(){ - return msg; - } - - /** - * Those methods are expected to be override by Inflater and Deflater. - * In the future, they will become abstract methods. - */ - public int end(){ return Z_OK; } - public boolean finished(){ return false; } -} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java Tue May 06 17:46:47 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package org.apidesign.bck2brwsr.emul.zip; - -/* - * This class defines the constants that are used by the classes - * which manipulate Zip64 files. - */ - -public class ZipConstants64 { - - /* - * ZIP64 constants - */ - static final long ZIP64_ENDSIG = 0x06064b50L; // "PK\006\006" - static final long ZIP64_LOCSIG = 0x07064b50L; // "PK\006\007" - static final int ZIP64_ENDHDR = 56; // ZIP64 end header size - static final int ZIP64_LOCHDR = 20; // ZIP64 end loc header size - static final int ZIP64_EXTHDR = 24; // EXT header size - static final int ZIP64_EXTID = 0x0001; // Extra field Zip64 header ID - - static final int ZIP64_MAGICCOUNT = 0xFFFF; - static final long ZIP64_MAGICVAL = 0xFFFFFFFFL; - - /* - * Zip64 End of central directory (END) header field offsets - */ - static final int ZIP64_ENDLEN = 4; // size of zip64 end of central dir - static final int ZIP64_ENDVEM = 12; // version made by - static final int ZIP64_ENDVER = 14; // version needed to extract - static final int ZIP64_ENDNMD = 16; // number of this disk - static final int ZIP64_ENDDSK = 20; // disk number of start - static final int ZIP64_ENDTOD = 24; // total number of entries on this disk - static final int ZIP64_ENDTOT = 32; // total number of entries - static final int ZIP64_ENDSIZ = 40; // central directory size in bytes - static final int ZIP64_ENDOFF = 48; // offset of first CEN header - static final int ZIP64_ENDEXT = 56; // zip64 extensible data sector - - /* - * Zip64 End of central directory locator field offsets - */ - static final int ZIP64_LOCDSK = 4; // disk number start - static final int ZIP64_LOCOFF = 8; // offset of zip64 end - static final int ZIP64_LOCTOT = 16; // total number of disks - - /* - * Zip64 Extra local (EXT) header field offsets - */ - static final int ZIP64_EXTCRC = 4; // uncompressed file crc-32 value - static final int ZIP64_EXTSIZ = 8; // compressed size, 8-byte - static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte - - /* - * Language encoding flag EFS - */ - static final int EFS = 0x800; // If this bit is set the filename and - // comment fields for this file must be - // encoded using UTF-8. - - private ZipConstants64() {} -} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java Tue May 06 17:46:47 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,468 +0,0 @@ -/* - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package org.apidesign.bck2brwsr.emul.zip; - -import java.util.zip.*; -import java.io.InputStream; -import java.io.IOException; -import java.io.EOFException; -import java.io.PushbackInputStream; -import static org.apidesign.bck2brwsr.emul.zip.ZipConstants64.*; -import static java.util.zip.ZipInputStream.*; - -/** - * This class implements an input stream filter for reading files in the - * ZIP file format. Includes support for both compressed and uncompressed - * entries. - * - * @author David Connelly - */ -public -class ZipInputStream extends InflaterInputStream { - private ZipEntry entry; - private int flag; - private CRC32 crc = new CRC32(); - private long remaining; - private byte[] tmpbuf = new byte[512]; - - private static final int STORED = ZipEntry.STORED; - private static final int DEFLATED = ZipEntry.DEFLATED; - - private boolean closed = false; - // this flag is set to true after EOF has reached for - // one entry - private boolean entryEOF = false; - - /** - * Check to make sure that this stream has not been closed - */ - private void ensureOpen() throws IOException { - if (closed) { - throw new IOException("Stream closed"); - } - } - - /** - * Creates a new ZIP input stream. - * - *The UTF-8 {@link java.nio.charset.Charset charset} is used to - * decode the entry names. - * - * @param in the actual input stream - */ - public ZipInputStream(InputStream in) { -// this(in, "UTF-8"); - super(new PushbackInputStream(in, 512), new Inflater(true), 512); - //usesDefaultInflater = true; - if(in == null) { - throw new NullPointerException("in is null"); - } - } - - /** - * Creates a new ZIP input stream. - * - * @param in the actual input stream - * - * @param charset - * The {@linkplain java.nio.charset.Charset charset} to be - * used to decode the ZIP entry name (ignored if the - * language - * encoding bit of the ZIP entry's general purpose bit - * flag is set). - * - * @since 1.7 - * - public ZipInputStream(InputStream in, Charset charset) { - super(new PushbackInputStream(in, 512), new Inflater(true), 512); - usesDefaultInflater = true; - if(in == null) { - throw new NullPointerException("in is null"); - } - if (charset == null) - throw new NullPointerException("charset is null"); - this.zc = ZipCoder.get(charset); - } - */ - - /** - * Reads the next ZIP file entry and positions the stream at the - * beginning of the entry data. - * @return the next ZIP file entry, or null if there are no more entries - * @exception ZipException if a ZIP file error has occurred - * @exception IOException if an I/O error has occurred - */ - public ZipEntry getNextEntry() throws IOException { - ensureOpen(); - if (entry != null) { - closeEntry(); - } - crc.reset(); - inf.reset(); - if ((entry = readLOC()) == null) { - return null; - } - if (entry.getMethod() == STORED) { - remaining = entry.getSize(); - } - entryEOF = false; - return entry; - } - - /** - * Closes the current ZIP entry and positions the stream for reading the - * next entry. - * @exception ZipException if a ZIP file error has occurred - * @exception IOException if an I/O error has occurred - */ - public void closeEntry() throws IOException { - ensureOpen(); - while (read(tmpbuf, 0, tmpbuf.length) != -1) ; - entryEOF = true; - } - - /** - * Returns 0 after EOF has reached for the current entry data, - * otherwise always return 1. - *
- * Programs should not count on this method to return the actual number
- * of bytes that could be read without blocking.
- *
- * @return 1 before EOF and 0 after EOF has reached for current entry.
- * @exception IOException if an I/O error occurs.
- *
- */
- public int available() throws IOException {
- ensureOpen();
- if (entryEOF) {
- return 0;
- } else {
- return 1;
- }
- }
-
- /**
- * Reads from the current ZIP entry into an array of bytes.
- * If len
is not zero, the method
- * blocks until some input is available; otherwise, no
- * bytes are read and 0
is returned.
- * @param b the buffer into which the data is read
- * @param off the start offset in the destination array b
- * @param len the maximum number of bytes read
- * @return the actual number of bytes read, or -1 if the end of the
- * entry is reached
- * @exception NullPointerException if b
is null
.
- * @exception IndexOutOfBoundsException if off
is negative,
- * len
is negative, or len
is greater than
- * b.length - off
- * @exception ZipException if a ZIP file error has occurred
- * @exception IOException if an I/O error has occurred
- */
- public int read(byte[] b, int off, int len) throws IOException {
- ensureOpen();
- if (off < 0 || len < 0 || off > b.length - len) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return 0;
- }
-
- if (entry == null) {
- return -1;
- }
- switch (entry.getMethod()) {
- case DEFLATED:
- len = super.read(b, off, len);
- if (len == -1) {
- readEnd(entry);
- entryEOF = true;
- entry = null;
- } else {
- crc.update(b, off, len);
- }
- return len;
- case STORED:
- if (remaining <= 0) {
- entryEOF = true;
- entry = null;
- return -1;
- }
- if (len > remaining) {
- len = (int)remaining;
- }
- len = in.read(b, off, len);
- if (len == -1) {
- throw new ZipException("unexpected EOF");
- }
- crc.update(b, off, len);
- remaining -= len;
- if (remaining == 0 && entry.getCrc() != crc.getValue()) {
- throw new ZipException(
- "invalid entry CRC (expected 0x" + Long.toHexString(entry.getCrc()) +
- " but got 0x" + Long.toHexString(crc.getValue()) + ")");
- }
- return len;
- default:
- throw new ZipException("invalid compression method");
- }
- }
-
- /**
- * Skips specified number of bytes in the current ZIP entry.
- * @param n the number of bytes to skip
- * @return the actual number of bytes skipped
- * @exception ZipException if a ZIP file error has occurred
- * @exception IOException if an I/O error has occurred
- * @exception IllegalArgumentException if n < 0
- */
- public long skip(long n) throws IOException {
- if (n < 0) {
- throw new IllegalArgumentException("negative skip length");
- }
- ensureOpen();
- int max = (int)Math.min(n, Integer.MAX_VALUE);
- int total = 0;
- while (total < max) {
- int len = max - total;
- if (len > tmpbuf.length) {
- len = tmpbuf.length;
- }
- len = read(tmpbuf, 0, len);
- if (len == -1) {
- entryEOF = true;
- break;
- }
- total += len;
- }
- return total;
- }
-
- /**
- * Closes this input stream and releases any system resources associated
- * with the stream.
- * @exception IOException if an I/O error has occurred
- */
- public void close() throws IOException {
- if (!closed) {
- super.close();
- closed = true;
- }
- }
-
- private byte[] b = new byte[256];
-
- /*
- * Reads local file (LOC) header for next entry.
- */
- private ZipEntry readLOC() throws IOException {
- try {
- readFully(tmpbuf, 0, LOCHDR);
- } catch (EOFException e) {
- return null;
- }
- if (get32(tmpbuf, 0) != LOCSIG) {
- return null;
- }
- // get flag first, we need check EFS.
- flag = get16(tmpbuf, LOCFLG);
- // get the entry name and create the ZipEntry first
- int len = get16(tmpbuf, LOCNAM);
- int blen = b.length;
- if (len > blen) {
- do
- blen = blen * 2;
- while (len > blen);
- b = new byte[blen];
- }
- readFully(b, 0, len);
- // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
- ZipEntry e = createZipEntry(((flag & EFS) != 0)
- ? toStringUTF8(b, len)
- : toString(b, len));
- // now get the remaining fields for the entry
- if ((flag & 1) == 1) {
- throw new ZipException("encrypted ZIP entry not supported");
- }
- e.setMethod(get16(tmpbuf, LOCHOW));
- e.setTime(get32(tmpbuf, LOCTIM));
- if ((flag & 8) == 8) {
- /* "Data Descriptor" present */
- if (e.getMethod() != DEFLATED) {
- throw new ZipException(
- "only DEFLATED entries can have EXT descriptor");
- }
- } else {
- e.setCrc(get32(tmpbuf, LOCCRC));
- e.setCompressedSize(get32(tmpbuf, LOCSIZ));
- e.setSize(get32(tmpbuf, LOCLEN));
- }
- len = get16(tmpbuf, LOCEXT);
- if (len > 0) {
- byte[] bb = new byte[len];
- readFully(bb, 0, len);
- e.setExtra(bb);
- // extra fields are in "HeaderID(2)DataSize(2)Data... format
- if (e.getCompressedSize() == ZIP64_MAGICVAL || e.getCompressedSize() == ZIP64_MAGICVAL) {
- int off = 0;
- while (off + 4 < len) {
- int sz = get16(bb, off + 2);
- if (get16(bb, off) == ZIP64_EXTID) {
- off += 4;
- // LOC extra zip64 entry MUST include BOTH original and
- // compressed file size fields
- if (sz < 16 || (off + sz) > len ) {
- // Invalid zip64 extra fields, simply skip. Even it's
- // rare, it's possible the entry size happens to be
- // the magic value and it "accidnetly" has some bytes
- // in extra match the id.
- return e;
- }
- e.setSize(get64(bb, off));
- e.setCompressedSize(get64(bb, off + 8));
- break;
- }
- off += (sz + 4);
- }
- }
- }
- return e;
- }
-
- /**
- * Creates a new ZipEntry
object for the specified
- * entry name.
- *
- * @param name the ZIP file entry name
- * @return the ZipEntry just created
- */
- protected ZipEntry createZipEntry(String name) {
- return new ZipEntry(name);
- }
-
- /*
- * Reads end of deflated entry as well as EXT descriptor if present.
- */
- private void readEnd(ZipEntry e) throws IOException {
- int n = inf.getRemaining();
- if (n > 0) {
- ((PushbackInputStream)in).unread(buf, len - n, n);
- }
- if ((flag & 8) == 8) {
- /* "Data Descriptor" present */
- if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
- inf.getBytesRead() > ZIP64_MAGICVAL) {
- // ZIP64 format
- readFully(tmpbuf, 0, ZIP64_EXTHDR);
- long sig = get32(tmpbuf, 0);
- if (sig != EXTSIG) { // no EXTSIG present
- e.setCrc(sig);
- e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC));
- e.setSize(get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC));
- ((PushbackInputStream)in).unread(
- tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
- } else {
- e.setCrc(get32(tmpbuf, ZIP64_EXTCRC));
- e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ));
- e.setSize(get64(tmpbuf, ZIP64_EXTLEN));
- }
- } else {
- readFully(tmpbuf, 0, EXTHDR);
- long sig = get32(tmpbuf, 0);
- if (sig != EXTSIG) { // no EXTSIG present
- e.setCrc(sig);
- e.setCompressedSize(get32(tmpbuf, EXTSIZ - EXTCRC));
- e.setSize(get32(tmpbuf, EXTLEN - EXTCRC));
- ((PushbackInputStream)in).unread(
- tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
- } else {
- e.setCrc(get32(tmpbuf, EXTCRC));
- e.setCompressedSize(get32(tmpbuf, EXTSIZ));
- e.setSize(get32(tmpbuf, EXTLEN));
- }
- }
- }
- if (e.getSize() != inf.getBytesWritten()) {
- throw new ZipException(
- "invalid entry size (expected " + e.getSize() +
- " but got " + inf.getBytesWritten() + " bytes)");
- }
- if (e.getCompressedSize() != inf.getBytesRead()) {
- throw new ZipException(
- "invalid entry compressed size (expected " + e.getCompressedSize() +
- " but got " + inf.getBytesRead() + " bytes)");
- }
- if (e.getCrc() != crc.getValue()) {
- throw new ZipException(
- "invalid entry CRC (expected 0x" + Long.toHexString(e.getCrc()) +
- " but got 0x" + Long.toHexString(crc.getValue()) + ")");
- }
- }
-
- /*
- * Reads bytes, blocking until all bytes are read.
- */
- private void readFully(byte[] b, int off, int len) throws IOException {
- while (len > 0) {
- int n = in.read(b, off, len);
- if (n == -1) {
- throw new EOFException();
- }
- off += n;
- len -= n;
- }
- }
-
- /*
- * Fetches unsigned 16-bit value from byte array at specified offset.
- * The bytes are assumed to be in Intel (little-endian) byte order.
- */
- private static final int get16(byte b[], int off) {
- return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
- }
-
- /*
- * Fetches unsigned 32-bit value from byte array at specified offset.
- * The bytes are assumed to be in Intel (little-endian) byte order.
- */
- private static final long get32(byte b[], int off) {
- return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
- }
-
- /*
- * Fetches signed 64-bit value from byte array at specified offset.
- * The bytes are assumed to be in Intel (little-endian) byte order.
- */
- private static final long get64(byte b[], int off) {
- return get32(b, off) | (get32(b, off+4) << 32);
- }
-
- private static String toStringUTF8(byte[] arr, int len) {
- return new String(arr, 0, len);
- }
-
- private static String toString(byte[] b, int len) {
- return new String(b, 0, len);
- }
-}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/pom.xml
--- a/rt/emul/pom.xml Tue May 06 17:46:47 2014 +0200
+++ b/rt/emul/pom.xml Sun May 11 14:01:18 2014 +0200
@@ -16,5 +16,6 @@
+ * The specification for Adler32 may be found in RFC 1950. + * (ZLIB Compressed Data Format Specification version 3.3) + *
+ *
+ * From that document: + *
+ * "ADLER32 (Adler-32 checksum) + * This contains a checksum value of the uncompressed data + * (excluding any dictionary data) computed according to Adler-32 + * algorithm. This algorithm is a 32-bit extension and improvement + * of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 + * standard. + *
+ * Adler-32 is composed of two sums accumulated per byte: s1 is + * the sum of all bytes, s2 is the sum of all s1 values. Both sums + * are done modulo 65521. s1 is initialized to 1, s2 to zero. The + * Adler-32 checksum is stored as s2*65536 + s1 in most- + * significant-byte first (network) order." + *
+ * "8.2. The Adler-32 algorithm + *
+ * The Adler-32 algorithm is much faster than the CRC32 algorithm yet + * still provides an extremely low probability of undetected errors. + *
+ * The modulo on unsigned long accumulators can be delayed for 5552 + * bytes, so the modulo operation time is negligible. If the bytes + * are a, b, c, the second sum is 3a + 2b + c + 3, and so is position + * and order sensitive, unlike the first sum, which is just a + * checksum. That 65521 is prime is important to avoid a possible + * large class of two-byte errors that leave the check unchanged. + * (The Fletcher checksum uses 255, which is not prime and which also + * makes the Fletcher check insensitive to single byte changes 0 <-> + * 255.) + *
+ * The sum s1 is initialized to 1 instead of zero to make the length
+ * of the sequence part of s2, so that the length does not have to be
+ * checked separately. (Any sequence of zeroes has a Fletcher
+ * checksum of zero.)"
+ *
+ * @author John Leuner, Per Bothner
+ * @since JDK 1.1
+ *
+ * @see InflaterInputStream
+ * @see DeflaterOutputStream
+ */
+public class Adler32 implements Checksum
+{
+
+ /** largest prime smaller than 65536 */
+ private static final int BASE = 65521;
+
+ private int checksum; //we do all in int.
+
+ //Note that java doesn't have unsigned integers,
+ //so we have to be careful with what arithmetic
+ //we do. We return the checksum as a long to
+ //avoid sign confusion.
+
+ /**
+ * Creates a new instance of the Adler32
class.
+ * The checksum starts off with a value of 1.
+ */
+ public Adler32 ()
+ {
+ reset();
+ }
+
+ /**
+ * Resets the Adler32 checksum to the initial value.
+ */
+ public void reset ()
+ {
+ checksum = 1; //Initialize to 1
+ }
+
+ /**
+ * Updates the checksum with the byte b.
+ *
+ * @param bval the data value to add. The high byte of the int is ignored.
+ */
+ public void update (int bval)
+ {
+ //We could make a length 1 byte array and call update again, but I
+ //would rather not have that overhead
+ int s1 = checksum & 0xffff;
+ int s2 = checksum >>> 16;
+
+ s1 = (s1 + (bval & 0xFF)) % BASE;
+ s2 = (s1 + s2) % BASE;
+
+ checksum = (s2 << 16) + s1;
+ }
+
+ /**
+ * Updates the checksum with the bytes taken from the array.
+ *
+ * @param buffer an array of bytes
+ */
+ public void update (byte[] buffer)
+ {
+ update(buffer, 0, buffer.length);
+ }
+
+ /**
+ * Updates the checksum with the bytes taken from the array.
+ *
+ * @param buf an array of bytes
+ * @param off the start of the data used for this update
+ * @param len the number of bytes to use for this update
+ */
+ public void update (byte[] buf, int off, int len)
+ {
+ //(By Per Bothner)
+ int s1 = checksum & 0xffff;
+ int s2 = checksum >>> 16;
+
+ while (len > 0)
+ {
+ // We can defer the modulo operation:
+ // s1 maximally grows from 65521 to 65521 + 255 * 3800
+ // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
+ int n = 3800;
+ if (n > len)
+ n = len;
+ len -= n;
+ while (--n >= 0)
+ {
+ s1 = s1 + (buf[off++] & 0xFF);
+ s2 = s2 + s1;
+ }
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+
+ /*Old implementation, borrowed from somewhere:
+ int n;
+
+ while (len-- > 0) {
+
+ s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
+ s2 = (s2 + s1) % BASE;
+ }*/
+
+ checksum = (s2 << 16) | s1;
+ }
+
+ /**
+ * Returns the Adler32 data checksum computed so far.
+ */
+ public long getValue()
+ {
+ return (long) checksum & 0xffffffffL;
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/CRC32.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/CRC32.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,132 @@
+/* CRC32.java - Computes CRC32 data checksum of a data stream
+ 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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;
+
+/*
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * The actual CRC32 algorithm is taken from RFC 1952.
+ * Status: Believed complete and correct.
+ */
+
+/**
+ * Computes CRC32 data checksum of a data stream.
+ * The actual CRC32 algorithm is described in RFC 1952
+ * (GZIP file format specification version 4.3).
+ * Can be used to get the CRC32 over a stream if used with checked input/output
+ * streams.
+ *
+ * @see InflaterInputStream
+ * @see DeflaterOutputStream
+ *
+ * @author Per Bothner
+ * @date April 1, 1999.
+ */
+public class CRC32 implements Checksum
+{
+ /** The crc data checksum so far. */
+ private int crc = 0;
+
+ /** The fast CRC table. Computed once when the CRC32 class is loaded. */
+ private static int[] crc_table = make_crc_table();
+
+ /** Make the table for a fast CRC. */
+ private static int[] make_crc_table ()
+ {
+ int[] crc_table = new int[256];
+ for (int n = 0; n < 256; n++)
+ {
+ int c = n;
+ for (int k = 8; --k >= 0; )
+ {
+ if ((c & 1) != 0)
+ c = 0xedb88320 ^ (c >>> 1);
+ else
+ c = c >>> 1;
+ }
+ crc_table[n] = c;
+ }
+ return crc_table;
+ }
+
+ /**
+ * Returns the CRC32 data checksum computed so far.
+ */
+ public long getValue ()
+ {
+ return (long) crc & 0xffffffffL;
+ }
+
+ /**
+ * Resets the CRC32 data checksum as if no update was ever called.
+ */
+ public void reset () { crc = 0; }
+
+ /**
+ * Updates the checksum with the int bval.
+ *
+ * @param bval (the byte is taken as the lower 8 bits of bval)
+ */
+
+ public void update (int bval)
+ {
+ int c = ~crc;
+ c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
+ crc = ~c;
+ }
+
+ /**
+ * Adds the byte array to the data checksum.
+ *
+ * @param buf the buffer which contains the data
+ * @param off the offset in the buffer where the data starts
+ * @param len the length of the data
+ */
+ public void update (byte[] buf, int off, int len)
+ {
+ int c = ~crc;
+ while (--len >= 0)
+ c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
+ crc = ~c;
+ }
+
+ /**
+ * Adds the complete byte array to the data checksum.
+ */
+ public void update (byte[] buf) { update(buf, 0, buf.length); }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/Checksum.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/Checksum.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.zip;
+
+/**
+ * An interface representing a data checksum.
+ *
+ * @author David Connelly
+ */
+public
+interface Checksum {
+ /**
+ * Updates the current checksum with the specified byte.
+ *
+ * @param b the byte to update the checksum with
+ */
+ public void update(int b);
+
+ /**
+ * Updates the current checksum with the specified array of bytes.
+ * @param b the byte array to update the checksum with
+ * @param off the start offset of the data
+ * @param len the number of bytes to use for the update
+ */
+ public void update(byte[] b, int off, int len);
+
+ /**
+ * Returns the current checksum value.
+ * @return the current checksum value
+ */
+ public long getValue();
+
+ /**
+ * Resets the checksum to its initial value.
+ */
+ public void reset();
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/DataFormatException.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/DataFormatException.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.zip;
+
+/**
+ * Signals that a data format error has occurred.
+ *
+ * @author David Connelly
+ */
+public
+class DataFormatException extends Exception {
+ private static final long serialVersionUID = 2219632870893641452L;
+
+ /**
+ * Constructs a DataFormatException with no detail message.
+ */
+ public DataFormatException() {
+ super();
+ }
+
+ /**
+ * Constructs a DataFormatException with the specified detail message.
+ * A detail message is a String that describes this particular exception.
+ * @param s the String containing a detail message
+ */
+ public DataFormatException(String s) {
+ super(s);
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/Inflater.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/Inflater.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,310 @@
+/*
+ * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.zip;
+
+/**
+ * This class provides support for general purpose decompression using the
+ * popular ZLIB compression library. The ZLIB compression library was
+ * initially developed as part of the PNG graphics standard and is not
+ * protected by patents. It is fully described in the specifications at
+ * the java.util.zip
+ * package description.
+ *
+ *
The following code fragment demonstrates a trivial compression + * and decompression of a string using Deflater and + * Inflater. + * + *
+ * + * @see Deflater + * @author David Connelly + * + */ +public +class Inflater { + private final org.apidesign.bck2brwsr.emul.zip.Inflater impl; + + /** + * Creates a new decompressor. If the parameter 'nowrap' is true then + * the ZLIB header and checksum fields will not be used. This provides + * compatibility with the compression format used by both GZIP and PKZIP. + *+ * try { + * // Encode a String into bytes + * String inputString = "blahblahblah\u20AC\u20AC"; + * byte[] input = inputString.getBytes("UTF-8"); + * + * // Compress the bytes + * byte[] output = new byte[100]; + * Deflater compresser = new Deflater(); + * compresser.setInput(input); + * compresser.finish(); + * int compressedDataLength = compresser.deflate(output); + * + * // Decompress the bytes + * Inflater decompresser = new Inflater(); + * decompresser.setInput(output, 0, compressedDataLength); + * byte[] result = new byte[100]; + * int resultLength = decompresser.inflate(result); + * decompresser.end(); + * + * // Decode the bytes into a String + * String outputString = new String(result, 0, resultLength, "UTF-8"); + * } catch(java.io.UnsupportedEncodingException ex) { + * // handle + * } catch (java.util.zip.DataFormatException ex) { + * // handle + * } + *
+ * Note: When using the 'nowrap' option it is also necessary to provide + * an extra "dummy" byte as input. This is required by the ZLIB native + * library in order to support certain optimizations. + * + * @param nowrap if true then support GZIP compatible compression + */ + public Inflater(boolean nowrap) { + if (getClass() == org.apidesign.bck2brwsr.emul.zip.Inflater.class) { + impl = null; + } else { + impl = new org.apidesign.bck2brwsr.emul.zip.Inflater(nowrap); + } + } + + /** + * Creates a new decompressor. + */ + public Inflater() { + this(false); + } + + /** + * Sets input data for decompression. Should be called whenever + * needsInput() returns true indicating that more input data is + * required. + * @param b the input data bytes + * @param off the start offset of the input data + * @param len the length of the input data + * @see Inflater#needsInput + */ + public void setInput(byte[] b, int off, int len) { + impl.setInput(b, off, len); + } + + /** + * Sets input data for decompression. Should be called whenever + * needsInput() returns true indicating that more input data is + * required. + * @param b the input data bytes + * @see Inflater#needsInput + */ + public void setInput(byte[] b) { + impl.setInput(b); + } + + /** + * Sets the preset dictionary to the given array of bytes. Should be + * called when inflate() returns 0 and needsDictionary() returns true + * indicating that a preset dictionary is required. The method getAdler() + * can be used to get the Adler-32 value of the dictionary needed. + * @param b the dictionary data bytes + * @param off the start offset of the data + * @param len the length of the data + * @see Inflater#needsDictionary + * @see Inflater#getAdler + */ + public void setDictionary(byte[] b, int off, int len) { + impl.setDictionary(b, off, len); + } + + /** + * Sets the preset dictionary to the given array of bytes. Should be + * called when inflate() returns 0 and needsDictionary() returns true + * indicating that a preset dictionary is required. The method getAdler() + * can be used to get the Adler-32 value of the dictionary needed. + * @param b the dictionary data bytes + * @see Inflater#needsDictionary + * @see Inflater#getAdler + */ + public void setDictionary(byte[] b) { + impl.setDictionary(b); + } + + /** + * Returns the total number of bytes remaining in the input buffer. + * This can be used to find out what bytes still remain in the input + * buffer after decompression has finished. + * @return the total number of bytes remaining in the input buffer + */ + public int getRemaining() { + return impl.getRemaining(); + } + + /** + * Returns true if no data remains in the input buffer. This can + * be used to determine if #setInput should be called in order + * to provide more input. + * @return true if no data remains in the input buffer + */ + public boolean needsInput() { + return impl.needsInput(); + } + + /** + * Returns true if a preset dictionary is needed for decompression. + * @return true if a preset dictionary is needed for decompression + * @see Inflater#setDictionary + */ + public boolean needsDictionary() { + return impl.needsDictionary(); + } + + /** + * Returns true if the end of the compressed data stream has been + * reached. + * @return true if the end of the compressed data stream has been + * reached + */ + public boolean finished() { + return impl.finished(); + } + + /** + * Uncompresses bytes into specified buffer. Returns actual number + * of bytes uncompressed. A return value of 0 indicates that + * needsInput() or needsDictionary() should be called in order to + * determine if more input data or a preset dictionary is required. + * In the latter case, getAdler() can be used to get the Adler-32 + * value of the dictionary required. + * @param b the buffer for the uncompressed data + * @param off the start offset of the data + * @param len the maximum number of uncompressed bytes + * @return the actual number of uncompressed bytes + * @exception DataFormatException if the compressed data format is invalid + * @see Inflater#needsInput + * @see Inflater#needsDictionary + */ + public int inflate(byte[] b, int off, int len) + throws DataFormatException + { + return impl.inflate(b, off, len); + } + + /** + * Uncompresses bytes into specified buffer. Returns actual number + * of bytes uncompressed. A return value of 0 indicates that + * needsInput() or needsDictionary() should be called in order to + * determine if more input data or a preset dictionary is required. + * In the latter case, getAdler() can be used to get the Adler-32 + * value of the dictionary required. + * @param b the buffer for the uncompressed data + * @return the actual number of uncompressed bytes + * @exception DataFormatException if the compressed data format is invalid + * @see Inflater#needsInput + * @see Inflater#needsDictionary + */ + public int inflate(byte[] b) throws DataFormatException { + return impl.inflate(b); + } + + /** + * Returns the ADLER-32 value of the uncompressed data. + * @return the ADLER-32 value of the uncompressed data + */ + public int getAdler() { + return impl.getAdler(); + } + + /** + * Returns the total number of compressed bytes input so far. + * + *
Since the number of bytes may be greater than + * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now + * the preferred means of obtaining this information.
+ * + * @return the total number of compressed bytes input so far + */ + public int getTotalIn() { + return impl.getTotalIn(); + } + + /** + * Returns the total number of compressed bytes input so far. + * + * @return the total (non-negative) number of compressed bytes input so far + * @since 1.5 + */ + public long getBytesRead() { + return impl.getBytesRead(); + } + + /** + * Returns the total number of uncompressed bytes output so far. + * + *Since the number of bytes may be greater than + * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now + * the preferred means of obtaining this information.
+ * + * @return the total number of uncompressed bytes output so far + */ + public int getTotalOut() { + return impl.getTotalOut(); + } + + /** + * Returns the total number of uncompressed bytes output so far. + * + * @return the total (non-negative) number of uncompressed bytes output so far + * @since 1.5 + */ + public long getBytesWritten() { + return impl.getBytesWritten(); + } + + /** + * Resets inflater so that a new set of input data can be processed. + */ + public void reset() { + impl.reset(); + } + + /** + * Closes the decompressor and discards any unprocessed input. + * This method should be called when the decompressor is no longer + * being used, but will also be called automatically by the finalize() + * method. Once this method is called, the behavior of the Inflater + * object is undefined. + */ + public void end() { + impl.end(); + } + + /** + * Closes the decompressor when garbage is collected. + */ + protected void finalize() { + end(); + } +} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/InflaterInputStream.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/emul/zip/src/main/java/java/util/zip/InflaterInputStream.java Sun May 11 14:01:18 2014 +0200 @@ -0,0 +1,288 @@ +/* + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.util.zip; + +import java.io.FilterInputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.EOFException; + +/** + * This class implements a stream filter for uncompressing data in the + * "deflate" compression format. It is also used as the basis for other + * decompression filters, such as GZIPInputStream. + * + * @see Inflater + * @author David Connelly + */ +public +class InflaterInputStream extends FilterInputStream { + /** + * Decompressor for this stream. + */ + protected Inflater inf; + + /** + * Input buffer for decompression. + */ + protected byte[] buf; + + /** + * Length of input buffer. + */ + protected int len; + + private boolean closed = false; + // this flag is set to true after EOF has reached + private boolean reachEOF = false; + + /** + * Check to make sure that this stream has not been closed + */ + private void ensureOpen() throws IOException { + if (closed) { + throw new IOException("Stream closed"); + } + } + + + /** + * Creates a new input stream with the specified decompressor and + * buffer size. + * @param in the input stream + * @param inf the decompressor ("inflater") + * @param size the input buffer size + * @exception IllegalArgumentException if size is <= 0 + */ + public InflaterInputStream(InputStream in, Inflater inf, int size) { + super(in); + if (in == null || inf == null) { + throw new NullPointerException(); + } else if (size <= 0) { + throw new IllegalArgumentException("buffer size <= 0"); + } + this.inf = inf; + buf = new byte[size]; + } + + /** + * Creates a new input stream with the specified decompressor and a + * default buffer size. + * @param in the input stream + * @param inf the decompressor ("inflater") + */ + public InflaterInputStream(InputStream in, Inflater inf) { + this(in, inf, 512); + } + + boolean usesDefaultInflater = false; + + /** + * Creates a new input stream with a default decompressor and buffer size. + * @param in the input stream + */ + public InflaterInputStream(InputStream in) { + this(in, new Inflater()); + usesDefaultInflater = true; + } + + private byte[] singleByteBuf = new byte[1]; + + /** + * Reads a byte of uncompressed data. This method will block until + * enough input is available for decompression. + * @return the byte read, or -1 if end of compressed input is reached + * @exception IOException if an I/O error has occurred + */ + public int read() throws IOException { + ensureOpen(); + return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff; + } + + /** + * Reads uncompressed data into an array of bytes. Iflen
is not
+ * zero, the method will block until some input can be decompressed; otherwise,
+ * no bytes are read and 0
is returned.
+ * @param b the buffer into which the data is read
+ * @param off the start offset in the destination array b
+ * @param len the maximum number of bytes read
+ * @return the actual number of bytes read, or -1 if the end of the
+ * compressed input is reached or a preset dictionary is needed
+ * @exception NullPointerException If b
is null
.
+ * @exception IndexOutOfBoundsException If off
is negative,
+ * len
is negative, or len
is greater than
+ * b.length - off
+ * @exception ZipException if a ZIP format error has occurred
+ * @exception IOException if an I/O error has occurred
+ */
+ public int read(byte[] b, int off, int len) throws IOException {
+ ensureOpen();
+ if (b == null) {
+ throw new NullPointerException();
+ } else if (off < 0 || len < 0 || len > b.length - off) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+ try {
+ int n;
+ while ((n = inf.inflate(b, off, len)) == 0) {
+ if (inf.finished() || inf.needsDictionary()) {
+ reachEOF = true;
+ return -1;
+ }
+ if (inf.needsInput()) {
+ fill();
+ }
+ }
+ return n;
+ } catch (DataFormatException e) {
+ String s = e.getMessage();
+ throw new ZipException(s != null ? s : "Invalid ZLIB data format");
+ }
+ }
+
+ /**
+ * Returns 0 after EOF has been reached, otherwise always return 1.
+ *
+ * Programs should not count on this method to return the actual number
+ * of bytes that could be read without blocking.
+ *
+ * @return 1 before EOF and 0 after EOF.
+ * @exception IOException if an I/O error occurs.
+ *
+ */
+ public int available() throws IOException {
+ ensureOpen();
+ if (reachEOF) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+
+ private byte[] b = new byte[512];
+
+ /**
+ * Skips specified number of bytes of uncompressed data.
+ * @param n the number of bytes to skip
+ * @return the actual number of bytes skipped.
+ * @exception IOException if an I/O error has occurred
+ * @exception IllegalArgumentException if n < 0
+ */
+ public long skip(long n) throws IOException {
+ if (n < 0) {
+ throw new IllegalArgumentException("negative skip length");
+ }
+ ensureOpen();
+ int max = (int)Math.min(n, Integer.MAX_VALUE);
+ int total = 0;
+ while (total < max) {
+ int len = max - total;
+ if (len > b.length) {
+ len = b.length;
+ }
+ len = read(b, 0, len);
+ if (len == -1) {
+ reachEOF = true;
+ break;
+ }
+ total += len;
+ }
+ return total;
+ }
+
+ /**
+ * Closes this input stream and releases any system resources associated
+ * with the stream.
+ * @exception IOException if an I/O error has occurred
+ */
+ public void close() throws IOException {
+ if (!closed) {
+ if (usesDefaultInflater)
+ inf.end();
+ in.close();
+ closed = true;
+ }
+ }
+
+ /**
+ * Fills input buffer with more data to decompress.
+ * @exception IOException if an I/O error has occurred
+ */
+ protected void fill() throws IOException {
+ ensureOpen();
+ len = in.read(buf, 0, buf.length);
+ if (len == -1) {
+ throw new EOFException("Unexpected end of ZLIB input stream");
+ }
+ inf.setInput(buf, 0, len);
+ }
+
+ /**
+ * Tests if this input stream supports the mark
and
+ * reset
methods. The markSupported
+ * method of InflaterInputStream
returns
+ * false
.
+ *
+ * @return a boolean
indicating if this stream type supports
+ * the mark
and reset
methods.
+ * @see java.io.InputStream#mark(int)
+ * @see java.io.InputStream#reset()
+ */
+ public boolean markSupported() {
+ return false;
+ }
+
+ /**
+ * Marks the current position in this input stream.
+ *
+ *
The mark
method of InflaterInputStream
+ * does nothing.
+ *
+ * @param readlimit the maximum limit of bytes that can be read before
+ * the mark position becomes invalid.
+ * @see java.io.InputStream#reset()
+ */
+ public synchronized void mark(int readlimit) {
+ }
+
+ /**
+ * Repositions this stream to the position at the time the
+ * mark
method was last called on this input stream.
+ *
+ *
The method reset
for class
+ * InflaterInputStream
does nothing except throw an
+ * IOException
.
+ *
+ * @exception IOException if this method is invoked.
+ * @see java.io.InputStream#mark(int)
+ * @see java.io.IOException
+ */
+ public synchronized void reset() throws IOException {
+ throw new IOException("mark/reset not supported");
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/ZStreamRef.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/ZStreamRef.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.zip;
+
+/**
+ * A reference to the native zlib's z_stream structure.
+ */
+
+class ZStreamRef {
+
+ private long address;
+ ZStreamRef (long address) {
+ this.address = address;
+ }
+
+ long address() {
+ return address;
+ }
+
+ void clear() {
+ address = 0;
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/ZipConstants.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/ZipConstants.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.zip;
+
+/*
+ * This interface defines the constants that are used by the classes
+ * which manipulate ZIP files.
+ *
+ * @author David Connelly
+ */
+interface ZipConstants {
+ /*
+ * Header signatures
+ */
+ static long LOCSIG = 0x04034b50L; // "PK\003\004"
+ static long EXTSIG = 0x08074b50L; // "PK\007\008"
+ static long CENSIG = 0x02014b50L; // "PK\001\002"
+ static long ENDSIG = 0x06054b50L; // "PK\005\006"
+
+ /*
+ * Header sizes in bytes (including signatures)
+ */
+ static final int LOCHDR = 30; // LOC header size
+ static final int EXTHDR = 16; // EXT header size
+ static final int CENHDR = 46; // CEN header size
+ static final int ENDHDR = 22; // END header size
+
+ /*
+ * Local file (LOC) header field offsets
+ */
+ static final int LOCVER = 4; // version needed to extract
+ static final int LOCFLG = 6; // general purpose bit flag
+ static final int LOCHOW = 8; // compression method
+ static final int LOCTIM = 10; // modification time
+ static final int LOCCRC = 14; // uncompressed file crc-32 value
+ static final int LOCSIZ = 18; // compressed size
+ static final int LOCLEN = 22; // uncompressed size
+ static final int LOCNAM = 26; // filename length
+ static final int LOCEXT = 28; // extra field length
+
+ /*
+ * Extra local (EXT) header field offsets
+ */
+ static final int EXTCRC = 4; // uncompressed file crc-32 value
+ static final int EXTSIZ = 8; // compressed size
+ static final int EXTLEN = 12; // uncompressed size
+
+ /*
+ * Central directory (CEN) header field offsets
+ */
+ static final int CENVEM = 4; // version made by
+ static final int CENVER = 6; // version needed to extract
+ static final int CENFLG = 8; // encrypt, decrypt flags
+ static final int CENHOW = 10; // compression method
+ static final int CENTIM = 12; // modification time
+ static final int CENCRC = 16; // uncompressed file crc-32 value
+ static final int CENSIZ = 20; // compressed size
+ static final int CENLEN = 24; // uncompressed size
+ static final int CENNAM = 28; // filename length
+ static final int CENEXT = 30; // extra field length
+ static final int CENCOM = 32; // comment length
+ static final int CENDSK = 34; // disk number start
+ static final int CENATT = 36; // internal file attributes
+ static final int CENATX = 38; // external file attributes
+ static final int CENOFF = 42; // LOC header offset
+
+ /*
+ * End of central directory (END) header field offsets
+ */
+ static final int ENDSUB = 8; // number of entries on this disk
+ static final int ENDTOT = 10; // total number of entries
+ static final int ENDSIZ = 12; // central directory size in bytes
+ static final int ENDOFF = 16; // offset of first CEN header
+ static final int ENDCOM = 20; // zip file comment length
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/ZipEntry.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/ZipEntry.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,331 @@
+/*
+ * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.zip;
+
+/**
+ * This class is used to represent a ZIP file entry.
+ *
+ * @author David Connelly
+ */
+public
+class ZipEntry implements ZipConstants, Cloneable {
+ String name; // entry name
+ long time = -1; // modification time (in DOS time)
+ long crc = -1; // crc-32 of entry data
+ long size = -1; // uncompressed size of entry data
+ long csize = -1; // compressed size of entry data
+ int method = -1; // compression method
+ int flag = 0; // general purpose flag
+ byte[] extra; // optional extra field data for entry
+ String comment; // optional comment string for entry
+
+ /**
+ * Compression method for uncompressed entries.
+ */
+ public static final int STORED = 0;
+
+ /**
+ * Compression method for compressed (deflated) entries.
+ */
+ public static final int DEFLATED = 8;
+
+ /**
+ * Creates a new zip entry with the specified name.
+ *
+ * @param name the entry name
+ * @exception NullPointerException if the entry name is null
+ * @exception IllegalArgumentException if the entry name is longer than
+ * 0xFFFF bytes
+ */
+ public ZipEntry(String name) {
+ if (name == null) {
+ throw new NullPointerException();
+ }
+ if (name.length() > 0xFFFF) {
+ throw new IllegalArgumentException("entry name too long");
+ }
+ this.name = name;
+ }
+
+ /**
+ * Creates a new zip entry with fields taken from the specified
+ * zip entry.
+ * @param e a zip Entry object
+ */
+ public ZipEntry(ZipEntry e) {
+ name = e.name;
+ time = e.time;
+ crc = e.crc;
+ size = e.size;
+ csize = e.csize;
+ method = e.method;
+ flag = e.flag;
+ extra = e.extra;
+ comment = e.comment;
+ }
+
+ /*
+ * Creates a new un-initialized zip entry
+ */
+ ZipEntry() {}
+
+ /**
+ * Returns the name of the entry.
+ * @return the name of the entry
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the modification time of the entry.
+ * @param time the entry modification time in number of milliseconds
+ * since the epoch
+ * @see #getTime()
+ */
+ public void setTime(long time) {
+ this.time = javaToDosTime(time);
+ }
+
+ /**
+ * Returns the modification time of the entry, or -1 if not specified.
+ * @return the modification time of the entry, or -1 if not specified
+ * @see #setTime(long)
+ */
+ public long getTime() {
+ return time != -1 ? dosToJavaTime(time) : -1;
+ }
+
+ /**
+ * Sets the uncompressed size of the entry data.
+ * @param size the uncompressed size in bytes
+ * @exception IllegalArgumentException if the specified size is less
+ * than 0, is greater than 0xFFFFFFFF when
+ * ZIP64 format is not supported,
+ * or is less than 0 when ZIP64 is supported
+ * @see #getSize()
+ */
+ public void setSize(long size) {
+ if (size < 0) {
+ throw new IllegalArgumentException("invalid entry size");
+ }
+ this.size = size;
+ }
+
+ /**
+ * Returns the uncompressed size of the entry data, or -1 if not known.
+ * @return the uncompressed size of the entry data, or -1 if not known
+ * @see #setSize(long)
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
+ * Returns the size of the compressed entry data, or -1 if not known.
+ * In the case of a stored entry, the compressed size will be the same
+ * as the uncompressed size of the entry.
+ * @return the size of the compressed entry data, or -1 if not known
+ * @see #setCompressedSize(long)
+ */
+ public long getCompressedSize() {
+ return csize;
+ }
+
+ /**
+ * Sets the size of the compressed entry data.
+ * @param csize the compressed size to set to
+ * @see #getCompressedSize()
+ */
+ public void setCompressedSize(long csize) {
+ this.csize = csize;
+ }
+
+ /**
+ * Sets the CRC-32 checksum of the uncompressed entry data.
+ * @param crc the CRC-32 value
+ * @exception IllegalArgumentException if the specified CRC-32 value is
+ * less than 0 or greater than 0xFFFFFFFF
+ * @see #getCrc()
+ */
+ public void setCrc(long crc) {
+ if (crc < 0 || crc > 0xFFFFFFFFL) {
+ throw new IllegalArgumentException("invalid entry crc-32");
+ }
+ this.crc = crc;
+ }
+
+ /**
+ * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
+ * not known.
+ * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
+ * not known
+ * @see #setCrc(long)
+ */
+ public long getCrc() {
+ return crc;
+ }
+
+ /**
+ * Sets the compression method for the entry.
+ * @param method the compression method, either STORED or DEFLATED
+ * @exception IllegalArgumentException if the specified compression
+ * method is invalid
+ * @see #getMethod()
+ */
+ public void setMethod(int method) {
+ if (method != STORED && method != DEFLATED) {
+ throw new IllegalArgumentException("invalid compression method");
+ }
+ this.method = method;
+ }
+
+ /**
+ * Returns the compression method of the entry, or -1 if not specified.
+ * @return the compression method of the entry, or -1 if not specified
+ * @see #setMethod(int)
+ */
+ public int getMethod() {
+ return method;
+ }
+
+ /**
+ * Sets the optional extra field data for the entry.
+ * @param extra the extra field data bytes
+ * @exception IllegalArgumentException if the length of the specified
+ * extra field data is greater than 0xFFFF bytes
+ * @see #getExtra()
+ */
+ public void setExtra(byte[] extra) {
+ if (extra != null && extra.length > 0xFFFF) {
+ throw new IllegalArgumentException("invalid extra field length");
+ }
+ this.extra = extra;
+ }
+
+ /**
+ * Returns the extra field data for the entry, or null if none.
+ * @return the extra field data for the entry, or null if none
+ * @see #setExtra(byte[])
+ */
+ public byte[] getExtra() {
+ return extra;
+ }
+
+ /**
+ * Sets the optional comment string for the entry.
+ *
+ *
ZIP entry comments have maximum length of 0xffff. If the length of the
+ * specified comment string is greater than 0xFFFF bytes after encoding, only
+ * the first 0xFFFF bytes are output to the ZIP file entry.
+ *
+ * @param comment the comment string
+ *
+ * @see #getComment()
+ */
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ /**
+ * Returns the comment string for the entry, or null if none.
+ * @return the comment string for the entry, or null if none
+ * @see #setComment(String)
+ */
+ public String getComment() {
+ return comment;
+ }
+
+ /**
+ * Returns true if this is a directory entry. A directory entry is
+ * defined to be one whose name ends with a '/'.
+ * @return true if this is a directory entry
+ */
+ public boolean isDirectory() {
+ return name.endsWith("/");
+ }
+
+ /**
+ * Returns a string representation of the ZIP entry.
+ */
+ public String toString() {
+ return getName();
+ }
+
+ /*
+ * Converts DOS time to Java time (number of milliseconds since epoch).
+ */
+ private static long dosToJavaTime(long dtime) {
+ return dtime;
+ /* XXX:
+ Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
+ (int)(((dtime >> 21) & 0x0f) - 1),
+ (int)((dtime >> 16) & 0x1f),
+ (int)((dtime >> 11) & 0x1f),
+ (int)((dtime >> 5) & 0x3f),
+ (int)((dtime << 1) & 0x3e));
+ return d.getTime();
+ */
+ }
+
+ /*
+ * Converts Java time to DOS time.
+ */
+ private static long javaToDosTime(long time) {
+ return time;
+ /* XXX:
+ Date d = new Date(time);
+ int year = d.getYear() + 1900;
+ if (year < 1980) {
+ return (1 << 21) | (1 << 16);
+ }
+ return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
+ d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
+ d.getSeconds() >> 1;
+ */
+ }
+
+ /**
+ * Returns the hash code value for this entry.
+ */
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ /**
+ * Returns a copy of this entry.
+ */
+ public Object clone() {
+ try {
+ ZipEntry e = (ZipEntry)super.clone();
+ e.extra = (extra == null) ? null : extra.clone();
+ return e;
+ } catch (CloneNotSupportedException e) {
+ // This should never happen, since we are Cloneable
+ throw new IllegalStateException();
+ }
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/ZipException.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/ZipException.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.zip;
+
+import java.io.IOException;
+
+/**
+ * Signals that a Zip exception of some sort has occurred.
+ *
+ * @author unascribed
+ * @see java.io.IOException
+ * @since JDK1.0
+ */
+
+public
+class ZipException extends IOException {
+ private static final long serialVersionUID = 8000196834066748623L;
+
+ /**
+ * Constructs a ZipException
with null
+ * as its error detail message.
+ */
+ public ZipException() {
+ super();
+ }
+
+ /**
+ * Constructs a ZipException
with the specified detail
+ * message.
+ *
+ * @param s the detail message.
+ */
+
+ public ZipException(String s) {
+ super(s);
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/ZipInputStream.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/ZipInputStream.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util.zip;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * This class implements an input stream filter for reading files in the
+ * ZIP file format. Includes support for both compressed and uncompressed
+ * entries.
+ *
+ * @author David Connelly
+ */
+public
+class ZipInputStream extends InflaterInputStream implements ZipConstants {
+ private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
+
+ /**
+ * Creates a new ZIP input stream.
+ *
+ *
The UTF-8 {@link java.nio.charset.Charset charset} is used to + * decode the entry names. + * + * @param in the actual input stream + */ + public ZipInputStream(InputStream in) { + super(in); + impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in); + } + + /** + * Creates a new ZIP input stream. + * + * @param in the actual input stream + * + * @param charset + * The {@linkplain java.nio.charset.Charset charset} to be + * used to decode the ZIP entry name (ignored if the + * language + * encoding bit of the ZIP entry's general purpose bit + * flag is set). + * + * @since 1.7 + * + public ZipInputStream(InputStream in, Charset charset) { + super(new PushbackInputStream(in, 512), new Inflater(true), 512); + usesDefaultInflater = true; + if(in == null) { + throw new NullPointerException("in is null"); + } + if (charset == null) + throw new NullPointerException("charset is null"); + this.zc = ZipCoder.get(charset); + } + */ + + /** + * Reads the next ZIP file entry and positions the stream at the + * beginning of the entry data. + * @return the next ZIP file entry, or null if there are no more entries + * @exception ZipException if a ZIP file error has occurred + * @exception IOException if an I/O error has occurred + */ + public ZipEntry getNextEntry() throws IOException { + return impl.getNextEntry(); + } + + /** + * Closes the current ZIP entry and positions the stream for reading the + * next entry. + * @exception ZipException if a ZIP file error has occurred + * @exception IOException if an I/O error has occurred + */ + public void closeEntry() throws IOException { + impl.closeEntry(); + } + + /** + * Returns 0 after EOF has reached for the current entry data, + * otherwise always return 1. + *
+ * Programs should not count on this method to return the actual number
+ * of bytes that could be read without blocking.
+ *
+ * @return 1 before EOF and 0 after EOF has reached for current entry.
+ * @exception IOException if an I/O error occurs.
+ *
+ */
+ public int available() throws IOException {
+ return impl.available();
+ }
+
+ /**
+ * Reads from the current ZIP entry into an array of bytes.
+ * If
+
+
+
+
+
+
+
+
+ The following code fragment demonstrates a trivial compression
+ * and decompression of a string using Deflater and
+ * Inflater.
+ *
+ *
+ * Note: When using the 'nowrap' option it is also necessary to provide
+ * an extra "dummy" byte as input. This is required by the ZLIB native
+ * library in order to support certain optimizations.
+ *
+ * @param nowrap if true then support GZIP compatible compression
+ */
+ public Inflater(boolean nowrap) {
+ this.nowrap = nowrap;
+ reset();
+ }
+
+ /**
+ * Creates a new decompressor.
+ */
+ public Inflater() {
+ this(false);
+ }
+
+ /**
+ * Sets input data for decompression. Should be called whenever
+ * needsInput() returns true indicating that more input data is
+ * required.
+ * @param b the input data bytes
+ * @param off the start offset of the input data
+ * @param len the length of the input data
+ * @see Inflater#needsInput
+ */
+ public void setInput(byte[] b, int off, int len) {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+ if (off < 0 || len < 0 || off > b.length - len) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ impl.setInput(b, off, len, false);
+ }
+
+ /**
+ * Sets input data for decompression. Should be called whenever
+ * needsInput() returns true indicating that more input data is
+ * required.
+ * @param b the input data bytes
+ * @see Inflater#needsInput
+ */
+ public void setInput(byte[] b) {
+ setInput(b, 0, b.length);
+ }
+
+ /**
+ * Sets the preset dictionary to the given array of bytes. Should be
+ * called when inflate() returns 0 and needsDictionary() returns true
+ * indicating that a preset dictionary is required. The method getAdler()
+ * can be used to get the Adler-32 value of the dictionary needed.
+ * @param b the dictionary data bytes
+ * @param off the start offset of the data
+ * @param len the length of the data
+ * @see Inflater#needsDictionary
+ * @see Inflater#getAdler
+ */
+ public void setDictionary(byte[] b, int off, int len) {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+ if (off < 0 || len < 0 || off > b.length - len) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ byte[] arr;
+ if (off == 0) {
+ arr = b;
+ } else {
+ arr = new byte[len];
+ FastJar.arraycopy(b, off, arr, 0, len);
+ }
+ impl.setDictionary(arr, len);
+ }
+
+ /**
+ * Sets the preset dictionary to the given array of bytes. Should be
+ * called when inflate() returns 0 and needsDictionary() returns true
+ * indicating that a preset dictionary is required. The method getAdler()
+ * can be used to get the Adler-32 value of the dictionary needed.
+ * @param b the dictionary data bytes
+ * @see Inflater#needsDictionary
+ * @see Inflater#getAdler
+ */
+ public void setDictionary(byte[] b) {
+ impl.setDictionary(b, b.length);
+ }
+
+ /**
+ * Returns the total number of bytes remaining in the input buffer.
+ * This can be used to find out what bytes still remain in the input
+ * buffer after decompression has finished.
+ * @return the total number of bytes remaining in the input buffer
+ */
+ public int getRemaining() {
+ return impl.getAvailIn();
+ }
+
+ /**
+ * Returns true if no data remains in the input buffer. This can
+ * be used to determine if #setInput should be called in order
+ * to provide more input.
+ * @return true if no data remains in the input buffer
+ */
+ public boolean needsInput() {
+ return getRemaining() <= 0;
+ }
+
+ /**
+ * Returns true if a preset dictionary is needed for decompression.
+ * @return true if a preset dictionary is needed for decompression
+ * @see Inflater#setDictionary
+ */
+ public boolean needsDictionary() {
+ return impl.needDict();
+ }
+
+ /**
+ * Returns true if the end of the compressed data stream has been
+ * reached.
+ * @return true if the end of the compressed data stream has been
+ * reached
+ */
+ public boolean finished() {
+ return impl.finished();
+ }
+
+ /**
+ * Uncompresses bytes into specified buffer. Returns actual number
+ * of bytes uncompressed. A return value of 0 indicates that
+ * needsInput() or needsDictionary() should be called in order to
+ * determine if more input data or a preset dictionary is required.
+ * In the latter case, getAdler() can be used to get the Adler-32
+ * value of the dictionary required.
+ * @param b the buffer for the uncompressed data
+ * @param off the start offset of the data
+ * @param len the maximum number of uncompressed bytes
+ * @return the actual number of uncompressed bytes
+ * @exception DataFormatException if the compressed data format is invalid
+ * @see Inflater#needsInput
+ * @see Inflater#needsDictionary
+ */
+ public int inflate(byte[] b, int off, int len)
+ throws DataFormatException
+ {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+ if (off < 0 || len < 0 || off > b.length - len) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ impl.setOutput(b, off, len);
+ int err = impl.inflate(JzLibInflater.Z_NO_FLUSH);
+ return impl.next_out_index - off;
+ }
+
+ /**
+ * Uncompresses bytes into specified buffer. Returns actual number
+ * of bytes uncompressed. A return value of 0 indicates that
+ * needsInput() or needsDictionary() should be called in order to
+ * determine if more input data or a preset dictionary is required.
+ * In the latter case, getAdler() can be used to get the Adler-32
+ * value of the dictionary required.
+ * @param b the buffer for the uncompressed data
+ * @return the actual number of uncompressed bytes
+ * @exception DataFormatException if the compressed data format is invalid
+ * @see Inflater#needsInput
+ * @see Inflater#needsDictionary
+ */
+ public int inflate(byte[] b) throws DataFormatException {
+ return inflate(b, 0, b.length);
+ }
+
+ /**
+ * Returns the ADLER-32 value of the uncompressed data.
+ * @return the ADLER-32 value of the uncompressed data
+ */
+ public int getAdler() {
+ return (int) impl.getAdler();
+ }
+
+ /**
+ * Returns the total number of compressed bytes input so far.
+ *
+ * Since the number of bytes may be greater than
+ * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
+ * the preferred means of obtaining this information.len
is not zero, the method
+ * blocks until some input is available; otherwise, no
+ * bytes are read and 0
is returned.
+ * @param b the buffer into which the data is read
+ * @param off the start offset in the destination array b
+ * @param len the maximum number of bytes read
+ * @return the actual number of bytes read, or -1 if the end of the
+ * entry is reached
+ * @exception NullPointerException if b
is null
.
+ * @exception IndexOutOfBoundsException if off
is negative,
+ * len
is negative, or len
is greater than
+ * b.length - off
+ * @exception ZipException if a ZIP file error has occurred
+ * @exception IOException if an I/O error has occurred
+ */
+ public int read(byte[] b, int off, int len) throws IOException {
+ return impl.read(b, off, len);
+ }
+
+ /**
+ * Skips specified number of bytes in the current ZIP entry.
+ * @param n the number of bytes to skip
+ * @return the actual number of bytes skipped
+ * @exception ZipException if a ZIP file error has occurred
+ * @exception IOException if an I/O error has occurred
+ * @exception IllegalArgumentException if n < 0
+ */
+ public long skip(long n) throws IOException {
+ return impl.skip(n);
+ }
+
+ /**
+ * Closes this input stream and releases any system resources associated
+ * with the stream.
+ * @exception IOException if an I/O error has occurred
+ */
+ public void close() throws IOException {
+ impl.close();
+ }
+
+ /**
+ * Creates a new ZipEntry
object for the specified
+ * entry name.
+ *
+ * @param name the ZIP file entry name
+ * @return the ZipEntry just created
+ */
+ protected ZipEntry createZipEntry(String name) {
+ return new ZipEntry(name);
+ }
+
+ @Override
+ public int read() throws IOException {
+ return impl.read();
+ }
+
+ @Override
+ public boolean markSupported() {
+ return impl.markSupported();
+ }
+
+ @Override
+ public void mark(int readlimit) {
+ impl.mark(readlimit);
+ }
+
+ @Override
+ public void reset() throws IOException {
+ impl.reset();
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ return impl.read(b);
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/java/util/zip/package-info.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/java/util/zip/package-info.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,22 @@
+/**
+ * Back 2 Browser Bytecode Translator
+ * Copyright (C) 2012 Jaroslav Tulach Package Specification
+
+
+
+
+
+
+
+
+@since JDK1.1
+
+
+
+
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,139 @@
+/* -*-mode:java; c-basic-offset:2; -*- */
+/*
+Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution.
+
+ 3. The names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ * This program is based on zlib-1.1.3, so all credit should go authors
+ * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
+ * and contributors of zlib.
+ */
+
+package org.apidesign.bck2brwsr.emul.zip;
+
+final class Adler32 implements Checksum {
+
+ // largest prime smaller than 65536
+ static final private int BASE=65521;
+ // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
+ static final private int NMAX=5552;
+
+ private long s1=1L;
+ private long s2=0L;
+
+ public void reset(long init){
+ s1=init&0xffff;
+ s2=(init>>16)&0xffff;
+ }
+
+ public void reset(){
+ s1=1L;
+ s2=0L;
+ }
+
+ public long getValue(){
+ return ((s2<<16)|s1);
+ }
+
+ public void update(byte[] buf, int index, int len){
+
+ if(len==1){
+ s1+=buf[index++]&0xff; s2+=s1;
+ s1%=BASE;
+ s2%=BASE;
+ return;
+ }
+
+ int len1 = len/NMAX;
+ int len2 = len%NMAX;
+ while(len1-->0) {
+ int k=NMAX;
+ len-=k;
+ while(k-->0){
+ s1+=buf[index++]&0xff; s2+=s1;
+ }
+ s1%=BASE;
+ s2%=BASE;
+ }
+
+ int k=len2;
+ len-=k;
+ while(k-->0){
+ s1+=buf[index++]&0xff; s2+=s1;
+ }
+ s1%=BASE;
+ s2%=BASE;
+ }
+
+ public Adler32 copy(){
+ Adler32 foo = new Adler32();
+ foo.s1 = this.s1;
+ foo.s2 = this.s2;
+ return foo;
+ }
+
+ // The following logic has come from zlib.1.2.
+ static long combine(long adler1, long adler2, long len2){
+ long BASEL = (long)BASE;
+ long sum1;
+ long sum2;
+ long rem; // unsigned int
+
+ rem = len2 % BASEL;
+ sum1 = adler1 & 0xffffL;
+ sum2 = rem * sum1;
+ sum2 %= BASEL; // MOD(sum2);
+ sum1 += (adler2 & 0xffffL) + BASEL - 1;
+ sum2 += ((adler1 >> 16) & 0xffffL) + ((adler2 >> 16) & 0xffffL) + BASEL - rem;
+ if (sum1 >= BASEL) sum1 -= BASEL;
+ if (sum1 >= BASEL) sum1 -= BASEL;
+ if (sum2 >= (BASEL << 1)) sum2 -= (BASEL << 1);
+ if (sum2 >= BASEL) sum2 -= BASEL;
+ return sum1 | (sum2 << 16);
+ }
+
+/*
+ private java.util.zip.Adler32 adler=new java.util.zip.Adler32();
+ public void update(byte[] buf, int index, int len){
+ if(buf==null) {adler.reset();}
+ else{adler.update(buf, index, len);}
+ }
+ public void reset(){
+ adler.reset();
+ }
+ public void reset(long init){
+ if(init==1L){
+ adler.reset();
+ }
+ else{
+ System.err.println("unsupported operation");
+ }
+ }
+ public long getValue(){
+ return adler.getValue();
+ }
+*/
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,181 @@
+/* -*-mode:java; c-basic-offset:2; -*- */
+/*
+Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution.
+
+ 3. The names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ * This program is based on zlib-1.1.3, so all credit should go authors
+ * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
+ * and contributors of zlib.
+ */
+
+package org.apidesign.bck2brwsr.emul.zip;
+
+
+
+final class CRC32 implements Checksum {
+
+ /*
+ * The following logic has come from RFC1952.
+ */
+ private int v = 0;
+ private static int[] crc_table = null;
+ static {
+ crc_table = new int[256];
+ for (int n = 0; n < 256; n++) {
+ int c = n;
+ for (int k = 8; --k >= 0; ) {
+ if ((c & 1) != 0)
+ c = 0xedb88320 ^ (c >>> 1);
+ else
+ c = c >>> 1;
+ }
+ crc_table[n] = c;
+ }
+ }
+
+ public void update (byte[] buf, int index, int len) {
+ int c = ~v;
+ while (--len >= 0)
+ c = crc_table[(c^buf[index++])&0xff]^(c >>> 8);
+ v = ~c;
+ }
+
+ public void reset(){
+ v = 0;
+ }
+
+ public void reset(long vv){
+ v = (int)(vv&0xffffffffL);
+ }
+
+ public long getValue(){
+ return (long)(v&0xffffffffL);
+ }
+
+ // The following logic has come from zlib.1.2.
+ private static final int GF2_DIM = 32;
+ static long combine(long crc1, long crc2, long len2){
+ long row;
+ long[] even = new long[GF2_DIM];
+ long[] odd = new long[GF2_DIM];
+
+ // degenerate case (also disallow negative lengths)
+ if (len2 <= 0)
+ return crc1;
+
+ // put operator for one zero bit in odd
+ odd[0] = 0xedb88320L; // CRC-32 polynomial
+ row = 1;
+ for (int n = 1; n < GF2_DIM; n++) {
+ odd[n] = row;
+ row <<= 1;
+ }
+
+ // put operator for two zero bits in even
+ gf2_matrix_square(even, odd);
+
+ // put operator for four zero bits in odd
+ gf2_matrix_square(odd, even);
+
+ // apply len2 zeros to crc1 (first square will put the operator for one
+ // zero byte, eight zero bits, in even)
+ do {
+ // apply zeros operator for this bit of len2
+ gf2_matrix_square(even, odd);
+ if ((len2 & 1)!=0)
+ crc1 = gf2_matrix_times(even, crc1);
+ len2 >>= 1;
+
+ // if no more bits set, then done
+ if (len2 == 0)
+ break;
+
+ // another iteration of the loop with odd and even swapped
+ gf2_matrix_square(odd, even);
+ if ((len2 & 1)!=0)
+ crc1 = gf2_matrix_times(odd, crc1);
+ len2 >>= 1;
+
+ // if no more bits set, then done
+ } while (len2 != 0);
+
+ /* return combined crc */
+ crc1 ^= crc2;
+ return crc1;
+ }
+
+ private static long gf2_matrix_times(long[] mat, long vec){
+ long sum = 0;
+ int index = 0;
+ while (vec!=0) {
+ if ((vec & 1)!=0)
+ sum ^= mat[index];
+ vec >>= 1;
+ index++;
+ }
+ return sum;
+ }
+
+ static final void gf2_matrix_square(long[] square, long[] mat) {
+ for (int n = 0; n < GF2_DIM; n++)
+ square[n] = gf2_matrix_times(mat, mat[n]);
+ }
+
+ /*
+ private java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
+
+ public void update(byte[] buf, int index, int len){
+ if(buf==null) {crc32.reset();}
+ else{crc32.update(buf, index, len);}
+ }
+ public void reset(){
+ crc32.reset();
+ }
+ public void reset(long init){
+ if(init==0L){
+ crc32.reset();
+ }
+ else{
+ System.err.println("unsupported operation");
+ }
+ }
+ public long getValue(){
+ return crc32.getValue();
+ }
+*/
+ public CRC32 copy(){
+ CRC32 foo = new CRC32();
+ foo.v = this.v;
+ return foo;
+ }
+
+ public static int[] getCRC32Table(){
+ int[] tmp = new int[crc_table.length];
+ FastJar.arraycopy(crc_table, 0, tmp, 0, tmp.length);
+ return tmp;
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,43 @@
+/* -*-mode:java; c-basic-offset:2; -*- */
+/*
+Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution.
+
+ 3. The names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ * This program is based on zlib-1.1.3, so all credit should go authors
+ * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
+ * and contributors of zlib.
+ */
+
+package org.apidesign.bck2brwsr.emul.zip;
+
+interface Checksum {
+ void update(byte[] buf, int index, int len);
+ void reset();
+ void reset(long init);
+ long getValue();
+ Checksum copy();
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,198 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2007 Sun Microsystems, Inc.
+ */
+package org.apidesign.bck2brwsr.emul.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import org.apidesign.bck2brwsr.core.JavaScriptBody;
+
+/**
+ *
+ * @author Tomas Zezula
+ */
+public final class FastJar {
+ private final byte[] arr;
+
+ public FastJar(byte[] arr) {
+ this.arr = arr;
+ }
+
+
+ private static final int GIVE_UP = 1<<16;
+
+ public static final class Entry {
+
+ public final String name;
+ final long offset;
+ private final long dosTime;
+
+ Entry (String name, long offset, long time) {
+ assert name != null;
+ this.name = name;
+ this.offset = offset;
+ this.dosTime = time;
+ }
+/*
+ public long getTime () {
+ Date d = new Date((int)(((dosTime >> 25) & 0x7f) + 80),
+ (int)(((dosTime >> 21) & 0x0f) - 1),
+ (int)((dosTime >> 16) & 0x1f),
+ (int)((dosTime >> 11) & 0x1f),
+ (int)((dosTime >> 5) & 0x3f),
+ (int)((dosTime << 1) & 0x3e));
+ return d.getTime();
+ }
+ */
+ }
+
+ public InputStream getInputStream (final Entry e) throws IOException {
+ return getInputStream(arr, e.offset);
+ }
+
+ private static InputStream getInputStream (byte[] arr, final long offset) throws IOException {
+ ByteArrayInputStream is = new ByteArrayInputStream(arr);
+ is.skip(offset);
+ ZipInputStream in = new ZipInputStream (is);
+ ZipEntry e = in.getNextEntry();
+ if (e != null && e.getCrc() == 0L && e.getMethod() == ZipEntry.STORED) {
+ int cp = arr.length - is.available();
+ return new ByteArrayInputStream(arr, cp, (int)e.getSize());
+ }
+ return in;
+ }
+
+ public Entry[] list() throws IOException {
+ final int size = arr.length;
+
+ int at = size - ZipInputStream.ENDHDR;
+
+ byte[] data = new byte[ZipInputStream.ENDHDR];
+ int giveup = 0;
+
+ do {
+ FastJar.arraycopy(arr, at, data, 0, data.length);
+ at--;
+ giveup++;
+ if (giveup > GIVE_UP) {
+ throw new IOException ();
+ }
+ } while (getsig(data) != ZipInputStream.ENDSIG);
+
+
+ final long censize = endsiz(data);
+ final long cenoff = endoff(data);
+ at = (int) cenoff;
+
+ Entry[] result = new Entry[0];
+ int cenread = 0;
+ data = new byte[ZipInputStream.CENHDR];
+ while (cenread < censize) {
+ FastJar.arraycopy(arr, at, data, 0, data.length);
+ at += data.length;
+ if (getsig(data) != ZipInputStream.CENSIG) {
+ throw new IOException("No central table"); //NOI18N
+ }
+ int cennam = cennam(data);
+ int cenext = cenext(data);
+ int cencom = cencom(data);
+ long lhoff = cenoff(data);
+ long centim = centim(data);
+ String name = new String(arr, at, cennam, "UTF-8");
+ at += cennam;
+ int seekby = cenext+cencom;
+ int cendatalen = ZipInputStream.CENHDR + cennam + seekby;
+ cenread+=cendatalen;
+ result = addEntry(result, new Entry(name,lhoff, centim));
+ at += seekby;
+ }
+ return result;
+ }
+
+ private Entry[] addEntry(Entry[] result, Entry entry) {
+ Entry[] e = new Entry[result.length + 1];
+ e[result.length] = entry;
+ FastJar.arraycopy(result, 0, e, 0, result.length);
+ return e;
+ }
+
+ private static final long getsig(final byte[] b) throws IOException {return get32(b,0);}
+ private static final long endsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDSIZ);}
+ private static final long endoff(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDOFF);}
+ private static final long cenlen(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENLEN);}
+ private static final long censiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENSIZ);}
+ private static final long centim(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENTIM);}
+ private static final int cennam(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENNAM);}
+ private static final int cenext(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENEXT);}
+ private static final int cencom(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENCOM);}
+ private static final long cenoff (final byte[] b) throws IOException {return get32(b,ZipInputStream.CENOFF);}
+ private static final int lochow(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCHOW);}
+ private static final int locname(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCNAM);}
+ private static final int locext(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCEXT);}
+ private static final long locsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.LOCSIZ);}
+
+ private static final int get16(final byte[] b, int off) throws IOException {
+ final int b1 = b[off];
+ final int b2 = b[off+1];
+ return (b1 & 0xff) | ((b2 & 0xff) << 8);
+ }
+
+ private static final long get32(final byte[] b, int off) throws IOException {
+ final int s1 = get16(b, off);
+ final int s2 = get16(b, off+2);
+ return s1 | ((long)s2 << 16);
+ }
+
+ @JavaScriptBody(args = {"value", "srcBegin", "dst", "dstBegin", "count"}, body
+ = "if (srcBegin < dstBegin) {\n"
+ + " while (count-- > 0) {\n"
+ + " dst[dstBegin + count] = value[srcBegin + count];\n"
+ + " }\n"
+ + "} else {\n"
+ + " while (count-- > 0) {\n"
+ + " dst[dstBegin++] = value[srcBegin++];\n"
+ + " }\n"
+ + "}"
+ )
+ static void arraycopy(Object src, int srcBegin, Object dst, int dstBegin, int count) {
+ try {
+ Class> system = Class.forName("java.lang.System");
+ Method m = system.getMethod("arraycopy", Object.class, int.class, Object.class, int.class, int.class);
+ m.invoke(null, src, srcBegin, dst, dstBegin, count);
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
+ }
+ }
+
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,215 @@
+/* -*-mode:java; c-basic-offset:2; -*- */
+/*
+Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution.
+
+ 3. The names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ * This program is based on zlib-1.1.3, so all credit should go authors
+ * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
+ * and contributors of zlib.
+ */
+
+package org.apidesign.bck2brwsr.emul.zip;
+
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @see "http://www.ietf.org/rfc/rfc1952.txt"
+ */
+final class GZIPHeader implements Cloneable {
+
+ public static final byte OS_MSDOS = (byte) 0x00;
+ public static final byte OS_AMIGA = (byte) 0x01;
+ public static final byte OS_VMS = (byte) 0x02;
+ public static final byte OS_UNIX = (byte) 0x03;
+ public static final byte OS_ATARI = (byte) 0x05;
+ public static final byte OS_OS2 = (byte) 0x06;
+ public static final byte OS_MACOS = (byte) 0x07;
+ public static final byte OS_TOPS20 = (byte) 0x0a;
+ public static final byte OS_WIN32 = (byte) 0x0b;
+ public static final byte OS_VMCMS = (byte) 0x04;
+ public static final byte OS_ZSYSTEM = (byte) 0x08;
+ public static final byte OS_CPM = (byte) 0x09;
+ public static final byte OS_QDOS = (byte) 0x0c;
+ public static final byte OS_RISCOS = (byte) 0x0d;
+ public static final byte OS_UNKNOWN = (byte) 0xff;
+
+ boolean text = false;
+ private boolean fhcrc = false;
+ long time;
+ int xflags;
+ int os = 255;
+ byte[] extra;
+ byte[] name;
+ byte[] comment;
+ int hcrc;
+ long crc;
+ boolean done = false;
+ long mtime = 0;
+
+ public void setModifiedTime(long mtime) {
+ this.mtime = mtime;
+ }
+
+ public long getModifiedTime() {
+ return mtime;
+ }
+
+ public void setOS(int os) {
+ if((0<=os && os <=13) || os==255)
+ this.os=os;
+ else
+ throw new IllegalArgumentException("os: "+os);
+ }
+
+ public int getOS(){
+ return os;
+ }
+
+ public void setName(String name) {
+ try{
+ this.name=name.getBytes("ISO-8859-1");
+ }
+ catch(UnsupportedEncodingException e){
+ throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
+ }
+ }
+
+ public String getName(){
+ if(name==null) return "";
+ try {
+ return new String(name, "ISO-8859-1");
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException(e.toString());
+ }
+ }
+
+ public void setComment(String comment) {
+ try{
+ this.comment=comment.getBytes("ISO-8859-1");
+ }
+ catch(UnsupportedEncodingException e){
+ throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
+ }
+ }
+
+ public String getComment(){
+ if(comment==null) return "";
+ try {
+ return new String(comment, "ISO-8859-1");
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException(e.toString());
+ }
+ }
+
+ public void setCRC(long crc){
+ this.crc = crc;
+ }
+
+ public long getCRC(){
+ return crc;
+ }
+/*
+ void put(Deflate d){
+ int flag = 0;
+ if(text){
+ flag |= 1; // FTEXT
+ }
+ if(fhcrc){
+ flag |= 2; // FHCRC
+ }
+ if(extra!=null){
+ flag |= 4; // FEXTRA
+ }
+ if(name!=null){
+ flag |= 8; // FNAME
+ }
+ if(comment!=null){
+ flag |= 16; // FCOMMENT
+ }
+ int xfl = 0;
+ if(d.level == JZlib.Z_BEST_SPEED){
+ xfl |= 4;
+ }
+ else if (d.level == JZlib.Z_BEST_COMPRESSION){
+ xfl |= 2;
+ }
+
+ d.put_short((short)0x8b1f); // ID1 ID2
+ d.put_byte((byte)8); // CM(Compression Method)
+ d.put_byte((byte)flag);
+ d.put_byte((byte)mtime);
+ d.put_byte((byte)(mtime>>8));
+ d.put_byte((byte)(mtime>>16));
+ d.put_byte((byte)(mtime>>24));
+ d.put_byte((byte)xfl);
+ d.put_byte((byte)os);
+
+ if(extra!=null){
+ d.put_byte((byte)extra.length);
+ d.put_byte((byte)(extra.length>>8));
+ d.put_byte(extra, 0, extra.length);
+ }
+
+ if(name!=null){
+ d.put_byte(name, 0, name.length);
+ d.put_byte((byte)0);
+ }
+
+ if(comment!=null){
+ d.put_byte(comment, 0, comment.length);
+ d.put_byte((byte)0);
+ }
+ }
+*/
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ GZIPHeader gheader = (GZIPHeader)super.clone();
+ byte[] tmp;
+ if(gheader.extra!=null){
+ tmp=new byte[gheader.extra.length];
+ FastJar.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
+ gheader.extra = tmp;
+ }
+
+ if(gheader.name!=null){
+ tmp=new byte[gheader.name.length];
+ FastJar.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
+ gheader.name = tmp;
+ }
+
+ if(gheader.comment!=null){
+ tmp=new byte[gheader.comment.length];
+ FastJar.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
+ gheader.comment = tmp;
+ }
+
+ return gheader;
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,616 @@
+/* -*-mode:java; c-basic-offset:2; -*- */
+/*
+Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution.
+
+ 3. The names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ * This program is based on zlib-1.1.3, so all credit should go authors
+ * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
+ * and contributors of zlib.
+ */
+
+package org.apidesign.bck2brwsr.emul.zip;
+
+
+
+final class InfBlocks{
+ static final private int MANY=1440;
+
+ // And'ing with mask[n] masks the lower n bits
+ static final private int[] inflate_mask = {
+ 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
+ 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
+ 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
+ 0x00007fff, 0x0000ffff
+ };
+
+ // Table for deflate from PKZIP's appnote.txt.
+ static final int[] border = { // Order of the bit length code lengths
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+ };
+
+ static final private int Z_OK=0;
+ static final private int Z_STREAM_END=1;
+ static final private int Z_NEED_DICT=2;
+ static final private int Z_ERRNO=-1;
+ static final private int Z_STREAM_ERROR=-2;
+ static final private int Z_DATA_ERROR=-3;
+ static final private int Z_MEM_ERROR=-4;
+ static final private int Z_BUF_ERROR=-5;
+ static final private int Z_VERSION_ERROR=-6;
+
+ static final private int TYPE=0; // get type bits (3, including end bit)
+ static final private int LENS=1; // get lengths for stored
+ static final private int STORED=2;// processing stored block
+ static final private int TABLE=3; // get table lengths
+ static final private int BTREE=4; // get bit lengths tree for a dynamic block
+ static final private int DTREE=5; // get length, distance trees for a dynamic block
+ static final private int CODES=6; // processing fixed or dynamic block
+ static final private int DRY=7; // output remaining window bytes
+ static final private int DONE=8; // finished last block, done
+ static final private int BAD=9; // ot a data error--stuck here
+
+ int mode; // current inflate_block mode
+
+ int left; // if STORED, bytes left to copy
+
+ int table; // table lengths (14 bits)
+ int index; // index into blens (or border)
+ int[] blens; // bit lengths of codes
+ int[] bb=new int[1]; // bit length tree depth
+ int[] tb=new int[1]; // bit length decoding tree
+
+ int[] bl=new int[1];
+ int[] bd=new int[1];
+
+ int[][] tl=new int[1][];
+ int[][] td=new int[1][];
+ int[] tli=new int[1]; // tl_index
+ int[] tdi=new int[1]; // td_index
+
+ private final InfCodes codes; // if CODES, current state
+
+ int last; // true if this block is the last block
+
+ // mode independent information
+ int bitk; // bits in bit buffer
+ int bitb; // bit buffer
+ int[] hufts; // single malloc for tree space
+ byte[] window; // sliding window
+ int end; // one byte after sliding window
+ int read; // window read pointer
+ int write; // window write pointer
+ private boolean check;
+
+ private final InfTree inftree=new InfTree();
+
+ private final ZStream z;
+
+ InfBlocks(ZStream z, int w){
+ this.z=z;
+ this.codes=new InfCodes(this.z, this);
+ hufts=new int[MANY*3];
+ window=new byte[w];
+ end=w;
+ this.check = (z.istate.wrap==0) ? false : true;
+ mode = TYPE;
+ reset();
+ }
+
+ void reset(){
+ if(mode==BTREE || mode==DTREE){
+ }
+ if(mode==CODES){
+ codes.free(z);
+ }
+ mode=TYPE;
+ bitk=0;
+ bitb=0;
+ read=write=0;
+ if(check){
+ z.adler.reset();
+ }
+ }
+
+ int proc(int r){
+ int t; // temporary storage
+ int b; // bit buffer
+ int k; // bits in bit buffer
+ int p; // input data pointer
+ int n; // bytes available there
+ int q; // output window write pointer
+ int m; // bytes to end of window or read pointer
+
+ // copy input/output information to locals (UPDATE macro restores)
+ {p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;}
+ {q=write;m=(int)(qjava.util.zip
classes are based.
+
+ *
+ * @see Deflater
+ * @author David Connelly
+ *
+ */
+public
+class Inflater extends java.util.zip.Inflater {
+ private final boolean nowrap;
+ private JzLibInflater impl;
+
+ /**
+ * Creates a new decompressor. If the parameter 'nowrap' is true then
+ * the ZLIB header and checksum fields will not be used. This provides
+ * compatibility with the compression format used by both GZIP and PKZIP.
+ *
+ * try {
+ * // Encode a String into bytes
+ * String inputString = "blahblahblah\u20AC\u20AC";
+ * byte[] input = inputString.getBytes("UTF-8");
+ *
+ * // Compress the bytes
+ * byte[] output = new byte[100];
+ * Deflater compresser = new Deflater();
+ * compresser.setInput(input);
+ * compresser.finish();
+ * int compressedDataLength = compresser.deflate(output);
+ *
+ * // Decompress the bytes
+ * Inflater decompresser = new Inflater();
+ * decompresser.setInput(output, 0, compressedDataLength);
+ * byte[] result = new byte[100];
+ * int resultLength = decompresser.inflate(result);
+ * decompresser.end();
+ *
+ * // Decode the bytes into a String
+ * String outputString = new String(result, 0, resultLength, "UTF-8");
+ * } catch(java.io.UnsupportedEncodingException ex) {
+ * // handle
+ * } catch (java.util.zip.DataFormatException ex) {
+ * // handle
+ * }
+ *
Since the number of bytes may be greater than + * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now + * the preferred means of obtaining this information.
+ * + * @return the total number of uncompressed bytes output so far + */ + public int getTotalOut() { + return (int) getBytesWritten(); + } + + /** + * Returns the total number of uncompressed bytes output so far. + * + * @return the total (non-negative) number of uncompressed bytes output so far + * @since 1.5 + */ + public long getBytesWritten() { + return impl.total_out; + } + + /** + * Resets inflater so that a new set of input data can be processed. + */ + public void reset() { + impl = new JzLibInflater(15, nowrap); + } + + /** + * Closes the decompressor and discards any unprocessed input. + * This method should be called when the decompressor is no longer + * being used, but will also be called automatically by the finalize() + * method. Once this method is called, the behavior of the Inflater + * object is undefined. + */ + public void end() { + impl.end(); + } + + /** + * Closes the decompressor when garbage is collected. + */ + protected void finalize() { + end(); + } +} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java Sun May 11 14:01:18 2014 +0200 @@ -0,0 +1,137 @@ +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ +/* +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + + 3. The names of the authors may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * This program is based on zlib-1.1.3, so all credit should go authors + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) + * and contributors of zlib. + */ + +package org.apidesign.bck2brwsr.emul.zip; + +final class JzLibInflater extends ZStream{ + + static final private int MAX_WBITS=15; // 32K LZ77 window + static final private int DEF_WBITS=MAX_WBITS; + + public static final int Z_NO_FLUSH=0; + static final private int Z_PARTIAL_FLUSH=1; + static final private int Z_SYNC_FLUSH=2; + static final private int Z_FULL_FLUSH=3; + static final private int Z_FINISH=4; + + static final private int MAX_MEM_LEVEL=9; + + static final private int Z_OK=0; + static final private int Z_STREAM_END=1; + static final private int Z_NEED_DICT=2; + static final private int Z_ERRNO=-1; + static final private int Z_STREAM_ERROR=-2; + static final private int Z_DATA_ERROR=-3; + static final private int Z_MEM_ERROR=-4; + static final private int Z_BUF_ERROR=-5; + static final private int Z_VERSION_ERROR=-6; + + public JzLibInflater() { + super(); + init(); + } + + public JzLibInflater(int w) { + this(w, false); + } + + public JzLibInflater(int w, boolean nowrap) { + super(); + int ret = init(w, nowrap); + if(ret!=Z_OK) + throw new IllegalStateException(ret+": "+msg); + } + + private boolean finished = false; + + public int init(){ + return init(DEF_WBITS); + } + + public int init(boolean nowrap){ + return init(DEF_WBITS, nowrap); + } + + public int init(int w){ + return init(w, false); + } + + public int init(int w, boolean nowrap){ + finished = false; + istate=new Inflate(this); + return istate.inflateInit(nowrap?-w:w); + } + + public int inflate(int f){ + if(istate==null) return Z_STREAM_ERROR; + int ret = istate.inflate(f); + if(ret == Z_STREAM_END) + finished = true; + return ret; + } + + public int end(){ + finished = true; + if(istate==null) return Z_STREAM_ERROR; + int ret=istate.inflateEnd(); +// istate = null; + return ret; + } + + public int sync(){ + if(istate == null) + return Z_STREAM_ERROR; + return istate.inflateSync(); + } + + public int syncPoint(){ + if(istate == null) + return Z_STREAM_ERROR; + return istate.inflateSyncPoint(); + } + + public int setDictionary(byte[] dictionary, int dictLength){ + if(istate == null) + return Z_STREAM_ERROR; + return istate.inflateSetDictionary(dictionary, dictLength); + } + + public boolean finished(){ + return istate.mode==12 /*DONE*/; + } + + public boolean needDict() { + return istate == null ? false : istate.mode == Inflate.DICT0; + } +} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java Sun May 11 14:01:18 2014 +0200 @@ -0,0 +1,253 @@ +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ +/* +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + + 3. The names of the authors may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * This program is based on zlib-1.1.3, so all credit should go authors + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) + * and contributors of zlib. + */ + +package org.apidesign.bck2brwsr.emul.zip; + + + +/** + * ZStream + * + * @deprecated Not for public use in the future. + */ +@Deprecated +class ZStream{ + + static final private int MAX_WBITS=15; // 32K LZ77 window + static final private int DEF_WBITS=MAX_WBITS; + + static final private int Z_NO_FLUSH=0; + static final private int Z_PARTIAL_FLUSH=1; + static final private int Z_SYNC_FLUSH=2; + static final private int Z_FULL_FLUSH=3; + static final private int Z_FINISH=4; + + static final private int MAX_MEM_LEVEL=9; + + static final private int Z_OK=0; + static final private int Z_STREAM_END=1; + static final private int Z_NEED_DICT=2; + static final private int Z_ERRNO=-1; + static final private int Z_STREAM_ERROR=-2; + static final private int Z_DATA_ERROR=-3; + static final private int Z_MEM_ERROR=-4; + static final private int Z_BUF_ERROR=-5; + static final private int Z_VERSION_ERROR=-6; + + public byte[] next_in; // next input byte + public int next_in_index; + public int avail_in; // number of bytes available at next_in + public long total_in; // total nb of input bytes read so far + + public byte[] next_out; // next output byte should be put there + public int next_out_index; + public int avail_out; // remaining free space at next_out + public long total_out; // total nb of bytes output so far + + public String msg; + + Inflate istate; + + int data_type; // best guess about the data type: ascii or binary + + Checksum adler; + + public ZStream(){ + this(new Adler32()); + } + + public ZStream(Checksum adler){ + this.adler=adler; + } + + public int inflateInit(){ + return inflateInit(DEF_WBITS); + } + public int inflateInit(boolean nowrap){ + return inflateInit(DEF_WBITS, nowrap); + } + public int inflateInit(int w){ + return inflateInit(w, false); + } + + public int inflateInit(int w, boolean nowrap){ + istate=new Inflate(this); + return istate.inflateInit(nowrap?-w:w); + } + + public int inflate(int f){ + if(istate==null) return Z_STREAM_ERROR; + return istate.inflate(f); + } + public int inflateEnd(){ + if(istate==null) return Z_STREAM_ERROR; + int ret=istate.inflateEnd(); +// istate = null; + return ret; + } + + public int inflateSync(){ + if(istate == null) + return Z_STREAM_ERROR; + return istate.inflateSync(); + } + public int inflateSyncPoint(){ + if(istate == null) + return Z_STREAM_ERROR; + return istate.inflateSyncPoint(); + } + public int inflateSetDictionary(byte[] dictionary, int dictLength){ + if(istate == null) + return Z_STREAM_ERROR; + return istate.inflateSetDictionary(dictionary, dictLength); + } + public boolean inflateFinished(){ + return istate.mode==12 /*DONE*/; + } + + + public long getAdler(){ + return adler.getValue(); + } + + public void free(){ + next_in=null; + next_out=null; + msg=null; + } + + public void setOutput(byte[] buf){ + setOutput(buf, 0, buf.length); + } + + public void setOutput(byte[] buf, int off, int len){ + next_out = buf; + next_out_index = off; + avail_out = len; + } + + public void setInput(byte[] buf){ + setInput(buf, 0, buf.length, false); + } + + public void setInput(byte[] buf, boolean append){ + setInput(buf, 0, buf.length, append); + } + + public void setInput(byte[] buf, int off, int len, boolean append){ + if(len<=0 && append && next_in!=null) return; + + if(avail_in>0 && append){ + byte[] tmp = new byte[avail_in+len]; + FastJar.arraycopy(next_in, next_in_index, tmp, 0, avail_in); + FastJar.arraycopy(buf, off, tmp, avail_in, len); + next_in=tmp; + next_in_index=0; + avail_in+=len; + } + else{ + next_in=buf; + next_in_index=off; + avail_in=len; + } + } + + public byte[] getNextIn(){ + return next_in; + } + + public void setNextIn(byte[] next_in){ + this.next_in = next_in; + } + + public int getNextInIndex(){ + return next_in_index; + } + + public void setNextInIndex(int next_in_index){ + this.next_in_index = next_in_index; + } + + public int getAvailIn(){ + return avail_in; + } + + public void setAvailIn(int avail_in){ + this.avail_in = avail_in; + } + + public byte[] getNextOut(){ + return next_out; + } + + public void setNextOut(byte[] next_out){ + this.next_out = next_out; + } + + public int getNextOutIndex(){ + return next_out_index; + } + + public void setNextOutIndex(int next_out_index){ + this.next_out_index = next_out_index; + } + + public int getAvailOut(){ + return avail_out; + + } + + public void setAvailOut(int avail_out){ + this.avail_out = avail_out; + } + + public long getTotalOut(){ + return total_out; + } + + public long getTotalIn(){ + return total_in; + } + + public String getMessage(){ + return msg; + } + + /** + * Those methods are expected to be override by Inflater and Deflater. + * In the future, they will become abstract methods. + */ + public int end(){ return Z_OK; } + public boolean finished(){ return false; } +} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java Sun May 11 14:01:18 2014 +0200 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package org.apidesign.bck2brwsr.emul.zip; + +/* + * This class defines the constants that are used by the classes + * which manipulate Zip64 files. + */ + +public class ZipConstants64 { + + /* + * ZIP64 constants + */ + static final long ZIP64_ENDSIG = 0x06064b50L; // "PK\006\006" + static final long ZIP64_LOCSIG = 0x07064b50L; // "PK\006\007" + static final int ZIP64_ENDHDR = 56; // ZIP64 end header size + static final int ZIP64_LOCHDR = 20; // ZIP64 end loc header size + static final int ZIP64_EXTHDR = 24; // EXT header size + static final int ZIP64_EXTID = 0x0001; // Extra field Zip64 header ID + + static final int ZIP64_MAGICCOUNT = 0xFFFF; + static final long ZIP64_MAGICVAL = 0xFFFFFFFFL; + + /* + * Zip64 End of central directory (END) header field offsets + */ + static final int ZIP64_ENDLEN = 4; // size of zip64 end of central dir + static final int ZIP64_ENDVEM = 12; // version made by + static final int ZIP64_ENDVER = 14; // version needed to extract + static final int ZIP64_ENDNMD = 16; // number of this disk + static final int ZIP64_ENDDSK = 20; // disk number of start + static final int ZIP64_ENDTOD = 24; // total number of entries on this disk + static final int ZIP64_ENDTOT = 32; // total number of entries + static final int ZIP64_ENDSIZ = 40; // central directory size in bytes + static final int ZIP64_ENDOFF = 48; // offset of first CEN header + static final int ZIP64_ENDEXT = 56; // zip64 extensible data sector + + /* + * Zip64 End of central directory locator field offsets + */ + static final int ZIP64_LOCDSK = 4; // disk number start + static final int ZIP64_LOCOFF = 8; // offset of zip64 end + static final int ZIP64_LOCTOT = 16; // total number of disks + + /* + * Zip64 Extra local (EXT) header field offsets + */ + static final int ZIP64_EXTCRC = 4; // uncompressed file crc-32 value + static final int ZIP64_EXTSIZ = 8; // compressed size, 8-byte + static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte + + /* + * Language encoding flag EFS + */ + static final int EFS = 0x800; // If this bit is set the filename and + // comment fields for this file must be + // encoded using UTF-8. + + private ZipConstants64() {} +} diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java Sun May 11 14:01:18 2014 +0200 @@ -0,0 +1,468 @@ +/* + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package org.apidesign.bck2brwsr.emul.zip; + +import java.util.zip.*; +import java.io.InputStream; +import java.io.IOException; +import java.io.EOFException; +import java.io.PushbackInputStream; +import static org.apidesign.bck2brwsr.emul.zip.ZipConstants64.*; +import static java.util.zip.ZipInputStream.*; + +/** + * This class implements an input stream filter for reading files in the + * ZIP file format. Includes support for both compressed and uncompressed + * entries. + * + * @author David Connelly + */ +public +class ZipInputStream extends InflaterInputStream { + private ZipEntry entry; + private int flag; + private CRC32 crc = new CRC32(); + private long remaining; + private byte[] tmpbuf = new byte[512]; + + private static final int STORED = ZipEntry.STORED; + private static final int DEFLATED = ZipEntry.DEFLATED; + + private boolean closed = false; + // this flag is set to true after EOF has reached for + // one entry + private boolean entryEOF = false; + + /** + * Check to make sure that this stream has not been closed + */ + private void ensureOpen() throws IOException { + if (closed) { + throw new IOException("Stream closed"); + } + } + + /** + * Creates a new ZIP input stream. + * + *The UTF-8 {@link java.nio.charset.Charset charset} is used to + * decode the entry names. + * + * @param in the actual input stream + */ + public ZipInputStream(InputStream in) { +// this(in, "UTF-8"); + super(new PushbackInputStream(in, 512), new Inflater(true), 512); + //usesDefaultInflater = true; + if(in == null) { + throw new NullPointerException("in is null"); + } + } + + /** + * Creates a new ZIP input stream. + * + * @param in the actual input stream + * + * @param charset + * The {@linkplain java.nio.charset.Charset charset} to be + * used to decode the ZIP entry name (ignored if the + * language + * encoding bit of the ZIP entry's general purpose bit + * flag is set). + * + * @since 1.7 + * + public ZipInputStream(InputStream in, Charset charset) { + super(new PushbackInputStream(in, 512), new Inflater(true), 512); + usesDefaultInflater = true; + if(in == null) { + throw new NullPointerException("in is null"); + } + if (charset == null) + throw new NullPointerException("charset is null"); + this.zc = ZipCoder.get(charset); + } + */ + + /** + * Reads the next ZIP file entry and positions the stream at the + * beginning of the entry data. + * @return the next ZIP file entry, or null if there are no more entries + * @exception ZipException if a ZIP file error has occurred + * @exception IOException if an I/O error has occurred + */ + public ZipEntry getNextEntry() throws IOException { + ensureOpen(); + if (entry != null) { + closeEntry(); + } + crc.reset(); + inf.reset(); + if ((entry = readLOC()) == null) { + return null; + } + if (entry.getMethod() == STORED) { + remaining = entry.getSize(); + } + entryEOF = false; + return entry; + } + + /** + * Closes the current ZIP entry and positions the stream for reading the + * next entry. + * @exception ZipException if a ZIP file error has occurred + * @exception IOException if an I/O error has occurred + */ + public void closeEntry() throws IOException { + ensureOpen(); + while (read(tmpbuf, 0, tmpbuf.length) != -1) ; + entryEOF = true; + } + + /** + * Returns 0 after EOF has reached for the current entry data, + * otherwise always return 1. + *
+ * Programs should not count on this method to return the actual number
+ * of bytes that could be read without blocking.
+ *
+ * @return 1 before EOF and 0 after EOF has reached for current entry.
+ * @exception IOException if an I/O error occurs.
+ *
+ */
+ public int available() throws IOException {
+ ensureOpen();
+ if (entryEOF) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+
+ /**
+ * Reads from the current ZIP entry into an array of bytes.
+ * If len
is not zero, the method
+ * blocks until some input is available; otherwise, no
+ * bytes are read and 0
is returned.
+ * @param b the buffer into which the data is read
+ * @param off the start offset in the destination array b
+ * @param len the maximum number of bytes read
+ * @return the actual number of bytes read, or -1 if the end of the
+ * entry is reached
+ * @exception NullPointerException if b
is null
.
+ * @exception IndexOutOfBoundsException if off
is negative,
+ * len
is negative, or len
is greater than
+ * b.length - off
+ * @exception ZipException if a ZIP file error has occurred
+ * @exception IOException if an I/O error has occurred
+ */
+ public int read(byte[] b, int off, int len) throws IOException {
+ ensureOpen();
+ if (off < 0 || len < 0 || off > b.length - len) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+
+ if (entry == null) {
+ return -1;
+ }
+ switch (entry.getMethod()) {
+ case DEFLATED:
+ len = super.read(b, off, len);
+ if (len == -1) {
+ readEnd(entry);
+ entryEOF = true;
+ entry = null;
+ } else {
+ crc.update(b, off, len);
+ }
+ return len;
+ case STORED:
+ if (remaining <= 0) {
+ entryEOF = true;
+ entry = null;
+ return -1;
+ }
+ if (len > remaining) {
+ len = (int)remaining;
+ }
+ len = in.read(b, off, len);
+ if (len == -1) {
+ throw new ZipException("unexpected EOF");
+ }
+ crc.update(b, off, len);
+ remaining -= len;
+ if (remaining == 0 && entry.getCrc() != crc.getValue()) {
+ throw new ZipException(
+ "invalid entry CRC (expected 0x" + Long.toHexString(entry.getCrc()) +
+ " but got 0x" + Long.toHexString(crc.getValue()) + ")");
+ }
+ return len;
+ default:
+ throw new ZipException("invalid compression method");
+ }
+ }
+
+ /**
+ * Skips specified number of bytes in the current ZIP entry.
+ * @param n the number of bytes to skip
+ * @return the actual number of bytes skipped
+ * @exception ZipException if a ZIP file error has occurred
+ * @exception IOException if an I/O error has occurred
+ * @exception IllegalArgumentException if n < 0
+ */
+ public long skip(long n) throws IOException {
+ if (n < 0) {
+ throw new IllegalArgumentException("negative skip length");
+ }
+ ensureOpen();
+ int max = (int)Math.min(n, Integer.MAX_VALUE);
+ int total = 0;
+ while (total < max) {
+ int len = max - total;
+ if (len > tmpbuf.length) {
+ len = tmpbuf.length;
+ }
+ len = read(tmpbuf, 0, len);
+ if (len == -1) {
+ entryEOF = true;
+ break;
+ }
+ total += len;
+ }
+ return total;
+ }
+
+ /**
+ * Closes this input stream and releases any system resources associated
+ * with the stream.
+ * @exception IOException if an I/O error has occurred
+ */
+ public void close() throws IOException {
+ if (!closed) {
+ super.close();
+ closed = true;
+ }
+ }
+
+ private byte[] b = new byte[256];
+
+ /*
+ * Reads local file (LOC) header for next entry.
+ */
+ private ZipEntry readLOC() throws IOException {
+ try {
+ readFully(tmpbuf, 0, LOCHDR);
+ } catch (EOFException e) {
+ return null;
+ }
+ if (get32(tmpbuf, 0) != LOCSIG) {
+ return null;
+ }
+ // get flag first, we need check EFS.
+ flag = get16(tmpbuf, LOCFLG);
+ // get the entry name and create the ZipEntry first
+ int len = get16(tmpbuf, LOCNAM);
+ int blen = b.length;
+ if (len > blen) {
+ do
+ blen = blen * 2;
+ while (len > blen);
+ b = new byte[blen];
+ }
+ readFully(b, 0, len);
+ // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
+ ZipEntry e = createZipEntry(((flag & EFS) != 0)
+ ? toStringUTF8(b, len)
+ : toString(b, len));
+ // now get the remaining fields for the entry
+ if ((flag & 1) == 1) {
+ throw new ZipException("encrypted ZIP entry not supported");
+ }
+ e.setMethod(get16(tmpbuf, LOCHOW));
+ e.setTime(get32(tmpbuf, LOCTIM));
+ if ((flag & 8) == 8) {
+ /* "Data Descriptor" present */
+ if (e.getMethod() != DEFLATED) {
+ throw new ZipException(
+ "only DEFLATED entries can have EXT descriptor");
+ }
+ } else {
+ e.setCrc(get32(tmpbuf, LOCCRC));
+ e.setCompressedSize(get32(tmpbuf, LOCSIZ));
+ e.setSize(get32(tmpbuf, LOCLEN));
+ }
+ len = get16(tmpbuf, LOCEXT);
+ if (len > 0) {
+ byte[] bb = new byte[len];
+ readFully(bb, 0, len);
+ e.setExtra(bb);
+ // extra fields are in "HeaderID(2)DataSize(2)Data... format
+ if (e.getCompressedSize() == ZIP64_MAGICVAL || e.getCompressedSize() == ZIP64_MAGICVAL) {
+ int off = 0;
+ while (off + 4 < len) {
+ int sz = get16(bb, off + 2);
+ if (get16(bb, off) == ZIP64_EXTID) {
+ off += 4;
+ // LOC extra zip64 entry MUST include BOTH original and
+ // compressed file size fields
+ if (sz < 16 || (off + sz) > len ) {
+ // Invalid zip64 extra fields, simply skip. Even it's
+ // rare, it's possible the entry size happens to be
+ // the magic value and it "accidnetly" has some bytes
+ // in extra match the id.
+ return e;
+ }
+ e.setSize(get64(bb, off));
+ e.setCompressedSize(get64(bb, off + 8));
+ break;
+ }
+ off += (sz + 4);
+ }
+ }
+ }
+ return e;
+ }
+
+ /**
+ * Creates a new ZipEntry
object for the specified
+ * entry name.
+ *
+ * @param name the ZIP file entry name
+ * @return the ZipEntry just created
+ */
+ protected ZipEntry createZipEntry(String name) {
+ return new ZipEntry(name);
+ }
+
+ /*
+ * Reads end of deflated entry as well as EXT descriptor if present.
+ */
+ private void readEnd(ZipEntry e) throws IOException {
+ int n = inf.getRemaining();
+ if (n > 0) {
+ ((PushbackInputStream)in).unread(buf, len - n, n);
+ }
+ if ((flag & 8) == 8) {
+ /* "Data Descriptor" present */
+ if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
+ inf.getBytesRead() > ZIP64_MAGICVAL) {
+ // ZIP64 format
+ readFully(tmpbuf, 0, ZIP64_EXTHDR);
+ long sig = get32(tmpbuf, 0);
+ if (sig != EXTSIG) { // no EXTSIG present
+ e.setCrc(sig);
+ e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC));
+ e.setSize(get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC));
+ ((PushbackInputStream)in).unread(
+ tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
+ } else {
+ e.setCrc(get32(tmpbuf, ZIP64_EXTCRC));
+ e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ));
+ e.setSize(get64(tmpbuf, ZIP64_EXTLEN));
+ }
+ } else {
+ readFully(tmpbuf, 0, EXTHDR);
+ long sig = get32(tmpbuf, 0);
+ if (sig != EXTSIG) { // no EXTSIG present
+ e.setCrc(sig);
+ e.setCompressedSize(get32(tmpbuf, EXTSIZ - EXTCRC));
+ e.setSize(get32(tmpbuf, EXTLEN - EXTCRC));
+ ((PushbackInputStream)in).unread(
+ tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
+ } else {
+ e.setCrc(get32(tmpbuf, EXTCRC));
+ e.setCompressedSize(get32(tmpbuf, EXTSIZ));
+ e.setSize(get32(tmpbuf, EXTLEN));
+ }
+ }
+ }
+ if (e.getSize() != inf.getBytesWritten()) {
+ throw new ZipException(
+ "invalid entry size (expected " + e.getSize() +
+ " but got " + inf.getBytesWritten() + " bytes)");
+ }
+ if (e.getCompressedSize() != inf.getBytesRead()) {
+ throw new ZipException(
+ "invalid entry compressed size (expected " + e.getCompressedSize() +
+ " but got " + inf.getBytesRead() + " bytes)");
+ }
+ if (e.getCrc() != crc.getValue()) {
+ throw new ZipException(
+ "invalid entry CRC (expected 0x" + Long.toHexString(e.getCrc()) +
+ " but got 0x" + Long.toHexString(crc.getValue()) + ")");
+ }
+ }
+
+ /*
+ * Reads bytes, blocking until all bytes are read.
+ */
+ private void readFully(byte[] b, int off, int len) throws IOException {
+ while (len > 0) {
+ int n = in.read(b, off, len);
+ if (n == -1) {
+ throw new EOFException();
+ }
+ off += n;
+ len -= n;
+ }
+ }
+
+ /*
+ * Fetches unsigned 16-bit value from byte array at specified offset.
+ * The bytes are assumed to be in Intel (little-endian) byte order.
+ */
+ private static final int get16(byte b[], int off) {
+ return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
+ }
+
+ /*
+ * Fetches unsigned 32-bit value from byte array at specified offset.
+ * The bytes are assumed to be in Intel (little-endian) byte order.
+ */
+ private static final long get32(byte b[], int off) {
+ return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
+ }
+
+ /*
+ * Fetches signed 64-bit value from byte array at specified offset.
+ * The bytes are assumed to be in Intel (little-endian) byte order.
+ */
+ private static final long get64(byte b[], int off) {
+ return get32(b, off) | (get32(b, off+4) << 32);
+ }
+
+ private static String toStringUTF8(byte[] arr, int len) {
+ return new String(arr, 0, len);
+ }
+
+ private static String toString(byte[] b, int len) {
+ return new String(b, 0, len);
+ }
+}
diff -r ae8575329e1b -r bfda398c3a68 rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/vmzip/ZipResources.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/vmzip/ZipResources.java Sun May 11 14:01:18 2014 +0200
@@ -0,0 +1,108 @@
+/**
+ * Back 2 Browser Bytecode Translator
+ * Copyright (C) 2012 Jaroslav Tulach