Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1 @@
98ee3c5195646bd091190f6eec2481eb9c8a2a1b

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,430 @@
/*
* 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.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
*/
package java.util.concurrent.locks;
import java.util.concurrent.*;
/**
* Basic thread blocking primitives for creating locks and other
* synchronization classes.
*
* <p>This class associates, with each thread that uses it, a permit
* (in the sense of the {@link java.util.concurrent.Semaphore
* Semaphore} class). A call to {@code park} will return immediately
* if the permit is available, consuming it in the process; otherwise
* it <em>may</em> block. A call to {@code unpark} makes the permit
* available, if it was not already available. (Unlike with Semaphores
* though, permits do not accumulate. There is at most one.)
*
* <p>Methods {@code park} and {@code unpark} provide efficient
* means of blocking and unblocking threads that do not encounter the
* problems that cause the deprecated methods {@code Thread.suspend}
* and {@code Thread.resume} to be unusable for such purposes: Races
* between one thread invoking {@code park} and another thread trying
* to {@code unpark} it will preserve liveness, due to the
* permit. Additionally, {@code park} will return if the caller's
* thread was interrupted, and timeout versions are supported. The
* {@code park} method may also return at any other time, for "no
* reason", so in general must be invoked within a loop that rechecks
* conditions upon return. In this sense {@code park} serves as an
* optimization of a "busy wait" that does not waste as much time
* spinning, but must be paired with an {@code unpark} to be
* effective.
*
* <p>The three forms of {@code park} each also support a
* {@code blocker} object parameter. This object is recorded while
* the thread is blocked to permit monitoring and diagnostic tools to
* identify the reasons that threads are blocked. (Such tools may
* access blockers using method {@link #getBlocker}.) The use of these
* forms rather than the original forms without this parameter is
* strongly encouraged. The normal argument to supply as a
* {@code blocker} within a lock implementation is {@code this}.
*
* <p>These methods are designed to be used as tools for creating
* higher-level synchronization utilities, and are not in themselves
* useful for most concurrency control applications. The {@code park}
* method is designed for use only in constructions of the form:
* <pre>while (!canProceed()) { ... LockSupport.park(this); }</pre>
* where neither {@code canProceed} nor any other actions prior to the
* call to {@code park} entail locking or blocking. Because only one
* permit is associated with each thread, any intermediary uses of
* {@code park} could interfere with its intended effects.
*
* <p><b>Sample Usage.</b> Here is a sketch of a first-in-first-out
* non-reentrant lock class:
* <pre>{@code
* class FIFOMutex {
* private final AtomicBoolean locked = new AtomicBoolean(false);
* private final Queue<Thread> waiters
* = new ConcurrentLinkedQueue<Thread>();
*
* public void lock() {
* boolean wasInterrupted = false;
* Thread current = Thread.currentThread();
* waiters.add(current);
*
* // Block while not first in queue or cannot acquire lock
* while (waiters.peek() != current ||
* !locked.compareAndSet(false, true)) {
* LockSupport.park(this);
* if (Thread.interrupted()) // ignore interrupts while waiting
* wasInterrupted = true;
* }
*
* waiters.remove();
* if (wasInterrupted) // reassert interrupt status on exit
* current.interrupt();
* }
*
* public void unlock() {
* locked.set(false);
* LockSupport.unpark(waiters.peek());
* }
* }}</pre>
*/
public class LockSupport {
private LockSupport() {} // Cannot be instantiated.
private static final int PARK_STATE_RUNNING = 0;
private static final int PARK_STATE_PERMIT = 1;
private static final int PARK_STATE_PARKED = 2;
// these native methods are all implemented in map.xml
private static native void setBlocker(Thread t, Object obj);
private static native int cmpxchgParkState(Thread t, int newValue, int comparand);
private static native Object getParkLock(Thread t);
private static native void setParkLock(Thread t, Object obj);
/**
* Makes available the permit for the given thread, if it
* was not already available. If the thread was blocked on
* {@code park} then it will unblock. Otherwise, its next call
* to {@code park} is guaranteed not to block. This operation
* is not guaranteed to have any effect at all if the given
* thread has not been started.
*
* @param thread the thread to unpark, or {@code null}, in which case
* this operation has no effect
*/
public static void unpark(Thread thread) {
if (thread != null)
{
if (cmpxchgParkState(thread, PARK_STATE_PERMIT, PARK_STATE_RUNNING) == PARK_STATE_PARKED)
{
if (cmpxchgParkState(thread, PARK_STATE_RUNNING, PARK_STATE_PARKED) == PARK_STATE_PARKED)
{
// thread is currently blocking, so we have to release it
Object lock = getParkLock(thread);
synchronized (lock)
{
lock.notify();
}
}
}
}
}
private static void parkImpl(Thread currentThread, boolean deadline, long nanos)
{
if (cmpxchgParkState(currentThread, PARK_STATE_RUNNING, PARK_STATE_PERMIT) == PARK_STATE_PERMIT)
{
// we consumed a permit
return;
}
Object lock = getParkLock(currentThread);
if (lock == null)
{
// we lazily allocate the lock object
lock = new Object();
setParkLock(currentThread, lock);
}
synchronized (lock)
{
if (cmpxchgParkState(currentThread, PARK_STATE_PARKED, PARK_STATE_RUNNING) == PARK_STATE_PERMIT)
{
// entering the parked state failed because we got a permit after the previous permit test
// release the permit and return
cmpxchgParkState(currentThread, PARK_STATE_RUNNING, PARK_STATE_PERMIT);
return;
}
if (deadline)
{
nanos -= System.currentTimeMillis() * 1000000;
}
if (nanos >= 0)
{
try
{
lock.wait(nanos / 1000000, (int)(nanos % 1000000));
}
catch (InterruptedException _)
{
currentThread.interrupt();
}
}
cmpxchgParkState(currentThread, PARK_STATE_RUNNING, PARK_STATE_PARKED);
}
}
/**
* Disables the current thread for thread scheduling purposes unless the
* permit is available.
*
* <p>If the permit is available then it is consumed and the call returns
* immediately; otherwise
* the current thread becomes disabled for thread scheduling
* purposes and lies dormant until one of three things happens:
*
* <ul>
* <li>Some other thread invokes {@link #unpark unpark} with the
* current thread as the target; or
*
* <li>Some other thread {@linkplain Thread#interrupt interrupts}
* the current thread; or
*
* <li>The call spuriously (that is, for no reason) returns.
* </ul>
*
* <p>This method does <em>not</em> report which of these caused the
* method to return. Callers should re-check the conditions which caused
* the thread to park in the first place. Callers may also determine,
* for example, the interrupt status of the thread upon return.
*
* @param blocker the synchronization object responsible for this
* thread parking
* @since 1.6
*/
public static void park(Object blocker) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
parkImpl(t, false, 0L);
setBlocker(t, null);
}
/**
* Disables the current thread for thread scheduling purposes, for up to
* the specified waiting time, unless the permit is available.
*
* <p>If the permit is available then it is consumed and the call
* returns immediately; otherwise the current thread becomes disabled
* for thread scheduling purposes and lies dormant until one of four
* things happens:
*
* <ul>
* <li>Some other thread invokes {@link #unpark unpark} with the
* current thread as the target; or
*
* <li>Some other thread {@linkplain Thread#interrupt interrupts}
* the current thread; or
*
* <li>The specified waiting time elapses; or
*
* <li>The call spuriously (that is, for no reason) returns.
* </ul>
*
* <p>This method does <em>not</em> report which of these caused the
* method to return. Callers should re-check the conditions which caused
* the thread to park in the first place. Callers may also determine,
* for example, the interrupt status of the thread, or the elapsed time
* upon return.
*
* @param blocker the synchronization object responsible for this
* thread parking
* @param nanos the maximum number of nanoseconds to wait
* @since 1.6
*/
public static void parkNanos(Object blocker, long nanos) {
if (nanos > 0) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
parkImpl(t, false, nanos);
setBlocker(t, null);
}
}
/**
* Disables the current thread for thread scheduling purposes, until
* the specified deadline, unless the permit is available.
*
* <p>If the permit is available then it is consumed and the call
* returns immediately; otherwise the current thread becomes disabled
* for thread scheduling purposes and lies dormant until one of four
* things happens:
*
* <ul>
* <li>Some other thread invokes {@link #unpark unpark} with the
* current thread as the target; or
*
* <li>Some other thread {@linkplain Thread#interrupt interrupts} the
* current thread; or
*
* <li>The specified deadline passes; or
*
* <li>The call spuriously (that is, for no reason) returns.
* </ul>
*
* <p>This method does <em>not</em> report which of these caused the
* method to return. Callers should re-check the conditions which caused
* the thread to park in the first place. Callers may also determine,
* for example, the interrupt status of the thread, or the current time
* upon return.
*
* @param blocker the synchronization object responsible for this
* thread parking
* @param deadline the absolute time, in milliseconds from the Epoch,
* to wait until
* @since 1.6
*/
public static void parkUntil(Object blocker, long deadline) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
parkImpl(t, true, deadline);
setBlocker(t, null);
}
/**
* Returns the blocker object supplied to the most recent
* invocation of a park method that has not yet unblocked, or null
* if not blocked. The value returned is just a momentary
* snapshot -- the thread may have since unblocked or blocked on a
* different blocker object.
*
* @param t the thread
* @return the blocker
* @throws NullPointerException if argument is null
* @since 1.6
*/
public static native Object getBlocker(Thread t); // implemented in map.xml
/**
* Disables the current thread for thread scheduling purposes unless the
* permit is available.
*
* <p>If the permit is available then it is consumed and the call
* returns immediately; otherwise the current thread becomes disabled
* for thread scheduling purposes and lies dormant until one of three
* things happens:
*
* <ul>
*
* <li>Some other thread invokes {@link #unpark unpark} with the
* current thread as the target; or
*
* <li>Some other thread {@linkplain Thread#interrupt interrupts}
* the current thread; or
*
* <li>The call spuriously (that is, for no reason) returns.
* </ul>
*
* <p>This method does <em>not</em> report which of these caused the
* method to return. Callers should re-check the conditions which caused
* the thread to park in the first place. Callers may also determine,
* for example, the interrupt status of the thread upon return.
*/
public static void park() {
parkImpl(Thread.currentThread(), false, 0L);
}
/**
* Disables the current thread for thread scheduling purposes, for up to
* the specified waiting time, unless the permit is available.
*
* <p>If the permit is available then it is consumed and the call
* returns immediately; otherwise the current thread becomes disabled
* for thread scheduling purposes and lies dormant until one of four
* things happens:
*
* <ul>
* <li>Some other thread invokes {@link #unpark unpark} with the
* current thread as the target; or
*
* <li>Some other thread {@linkplain Thread#interrupt interrupts}
* the current thread; or
*
* <li>The specified waiting time elapses; or
*
* <li>The call spuriously (that is, for no reason) returns.
* </ul>
*
* <p>This method does <em>not</em> report which of these caused the
* method to return. Callers should re-check the conditions which caused
* the thread to park in the first place. Callers may also determine,
* for example, the interrupt status of the thread, or the elapsed time
* upon return.
*
* @param nanos the maximum number of nanoseconds to wait
*/
public static void parkNanos(long nanos) {
if (nanos > 0)
parkImpl(Thread.currentThread(), false, nanos);
}
/**
* Disables the current thread for thread scheduling purposes, until
* the specified deadline, unless the permit is available.
*
* <p>If the permit is available then it is consumed and the call
* returns immediately; otherwise the current thread becomes disabled
* for thread scheduling purposes and lies dormant until one of four
* things happens:
*
* <ul>
* <li>Some other thread invokes {@link #unpark unpark} with the
* current thread as the target; or
*
* <li>Some other thread {@linkplain Thread#interrupt interrupts}
* the current thread; or
*
* <li>The specified deadline passes; or
*
* <li>The call spuriously (that is, for no reason) returns.
* </ul>
*
* <p>This method does <em>not</em> report which of these caused the
* method to return. Callers should re-check the conditions which caused
* the thread to park in the first place. Callers may also determine,
* for example, the interrupt status of the thread, or the current time
* upon return.
*
* @param deadline the absolute time, in milliseconds from the Epoch,
* to wait until
*/
public static void parkUntil(long deadline) {
parkImpl(Thread.currentThread(), true, deadline);
}
}

View File

@@ -0,0 +1,205 @@
/* Adler32.java - Computes Adler32 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., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/*
* Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* The actual Adler32 algorithm is taken from RFC 1950.
* Status: Believed complete and correct.
*/
/**
* Computes Adler32 checksum for a stream of data. An Adler32
* checksum is not as reliable as a CRC32 checksum, but a lot faster to
* compute.
*<p>
* The specification for Adler32 may be found in RFC 1950.
* (ZLIB Compressed Data Format Specification version 3.3)
*<p>
*<p>
* From that document:
*<p>
* "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.
*<p>
* 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."
*<p>
* "8.2. The Adler-32 algorithm
*<p>
* The Adler-32 algorithm is much faster than the CRC32 algorithm yet
* still provides an extremely low probability of undetected errors.
*<p>
* 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.)
*<p>
* 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 adler; //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 <code>Adler32</code> class.
* The checksum starts off with a value of 1.
*/
public Adler32 ()
{
reset();
}
/**
* Resets the Adler32 checksum to the initial value.
*/
public void reset ()
{
adler = 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 = adler & 0xffff;
int s2 = adler >>> 16;
s1 = (s1 + (bval & 0xFF)) % BASE;
s2 = (s1 + s2) % BASE;
adler = (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 = adler & 0xffff;
int s2 = adler >>> 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;
}*/
adler = (s2 << 16) | s1;
}
/**
* Returns the Adler32 data checksum computed so far.
*/
public long getValue()
{
return (long) adler & 0xffffffffL;
}
}

View File

@@ -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., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/*
* 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); }
}

View File

@@ -0,0 +1,98 @@
/*
Copyright (C) 2013 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package java.util.zip;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.LinkedHashMap;
final class ClassStubZipEntry extends ZipEntry
{
private final String zipFilePath;
ClassStubZipEntry(String zipFilePath, String name)
{
super(name);
this.zipFilePath = zipFilePath;
}
private File getFile()
{
return new File(new File(zipFilePath).getParentFile().getParentFile(), "classes" + File.separator + name);
}
public long getSize()
{
if (size == -1)
{
size = getFile().length();
}
return size;
}
public long getCompressedSize()
{
if (csize == -1)
{
csize = getSize();
}
return csize;
}
public long getCrc()
{
if (crc == -1)
{
crc = computeCrc();
}
return crc;
}
private long computeCrc()
{
try (InputStream in = getInputStream())
{
CRC32 crc = new CRC32();
int b;
while ((b = in.read()) != -1)
{
crc.update(b);
}
return crc.getValue();
}
catch (IOException _)
{
return 0;
}
}
final InputStream getInputStream() throws IOException
{
return new FileInputStream(getFile());
}
static native void expandIkvmClasses(ZipFile zipFile, LinkedHashMap<String, ZipEntry> entries);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,78 @@
/* java.util.zip.DeflaterConstants
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
interface DeflaterConstants
{
boolean DEBUGGING = false;
int STORED_BLOCK = 0;
int STATIC_TREES = 1;
int DYN_TREES = 2;
int PRESET_DICT = 0x20;
int DEFAULT_MEM_LEVEL = 8;
int MAX_MATCH = 258;
int MIN_MATCH = 3;
int MAX_WBITS = 15;
int WSIZE = 1 << MAX_WBITS;
int WMASK = WSIZE - 1;
int HASH_BITS = DEFAULT_MEM_LEVEL + 7;
int HASH_SIZE = 1 << HASH_BITS;
int HASH_MASK = HASH_SIZE - 1;
int HASH_SHIFT = (HASH_BITS + MIN_MATCH - 1) / MIN_MATCH;
int MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;
int MAX_DIST = WSIZE - MIN_LOOKAHEAD;
int PENDING_BUF_SIZE = 1 << (DEFAULT_MEM_LEVEL + 8);
int MAX_BLOCK_SIZE = Math.min(65535, PENDING_BUF_SIZE-5);
int DEFLATE_STORED = 0;
int DEFLATE_FAST = 1;
int DEFLATE_SLOW = 2;
int GOOD_LENGTH[] = { 0,4, 4, 4, 4, 8, 8, 8, 32, 32 };
int MAX_LAZY[] = { 0,4, 5, 6, 4,16, 16, 32, 128, 258 };
int NICE_LENGTH[] = { 0,8,16,32,16,32,128,128, 258, 258 };
int MAX_CHAIN[] = { 0,4, 8,32,16,32,128,256,1024,4096 };
int COMPR_FUNC[] = { 0,1, 1, 1, 1, 2, 2, 2, 2, 2 };
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
/* java.util.zip.DeflaterPending
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/**
* This class stores the pending output of the Deflater.
*
* @author Jochen Hoenicke
* @date Jan 5, 2000
*/
class DeflaterPending extends PendingBuffer
{
public DeflaterPending()
{
super(DeflaterConstants.PENDING_BUF_SIZE);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,203 @@
/* java.util.zip.InflaterDynHeader
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
class InflaterDynHeader
{
private static final int LNUM = 0;
private static final int DNUM = 1;
private static final int BLNUM = 2;
private static final int BLLENS = 3;
private static final int LENS = 4;
private static final int REPS = 5;
private static final int repMin[] = { 3, 3, 11 };
private static final int repBits[] = { 2, 3, 7 };
private byte[] blLens;
private byte[] litdistLens;
private InflaterHuffmanTree blTree;
private int mode;
private int lnum, dnum, blnum, num;
private int repSymbol;
private byte lastLen;
private int ptr;
private static final int[] BL_ORDER =
{ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
public InflaterDynHeader()
{
}
public boolean decode(StreamManipulator input) throws DataFormatException
{
decode_loop:
for (;;)
{
switch (mode)
{
case LNUM:
lnum = input.peekBits(5);
if (lnum < 0)
return false;
lnum += 257;
input.dropBits(5);
// System.err.println("LNUM: "+lnum);
mode = DNUM;
/* fall through */
case DNUM:
dnum = input.peekBits(5);
if (dnum < 0)
return false;
dnum++;
input.dropBits(5);
// System.err.println("DNUM: "+dnum);
num = lnum+dnum;
litdistLens = new byte[num];
mode = BLNUM;
/* fall through */
case BLNUM:
blnum = input.peekBits(4);
if (blnum < 0)
return false;
blnum += 4;
input.dropBits(4);
blLens = new byte[19];
ptr = 0;
// System.err.println("BLNUM: "+blnum);
mode = BLLENS;
/* fall through */
case BLLENS:
while (ptr < blnum)
{
int len = input.peekBits(3);
if (len < 0)
return false;
input.dropBits(3);
// System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
blLens[BL_ORDER[ptr]] = (byte) len;
ptr++;
}
blTree = new InflaterHuffmanTree(blLens);
blLens = null;
ptr = 0;
mode = LENS;
/* fall through */
case LENS:
{
int symbol;
while (((symbol = blTree.getSymbol(input)) & ~15) == 0)
{
/* Normal case: symbol in [0..15] */
// System.err.println("litdistLens["+ptr+"]: "+symbol);
litdistLens[ptr++] = lastLen = (byte) symbol;
if (ptr == num)
{
/* Finished */
return true;
}
}
/* need more input ? */
if (symbol < 0)
return false;
/* otherwise repeat code */
if (symbol >= 17)
{
/* repeat zero */
// System.err.println("repeating zero");
lastLen = 0;
}
else
{
if (ptr == 0)
throw new DataFormatException();
}
repSymbol = symbol-16;
mode = REPS;
}
/* fall through */
case REPS:
{
int bits = repBits[repSymbol];
int count = input.peekBits(bits);
if (count < 0)
return false;
input.dropBits(bits);
count += repMin[repSymbol];
// System.err.println("litdistLens repeated: "+count);
if (ptr + count > num)
throw new DataFormatException();
while (count-- > 0)
litdistLens[ptr++] = lastLen;
if (ptr == num)
{
/* Finished */
return true;
}
}
mode = LENS;
continue decode_loop;
}
}
}
public InflaterHuffmanTree buildLitLenTree() throws DataFormatException
{
byte[] litlenLens = new byte[lnum];
System.arraycopy(litdistLens, 0, litlenLens, 0, lnum);
return new InflaterHuffmanTree(litlenLens);
}
public InflaterHuffmanTree buildDistTree() throws DataFormatException
{
byte[] distLens = new byte[dnum];
System.arraycopy(litdistLens, lnum, distLens, 0, dnum);
return new InflaterHuffmanTree(distLens);
}
}

View File

@@ -0,0 +1,220 @@
/* InflaterHuffmanTree.java --
Copyright (C) 2001, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
class InflaterHuffmanTree
{
private static final int MAX_BITLEN = 15;
private short[] tree;
static InflaterHuffmanTree defLitLenTree, defDistTree;
static
{
try
{
byte[] codeLengths = new byte[288];
int i = 0;
while (i < 144)
codeLengths[i++] = 8;
while (i < 256)
codeLengths[i++] = 9;
while (i < 280)
codeLengths[i++] = 7;
while (i < 288)
codeLengths[i++] = 8;
defLitLenTree = new InflaterHuffmanTree(codeLengths);
codeLengths = new byte[32];
i = 0;
while (i < 32)
codeLengths[i++] = 5;
defDistTree = new InflaterHuffmanTree(codeLengths);
}
catch (DataFormatException ex)
{
throw new InternalError
("InflaterHuffmanTree: static tree length illegal");
}
}
/**
* Constructs a Huffman tree from the array of code lengths.
*
* @param codeLengths the array of code lengths
*/
InflaterHuffmanTree(byte[] codeLengths) throws DataFormatException
{
buildTree(codeLengths);
}
private void buildTree(byte[] codeLengths) throws DataFormatException
{
int[] blCount = new int[MAX_BITLEN+1];
int[] nextCode = new int[MAX_BITLEN+1];
for (int i = 0; i < codeLengths.length; i++)
{
int bits = codeLengths[i];
if (bits > 0)
blCount[bits]++;
}
int max = 0;
int code = 0;
int treeSize = 512;
for (int bits = 1; bits <= MAX_BITLEN; bits++)
{
nextCode[bits] = code;
if (blCount[bits] > 0)
max = bits;
code += blCount[bits] << (16 - bits);
if (bits >= 10)
{
/* We need an extra table for bit lengths >= 10. */
int start = nextCode[bits] & 0x1ff80;
int end = code & 0x1ff80;
treeSize += (end - start) >> (16 - bits);
}
}
if (code != 65536 && max > 1)
throw new DataFormatException("incomplete dynamic bit lengths tree");
/* Now create and fill the extra tables from longest to shortest
* bit len. This way the sub trees will be aligned.
*/
tree = new short[treeSize];
int treePtr = 512;
for (int bits = MAX_BITLEN; bits >= 10; bits--)
{
int end = code & 0x1ff80;
code -= blCount[bits] << (16 - bits);
int start = code & 0x1ff80;
for (int i = start; i < end; i += 1 << 7)
{
tree[DeflaterHuffman.bitReverse(i)]
= (short) ((-treePtr << 4) | bits);
treePtr += 1 << (bits-9);
}
}
for (int i = 0; i < codeLengths.length; i++)
{
int bits = codeLengths[i];
if (bits == 0)
continue;
code = nextCode[bits];
int revcode = DeflaterHuffman.bitReverse(code);
if (bits <= 9)
{
do
{
tree[revcode] = (short) ((i << 4) | bits);
revcode += 1 << bits;
}
while (revcode < 512);
}
else
{
int subTree = tree[revcode & 511];
int treeLen = 1 << (subTree & 15);
subTree = -(subTree >> 4);
do
{
tree[subTree | (revcode >> 9)] = (short) ((i << 4) | bits);
revcode += 1 << bits;
}
while (revcode < treeLen);
}
nextCode[bits] = code + (1 << (16 - bits));
}
}
/**
* Reads the next symbol from input. The symbol is encoded using the
* huffman tree.
* @param input the input source.
* @return the next symbol, or -1 if not enough input is available.
*/
int getSymbol(StreamManipulator input) throws DataFormatException
{
int lookahead, symbol;
if ((lookahead = input.peekBits(9)) >= 0)
{
if ((symbol = tree[lookahead]) >= 0)
{
input.dropBits(symbol & 15);
return symbol >> 4;
}
int subtree = -(symbol >> 4);
int bitlen = symbol & 15;
if ((lookahead = input.peekBits(bitlen)) >= 0)
{
symbol = tree[subtree | (lookahead >> 9)];
input.dropBits(symbol & 15);
return symbol >> 4;
}
else
{
int bits = input.getAvailableBits();
lookahead = input.peekBits(bits);
symbol = tree[subtree | (lookahead >> 9)];
if ((symbol & 15) <= bits)
{
input.dropBits(symbol & 15);
return symbol >> 4;
}
else
return -1;
}
}
else
{
int bits = input.getAvailableBits();
lookahead = input.peekBits(bits);
symbol = tree[lookahead];
if (symbol >= 0 && (symbol & 15) <= bits)
{
input.dropBits(symbol & 15);
return symbol >> 4;
}
else
return -1;
}
}
}

View File

@@ -0,0 +1,178 @@
/* OutputWindow.java --
Copyright (C) 2001, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/**
* Contains the output from the Inflation process.
*
* We need to have a window so that we can refer backwards into the output stream
* to repeat stuff.
*
* @author John Leuner
* @since 1.1
*/
class OutputWindow
{
private static final int WINDOW_SIZE = 1 << 15;
private static final int WINDOW_MASK = WINDOW_SIZE - 1;
private byte[] window = new byte[WINDOW_SIZE]; //The window is 2^15 bytes
private int window_end = 0;
private int window_filled = 0;
public void write(int abyte)
{
if (window_filled++ == WINDOW_SIZE)
throw new IllegalStateException("Window full");
window[window_end++] = (byte) abyte;
window_end &= WINDOW_MASK;
}
private void slowRepeat(int rep_start, int len, int dist)
{
while (len-- > 0)
{
window[window_end++] = window[rep_start++];
window_end &= WINDOW_MASK;
rep_start &= WINDOW_MASK;
}
}
public void repeat(int len, int dist)
{
if ((window_filled += len) > WINDOW_SIZE)
throw new IllegalStateException("Window full");
int rep_start = (window_end - dist) & WINDOW_MASK;
int border = WINDOW_SIZE - len;
if (rep_start <= border && window_end < border)
{
if (len <= dist)
{
System.arraycopy(window, rep_start, window, window_end, len);
window_end += len;
}
else
{
/* We have to copy manually, since the repeat pattern overlaps.
*/
while (len-- > 0)
window[window_end++] = window[rep_start++];
}
}
else
slowRepeat(rep_start, len, dist);
}
public int copyStored(StreamManipulator input, int len)
{
len = Math.min(Math.min(len, WINDOW_SIZE - window_filled),
input.getAvailableBytes());
int copied;
int tailLen = WINDOW_SIZE - window_end;
if (len > tailLen)
{
copied = input.copyBytes(window, window_end, tailLen);
if (copied == tailLen)
copied += input.copyBytes(window, 0, len - tailLen);
}
else
copied = input.copyBytes(window, window_end, len);
window_end = (window_end + copied) & WINDOW_MASK;
window_filled += copied;
return copied;
}
public void copyDict(byte[] dict, int offset, int len)
{
if (window_filled > 0)
throw new IllegalStateException();
if (len > WINDOW_SIZE)
{
offset += len - WINDOW_SIZE;
len = WINDOW_SIZE;
}
System.arraycopy(dict, offset, window, 0, len);
window_end = len & WINDOW_MASK;
}
public int getFreeSpace()
{
return WINDOW_SIZE - window_filled;
}
public int getAvailable()
{
return window_filled;
}
public int copyOutput(byte[] output, int offset, int len)
{
int copy_end = window_end;
if (len > window_filled)
len = window_filled;
else
copy_end = (window_end - window_filled + len) & WINDOW_MASK;
int copied = len;
int tailLen = len - copy_end;
if (tailLen > 0)
{
System.arraycopy(window, WINDOW_SIZE - tailLen,
output, offset, tailLen);
offset += tailLen;
len = copy_end;
}
System.arraycopy(window, copy_end - len, output, offset, len);
window_filled -= copied;
if (window_filled < 0)
throw new IllegalStateException();
return copied;
}
public void reset() {
window_filled = window_end = 0;
}
}

View File

@@ -0,0 +1,200 @@
/* java.util.zip.PendingBuffer
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/**
* This class is general purpose class for writing data to a buffer.
*
* It allows you to write bits as well as bytes
*
* Based on DeflaterPending.java
*
* @author Jochen Hoenicke
* @date Jan 5, 2000
*/
class PendingBuffer
{
protected byte[] buf;
int start;
int end;
int bits;
int bitCount;
public PendingBuffer()
{
this( 4096 );
}
public PendingBuffer(int bufsize)
{
buf = new byte[bufsize];
}
public final void reset() {
start = end = bitCount = 0;
}
public final void writeByte(int b)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) b;
}
public final void writeShort(int s)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) s;
buf[end++] = (byte) (s >> 8);
}
public final void writeInt(int s)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) s;
buf[end++] = (byte) (s >> 8);
buf[end++] = (byte) (s >> 16);
buf[end++] = (byte) (s >> 24);
}
public final void writeBlock(byte[] block, int offset, int len)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
System.arraycopy(block, offset, buf, end, len);
end += len;
}
public final int getBitCount() {
return bitCount;
}
public final void alignToByte() {
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
if (bitCount > 0)
{
buf[end++] = (byte) bits;
if (bitCount > 8)
buf[end++] = (byte) (bits >>> 8);
}
bits = 0;
bitCount = 0;
}
public final void writeBits(int b, int count)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
if (DeflaterConstants.DEBUGGING)
System.err.println("writeBits("+Integer.toHexString(b)+","+count+")");
bits |= b << bitCount;
bitCount += count;
if (bitCount >= 16) {
buf[end++] = (byte) bits;
buf[end++] = (byte) (bits >>> 8);
bits >>>= 16;
bitCount -= 16;
}
}
public final void writeShortMSB(int s) {
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) (s >> 8);
buf[end++] = (byte) s;
}
public final boolean isFlushed() {
return end == 0;
}
/**
* Flushes the pending buffer into the given output array. If the
* output array is to small, only a partial flush is done.
*
* @param output the output array;
* @param offset the offset into output array;
* @param length the maximum number of bytes to store;
* @exception IndexOutOfBoundsException if offset or length are
* invalid.
*/
public final int flush(byte[] output, int offset, int length) {
if (bitCount >= 8)
{
buf[end++] = (byte) bits;
bits >>>= 8;
bitCount -= 8;
}
if (length > end - start)
{
length = end - start;
System.arraycopy(buf, start, output, offset, length);
start = 0;
end = 0;
}
else
{
System.arraycopy(buf, start, output, offset, length);
start += length;
}
return length;
}
/**
* Flushes the pending buffer and returns that data in a new array
*
* @return the output stream
*/
public final byte[] toByteArray()
{
byte[] ret = new byte[ end - start ];
System.arraycopy(buf, start, ret, 0, ret.length);
start = 0;
end = 0;
return ret;
}
}

View File

@@ -0,0 +1,216 @@
/* java.util.zip.StreamManipulator
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/**
* This class allows us to retrieve a specified amount of bits from
* the input buffer, as well as copy big byte blocks.
*
* It uses an int buffer to store up to 31 bits for direct
* manipulation. This guarantees that we can get at least 16 bits,
* but we only need at most 15, so this is all safe.
*
* There are some optimizations in this class, for example, you must
* never peek more then 8 bits more than needed, and you must first
* peek bits before you may drop them. This is not a general purpose
* class but optimized for the behaviour of the Inflater.
*
* @author John Leuner, Jochen Hoenicke
*/
class StreamManipulator
{
private byte[] window;
private int window_start = 0;
private int window_end = 0;
private int buffer = 0;
private int bits_in_buffer = 0;
/**
* Get the next n bits but don't increase input pointer. n must be
* less or equal 16 and if you if this call succeeds, you must drop
* at least n-8 bits in the next call.
*
* @return the value of the bits, or -1 if not enough bits available. */
public final int peekBits(int n)
{
if (bits_in_buffer < n)
{
if (window_start == window_end)
return -1;
buffer |= (window[window_start++] & 0xff
| (window[window_start++] & 0xff) << 8) << bits_in_buffer;
bits_in_buffer += 16;
}
return buffer & ((1 << n) - 1);
}
/* Drops the next n bits from the input. You should have called peekBits
* with a bigger or equal n before, to make sure that enough bits are in
* the bit buffer.
*/
public final void dropBits(int n)
{
buffer >>>= n;
bits_in_buffer -= n;
}
/**
* Gets the next n bits and increases input pointer. This is equivalent
* to peekBits followed by dropBits, except for correct error handling.
* @return the value of the bits, or -1 if not enough bits available.
*/
public final int getBits(int n)
{
int bits = peekBits(n);
if (bits >= 0)
dropBits(n);
return bits;
}
/**
* Gets the number of bits available in the bit buffer. This must be
* only called when a previous peekBits() returned -1.
* @return the number of bits available.
*/
public final int getAvailableBits()
{
return bits_in_buffer;
}
/**
* Gets the number of bytes available.
* @return the number of bytes available.
*/
public final int getAvailableBytes()
{
return window_end - window_start + (bits_in_buffer >> 3);
}
/**
* Skips to the next byte boundary.
*/
public void skipToByteBoundary()
{
buffer >>= (bits_in_buffer & 7);
bits_in_buffer &= ~7;
}
public final boolean needsInput() {
return window_start == window_end;
}
/* Copies length bytes from input buffer to output buffer starting
* at output[offset]. You have to make sure, that the buffer is
* byte aligned. If not enough bytes are available, copies fewer
* bytes.
* @param length the length to copy, 0 is allowed.
* @return the number of bytes copied, 0 if no byte is available.
*/
public int copyBytes(byte[] output, int offset, int length)
{
if (length < 0)
throw new IllegalArgumentException("length negative");
if ((bits_in_buffer & 7) != 0)
/* bits_in_buffer may only be 0 or 8 */
throw new IllegalStateException("Bit buffer is not aligned!");
int count = 0;
while (bits_in_buffer > 0 && length > 0)
{
output[offset++] = (byte) buffer;
buffer >>>= 8;
bits_in_buffer -= 8;
length--;
count++;
}
if (length == 0)
return count;
int avail = window_end - window_start;
if (length > avail)
length = avail;
System.arraycopy(window, window_start, output, offset, length);
window_start += length;
if (((window_start - window_end) & 1) != 0)
{
/* We always want an even number of bytes in input, see peekBits */
buffer = (window[window_start++] & 0xff);
bits_in_buffer = 8;
}
return count + length;
}
public StreamManipulator()
{
}
public void reset()
{
window_start = window_end = buffer = bits_in_buffer = 0;
}
public void setInput(byte[] buf, int off, int len)
{
if (window_start < window_end)
throw new IllegalStateException
("Old input was not completely processed");
int end = off + len;
/* We want to throw an ArrayIndexOutOfBoundsException early. The
* check is very tricky: it also handles integer wrap around.
*/
if (0 > off || off > end || end > buf.length)
throw new ArrayIndexOutOfBoundsException();
if ((len & 1) != 0)
{
/* We always want an even number of bytes in input, see peekBits */
buffer |= (buf[off++] & 0xff) << bits_in_buffer;
bits_in_buffer += 8;
}
window = buf;
window_start = off;
window_end = end;
}
}

View File

@@ -0,0 +1,330 @@
/* ZipEntry.java --
Copyright (C) 2001, 2002, 2004, 2005, 2011 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
import java.util.Date;
/**
* This class represents a member of a zip archive. ZipFile and
* ZipInputStream will give you instances of this class as information
* about the members in an archive. On the other hand ZipOutputStream
* needs an instance of this class to create a new member.
*
* @author Jochen Hoenicke
*/
public class ZipEntry implements ZipConstants, Cloneable
{
String name;
long time = -1;
long crc = -1;
long size = -1;
long csize = -1;
int method = -1;
int flag;
byte[] extra;
String comment;
long offset; /* used by ZipFile */
/**
* Compression method. This method doesn't compress at all.
*/
public static final int STORED = 0;
/**
* Compression method. This method uses the Deflater.
*/
public static final int DEFLATED = 8;
/**
* Creates a zip entry with the given name.
* @param name the name. May include directory components separated
* by '/'.
*
* @exception NullPointerException when name is null.
* @exception IllegalArgumentException when name is bigger then 65535 chars.
*/
public ZipEntry(String name)
{
int length = name.length();
if (length > 65535)
throw new IllegalArgumentException("name length is " + length);
this.name = name;
}
/**
* Creates a copy of the given zip entry.
* @param e the entry to copy.
*/
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;
}
ZipEntry()
{
}
/**
* Creates a copy of this zip entry.
*/
/**
* Clones the entry.
*/
public Object clone()
{
try
{
// The JCL says that the `extra' field is also copied.
ZipEntry clone = (ZipEntry)super.clone();
if (extra != null)
clone.extra = (byte[])extra.clone();
return clone;
}
catch (CloneNotSupportedException ex)
{
throw new InternalError();
}
}
/**
* Returns the entry name. The path components in the entry are
* always separated by slashes ('/').
*/
public String getName()
{
return name;
}
/**
* Sets the time of last modification of the entry.
* @time the time of last modification of the entry.
*/
public void setTime(long time)
{
Date d = new Date(time);
if (d.getYear() < 80)
{
d = new Date(80, 0, 1);
}
this.time = ((d.getYear() - 80) << 25)
| ((d.getMonth() + 1) << 21)
| (d.getDate() << 16)
| (d.getHours() << 11)
| (d.getMinutes() << 5)
| (d.getSeconds() >> 1);
}
/**
* Gets the time of last modification of the entry.
* @return the time of last modification of the entry, or -1 if unknown.
*/
public long getTime()
{
if (time == -1)
{
return -1;
}
Date d = new Date((int)(((time >> 25) & 0x7f) + 80),
(int)(((time >> 21) & 0x0f) - 1),
(int)((time >> 16) & 0x1f),
(int)((time >> 11) & 0x1f),
(int)((time >> 5) & 0x3f),
(int)((time << 1) & 0x3e));
return d.getTime();
}
/**
* Sets the size of the uncompressed data.
* @exception IllegalArgumentException if size is negative.
*/
public void setSize(long size)
{
if (size < 0)
throw new IllegalArgumentException();
this.size = size;
}
/**
* Gets the size of the uncompressed data.
* @return the size or -1 if unknown.
*/
public long getSize()
{
return size;
}
/**
* Sets the size of the compressed data.
*/
public void setCompressedSize(long csize)
{
this.csize = csize;
}
/**
* Gets the size of the compressed data.
* @return the size or -1 if unknown.
*/
public long getCompressedSize()
{
return csize;
}
/**
* Sets the crc of the uncompressed data.
* @exception IllegalArgumentException if crc is not in 0..0xffffffffL
*/
public void setCrc(long crc)
{
if ((crc & 0xffffffff00000000L) != 0)
throw new IllegalArgumentException();
this.crc = crc;
}
/**
* Gets the crc of the uncompressed data.
* @return the crc or -1 if unknown.
*/
public long getCrc()
{
return crc;
}
/**
* Sets the compression method. Only DEFLATED and STORED are
* supported.
* @exception IllegalArgumentException if method is not supported.
* @see ZipOutputStream#DEFLATED
* @see ZipOutputStream#STORED
*/
public void setMethod(int method)
{
if (method != ZipOutputStream.STORED
&& method != ZipOutputStream.DEFLATED)
throw new IllegalArgumentException();
this.method = method;
}
/**
* Gets the compression method.
* @return the compression method or -1 if unknown.
*/
public int getMethod()
{
return method;
}
/**
* Sets the extra data.
* @exception IllegalArgumentException if extra is longer than 0xffff bytes.
*/
public void setExtra(byte[] extra)
{
if (extra == null)
{
this.extra = null;
return;
}
if (extra.length > 0xffff)
throw new IllegalArgumentException();
this.extra = extra;
}
/**
* Gets the extra data.
* @return the extra data or null if not set.
*/
public byte[] getExtra()
{
return extra;
}
/**
* Sets the entry comment.
*/
public void setComment(String comment)
{
this.comment = comment;
}
/**
* Gets the comment.
* @return the comment or null if not set.
*/
public String getComment()
{
return comment;
}
/**
* Gets true, if the entry is a directory. This is solely
* determined by the name, a trailing slash '/' marks a directory.
*/
public boolean isDirectory()
{
int nlen = name.length();
return nlen > 0 && name.charAt(nlen - 1) == '/';
}
/**
* Gets the string representation of this ZipEntry. This is just
* the name as returned by getName().
*/
public String toString()
{
return getName();
}
/**
* Gets the hashCode of this ZipEntry. This is just the hashCode
* of the name. Note that the equals method isn't changed, though.
*/
public int hashCode()
{
return name.hashCode();
}
}

File diff suppressed because it is too large Load Diff