1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/emul/mini/src/main/java/java/util/zip/CRC32.java Wed Jan 30 14:01:52 2013 +0100
1.3 @@ -0,0 +1,93 @@
1.4 +/*
1.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +package java.util.zip;
1.30 +
1.31 +/**
1.32 + * A class that can be used to compute the CRC-32 of a data stream.
1.33 + *
1.34 + * @see Checksum
1.35 + * @author David Connelly
1.36 + */
1.37 +public
1.38 +class CRC32 implements Checksum {
1.39 + private int crc;
1.40 +
1.41 + /**
1.42 + * Creates a new CRC32 object.
1.43 + */
1.44 + public CRC32() {
1.45 + }
1.46 +
1.47 +
1.48 + /**
1.49 + * Updates the CRC-32 checksum with the specified byte (the low
1.50 + * eight bits of the argument b).
1.51 + *
1.52 + * @param b the byte to update the checksum with
1.53 + */
1.54 + public void update(int b) {
1.55 + crc = update(crc, b);
1.56 + }
1.57 +
1.58 + /**
1.59 + * Updates the CRC-32 checksum with the specified array of bytes.
1.60 + */
1.61 + public void update(byte[] b, int off, int len) {
1.62 + if (b == null) {
1.63 + throw new NullPointerException();
1.64 + }
1.65 + if (off < 0 || len < 0 || off > b.length - len) {
1.66 + throw new ArrayIndexOutOfBoundsException();
1.67 + }
1.68 + crc = updateBytes(crc, b, off, len);
1.69 + }
1.70 +
1.71 + /**
1.72 + * Updates the CRC-32 checksum with the specified array of bytes.
1.73 + *
1.74 + * @param b the array of bytes to update the checksum with
1.75 + */
1.76 + public void update(byte[] b) {
1.77 + crc = updateBytes(crc, b, 0, b.length);
1.78 + }
1.79 +
1.80 + /**
1.81 + * Resets CRC-32 to initial value.
1.82 + */
1.83 + public void reset() {
1.84 + crc = 0;
1.85 + }
1.86 +
1.87 + /**
1.88 + * Returns CRC-32 value.
1.89 + */
1.90 + public long getValue() {
1.91 + return (long)crc & 0xffffffffL;
1.92 + }
1.93 +
1.94 + private native static int update(int crc, int b);
1.95 + private native static int updateBytes(int crc, byte[] b, int off, int len);
1.96 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/emul/mini/src/main/java/java/util/zip/Checksum.java Wed Jan 30 14:01:52 2013 +0100
2.3 @@ -0,0 +1,60 @@
2.4 +/*
2.5 + * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2.7 + *
2.8 + * This code is free software; you can redistribute it and/or modify it
2.9 + * under the terms of the GNU General Public License version 2 only, as
2.10 + * published by the Free Software Foundation. Oracle designates this
2.11 + * particular file as subject to the "Classpath" exception as provided
2.12 + * by Oracle in the LICENSE file that accompanied this code.
2.13 + *
2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2.17 + * version 2 for more details (a copy is included in the LICENSE file that
2.18 + * accompanied this code).
2.19 + *
2.20 + * You should have received a copy of the GNU General Public License version
2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2.23 + *
2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2.25 + * or visit www.oracle.com if you need additional information or have any
2.26 + * questions.
2.27 + */
2.28 +
2.29 +package java.util.zip;
2.30 +
2.31 +/**
2.32 + * An interface representing a data checksum.
2.33 + *
2.34 + * @author David Connelly
2.35 + */
2.36 +public
2.37 +interface Checksum {
2.38 + /**
2.39 + * Updates the current checksum with the specified byte.
2.40 + *
2.41 + * @param b the byte to update the checksum with
2.42 + */
2.43 + public void update(int b);
2.44 +
2.45 + /**
2.46 + * Updates the current checksum with the specified array of bytes.
2.47 + * @param b the byte array to update the checksum with
2.48 + * @param off the start offset of the data
2.49 + * @param len the number of bytes to use for the update
2.50 + */
2.51 + public void update(byte[] b, int off, int len);
2.52 +
2.53 + /**
2.54 + * Returns the current checksum value.
2.55 + * @return the current checksum value
2.56 + */
2.57 + public long getValue();
2.58 +
2.59 + /**
2.60 + * Resets the checksum to its initial value.
2.61 + */
2.62 + public void reset();
2.63 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/emul/mini/src/main/java/java/util/zip/DataFormatException.java Wed Jan 30 14:01:52 2013 +0100
3.3 @@ -0,0 +1,52 @@
3.4 +/*
3.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3.7 + *
3.8 + * This code is free software; you can redistribute it and/or modify it
3.9 + * under the terms of the GNU General Public License version 2 only, as
3.10 + * published by the Free Software Foundation. Oracle designates this
3.11 + * particular file as subject to the "Classpath" exception as provided
3.12 + * by Oracle in the LICENSE file that accompanied this code.
3.13 + *
3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3.17 + * version 2 for more details (a copy is included in the LICENSE file that
3.18 + * accompanied this code).
3.19 + *
3.20 + * You should have received a copy of the GNU General Public License version
3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3.23 + *
3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3.25 + * or visit www.oracle.com if you need additional information or have any
3.26 + * questions.
3.27 + */
3.28 +
3.29 +package java.util.zip;
3.30 +
3.31 +/**
3.32 + * Signals that a data format error has occurred.
3.33 + *
3.34 + * @author David Connelly
3.35 + */
3.36 +public
3.37 +class DataFormatException extends Exception {
3.38 + private static final long serialVersionUID = 2219632870893641452L;
3.39 +
3.40 + /**
3.41 + * Constructs a DataFormatException with no detail message.
3.42 + */
3.43 + public DataFormatException() {
3.44 + super();
3.45 + }
3.46 +
3.47 + /**
3.48 + * Constructs a DataFormatException with the specified detail message.
3.49 + * A detail message is a String that describes this particular exception.
3.50 + * @param s the String containing a detail message
3.51 + */
3.52 + public DataFormatException(String s) {
3.53 + super(s);
3.54 + }
3.55 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/emul/mini/src/main/java/java/util/zip/Inflater.java Wed Jan 30 14:01:52 2013 +0100
4.3 @@ -0,0 +1,402 @@
4.4 +/*
4.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.7 + *
4.8 + * This code is free software; you can redistribute it and/or modify it
4.9 + * under the terms of the GNU General Public License version 2 only, as
4.10 + * published by the Free Software Foundation. Oracle designates this
4.11 + * particular file as subject to the "Classpath" exception as provided
4.12 + * by Oracle in the LICENSE file that accompanied this code.
4.13 + *
4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4.17 + * version 2 for more details (a copy is included in the LICENSE file that
4.18 + * accompanied this code).
4.19 + *
4.20 + * You should have received a copy of the GNU General Public License version
4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4.23 + *
4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4.25 + * or visit www.oracle.com if you need additional information or have any
4.26 + * questions.
4.27 + */
4.28 +
4.29 +package java.util.zip;
4.30 +
4.31 +/**
4.32 + * This class provides support for general purpose decompression using the
4.33 + * popular ZLIB compression library. The ZLIB compression library was
4.34 + * initially developed as part of the PNG graphics standard and is not
4.35 + * protected by patents. It is fully described in the specifications at
4.36 + * the <a href="package-summary.html#package_description">java.util.zip
4.37 + * package description</a>.
4.38 + *
4.39 + * <p>The following code fragment demonstrates a trivial compression
4.40 + * and decompression of a string using <tt>Deflater</tt> and
4.41 + * <tt>Inflater</tt>.
4.42 + *
4.43 + * <blockquote><pre>
4.44 + * try {
4.45 + * // Encode a String into bytes
4.46 + * String inputString = "blahblahblah\u20AC\u20AC";
4.47 + * byte[] input = inputString.getBytes("UTF-8");
4.48 + *
4.49 + * // Compress the bytes
4.50 + * byte[] output = new byte[100];
4.51 + * Deflater compresser = new Deflater();
4.52 + * compresser.setInput(input);
4.53 + * compresser.finish();
4.54 + * int compressedDataLength = compresser.deflate(output);
4.55 + *
4.56 + * // Decompress the bytes
4.57 + * Inflater decompresser = new Inflater();
4.58 + * decompresser.setInput(output, 0, compressedDataLength);
4.59 + * byte[] result = new byte[100];
4.60 + * int resultLength = decompresser.inflate(result);
4.61 + * decompresser.end();
4.62 + *
4.63 + * // Decode the bytes into a String
4.64 + * String outputString = new String(result, 0, resultLength, "UTF-8");
4.65 + * } catch(java.io.UnsupportedEncodingException ex) {
4.66 + * // handle
4.67 + * } catch (java.util.zip.DataFormatException ex) {
4.68 + * // handle
4.69 + * }
4.70 + * </pre></blockquote>
4.71 + *
4.72 + * @see Deflater
4.73 + * @author David Connelly
4.74 + *
4.75 + */
4.76 +public
4.77 +class Inflater {
4.78 +
4.79 + private final ZStreamRef zsRef;
4.80 + private byte[] buf = defaultBuf;
4.81 + private int off, len;
4.82 + private boolean finished;
4.83 + private boolean needDict;
4.84 +
4.85 + private static final byte[] defaultBuf = new byte[0];
4.86 +
4.87 + static {
4.88 + /* Zip library is loaded from System.initializeSystemClass */
4.89 + initIDs();
4.90 + }
4.91 +
4.92 + /**
4.93 + * Creates a new decompressor. If the parameter 'nowrap' is true then
4.94 + * the ZLIB header and checksum fields will not be used. This provides
4.95 + * compatibility with the compression format used by both GZIP and PKZIP.
4.96 + * <p>
4.97 + * Note: When using the 'nowrap' option it is also necessary to provide
4.98 + * an extra "dummy" byte as input. This is required by the ZLIB native
4.99 + * library in order to support certain optimizations.
4.100 + *
4.101 + * @param nowrap if true then support GZIP compatible compression
4.102 + */
4.103 + public Inflater(boolean nowrap) {
4.104 + zsRef = new ZStreamRef(init(nowrap));
4.105 + }
4.106 +
4.107 + /**
4.108 + * Creates a new decompressor.
4.109 + */
4.110 + public Inflater() {
4.111 + this(false);
4.112 + }
4.113 +
4.114 + /**
4.115 + * Sets input data for decompression. Should be called whenever
4.116 + * needsInput() returns true indicating that more input data is
4.117 + * required.
4.118 + * @param b the input data bytes
4.119 + * @param off the start offset of the input data
4.120 + * @param len the length of the input data
4.121 + * @see Inflater#needsInput
4.122 + */
4.123 + public void setInput(byte[] b, int off, int len) {
4.124 + if (b == null) {
4.125 + throw new NullPointerException();
4.126 + }
4.127 + if (off < 0 || len < 0 || off > b.length - len) {
4.128 + throw new ArrayIndexOutOfBoundsException();
4.129 + }
4.130 + synchronized (zsRef) {
4.131 + this.buf = b;
4.132 + this.off = off;
4.133 + this.len = len;
4.134 + }
4.135 + }
4.136 +
4.137 + /**
4.138 + * Sets input data for decompression. Should be called whenever
4.139 + * needsInput() returns true indicating that more input data is
4.140 + * required.
4.141 + * @param b the input data bytes
4.142 + * @see Inflater#needsInput
4.143 + */
4.144 + public void setInput(byte[] b) {
4.145 + setInput(b, 0, b.length);
4.146 + }
4.147 +
4.148 + /**
4.149 + * Sets the preset dictionary to the given array of bytes. Should be
4.150 + * called when inflate() returns 0 and needsDictionary() returns true
4.151 + * indicating that a preset dictionary is required. The method getAdler()
4.152 + * can be used to get the Adler-32 value of the dictionary needed.
4.153 + * @param b the dictionary data bytes
4.154 + * @param off the start offset of the data
4.155 + * @param len the length of the data
4.156 + * @see Inflater#needsDictionary
4.157 + * @see Inflater#getAdler
4.158 + */
4.159 + public void setDictionary(byte[] b, int off, int len) {
4.160 + if (b == null) {
4.161 + throw new NullPointerException();
4.162 + }
4.163 + if (off < 0 || len < 0 || off > b.length - len) {
4.164 + throw new ArrayIndexOutOfBoundsException();
4.165 + }
4.166 + synchronized (zsRef) {
4.167 + ensureOpen();
4.168 + setDictionary(zsRef.address(), b, off, len);
4.169 + needDict = false;
4.170 + }
4.171 + }
4.172 +
4.173 + /**
4.174 + * Sets the preset dictionary to the given array of bytes. Should be
4.175 + * called when inflate() returns 0 and needsDictionary() returns true
4.176 + * indicating that a preset dictionary is required. The method getAdler()
4.177 + * can be used to get the Adler-32 value of the dictionary needed.
4.178 + * @param b the dictionary data bytes
4.179 + * @see Inflater#needsDictionary
4.180 + * @see Inflater#getAdler
4.181 + */
4.182 + public void setDictionary(byte[] b) {
4.183 + setDictionary(b, 0, b.length);
4.184 + }
4.185 +
4.186 + /**
4.187 + * Returns the total number of bytes remaining in the input buffer.
4.188 + * This can be used to find out what bytes still remain in the input
4.189 + * buffer after decompression has finished.
4.190 + * @return the total number of bytes remaining in the input buffer
4.191 + */
4.192 + public int getRemaining() {
4.193 + synchronized (zsRef) {
4.194 + return len;
4.195 + }
4.196 + }
4.197 +
4.198 + /**
4.199 + * Returns true if no data remains in the input buffer. This can
4.200 + * be used to determine if #setInput should be called in order
4.201 + * to provide more input.
4.202 + * @return true if no data remains in the input buffer
4.203 + */
4.204 + public boolean needsInput() {
4.205 + synchronized (zsRef) {
4.206 + return len <= 0;
4.207 + }
4.208 + }
4.209 +
4.210 + /**
4.211 + * Returns true if a preset dictionary is needed for decompression.
4.212 + * @return true if a preset dictionary is needed for decompression
4.213 + * @see Inflater#setDictionary
4.214 + */
4.215 + public boolean needsDictionary() {
4.216 + synchronized (zsRef) {
4.217 + return needDict;
4.218 + }
4.219 + }
4.220 +
4.221 + /**
4.222 + * Returns true if the end of the compressed data stream has been
4.223 + * reached.
4.224 + * @return true if the end of the compressed data stream has been
4.225 + * reached
4.226 + */
4.227 + public boolean finished() {
4.228 + synchronized (zsRef) {
4.229 + return finished;
4.230 + }
4.231 + }
4.232 +
4.233 + /**
4.234 + * Uncompresses bytes into specified buffer. Returns actual number
4.235 + * of bytes uncompressed. A return value of 0 indicates that
4.236 + * needsInput() or needsDictionary() should be called in order to
4.237 + * determine if more input data or a preset dictionary is required.
4.238 + * In the latter case, getAdler() can be used to get the Adler-32
4.239 + * value of the dictionary required.
4.240 + * @param b the buffer for the uncompressed data
4.241 + * @param off the start offset of the data
4.242 + * @param len the maximum number of uncompressed bytes
4.243 + * @return the actual number of uncompressed bytes
4.244 + * @exception DataFormatException if the compressed data format is invalid
4.245 + * @see Inflater#needsInput
4.246 + * @see Inflater#needsDictionary
4.247 + */
4.248 + public int inflate(byte[] b, int off, int len)
4.249 + throws DataFormatException
4.250 + {
4.251 + if (b == null) {
4.252 + throw new NullPointerException();
4.253 + }
4.254 + if (off < 0 || len < 0 || off > b.length - len) {
4.255 + throw new ArrayIndexOutOfBoundsException();
4.256 + }
4.257 + synchronized (zsRef) {
4.258 + ensureOpen();
4.259 + return inflateBytes(zsRef.address(), b, off, len);
4.260 + }
4.261 + }
4.262 +
4.263 + /**
4.264 + * Uncompresses bytes into specified buffer. Returns actual number
4.265 + * of bytes uncompressed. A return value of 0 indicates that
4.266 + * needsInput() or needsDictionary() should be called in order to
4.267 + * determine if more input data or a preset dictionary is required.
4.268 + * In the latter case, getAdler() can be used to get the Adler-32
4.269 + * value of the dictionary required.
4.270 + * @param b the buffer for the uncompressed data
4.271 + * @return the actual number of uncompressed bytes
4.272 + * @exception DataFormatException if the compressed data format is invalid
4.273 + * @see Inflater#needsInput
4.274 + * @see Inflater#needsDictionary
4.275 + */
4.276 + public int inflate(byte[] b) throws DataFormatException {
4.277 + return inflate(b, 0, b.length);
4.278 + }
4.279 +
4.280 + /**
4.281 + * Returns the ADLER-32 value of the uncompressed data.
4.282 + * @return the ADLER-32 value of the uncompressed data
4.283 + */
4.284 + public int getAdler() {
4.285 + synchronized (zsRef) {
4.286 + ensureOpen();
4.287 + return getAdler(zsRef.address());
4.288 + }
4.289 + }
4.290 +
4.291 + /**
4.292 + * Returns the total number of compressed bytes input so far.
4.293 + *
4.294 + * <p>Since the number of bytes may be greater than
4.295 + * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
4.296 + * the preferred means of obtaining this information.</p>
4.297 + *
4.298 + * @return the total number of compressed bytes input so far
4.299 + */
4.300 + public int getTotalIn() {
4.301 + return (int) getBytesRead();
4.302 + }
4.303 +
4.304 + /**
4.305 + * Returns the total number of compressed bytes input so far.</p>
4.306 + *
4.307 + * @return the total (non-negative) number of compressed bytes input so far
4.308 + * @since 1.5
4.309 + */
4.310 + public long getBytesRead() {
4.311 + synchronized (zsRef) {
4.312 + ensureOpen();
4.313 + return getBytesRead(zsRef.address());
4.314 + }
4.315 + }
4.316 +
4.317 + /**
4.318 + * Returns the total number of uncompressed bytes output so far.
4.319 + *
4.320 + * <p>Since the number of bytes may be greater than
4.321 + * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
4.322 + * the preferred means of obtaining this information.</p>
4.323 + *
4.324 + * @return the total number of uncompressed bytes output so far
4.325 + */
4.326 + public int getTotalOut() {
4.327 + return (int) getBytesWritten();
4.328 + }
4.329 +
4.330 + /**
4.331 + * Returns the total number of uncompressed bytes output so far.</p>
4.332 + *
4.333 + * @return the total (non-negative) number of uncompressed bytes output so far
4.334 + * @since 1.5
4.335 + */
4.336 + public long getBytesWritten() {
4.337 + synchronized (zsRef) {
4.338 + ensureOpen();
4.339 + return getBytesWritten(zsRef.address());
4.340 + }
4.341 + }
4.342 +
4.343 + /**
4.344 + * Resets inflater so that a new set of input data can be processed.
4.345 + */
4.346 + public void reset() {
4.347 + synchronized (zsRef) {
4.348 + ensureOpen();
4.349 + reset(zsRef.address());
4.350 + buf = defaultBuf;
4.351 + finished = false;
4.352 + needDict = false;
4.353 + off = len = 0;
4.354 + }
4.355 + }
4.356 +
4.357 + /**
4.358 + * Closes the decompressor and discards any unprocessed input.
4.359 + * This method should be called when the decompressor is no longer
4.360 + * being used, but will also be called automatically by the finalize()
4.361 + * method. Once this method is called, the behavior of the Inflater
4.362 + * object is undefined.
4.363 + */
4.364 + public void end() {
4.365 + synchronized (zsRef) {
4.366 + long addr = zsRef.address();
4.367 + zsRef.clear();
4.368 + if (addr != 0) {
4.369 + end(addr);
4.370 + buf = null;
4.371 + }
4.372 + }
4.373 + }
4.374 +
4.375 + /**
4.376 + * Closes the decompressor when garbage is collected.
4.377 + */
4.378 + protected void finalize() {
4.379 + end();
4.380 + }
4.381 +
4.382 + private void ensureOpen () {
4.383 + assert Thread.holdsLock(zsRef);
4.384 + if (zsRef.address() == 0)
4.385 + throw new NullPointerException("Inflater has been closed");
4.386 + }
4.387 +
4.388 + boolean ended() {
4.389 + synchronized (zsRef) {
4.390 + return zsRef.address() == 0;
4.391 + }
4.392 + }
4.393 +
4.394 + private native static void initIDs();
4.395 + private native static long init(boolean nowrap);
4.396 + private native static void setDictionary(long addr, byte[] b, int off,
4.397 + int len);
4.398 + private native int inflateBytes(long addr, byte[] b, int off, int len)
4.399 + throws DataFormatException;
4.400 + private native static int getAdler(long addr);
4.401 + private native static long getBytesRead(long addr);
4.402 + private native static long getBytesWritten(long addr);
4.403 + private native static void reset(long addr);
4.404 + private native static void end(long addr);
4.405 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/emul/mini/src/main/java/java/util/zip/InflaterInputStream.java Wed Jan 30 14:01:52 2013 +0100
5.3 @@ -0,0 +1,288 @@
5.4 +/*
5.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.7 + *
5.8 + * This code is free software; you can redistribute it and/or modify it
5.9 + * under the terms of the GNU General Public License version 2 only, as
5.10 + * published by the Free Software Foundation. Oracle designates this
5.11 + * particular file as subject to the "Classpath" exception as provided
5.12 + * by Oracle in the LICENSE file that accompanied this code.
5.13 + *
5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5.17 + * version 2 for more details (a copy is included in the LICENSE file that
5.18 + * accompanied this code).
5.19 + *
5.20 + * You should have received a copy of the GNU General Public License version
5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5.23 + *
5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5.25 + * or visit www.oracle.com if you need additional information or have any
5.26 + * questions.
5.27 + */
5.28 +
5.29 +package java.util.zip;
5.30 +
5.31 +import java.io.FilterInputStream;
5.32 +import java.io.InputStream;
5.33 +import java.io.IOException;
5.34 +import java.io.EOFException;
5.35 +
5.36 +/**
5.37 + * This class implements a stream filter for uncompressing data in the
5.38 + * "deflate" compression format. It is also used as the basis for other
5.39 + * decompression filters, such as GZIPInputStream.
5.40 + *
5.41 + * @see Inflater
5.42 + * @author David Connelly
5.43 + */
5.44 +public
5.45 +class InflaterInputStream extends FilterInputStream {
5.46 + /**
5.47 + * Decompressor for this stream.
5.48 + */
5.49 + protected Inflater inf;
5.50 +
5.51 + /**
5.52 + * Input buffer for decompression.
5.53 + */
5.54 + protected byte[] buf;
5.55 +
5.56 + /**
5.57 + * Length of input buffer.
5.58 + */
5.59 + protected int len;
5.60 +
5.61 + private boolean closed = false;
5.62 + // this flag is set to true after EOF has reached
5.63 + private boolean reachEOF = false;
5.64 +
5.65 + /**
5.66 + * Check to make sure that this stream has not been closed
5.67 + */
5.68 + private void ensureOpen() throws IOException {
5.69 + if (closed) {
5.70 + throw new IOException("Stream closed");
5.71 + }
5.72 + }
5.73 +
5.74 +
5.75 + /**
5.76 + * Creates a new input stream with the specified decompressor and
5.77 + * buffer size.
5.78 + * @param in the input stream
5.79 + * @param inf the decompressor ("inflater")
5.80 + * @param size the input buffer size
5.81 + * @exception IllegalArgumentException if size is <= 0
5.82 + */
5.83 + public InflaterInputStream(InputStream in, Inflater inf, int size) {
5.84 + super(in);
5.85 + if (in == null || inf == null) {
5.86 + throw new NullPointerException();
5.87 + } else if (size <= 0) {
5.88 + throw new IllegalArgumentException("buffer size <= 0");
5.89 + }
5.90 + this.inf = inf;
5.91 + buf = new byte[size];
5.92 + }
5.93 +
5.94 + /**
5.95 + * Creates a new input stream with the specified decompressor and a
5.96 + * default buffer size.
5.97 + * @param in the input stream
5.98 + * @param inf the decompressor ("inflater")
5.99 + */
5.100 + public InflaterInputStream(InputStream in, Inflater inf) {
5.101 + this(in, inf, 512);
5.102 + }
5.103 +
5.104 + boolean usesDefaultInflater = false;
5.105 +
5.106 + /**
5.107 + * Creates a new input stream with a default decompressor and buffer size.
5.108 + * @param in the input stream
5.109 + */
5.110 + public InflaterInputStream(InputStream in) {
5.111 + this(in, new Inflater());
5.112 + usesDefaultInflater = true;
5.113 + }
5.114 +
5.115 + private byte[] singleByteBuf = new byte[1];
5.116 +
5.117 + /**
5.118 + * Reads a byte of uncompressed data. This method will block until
5.119 + * enough input is available for decompression.
5.120 + * @return the byte read, or -1 if end of compressed input is reached
5.121 + * @exception IOException if an I/O error has occurred
5.122 + */
5.123 + public int read() throws IOException {
5.124 + ensureOpen();
5.125 + return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff;
5.126 + }
5.127 +
5.128 + /**
5.129 + * Reads uncompressed data into an array of bytes. If <code>len</code> is not
5.130 + * zero, the method will block until some input can be decompressed; otherwise,
5.131 + * no bytes are read and <code>0</code> is returned.
5.132 + * @param b the buffer into which the data is read
5.133 + * @param off the start offset in the destination array <code>b</code>
5.134 + * @param len the maximum number of bytes read
5.135 + * @return the actual number of bytes read, or -1 if the end of the
5.136 + * compressed input is reached or a preset dictionary is needed
5.137 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
5.138 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
5.139 + * <code>len</code> is negative, or <code>len</code> is greater than
5.140 + * <code>b.length - off</code>
5.141 + * @exception ZipException if a ZIP format error has occurred
5.142 + * @exception IOException if an I/O error has occurred
5.143 + */
5.144 + public int read(byte[] b, int off, int len) throws IOException {
5.145 + ensureOpen();
5.146 + if (b == null) {
5.147 + throw new NullPointerException();
5.148 + } else if (off < 0 || len < 0 || len > b.length - off) {
5.149 + throw new IndexOutOfBoundsException();
5.150 + } else if (len == 0) {
5.151 + return 0;
5.152 + }
5.153 + try {
5.154 + int n;
5.155 + while ((n = inf.inflate(b, off, len)) == 0) {
5.156 + if (inf.finished() || inf.needsDictionary()) {
5.157 + reachEOF = true;
5.158 + return -1;
5.159 + }
5.160 + if (inf.needsInput()) {
5.161 + fill();
5.162 + }
5.163 + }
5.164 + return n;
5.165 + } catch (DataFormatException e) {
5.166 + String s = e.getMessage();
5.167 + throw new ZipException(s != null ? s : "Invalid ZLIB data format");
5.168 + }
5.169 + }
5.170 +
5.171 + /**
5.172 + * Returns 0 after EOF has been reached, otherwise always return 1.
5.173 + * <p>
5.174 + * Programs should not count on this method to return the actual number
5.175 + * of bytes that could be read without blocking.
5.176 + *
5.177 + * @return 1 before EOF and 0 after EOF.
5.178 + * @exception IOException if an I/O error occurs.
5.179 + *
5.180 + */
5.181 + public int available() throws IOException {
5.182 + ensureOpen();
5.183 + if (reachEOF) {
5.184 + return 0;
5.185 + } else {
5.186 + return 1;
5.187 + }
5.188 + }
5.189 +
5.190 + private byte[] b = new byte[512];
5.191 +
5.192 + /**
5.193 + * Skips specified number of bytes of uncompressed data.
5.194 + * @param n the number of bytes to skip
5.195 + * @return the actual number of bytes skipped.
5.196 + * @exception IOException if an I/O error has occurred
5.197 + * @exception IllegalArgumentException if n < 0
5.198 + */
5.199 + public long skip(long n) throws IOException {
5.200 + if (n < 0) {
5.201 + throw new IllegalArgumentException("negative skip length");
5.202 + }
5.203 + ensureOpen();
5.204 + int max = (int)Math.min(n, Integer.MAX_VALUE);
5.205 + int total = 0;
5.206 + while (total < max) {
5.207 + int len = max - total;
5.208 + if (len > b.length) {
5.209 + len = b.length;
5.210 + }
5.211 + len = read(b, 0, len);
5.212 + if (len == -1) {
5.213 + reachEOF = true;
5.214 + break;
5.215 + }
5.216 + total += len;
5.217 + }
5.218 + return total;
5.219 + }
5.220 +
5.221 + /**
5.222 + * Closes this input stream and releases any system resources associated
5.223 + * with the stream.
5.224 + * @exception IOException if an I/O error has occurred
5.225 + */
5.226 + public void close() throws IOException {
5.227 + if (!closed) {
5.228 + if (usesDefaultInflater)
5.229 + inf.end();
5.230 + in.close();
5.231 + closed = true;
5.232 + }
5.233 + }
5.234 +
5.235 + /**
5.236 + * Fills input buffer with more data to decompress.
5.237 + * @exception IOException if an I/O error has occurred
5.238 + */
5.239 + protected void fill() throws IOException {
5.240 + ensureOpen();
5.241 + len = in.read(buf, 0, buf.length);
5.242 + if (len == -1) {
5.243 + throw new EOFException("Unexpected end of ZLIB input stream");
5.244 + }
5.245 + inf.setInput(buf, 0, len);
5.246 + }
5.247 +
5.248 + /**
5.249 + * Tests if this input stream supports the <code>mark</code> and
5.250 + * <code>reset</code> methods. The <code>markSupported</code>
5.251 + * method of <code>InflaterInputStream</code> returns
5.252 + * <code>false</code>.
5.253 + *
5.254 + * @return a <code>boolean</code> indicating if this stream type supports
5.255 + * the <code>mark</code> and <code>reset</code> methods.
5.256 + * @see java.io.InputStream#mark(int)
5.257 + * @see java.io.InputStream#reset()
5.258 + */
5.259 + public boolean markSupported() {
5.260 + return false;
5.261 + }
5.262 +
5.263 + /**
5.264 + * Marks the current position in this input stream.
5.265 + *
5.266 + * <p> The <code>mark</code> method of <code>InflaterInputStream</code>
5.267 + * does nothing.
5.268 + *
5.269 + * @param readlimit the maximum limit of bytes that can be read before
5.270 + * the mark position becomes invalid.
5.271 + * @see java.io.InputStream#reset()
5.272 + */
5.273 + public synchronized void mark(int readlimit) {
5.274 + }
5.275 +
5.276 + /**
5.277 + * Repositions this stream to the position at the time the
5.278 + * <code>mark</code> method was last called on this input stream.
5.279 + *
5.280 + * <p> The method <code>reset</code> for class
5.281 + * <code>InflaterInputStream</code> does nothing except throw an
5.282 + * <code>IOException</code>.
5.283 + *
5.284 + * @exception IOException if this method is invoked.
5.285 + * @see java.io.InputStream#mark(int)
5.286 + * @see java.io.IOException
5.287 + */
5.288 + public synchronized void reset() throws IOException {
5.289 + throw new IOException("mark/reset not supported");
5.290 + }
5.291 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/emul/mini/src/main/java/java/util/zip/ZStreamRef.java Wed Jan 30 14:01:52 2013 +0100
6.3 @@ -0,0 +1,46 @@
6.4 +/*
6.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.7 + *
6.8 + * This code is free software; you can redistribute it and/or modify it
6.9 + * under the terms of the GNU General Public License version 2 only, as
6.10 + * published by the Free Software Foundation. Oracle designates this
6.11 + * particular file as subject to the "Classpath" exception as provided
6.12 + * by Oracle in the LICENSE file that accompanied this code.
6.13 + *
6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.17 + * version 2 for more details (a copy is included in the LICENSE file that
6.18 + * accompanied this code).
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License version
6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.23 + *
6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6.25 + * or visit www.oracle.com if you need additional information or have any
6.26 + * questions.
6.27 + */
6.28 +
6.29 +package java.util.zip;
6.30 +
6.31 +/**
6.32 + * A reference to the native zlib's z_stream structure.
6.33 + */
6.34 +
6.35 +class ZStreamRef {
6.36 +
6.37 + private long address;
6.38 + ZStreamRef (long address) {
6.39 + this.address = address;
6.40 + }
6.41 +
6.42 + long address() {
6.43 + return address;
6.44 + }
6.45 +
6.46 + void clear() {
6.47 + address = 0;
6.48 + }
6.49 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/emul/mini/src/main/java/java/util/zip/ZipConstants.java Wed Jan 30 14:01:52 2013 +0100
7.3 @@ -0,0 +1,98 @@
7.4 +/*
7.5 + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.7 + *
7.8 + * This code is free software; you can redistribute it and/or modify it
7.9 + * under the terms of the GNU General Public License version 2 only, as
7.10 + * published by the Free Software Foundation. Oracle designates this
7.11 + * particular file as subject to the "Classpath" exception as provided
7.12 + * by Oracle in the LICENSE file that accompanied this code.
7.13 + *
7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7.17 + * version 2 for more details (a copy is included in the LICENSE file that
7.18 + * accompanied this code).
7.19 + *
7.20 + * You should have received a copy of the GNU General Public License version
7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7.23 + *
7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7.25 + * or visit www.oracle.com if you need additional information or have any
7.26 + * questions.
7.27 + */
7.28 +
7.29 +package java.util.zip;
7.30 +
7.31 +/*
7.32 + * This interface defines the constants that are used by the classes
7.33 + * which manipulate ZIP files.
7.34 + *
7.35 + * @author David Connelly
7.36 + */
7.37 +interface ZipConstants {
7.38 + /*
7.39 + * Header signatures
7.40 + */
7.41 + static long LOCSIG = 0x04034b50L; // "PK\003\004"
7.42 + static long EXTSIG = 0x08074b50L; // "PK\007\008"
7.43 + static long CENSIG = 0x02014b50L; // "PK\001\002"
7.44 + static long ENDSIG = 0x06054b50L; // "PK\005\006"
7.45 +
7.46 + /*
7.47 + * Header sizes in bytes (including signatures)
7.48 + */
7.49 + static final int LOCHDR = 30; // LOC header size
7.50 + static final int EXTHDR = 16; // EXT header size
7.51 + static final int CENHDR = 46; // CEN header size
7.52 + static final int ENDHDR = 22; // END header size
7.53 +
7.54 + /*
7.55 + * Local file (LOC) header field offsets
7.56 + */
7.57 + static final int LOCVER = 4; // version needed to extract
7.58 + static final int LOCFLG = 6; // general purpose bit flag
7.59 + static final int LOCHOW = 8; // compression method
7.60 + static final int LOCTIM = 10; // modification time
7.61 + static final int LOCCRC = 14; // uncompressed file crc-32 value
7.62 + static final int LOCSIZ = 18; // compressed size
7.63 + static final int LOCLEN = 22; // uncompressed size
7.64 + static final int LOCNAM = 26; // filename length
7.65 + static final int LOCEXT = 28; // extra field length
7.66 +
7.67 + /*
7.68 + * Extra local (EXT) header field offsets
7.69 + */
7.70 + static final int EXTCRC = 4; // uncompressed file crc-32 value
7.71 + static final int EXTSIZ = 8; // compressed size
7.72 + static final int EXTLEN = 12; // uncompressed size
7.73 +
7.74 + /*
7.75 + * Central directory (CEN) header field offsets
7.76 + */
7.77 + static final int CENVEM = 4; // version made by
7.78 + static final int CENVER = 6; // version needed to extract
7.79 + static final int CENFLG = 8; // encrypt, decrypt flags
7.80 + static final int CENHOW = 10; // compression method
7.81 + static final int CENTIM = 12; // modification time
7.82 + static final int CENCRC = 16; // uncompressed file crc-32 value
7.83 + static final int CENSIZ = 20; // compressed size
7.84 + static final int CENLEN = 24; // uncompressed size
7.85 + static final int CENNAM = 28; // filename length
7.86 + static final int CENEXT = 30; // extra field length
7.87 + static final int CENCOM = 32; // comment length
7.88 + static final int CENDSK = 34; // disk number start
7.89 + static final int CENATT = 36; // internal file attributes
7.90 + static final int CENATX = 38; // external file attributes
7.91 + static final int CENOFF = 42; // LOC header offset
7.92 +
7.93 + /*
7.94 + * End of central directory (END) header field offsets
7.95 + */
7.96 + static final int ENDSUB = 8; // number of entries on this disk
7.97 + static final int ENDTOT = 10; // total number of entries
7.98 + static final int ENDSIZ = 12; // central directory size in bytes
7.99 + static final int ENDOFF = 16; // offset of first CEN header
7.100 + static final int ENDCOM = 20; // zip file comment length
7.101 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/emul/mini/src/main/java/java/util/zip/ZipConstants64.java Wed Jan 30 14:01:52 2013 +0100
8.3 @@ -0,0 +1,84 @@
8.4 +/*
8.5 + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8.7 + *
8.8 + * This code is free software; you can redistribute it and/or modify it
8.9 + * under the terms of the GNU General Public License version 2 only, as
8.10 + * published by the Free Software Foundation. Oracle designates this
8.11 + * particular file as subject to the "Classpath" exception as provided
8.12 + * by Oracle in the LICENSE file that accompanied this code.
8.13 + *
8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8.17 + * version 2 for more details (a copy is included in the LICENSE file that
8.18 + * accompanied this code).
8.19 + *
8.20 + * You should have received a copy of the GNU General Public License version
8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8.23 + *
8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8.25 + * or visit www.oracle.com if you need additional information or have any
8.26 + * questions.
8.27 + */
8.28 +
8.29 +package java.util.zip;
8.30 +
8.31 +/*
8.32 + * This class defines the constants that are used by the classes
8.33 + * which manipulate Zip64 files.
8.34 + */
8.35 +
8.36 +class ZipConstants64 {
8.37 +
8.38 + /*
8.39 + * ZIP64 constants
8.40 + */
8.41 + static final long ZIP64_ENDSIG = 0x06064b50L; // "PK\006\006"
8.42 + static final long ZIP64_LOCSIG = 0x07064b50L; // "PK\006\007"
8.43 + static final int ZIP64_ENDHDR = 56; // ZIP64 end header size
8.44 + static final int ZIP64_LOCHDR = 20; // ZIP64 end loc header size
8.45 + static final int ZIP64_EXTHDR = 24; // EXT header size
8.46 + static final int ZIP64_EXTID = 0x0001; // Extra field Zip64 header ID
8.47 +
8.48 + static final int ZIP64_MAGICCOUNT = 0xFFFF;
8.49 + static final long ZIP64_MAGICVAL = 0xFFFFFFFFL;
8.50 +
8.51 + /*
8.52 + * Zip64 End of central directory (END) header field offsets
8.53 + */
8.54 + static final int ZIP64_ENDLEN = 4; // size of zip64 end of central dir
8.55 + static final int ZIP64_ENDVEM = 12; // version made by
8.56 + static final int ZIP64_ENDVER = 14; // version needed to extract
8.57 + static final int ZIP64_ENDNMD = 16; // number of this disk
8.58 + static final int ZIP64_ENDDSK = 20; // disk number of start
8.59 + static final int ZIP64_ENDTOD = 24; // total number of entries on this disk
8.60 + static final int ZIP64_ENDTOT = 32; // total number of entries
8.61 + static final int ZIP64_ENDSIZ = 40; // central directory size in bytes
8.62 + static final int ZIP64_ENDOFF = 48; // offset of first CEN header
8.63 + static final int ZIP64_ENDEXT = 56; // zip64 extensible data sector
8.64 +
8.65 + /*
8.66 + * Zip64 End of central directory locator field offsets
8.67 + */
8.68 + static final int ZIP64_LOCDSK = 4; // disk number start
8.69 + static final int ZIP64_LOCOFF = 8; // offset of zip64 end
8.70 + static final int ZIP64_LOCTOT = 16; // total number of disks
8.71 +
8.72 + /*
8.73 + * Zip64 Extra local (EXT) header field offsets
8.74 + */
8.75 + static final int ZIP64_EXTCRC = 4; // uncompressed file crc-32 value
8.76 + static final int ZIP64_EXTSIZ = 8; // compressed size, 8-byte
8.77 + static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte
8.78 +
8.79 + /*
8.80 + * Language encoding flag EFS
8.81 + */
8.82 + static final int EFS = 0x800; // If this bit is set the filename and
8.83 + // comment fields for this file must be
8.84 + // encoded using UTF-8.
8.85 +
8.86 + private ZipConstants64() {}
8.87 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/emul/mini/src/main/java/java/util/zip/ZipEntry.java Wed Jan 30 14:01:52 2013 +0100
9.3 @@ -0,0 +1,327 @@
9.4 +/*
9.5 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9.7 + *
9.8 + * This code is free software; you can redistribute it and/or modify it
9.9 + * under the terms of the GNU General Public License version 2 only, as
9.10 + * published by the Free Software Foundation. Oracle designates this
9.11 + * particular file as subject to the "Classpath" exception as provided
9.12 + * by Oracle in the LICENSE file that accompanied this code.
9.13 + *
9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9.17 + * version 2 for more details (a copy is included in the LICENSE file that
9.18 + * accompanied this code).
9.19 + *
9.20 + * You should have received a copy of the GNU General Public License version
9.21 + * 2 along with this work; if not, write to the Free Software Foundation,
9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9.23 + *
9.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9.25 + * or visit www.oracle.com if you need additional information or have any
9.26 + * questions.
9.27 + */
9.28 +
9.29 +package java.util.zip;
9.30 +
9.31 +import java.util.Date;
9.32 +
9.33 +/**
9.34 + * This class is used to represent a ZIP file entry.
9.35 + *
9.36 + * @author David Connelly
9.37 + */
9.38 +public
9.39 +class ZipEntry implements ZipConstants, Cloneable {
9.40 + String name; // entry name
9.41 + long time = -1; // modification time (in DOS time)
9.42 + long crc = -1; // crc-32 of entry data
9.43 + long size = -1; // uncompressed size of entry data
9.44 + long csize = -1; // compressed size of entry data
9.45 + int method = -1; // compression method
9.46 + int flag = 0; // general purpose flag
9.47 + byte[] extra; // optional extra field data for entry
9.48 + String comment; // optional comment string for entry
9.49 +
9.50 + /**
9.51 + * Compression method for uncompressed entries.
9.52 + */
9.53 + public static final int STORED = 0;
9.54 +
9.55 + /**
9.56 + * Compression method for compressed (deflated) entries.
9.57 + */
9.58 + public static final int DEFLATED = 8;
9.59 +
9.60 + /**
9.61 + * Creates a new zip entry with the specified name.
9.62 + *
9.63 + * @param name the entry name
9.64 + * @exception NullPointerException if the entry name is null
9.65 + * @exception IllegalArgumentException if the entry name is longer than
9.66 + * 0xFFFF bytes
9.67 + */
9.68 + public ZipEntry(String name) {
9.69 + if (name == null) {
9.70 + throw new NullPointerException();
9.71 + }
9.72 + if (name.length() > 0xFFFF) {
9.73 + throw new IllegalArgumentException("entry name too long");
9.74 + }
9.75 + this.name = name;
9.76 + }
9.77 +
9.78 + /**
9.79 + * Creates a new zip entry with fields taken from the specified
9.80 + * zip entry.
9.81 + * @param e a zip Entry object
9.82 + */
9.83 + public ZipEntry(ZipEntry e) {
9.84 + name = e.name;
9.85 + time = e.time;
9.86 + crc = e.crc;
9.87 + size = e.size;
9.88 + csize = e.csize;
9.89 + method = e.method;
9.90 + flag = e.flag;
9.91 + extra = e.extra;
9.92 + comment = e.comment;
9.93 + }
9.94 +
9.95 + /*
9.96 + * Creates a new un-initialized zip entry
9.97 + */
9.98 + ZipEntry() {}
9.99 +
9.100 + /**
9.101 + * Returns the name of the entry.
9.102 + * @return the name of the entry
9.103 + */
9.104 + public String getName() {
9.105 + return name;
9.106 + }
9.107 +
9.108 + /**
9.109 + * Sets the modification time of the entry.
9.110 + * @param time the entry modification time in number of milliseconds
9.111 + * since the epoch
9.112 + * @see #getTime()
9.113 + */
9.114 + public void setTime(long time) {
9.115 + this.time = javaToDosTime(time);
9.116 + }
9.117 +
9.118 + /**
9.119 + * Returns the modification time of the entry, or -1 if not specified.
9.120 + * @return the modification time of the entry, or -1 if not specified
9.121 + * @see #setTime(long)
9.122 + */
9.123 + public long getTime() {
9.124 + return time != -1 ? dosToJavaTime(time) : -1;
9.125 + }
9.126 +
9.127 + /**
9.128 + * Sets the uncompressed size of the entry data.
9.129 + * @param size the uncompressed size in bytes
9.130 + * @exception IllegalArgumentException if the specified size is less
9.131 + * than 0, is greater than 0xFFFFFFFF when
9.132 + * <a href="package-summary.html#zip64">ZIP64 format</a> is not supported,
9.133 + * or is less than 0 when ZIP64 is supported
9.134 + * @see #getSize()
9.135 + */
9.136 + public void setSize(long size) {
9.137 + if (size < 0) {
9.138 + throw new IllegalArgumentException("invalid entry size");
9.139 + }
9.140 + this.size = size;
9.141 + }
9.142 +
9.143 + /**
9.144 + * Returns the uncompressed size of the entry data, or -1 if not known.
9.145 + * @return the uncompressed size of the entry data, or -1 if not known
9.146 + * @see #setSize(long)
9.147 + */
9.148 + public long getSize() {
9.149 + return size;
9.150 + }
9.151 +
9.152 + /**
9.153 + * Returns the size of the compressed entry data, or -1 if not known.
9.154 + * In the case of a stored entry, the compressed size will be the same
9.155 + * as the uncompressed size of the entry.
9.156 + * @return the size of the compressed entry data, or -1 if not known
9.157 + * @see #setCompressedSize(long)
9.158 + */
9.159 + public long getCompressedSize() {
9.160 + return csize;
9.161 + }
9.162 +
9.163 + /**
9.164 + * Sets the size of the compressed entry data.
9.165 + * @param csize the compressed size to set to
9.166 + * @see #getCompressedSize()
9.167 + */
9.168 + public void setCompressedSize(long csize) {
9.169 + this.csize = csize;
9.170 + }
9.171 +
9.172 + /**
9.173 + * Sets the CRC-32 checksum of the uncompressed entry data.
9.174 + * @param crc the CRC-32 value
9.175 + * @exception IllegalArgumentException if the specified CRC-32 value is
9.176 + * less than 0 or greater than 0xFFFFFFFF
9.177 + * @see #getCrc()
9.178 + */
9.179 + public void setCrc(long crc) {
9.180 + if (crc < 0 || crc > 0xFFFFFFFFL) {
9.181 + throw new IllegalArgumentException("invalid entry crc-32");
9.182 + }
9.183 + this.crc = crc;
9.184 + }
9.185 +
9.186 + /**
9.187 + * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
9.188 + * not known.
9.189 + * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
9.190 + * not known
9.191 + * @see #setCrc(long)
9.192 + */
9.193 + public long getCrc() {
9.194 + return crc;
9.195 + }
9.196 +
9.197 + /**
9.198 + * Sets the compression method for the entry.
9.199 + * @param method the compression method, either STORED or DEFLATED
9.200 + * @exception IllegalArgumentException if the specified compression
9.201 + * method is invalid
9.202 + * @see #getMethod()
9.203 + */
9.204 + public void setMethod(int method) {
9.205 + if (method != STORED && method != DEFLATED) {
9.206 + throw new IllegalArgumentException("invalid compression method");
9.207 + }
9.208 + this.method = method;
9.209 + }
9.210 +
9.211 + /**
9.212 + * Returns the compression method of the entry, or -1 if not specified.
9.213 + * @return the compression method of the entry, or -1 if not specified
9.214 + * @see #setMethod(int)
9.215 + */
9.216 + public int getMethod() {
9.217 + return method;
9.218 + }
9.219 +
9.220 + /**
9.221 + * Sets the optional extra field data for the entry.
9.222 + * @param extra the extra field data bytes
9.223 + * @exception IllegalArgumentException if the length of the specified
9.224 + * extra field data is greater than 0xFFFF bytes
9.225 + * @see #getExtra()
9.226 + */
9.227 + public void setExtra(byte[] extra) {
9.228 + if (extra != null && extra.length > 0xFFFF) {
9.229 + throw new IllegalArgumentException("invalid extra field length");
9.230 + }
9.231 + this.extra = extra;
9.232 + }
9.233 +
9.234 + /**
9.235 + * Returns the extra field data for the entry, or null if none.
9.236 + * @return the extra field data for the entry, or null if none
9.237 + * @see #setExtra(byte[])
9.238 + */
9.239 + public byte[] getExtra() {
9.240 + return extra;
9.241 + }
9.242 +
9.243 + /**
9.244 + * Sets the optional comment string for the entry.
9.245 + *
9.246 + * <p>ZIP entry comments have maximum length of 0xffff. If the length of the
9.247 + * specified comment string is greater than 0xFFFF bytes after encoding, only
9.248 + * the first 0xFFFF bytes are output to the ZIP file entry.
9.249 + *
9.250 + * @param comment the comment string
9.251 + *
9.252 + * @see #getComment()
9.253 + */
9.254 + public void setComment(String comment) {
9.255 + this.comment = comment;
9.256 + }
9.257 +
9.258 + /**
9.259 + * Returns the comment string for the entry, or null if none.
9.260 + * @return the comment string for the entry, or null if none
9.261 + * @see #setComment(String)
9.262 + */
9.263 + public String getComment() {
9.264 + return comment;
9.265 + }
9.266 +
9.267 + /**
9.268 + * Returns true if this is a directory entry. A directory entry is
9.269 + * defined to be one whose name ends with a '/'.
9.270 + * @return true if this is a directory entry
9.271 + */
9.272 + public boolean isDirectory() {
9.273 + return name.endsWith("/");
9.274 + }
9.275 +
9.276 + /**
9.277 + * Returns a string representation of the ZIP entry.
9.278 + */
9.279 + public String toString() {
9.280 + return getName();
9.281 + }
9.282 +
9.283 + /*
9.284 + * Converts DOS time to Java time (number of milliseconds since epoch).
9.285 + */
9.286 + private static long dosToJavaTime(long dtime) {
9.287 + Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
9.288 + (int)(((dtime >> 21) & 0x0f) - 1),
9.289 + (int)((dtime >> 16) & 0x1f),
9.290 + (int)((dtime >> 11) & 0x1f),
9.291 + (int)((dtime >> 5) & 0x3f),
9.292 + (int)((dtime << 1) & 0x3e));
9.293 + return d.getTime();
9.294 + }
9.295 +
9.296 + /*
9.297 + * Converts Java time to DOS time.
9.298 + */
9.299 + private static long javaToDosTime(long time) {
9.300 + Date d = new Date(time);
9.301 + int year = d.getYear() + 1900;
9.302 + if (year < 1980) {
9.303 + return (1 << 21) | (1 << 16);
9.304 + }
9.305 + return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
9.306 + d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
9.307 + d.getSeconds() >> 1;
9.308 + }
9.309 +
9.310 + /**
9.311 + * Returns the hash code value for this entry.
9.312 + */
9.313 + public int hashCode() {
9.314 + return name.hashCode();
9.315 + }
9.316 +
9.317 + /**
9.318 + * Returns a copy of this entry.
9.319 + */
9.320 + public Object clone() {
9.321 + try {
9.322 + ZipEntry e = (ZipEntry)super.clone();
9.323 + e.extra = (extra == null) ? null : extra.clone();
9.324 + return e;
9.325 + } catch (CloneNotSupportedException e) {
9.326 + // This should never happen, since we are Cloneable
9.327 + throw new InternalError();
9.328 + }
9.329 + }
9.330 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/emul/mini/src/main/java/java/util/zip/ZipException.java Wed Jan 30 14:01:52 2013 +0100
10.3 @@ -0,0 +1,60 @@
10.4 +/*
10.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10.7 + *
10.8 + * This code is free software; you can redistribute it and/or modify it
10.9 + * under the terms of the GNU General Public License version 2 only, as
10.10 + * published by the Free Software Foundation. Oracle designates this
10.11 + * particular file as subject to the "Classpath" exception as provided
10.12 + * by Oracle in the LICENSE file that accompanied this code.
10.13 + *
10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10.17 + * version 2 for more details (a copy is included in the LICENSE file that
10.18 + * accompanied this code).
10.19 + *
10.20 + * You should have received a copy of the GNU General Public License version
10.21 + * 2 along with this work; if not, write to the Free Software Foundation,
10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10.23 + *
10.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10.25 + * or visit www.oracle.com if you need additional information or have any
10.26 + * questions.
10.27 + */
10.28 +
10.29 +package java.util.zip;
10.30 +
10.31 +import java.io.IOException;
10.32 +
10.33 +/**
10.34 + * Signals that a Zip exception of some sort has occurred.
10.35 + *
10.36 + * @author unascribed
10.37 + * @see java.io.IOException
10.38 + * @since JDK1.0
10.39 + */
10.40 +
10.41 +public
10.42 +class ZipException extends IOException {
10.43 + private static final long serialVersionUID = 8000196834066748623L;
10.44 +
10.45 + /**
10.46 + * Constructs a <code>ZipException</code> with <code>null</code>
10.47 + * as its error detail message.
10.48 + */
10.49 + public ZipException() {
10.50 + super();
10.51 + }
10.52 +
10.53 + /**
10.54 + * Constructs a <code>ZipException</code> with the specified detail
10.55 + * message.
10.56 + *
10.57 + * @param s the detail message.
10.58 + */
10.59 +
10.60 + public ZipException(String s) {
10.61 + super(s);
10.62 + }
10.63 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/emul/mini/src/main/java/java/util/zip/ZipInputStream.java Wed Jan 30 14:01:52 2013 +0100
11.3 @@ -0,0 +1,456 @@
11.4 +/*
11.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11.7 + *
11.8 + * This code is free software; you can redistribute it and/or modify it
11.9 + * under the terms of the GNU General Public License version 2 only, as
11.10 + * published by the Free Software Foundation. Oracle designates this
11.11 + * particular file as subject to the "Classpath" exception as provided
11.12 + * by Oracle in the LICENSE file that accompanied this code.
11.13 + *
11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11.17 + * version 2 for more details (a copy is included in the LICENSE file that
11.18 + * accompanied this code).
11.19 + *
11.20 + * You should have received a copy of the GNU General Public License version
11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11.23 + *
11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
11.25 + * or visit www.oracle.com if you need additional information or have any
11.26 + * questions.
11.27 + */
11.28 +
11.29 +package java.util.zip;
11.30 +
11.31 +import java.io.InputStream;
11.32 +import java.io.IOException;
11.33 +import java.io.EOFException;
11.34 +import java.io.PushbackInputStream;
11.35 +import java.nio.charset.Charset;
11.36 +import java.nio.charset.StandardCharsets;
11.37 +import static java.util.zip.ZipConstants64.*;
11.38 +
11.39 +/**
11.40 + * This class implements an input stream filter for reading files in the
11.41 + * ZIP file format. Includes support for both compressed and uncompressed
11.42 + * entries.
11.43 + *
11.44 + * @author David Connelly
11.45 + */
11.46 +public
11.47 +class ZipInputStream extends InflaterInputStream implements ZipConstants {
11.48 + private ZipEntry entry;
11.49 + private int flag;
11.50 + private CRC32 crc = new CRC32();
11.51 + private long remaining;
11.52 + private byte[] tmpbuf = new byte[512];
11.53 +
11.54 + private static final int STORED = ZipEntry.STORED;
11.55 + private static final int DEFLATED = ZipEntry.DEFLATED;
11.56 +
11.57 + private boolean closed = false;
11.58 + // this flag is set to true after EOF has reached for
11.59 + // one entry
11.60 + private boolean entryEOF = false;
11.61 +
11.62 + private ZipCoder zc;
11.63 +
11.64 + /**
11.65 + * Check to make sure that this stream has not been closed
11.66 + */
11.67 + private void ensureOpen() throws IOException {
11.68 + if (closed) {
11.69 + throw new IOException("Stream closed");
11.70 + }
11.71 + }
11.72 +
11.73 + /**
11.74 + * Creates a new ZIP input stream.
11.75 + *
11.76 + * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
11.77 + * decode the entry names.
11.78 + *
11.79 + * @param in the actual input stream
11.80 + */
11.81 + public ZipInputStream(InputStream in) {
11.82 + this(in, StandardCharsets.UTF_8);
11.83 + }
11.84 +
11.85 + /**
11.86 + * Creates a new ZIP input stream.
11.87 + *
11.88 + * @param in the actual input stream
11.89 + *
11.90 + * @param charset
11.91 + * The {@linkplain java.nio.charset.Charset charset} to be
11.92 + * used to decode the ZIP entry name (ignored if the
11.93 + * <a href="package-summary.html#lang_encoding"> language
11.94 + * encoding bit</a> of the ZIP entry's general purpose bit
11.95 + * flag is set).
11.96 + *
11.97 + * @since 1.7
11.98 + */
11.99 + public ZipInputStream(InputStream in, Charset charset) {
11.100 + super(new PushbackInputStream(in, 512), new Inflater(true), 512);
11.101 + usesDefaultInflater = true;
11.102 + if(in == null) {
11.103 + throw new NullPointerException("in is null");
11.104 + }
11.105 + if (charset == null)
11.106 + throw new NullPointerException("charset is null");
11.107 + this.zc = ZipCoder.get(charset);
11.108 + }
11.109 +
11.110 + /**
11.111 + * Reads the next ZIP file entry and positions the stream at the
11.112 + * beginning of the entry data.
11.113 + * @return the next ZIP file entry, or null if there are no more entries
11.114 + * @exception ZipException if a ZIP file error has occurred
11.115 + * @exception IOException if an I/O error has occurred
11.116 + */
11.117 + public ZipEntry getNextEntry() throws IOException {
11.118 + ensureOpen();
11.119 + if (entry != null) {
11.120 + closeEntry();
11.121 + }
11.122 + crc.reset();
11.123 + inf.reset();
11.124 + if ((entry = readLOC()) == null) {
11.125 + return null;
11.126 + }
11.127 + if (entry.method == STORED) {
11.128 + remaining = entry.size;
11.129 + }
11.130 + entryEOF = false;
11.131 + return entry;
11.132 + }
11.133 +
11.134 + /**
11.135 + * Closes the current ZIP entry and positions the stream for reading the
11.136 + * next entry.
11.137 + * @exception ZipException if a ZIP file error has occurred
11.138 + * @exception IOException if an I/O error has occurred
11.139 + */
11.140 + public void closeEntry() throws IOException {
11.141 + ensureOpen();
11.142 + while (read(tmpbuf, 0, tmpbuf.length) != -1) ;
11.143 + entryEOF = true;
11.144 + }
11.145 +
11.146 + /**
11.147 + * Returns 0 after EOF has reached for the current entry data,
11.148 + * otherwise always return 1.
11.149 + * <p>
11.150 + * Programs should not count on this method to return the actual number
11.151 + * of bytes that could be read without blocking.
11.152 + *
11.153 + * @return 1 before EOF and 0 after EOF has reached for current entry.
11.154 + * @exception IOException if an I/O error occurs.
11.155 + *
11.156 + */
11.157 + public int available() throws IOException {
11.158 + ensureOpen();
11.159 + if (entryEOF) {
11.160 + return 0;
11.161 + } else {
11.162 + return 1;
11.163 + }
11.164 + }
11.165 +
11.166 + /**
11.167 + * Reads from the current ZIP entry into an array of bytes.
11.168 + * If <code>len</code> is not zero, the method
11.169 + * blocks until some input is available; otherwise, no
11.170 + * bytes are read and <code>0</code> is returned.
11.171 + * @param b the buffer into which the data is read
11.172 + * @param off the start offset in the destination array <code>b</code>
11.173 + * @param len the maximum number of bytes read
11.174 + * @return the actual number of bytes read, or -1 if the end of the
11.175 + * entry is reached
11.176 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
11.177 + * @exception IndexOutOfBoundsException if <code>off</code> is negative,
11.178 + * <code>len</code> is negative, or <code>len</code> is greater than
11.179 + * <code>b.length - off</code>
11.180 + * @exception ZipException if a ZIP file error has occurred
11.181 + * @exception IOException if an I/O error has occurred
11.182 + */
11.183 + public int read(byte[] b, int off, int len) throws IOException {
11.184 + ensureOpen();
11.185 + if (off < 0 || len < 0 || off > b.length - len) {
11.186 + throw new IndexOutOfBoundsException();
11.187 + } else if (len == 0) {
11.188 + return 0;
11.189 + }
11.190 +
11.191 + if (entry == null) {
11.192 + return -1;
11.193 + }
11.194 + switch (entry.method) {
11.195 + case DEFLATED:
11.196 + len = super.read(b, off, len);
11.197 + if (len == -1) {
11.198 + readEnd(entry);
11.199 + entryEOF = true;
11.200 + entry = null;
11.201 + } else {
11.202 + crc.update(b, off, len);
11.203 + }
11.204 + return len;
11.205 + case STORED:
11.206 + if (remaining <= 0) {
11.207 + entryEOF = true;
11.208 + entry = null;
11.209 + return -1;
11.210 + }
11.211 + if (len > remaining) {
11.212 + len = (int)remaining;
11.213 + }
11.214 + len = in.read(b, off, len);
11.215 + if (len == -1) {
11.216 + throw new ZipException("unexpected EOF");
11.217 + }
11.218 + crc.update(b, off, len);
11.219 + remaining -= len;
11.220 + if (remaining == 0 && entry.crc != crc.getValue()) {
11.221 + throw new ZipException(
11.222 + "invalid entry CRC (expected 0x" + Long.toHexString(entry.crc) +
11.223 + " but got 0x" + Long.toHexString(crc.getValue()) + ")");
11.224 + }
11.225 + return len;
11.226 + default:
11.227 + throw new ZipException("invalid compression method");
11.228 + }
11.229 + }
11.230 +
11.231 + /**
11.232 + * Skips specified number of bytes in the current ZIP entry.
11.233 + * @param n the number of bytes to skip
11.234 + * @return the actual number of bytes skipped
11.235 + * @exception ZipException if a ZIP file error has occurred
11.236 + * @exception IOException if an I/O error has occurred
11.237 + * @exception IllegalArgumentException if n < 0
11.238 + */
11.239 + public long skip(long n) throws IOException {
11.240 + if (n < 0) {
11.241 + throw new IllegalArgumentException("negative skip length");
11.242 + }
11.243 + ensureOpen();
11.244 + int max = (int)Math.min(n, Integer.MAX_VALUE);
11.245 + int total = 0;
11.246 + while (total < max) {
11.247 + int len = max - total;
11.248 + if (len > tmpbuf.length) {
11.249 + len = tmpbuf.length;
11.250 + }
11.251 + len = read(tmpbuf, 0, len);
11.252 + if (len == -1) {
11.253 + entryEOF = true;
11.254 + break;
11.255 + }
11.256 + total += len;
11.257 + }
11.258 + return total;
11.259 + }
11.260 +
11.261 + /**
11.262 + * Closes this input stream and releases any system resources associated
11.263 + * with the stream.
11.264 + * @exception IOException if an I/O error has occurred
11.265 + */
11.266 + public void close() throws IOException {
11.267 + if (!closed) {
11.268 + super.close();
11.269 + closed = true;
11.270 + }
11.271 + }
11.272 +
11.273 + private byte[] b = new byte[256];
11.274 +
11.275 + /*
11.276 + * Reads local file (LOC) header for next entry.
11.277 + */
11.278 + private ZipEntry readLOC() throws IOException {
11.279 + try {
11.280 + readFully(tmpbuf, 0, LOCHDR);
11.281 + } catch (EOFException e) {
11.282 + return null;
11.283 + }
11.284 + if (get32(tmpbuf, 0) != LOCSIG) {
11.285 + return null;
11.286 + }
11.287 + // get flag first, we need check EFS.
11.288 + flag = get16(tmpbuf, LOCFLG);
11.289 + // get the entry name and create the ZipEntry first
11.290 + int len = get16(tmpbuf, LOCNAM);
11.291 + int blen = b.length;
11.292 + if (len > blen) {
11.293 + do
11.294 + blen = blen * 2;
11.295 + while (len > blen);
11.296 + b = new byte[blen];
11.297 + }
11.298 + readFully(b, 0, len);
11.299 + // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
11.300 + ZipEntry e = createZipEntry(((flag & EFS) != 0)
11.301 + ? zc.toStringUTF8(b, len)
11.302 + : zc.toString(b, len));
11.303 + // now get the remaining fields for the entry
11.304 + if ((flag & 1) == 1) {
11.305 + throw new ZipException("encrypted ZIP entry not supported");
11.306 + }
11.307 + e.method = get16(tmpbuf, LOCHOW);
11.308 + e.time = get32(tmpbuf, LOCTIM);
11.309 + if ((flag & 8) == 8) {
11.310 + /* "Data Descriptor" present */
11.311 + if (e.method != DEFLATED) {
11.312 + throw new ZipException(
11.313 + "only DEFLATED entries can have EXT descriptor");
11.314 + }
11.315 + } else {
11.316 + e.crc = get32(tmpbuf, LOCCRC);
11.317 + e.csize = get32(tmpbuf, LOCSIZ);
11.318 + e.size = get32(tmpbuf, LOCLEN);
11.319 + }
11.320 + len = get16(tmpbuf, LOCEXT);
11.321 + if (len > 0) {
11.322 + byte[] bb = new byte[len];
11.323 + readFully(bb, 0, len);
11.324 + e.setExtra(bb);
11.325 + // extra fields are in "HeaderID(2)DataSize(2)Data... format
11.326 + if (e.csize == ZIP64_MAGICVAL || e.size == ZIP64_MAGICVAL) {
11.327 + int off = 0;
11.328 + while (off + 4 < len) {
11.329 + int sz = get16(bb, off + 2);
11.330 + if (get16(bb, off) == ZIP64_EXTID) {
11.331 + off += 4;
11.332 + // LOC extra zip64 entry MUST include BOTH original and
11.333 + // compressed file size fields
11.334 + if (sz < 16 || (off + sz) > len ) {
11.335 + // Invalid zip64 extra fields, simply skip. Even it's
11.336 + // rare, it's possible the entry size happens to be
11.337 + // the magic value and it "accidnetly" has some bytes
11.338 + // in extra match the id.
11.339 + return e;
11.340 + }
11.341 + e.size = get64(bb, off);
11.342 + e.csize = get64(bb, off + 8);
11.343 + break;
11.344 + }
11.345 + off += (sz + 4);
11.346 + }
11.347 + }
11.348 + }
11.349 + return e;
11.350 + }
11.351 +
11.352 + /**
11.353 + * Creates a new <code>ZipEntry</code> object for the specified
11.354 + * entry name.
11.355 + *
11.356 + * @param name the ZIP file entry name
11.357 + * @return the ZipEntry just created
11.358 + */
11.359 + protected ZipEntry createZipEntry(String name) {
11.360 + return new ZipEntry(name);
11.361 + }
11.362 +
11.363 + /*
11.364 + * Reads end of deflated entry as well as EXT descriptor if present.
11.365 + */
11.366 + private void readEnd(ZipEntry e) throws IOException {
11.367 + int n = inf.getRemaining();
11.368 + if (n > 0) {
11.369 + ((PushbackInputStream)in).unread(buf, len - n, n);
11.370 + }
11.371 + if ((flag & 8) == 8) {
11.372 + /* "Data Descriptor" present */
11.373 + if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
11.374 + inf.getBytesRead() > ZIP64_MAGICVAL) {
11.375 + // ZIP64 format
11.376 + readFully(tmpbuf, 0, ZIP64_EXTHDR);
11.377 + long sig = get32(tmpbuf, 0);
11.378 + if (sig != EXTSIG) { // no EXTSIG present
11.379 + e.crc = sig;
11.380 + e.csize = get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC);
11.381 + e.size = get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC);
11.382 + ((PushbackInputStream)in).unread(
11.383 + tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
11.384 + } else {
11.385 + e.crc = get32(tmpbuf, ZIP64_EXTCRC);
11.386 + e.csize = get64(tmpbuf, ZIP64_EXTSIZ);
11.387 + e.size = get64(tmpbuf, ZIP64_EXTLEN);
11.388 + }
11.389 + } else {
11.390 + readFully(tmpbuf, 0, EXTHDR);
11.391 + long sig = get32(tmpbuf, 0);
11.392 + if (sig != EXTSIG) { // no EXTSIG present
11.393 + e.crc = sig;
11.394 + e.csize = get32(tmpbuf, EXTSIZ - EXTCRC);
11.395 + e.size = get32(tmpbuf, EXTLEN - EXTCRC);
11.396 + ((PushbackInputStream)in).unread(
11.397 + tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
11.398 + } else {
11.399 + e.crc = get32(tmpbuf, EXTCRC);
11.400 + e.csize = get32(tmpbuf, EXTSIZ);
11.401 + e.size = get32(tmpbuf, EXTLEN);
11.402 + }
11.403 + }
11.404 + }
11.405 + if (e.size != inf.getBytesWritten()) {
11.406 + throw new ZipException(
11.407 + "invalid entry size (expected " + e.size +
11.408 + " but got " + inf.getBytesWritten() + " bytes)");
11.409 + }
11.410 + if (e.csize != inf.getBytesRead()) {
11.411 + throw new ZipException(
11.412 + "invalid entry compressed size (expected " + e.csize +
11.413 + " but got " + inf.getBytesRead() + " bytes)");
11.414 + }
11.415 + if (e.crc != crc.getValue()) {
11.416 + throw new ZipException(
11.417 + "invalid entry CRC (expected 0x" + Long.toHexString(e.crc) +
11.418 + " but got 0x" + Long.toHexString(crc.getValue()) + ")");
11.419 + }
11.420 + }
11.421 +
11.422 + /*
11.423 + * Reads bytes, blocking until all bytes are read.
11.424 + */
11.425 + private void readFully(byte[] b, int off, int len) throws IOException {
11.426 + while (len > 0) {
11.427 + int n = in.read(b, off, len);
11.428 + if (n == -1) {
11.429 + throw new EOFException();
11.430 + }
11.431 + off += n;
11.432 + len -= n;
11.433 + }
11.434 + }
11.435 +
11.436 + /*
11.437 + * Fetches unsigned 16-bit value from byte array at specified offset.
11.438 + * The bytes are assumed to be in Intel (little-endian) byte order.
11.439 + */
11.440 + private static final int get16(byte b[], int off) {
11.441 + return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
11.442 + }
11.443 +
11.444 + /*
11.445 + * Fetches unsigned 32-bit value from byte array at specified offset.
11.446 + * The bytes are assumed to be in Intel (little-endian) byte order.
11.447 + */
11.448 + private static final long get32(byte b[], int off) {
11.449 + return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
11.450 + }
11.451 +
11.452 + /*
11.453 + * Fetches signed 64-bit value from byte array at specified offset.
11.454 + * The bytes are assumed to be in Intel (little-endian) byte order.
11.455 + */
11.456 + private static final long get64(byte b[], int off) {
11.457 + return get32(b, off) | (get32(b, off+4) << 32);
11.458 + }
11.459 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/emul/mini/src/main/java/java/util/zip/package.html Wed Jan 30 14:01:52 2013 +0100
12.3 @@ -0,0 +1,98 @@
12.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
12.5 +<html>
12.6 +<head>
12.7 +<!--
12.8 +Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
12.9 +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12.10 +
12.11 +This code is free software; you can redistribute it and/or modify it
12.12 +under the terms of the GNU General Public License version 2 only, as
12.13 +published by the Free Software Foundation. Oracle designates this
12.14 +particular file as subject to the "Classpath" exception as provided
12.15 +by Oracle in the LICENSE file that accompanied this code.
12.16 +
12.17 +This code is distributed in the hope that it will be useful, but WITHOUT
12.18 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12.19 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12.20 +version 2 for more details (a copy is included in the LICENSE file that
12.21 +accompanied this code).
12.22 +
12.23 +You should have received a copy of the GNU General Public License version
12.24 +2 along with this work; if not, write to the Free Software Foundation,
12.25 +Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12.26 +
12.27 +Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12.28 +or visit www.oracle.com if you need additional information or have any
12.29 +questions.
12.30 +-->
12.31 +
12.32 +</head>
12.33 +<body bgcolor="white">
12.34 +
12.35 +Provides classes for reading and writing the standard ZIP and GZIP
12.36 +file formats. Also includes classes for compressing and decompressing
12.37 +data using the DEFLATE compression algorithm, which is used by the
12.38 +ZIP and GZIP file formats. Additionally, there are utility classes
12.39 +for computing the CRC-32 and Adler-32 checksums of arbitrary
12.40 +input streams.
12.41 +
12.42 +
12.43 +<h2>Package Specification</h2>
12.44 +
12.45 +</a>
12.46 +<ul>
12.47 + <li><a href="ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip">
12.48 + Info-ZIP Application Note 970311
12.49 + </a> - a detailed description of the Info-ZIP format upon which
12.50 + the <code>java.util.zip</code> classes are based.
12.51 +<p>
12.52 + <a name="zip64">
12.53 + <li>An implementation may optionally support the ZIP64(tm) format extensions
12.54 + defined by the
12.55 + <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
12.56 + PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions
12.57 + are used to overcome the size limitations of the original ZIP format.
12.58 +<p>
12.59 + <a name="lang_encoding">
12.60 + <li>APPENDIX D of <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
12.61 + PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to
12.62 + encode ZIP entry filename and comment fields using UTF-8.
12.63 +<p>
12.64 + <li><a href="http://www.ietf.org/rfc/rfc1950.txt">
12.65 + ZLIB Compressed Data Format Specification version 3.3</a>
12.66 +
12.67 + <a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a>
12.68 + (RFC 1950)
12.69 +<p>
12.70 + <li><a href="http://www.ietf.org/rfc/rfc1951.txt">
12.71 + DEFLATE Compressed Data Format Specification version 1.3</a>
12.72 +
12.73 + <a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a>
12.74 + (RFC 1951)
12.75 +<p>
12.76 + <li><a href="http://www.ietf.org/rfc/rfc1952.txt">
12.77 + GZIP file format specification version 4.3</a>
12.78 +
12.79 + <a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a>
12.80 + (RFC 1952)
12.81 +<p>
12.82 + <li>CRC-32 checksum is described in RFC 1952 (above)
12.83 +<p>
12.84 + <li>Adler-32 checksum is described in RFC 1950 (above)
12.85 +</ul>
12.86 +
12.87 +
12.88 +<!--
12.89 +<h2>Related Documentation</h2>
12.90 +
12.91 +For overviews, tutorials, examples, guides, and tool documentation, please see:
12.92 +<ul>
12.93 + <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
12.94 +</ul>
12.95 +-->
12.96 +
12.97 +@since JDK1.1
12.98 +</body>
12.99 +</html>
12.100 +
12.101 +