summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/java/util/zip
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/util/zip')
-rw-r--r--libjava/classpath/java/util/zip/Adler32.java66
-rw-r--r--libjava/classpath/java/util/zip/CRC32.java20
-rw-r--r--libjava/classpath/java/util/zip/CheckedInputStream.java16
-rw-r--r--libjava/classpath/java/util/zip/CheckedOutputStream.java2
-rw-r--r--libjava/classpath/java/util/zip/Deflater.java218
-rw-r--r--libjava/classpath/java/util/zip/DeflaterEngine.java618
-rw-r--r--libjava/classpath/java/util/zip/DeflaterHuffman.java726
-rw-r--r--libjava/classpath/java/util/zip/DeflaterOutputStream.java40
-rw-r--r--libjava/classpath/java/util/zip/DeflaterPending.java3
-rw-r--r--libjava/classpath/java/util/zip/GZIPInputStream.java86
-rw-r--r--libjava/classpath/java/util/zip/GZIPOutputStream.java64
-rw-r--r--libjava/classpath/java/util/zip/Inflater.java438
-rw-r--r--libjava/classpath/java/util/zip/InflaterDynHeader.java230
-rw-r--r--libjava/classpath/java/util/zip/InflaterHuffmanTree.java216
-rw-r--r--libjava/classpath/java/util/zip/InflaterInputStream.java76
-rw-r--r--libjava/classpath/java/util/zip/OutputWindow.java55
-rw-r--r--libjava/classpath/java/util/zip/PendingBuffer.java39
-rw-r--r--libjava/classpath/java/util/zip/StreamManipulator.java53
-rw-r--r--libjava/classpath/java/util/zip/ZipConstants.java1
-rw-r--r--libjava/classpath/java/util/zip/ZipEntry.java76
-rw-r--r--libjava/classpath/java/util/zip/ZipFile.java182
-rw-r--r--libjava/classpath/java/util/zip/ZipInputStream.java182
-rw-r--r--libjava/classpath/java/util/zip/ZipOutputStream.java212
23 files changed, 1806 insertions, 1813 deletions
diff --git a/libjava/classpath/java/util/zip/Adler32.java b/libjava/classpath/java/util/zip/Adler32.java
index 7c411384057..cc27da9277d 100644
--- a/libjava/classpath/java/util/zip/Adler32.java
+++ b/libjava/classpath/java/util/zip/Adler32.java
@@ -45,8 +45,8 @@ package java.util.zip;
*/
/**
- * Computes Adler32 checksum for a stream of data. An Adler32
- * checksum is not as reliable as a CRC32 checksum, but a lot faster to
+ * 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.
@@ -60,7 +60,7 @@ package java.util.zip;
* (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.
+ * 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
@@ -103,13 +103,13 @@ public class Adler32 implements Checksum
private int checksum; //we do all in int.
//Note that java doesn't have unsigned integers,
- //so we have to be careful with what arithmetic
- //we do. We return the checksum as a long to
+ //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.
+ * Creates a new instance of the <code>Adler32</code> class.
+ * The checksum starts off with a value of 1.
*/
public Adler32 ()
{
@@ -119,13 +119,13 @@ public class Adler32 implements Checksum
/**
* Resets the Adler32 checksum to the initial value.
*/
- public void reset ()
+ public void reset ()
{
- checksum = 1; //Initialize to 1
+ checksum = 1; //Initialize to 1
}
/**
- * Updates the checksum with the byte b.
+ * Updates the checksum with the byte b.
*
* @param bval the data value to add. The high byte of the int is ignored.
*/
@@ -135,16 +135,16 @@ public class Adler32 implements Checksum
//would rather not have that overhead
int s1 = checksum & 0xffff;
int s2 = checksum >>> 16;
-
+
s1 = (s1 + (bval & 0xFF)) % BASE;
s2 = (s1 + s2) % BASE;
-
+
checksum = (s2 << 16) + s1;
}
/**
- * Updates the checksum with the bytes taken from the array.
- *
+ * Updates the checksum with the bytes taken from the array.
+ *
* @param buffer an array of bytes
*/
public void update (byte[] buffer)
@@ -153,8 +153,8 @@ public class Adler32 implements Checksum
}
/**
- * Updates the checksum with the bytes taken from the array.
- *
+ * 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
@@ -167,31 +167,31 @@ public class Adler32 implements Checksum
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;
+ // 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;
+ s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
s2 = (s2 + s1) % BASE;
}*/
-
+
checksum = (s2 << 16) | s1;
}
diff --git a/libjava/classpath/java/util/zip/CRC32.java b/libjava/classpath/java/util/zip/CRC32.java
index 1c2b3973852..de2e7083db5 100644
--- a/libjava/classpath/java/util/zip/CRC32.java
+++ b/libjava/classpath/java/util/zip/CRC32.java
@@ -71,15 +71,15 @@ public class CRC32 implements Checksum
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;
+ 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;
}
@@ -98,7 +98,7 @@ public class CRC32 implements Checksum
public void reset () { crc = 0; }
/**
- * Updates the checksum with the int bval.
+ * Updates the checksum with the int bval.
*
* @param bval (the byte is taken as the lower 8 bits of bval)
*/
diff --git a/libjava/classpath/java/util/zip/CheckedInputStream.java b/libjava/classpath/java/util/zip/CheckedInputStream.java
index d743fbb2447..163a4c4aa30 100644
--- a/libjava/classpath/java/util/zip/CheckedInputStream.java
+++ b/libjava/classpath/java/util/zip/CheckedInputStream.java
@@ -7,7 +7,7 @@ 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
@@ -118,13 +118,13 @@ public class CheckedInputStream extends FilterInputStream
long s = 0;
while (n > 0)
{
- int r = in.read(buf, 0, min);
- if (r == -1)
- break;
- n -= r;
- s += r;
- min = (int) Math.min(n, 1024);
- sum.update(buf, 0, r);
+ int r = in.read(buf, 0, min);
+ if (r == -1)
+ break;
+ n -= r;
+ s += r;
+ min = (int) Math.min(n, 1024);
+ sum.update(buf, 0, r);
}
return s;
diff --git a/libjava/classpath/java/util/zip/CheckedOutputStream.java b/libjava/classpath/java/util/zip/CheckedOutputStream.java
index a3c19292fae..e0222258add 100644
--- a/libjava/classpath/java/util/zip/CheckedOutputStream.java
+++ b/libjava/classpath/java/util/zip/CheckedOutputStream.java
@@ -7,7 +7,7 @@ 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
diff --git a/libjava/classpath/java/util/zip/Deflater.java b/libjava/classpath/java/util/zip/Deflater.java
index 41d9881448c..dd81fe748ff 100644
--- a/libjava/classpath/java/util/zip/Deflater.java
+++ b/libjava/classpath/java/util/zip/Deflater.java
@@ -41,10 +41,10 @@ package java.util.zip;
* This is the Deflater class. The deflater class compresses input
* with the deflate algorithm described in RFC 1951. It has several
* compression levels and three different strategies described below.
- *
+ *
* This class is <i>not</i> thread safe. This is inherent in the API, due
* to the split of deflate and setInput.
- *
+ *
* @author Jochen Hoenicke
* @author Tom Tromey
*/
@@ -52,11 +52,11 @@ public class Deflater
{
/**
* The best and slowest compression level. This tries to find very
- * long and distant string repetitions.
+ * long and distant string repetitions.
*/
public static final int BEST_COMPRESSION = 9;
/**
- * The worst but fastest compression level.
+ * The worst but fastest compression level.
*/
public static final int BEST_SPEED = 1;
/**
@@ -78,10 +78,10 @@ public class Deflater
*/
public static final int FILTERED = 1;
- /**
+ /**
* This strategy will not look for string repetitions at all. It
* only encodes with Huffman trees (which means, that more common
- * characters get a smaller encoding.
+ * characters get a smaller encoding.
*/
public static final int HUFFMAN_ONLY = 2;
@@ -123,13 +123,13 @@ public class Deflater
* (6) FINISHED_STATE is entered, when everything has been flushed to the
* internal pending output buffer.
* (7) At any time (7)
- *
+ *
*/
private static final int IS_SETDICT = 0x01;
private static final int IS_FLUSHING = 0x04;
private static final int IS_FINISHING = 0x08;
-
+
private static final int INIT_STATE = 0x00;
private static final int SETDICT_STATE = 0x01;
private static final int INIT_FINISHING_STATE = 0x08;
@@ -151,7 +151,7 @@ public class Deflater
/** The total bytes of output written. */
private long totalOut;
-
+
/** The pending output. */
private DeflaterPending pending;
@@ -169,7 +169,7 @@ public class Deflater
/**
* Creates a new deflater with given compression level.
* @param lvl the compression level, a value between NO_COMPRESSION
- * and BEST_COMPRESSION, or DEFAULT_COMPRESSION.
+ * and BEST_COMPRESSION, or DEFAULT_COMPRESSION.
* @exception IllegalArgumentException if lvl is out of range.
*/
public Deflater(int lvl)
@@ -180,7 +180,7 @@ public class Deflater
/**
* Creates a new deflater with given compression level.
* @param lvl the compression level, a value between NO_COMPRESSION
- * and BEST_COMPRESSION.
+ * and BEST_COMPRESSION.
* @param nowrap true, iff we should suppress the deflate header at the
* beginning and the adler checksum at the end of the output. This is
* useful for the GZIP format.
@@ -201,26 +201,26 @@ public class Deflater
reset();
}
- /**
+ /**
* Resets the deflater. The deflater acts afterwards as if it was
* just created with the same compression level and strategy as it
- * had before.
+ * had before.
*/
- public void reset()
+ public void reset()
{
state = (noHeader ? BUSY_STATE : INIT_STATE);
totalOut = 0;
pending.reset();
engine.reset();
}
-
+
/**
* Frees all objects allocated by the compressor. There's no
* reason to call this, since you can just rely on garbage
* collection. Exists only for compatibility against Sun's JDK,
* where the compressor allocates native memory.
* If you call any method (even reset) afterwards the behaviour is
- * <i>undefined</i>.
+ * <i>undefined</i>.
*/
public void end()
{
@@ -229,7 +229,7 @@ public class Deflater
state = CLOSED_STATE;
}
- /**
+ /**
* Gets the current adler checksum of the data that was processed so
* far.
*/
@@ -238,7 +238,7 @@ public class Deflater
return engine.getAdler();
}
- /**
+ /**
* Gets the number of input bytes processed so far.
*/
public int getTotalIn()
@@ -246,7 +246,7 @@ public class Deflater
return (int) engine.getTotalIn();
}
- /**
+ /**
* Gets the number of input bytes processed so far.
* @since 1.5
*/
@@ -255,7 +255,7 @@ public class Deflater
return engine.getTotalIn();
}
- /**
+ /**
* Gets the number of output bytes so far.
*/
public int getTotalOut()
@@ -263,7 +263,7 @@ public class Deflater
return (int) totalOut;
}
- /**
+ /**
* Gets the number of output bytes so far.
* @since 1.5
*/
@@ -272,7 +272,7 @@ public class Deflater
return totalOut;
}
- /**
+ /**
* Finalizes this object.
*/
protected void finalize()
@@ -280,7 +280,7 @@ public class Deflater
/* Exists solely for compatibility. We don't have any native state. */
}
- /**
+ /**
* Flushes the current input block. Further calls to deflate() will
* produce enough output to inflate everything in the current input
* block. This is not part of Sun's JDK so I have made it package
@@ -291,7 +291,7 @@ public class Deflater
state |= IS_FLUSHING;
}
- /**
+ /**
* Finishes the deflater with the current input block. It is an error
* to give more input after this method was called. This method must
* be called to force all bytes to be flushed.
@@ -300,7 +300,7 @@ public class Deflater
state |= IS_FLUSHING | IS_FINISHING;
}
- /**
+ /**
* Returns true iff the stream was finished and no more output bytes
* are available.
*/
@@ -314,7 +314,7 @@ public class Deflater
* You should then call setInput(). <br>
*
* <em>NOTE</em>: This method can also return true when the stream
- * was finished.
+ * was finished.
*/
public boolean needsInput()
{
@@ -344,7 +344,7 @@ public class Deflater
* true again.
* @param input the buffer containing the input data.
* @param off the start of the data.
- * @param len the length of the data.
+ * @param len the length of the data.
* @exception IllegalStateException if the buffer was finished() or ended()
* or if previous input is still pending.
*/
@@ -355,11 +355,11 @@ public class Deflater
engine.setInput(input, off, len);
}
- /**
+ /**
* Sets the compression level. There is no guarantee of the exact
* position of the change, but if you call this when needsInput is
* true the change of compression level will occur somewhere near
- * before the end of the so far given input.
+ * before the end of the so far given input.
* @param lvl the new compression level.
*/
public void setLevel(int lvl)
@@ -372,12 +372,12 @@ public class Deflater
if (level != lvl)
{
- level = lvl;
- engine.setLevel(lvl);
+ level = lvl;
+ engine.setLevel(lvl);
}
}
- /**
+ /**
* Sets the compression strategy. Strategy is one of
* DEFAULT_STRATEGY, HUFFMAN_ONLY and FILTERED. For the exact
* position where the strategy is changed, the same as for
@@ -387,14 +387,14 @@ public class Deflater
public void setStrategy(int stgy)
{
if (stgy != DEFAULT_STRATEGY && stgy != FILTERED
- && stgy != HUFFMAN_ONLY)
+ && stgy != HUFFMAN_ONLY)
throw new IllegalArgumentException();
engine.setStrategy(stgy);
}
/**
- * Deflates the current input block to the given array. It returns
- * the number of bytes compressed, or 0 if either
+ * Deflates the current input block to the given array. It returns
+ * the number of bytes compressed, or 0 if either
* needsInput() or finished() returns true or length is zero.
* @param output the buffer where to write the compressed data.
*/
@@ -404,15 +404,15 @@ public class Deflater
}
/**
- * Deflates the current input block to the given array. It returns
- * the number of bytes compressed, or 0 if either
+ * Deflates the current input block to the given array. It returns
+ * the number of bytes compressed, or 0 if either
* needsInput() or finished() returns true or length is zero.
* @param output the buffer where to write the compressed data.
* @param offset the offset into the output array.
* @param length the maximum number of bytes that may be written.
* @exception IllegalStateException if end() was called.
* @exception IndexOutOfBoundsException if offset and/or length
- * don't match the array length.
+ * don't match the array length.
*/
public int deflate(byte[] output, int offset, int length)
{
@@ -423,78 +423,78 @@ public class Deflater
if (state < BUSY_STATE)
{
- /* output header */
- int header = (DEFLATED +
- ((DeflaterConstants.MAX_WBITS - 8) << 4)) << 8;
- int level_flags = (level - 1) >> 1;
- if (level_flags < 0 || level_flags > 3)
- level_flags = 3;
- header |= level_flags << 6;
- if ((state & IS_SETDICT) != 0)
- /* Dictionary was set */
- header |= DeflaterConstants.PRESET_DICT;
- header += 31 - (header % 31);
-
- pending.writeShortMSB(header);
- if ((state & IS_SETDICT) != 0)
- {
- int chksum = engine.getAdler();
- engine.resetAdler();
- pending.writeShortMSB(chksum >> 16);
- pending.writeShortMSB(chksum & 0xffff);
- }
-
- state = BUSY_STATE | (state & (IS_FLUSHING | IS_FINISHING));
+ /* output header */
+ int header = (DEFLATED +
+ ((DeflaterConstants.MAX_WBITS - 8) << 4)) << 8;
+ int level_flags = (level - 1) >> 1;
+ if (level_flags < 0 || level_flags > 3)
+ level_flags = 3;
+ header |= level_flags << 6;
+ if ((state & IS_SETDICT) != 0)
+ /* Dictionary was set */
+ header |= DeflaterConstants.PRESET_DICT;
+ header += 31 - (header % 31);
+
+ pending.writeShortMSB(header);
+ if ((state & IS_SETDICT) != 0)
+ {
+ int chksum = engine.getAdler();
+ engine.resetAdler();
+ pending.writeShortMSB(chksum >> 16);
+ pending.writeShortMSB(chksum & 0xffff);
+ }
+
+ state = BUSY_STATE | (state & (IS_FLUSHING | IS_FINISHING));
}
for (;;)
{
- int count = pending.flush(output, offset, length);
- offset += count;
- totalOut += count;
- length -= count;
- if (length == 0 || state == FINISHED_STATE)
- break;
-
- if (!engine.deflate((state & IS_FLUSHING) != 0,
- (state & IS_FINISHING) != 0))
- {
- if (state == BUSY_STATE)
- /* We need more input now */
- return origLength - length;
- else if (state == FLUSHING_STATE)
- {
- if (level != NO_COMPRESSION)
- {
- /* We have to supply some lookahead. 8 bit lookahead
- * are needed by the zlib inflater, and we must fill
- * the next byte, so that all bits are flushed.
- */
- int neededbits = 8 + ((-pending.getBitCount()) & 7);
- while (neededbits > 0)
- {
- /* write a static tree block consisting solely of
- * an EOF:
- */
- pending.writeBits(2, 10);
- neededbits -= 10;
- }
- }
- state = BUSY_STATE;
- }
- else if (state == FINISHING_STATE)
- {
- pending.alignToByte();
- /* We have completed the stream */
- if (!noHeader)
- {
- int adler = engine.getAdler();
- pending.writeShortMSB(adler >> 16);
- pending.writeShortMSB(adler & 0xffff);
- }
- state = FINISHED_STATE;
- }
- }
+ int count = pending.flush(output, offset, length);
+ offset += count;
+ totalOut += count;
+ length -= count;
+ if (length == 0 || state == FINISHED_STATE)
+ break;
+
+ if (!engine.deflate((state & IS_FLUSHING) != 0,
+ (state & IS_FINISHING) != 0))
+ {
+ if (state == BUSY_STATE)
+ /* We need more input now */
+ return origLength - length;
+ else if (state == FLUSHING_STATE)
+ {
+ if (level != NO_COMPRESSION)
+ {
+ /* We have to supply some lookahead. 8 bit lookahead
+ * are needed by the zlib inflater, and we must fill
+ * the next byte, so that all bits are flushed.
+ */
+ int neededbits = 8 + ((-pending.getBitCount()) & 7);
+ while (neededbits > 0)
+ {
+ /* write a static tree block consisting solely of
+ * an EOF:
+ */
+ pending.writeBits(2, 10);
+ neededbits -= 10;
+ }
+ }
+ state = BUSY_STATE;
+ }
+ else if (state == FINISHING_STATE)
+ {
+ pending.alignToByte();
+ /* We have completed the stream */
+ if (!noHeader)
+ {
+ int adler = engine.getAdler();
+ pending.writeShortMSB(adler >> 16);
+ pending.writeShortMSB(adler & 0xffff);
+ }
+ state = FINISHED_STATE;
+ }
+ }
}
return origLength - length;
@@ -503,10 +503,10 @@ public class Deflater
/**
* Sets the dictionary which should be used in the deflate process.
* This call is equivalent to <code>setDictionary(dict, 0,
- * dict.length)</code>.
- * @param dict the dictionary.
+ * dict.length)</code>.
+ * @param dict the dictionary.
* @exception IllegalStateException if setInput () or deflate ()
- * were already called or another dictionary was already set.
+ * were already called or another dictionary was already set.
*/
public void setDictionary(byte[] dict)
{
diff --git a/libjava/classpath/java/util/zip/DeflaterEngine.java b/libjava/classpath/java/util/zip/DeflaterEngine.java
index 38a82d8b77b..287558e3e84 100644
--- a/libjava/classpath/java/util/zip/DeflaterEngine.java
+++ b/libjava/classpath/java/util/zip/DeflaterEngine.java
@@ -45,7 +45,7 @@ class DeflaterEngine implements DeflaterConstants
/**
* Hashtable, hashing three characters to an index for window, so
- * that window[index]..window[index+2] have this hash code.
+ * that window[index]..window[index+2] have this hash code.
* Note that the array should really be unsigned short, so you need
* to and the values with 0xffff.
*/
@@ -53,7 +53,7 @@ class DeflaterEngine implements DeflaterConstants
/**
* prev[index & WMASK] points to the previous index that has the
- * same hash code as the string starting at index. This way
+ * same hash code as the string starting at index. This way
* entries with the same hash code are in a linked list.
* Note that the array should really be unsigned short, so you need
* to and the values with 0xffff.
@@ -78,7 +78,7 @@ class DeflaterEngine implements DeflaterConstants
private int lookahead;
/**
- * This array contains the part of the uncompressed stream that
+ * This array contains the part of the uncompressed stream that
* is of relevance. The current character is indexed by strstart.
*/
private byte[] window;
@@ -113,12 +113,12 @@ class DeflaterEngine implements DeflaterConstants
* second half is copied to the beginning.
*
* The head array is a hash table. Three characters build a hash value
- * and they the value points to the corresponding index in window of
+ * and they the value points to the corresponding index in window of
* the last string with this hash. The prev array implements a
* linked list of matches with the same hash: prev[index & WMASK] points
* to the previous index with the same hash.
- *
- *
+ *
+ *
*/
@@ -180,44 +180,44 @@ class DeflaterEngine implements DeflaterConstants
niceLength = DeflaterConstants.NICE_LENGTH[lvl];
max_chain = DeflaterConstants.MAX_CHAIN[lvl];
- if (DeflaterConstants.COMPR_FUNC[lvl] != comprFunc)
+ if (DeflaterConstants.COMPR_FUNC[lvl] != comprFunc)
{
- if (DeflaterConstants.DEBUGGING)
- System.err.println("Change from "+comprFunc +" to "
- + DeflaterConstants.COMPR_FUNC[lvl]);
- switch (comprFunc)
- {
- case DEFLATE_STORED:
- if (strstart > blockStart)
- {
- huffman.flushStoredBlock(window, blockStart,
- strstart - blockStart, false);
- blockStart = strstart;
- }
- updateHash();
- break;
- case DEFLATE_FAST:
- if (strstart > blockStart)
- {
- huffman.flushBlock(window, blockStart, strstart - blockStart,
- false);
- blockStart = strstart;
- }
- break;
- case DEFLATE_SLOW:
- if (prevAvailable)
- huffman.tallyLit(window[strstart-1] & 0xff);
- if (strstart > blockStart)
- {
- huffman.flushBlock(window, blockStart, strstart - blockStart,
- false);
- blockStart = strstart;
- }
- prevAvailable = false;
- matchLen = MIN_MATCH - 1;
- break;
- }
- comprFunc = COMPR_FUNC[lvl];
+ if (DeflaterConstants.DEBUGGING)
+ System.err.println("Change from "+comprFunc +" to "
+ + DeflaterConstants.COMPR_FUNC[lvl]);
+ switch (comprFunc)
+ {
+ case DEFLATE_STORED:
+ if (strstart > blockStart)
+ {
+ huffman.flushStoredBlock(window, blockStart,
+ strstart - blockStart, false);
+ blockStart = strstart;
+ }
+ updateHash();
+ break;
+ case DEFLATE_FAST:
+ if (strstart > blockStart)
+ {
+ huffman.flushBlock(window, blockStart, strstart - blockStart,
+ false);
+ blockStart = strstart;
+ }
+ break;
+ case DEFLATE_SLOW:
+ if (prevAvailable)
+ huffman.tallyLit(window[strstart-1] & 0xff);
+ if (strstart > blockStart)
+ {
+ huffman.flushBlock(window, blockStart, strstart - blockStart,
+ false);
+ blockStart = strstart;
+ }
+ prevAvailable = false;
+ matchLen = MIN_MATCH - 1;
+ break;
+ }
+ comprFunc = COMPR_FUNC[lvl];
}
}
@@ -225,7 +225,7 @@ class DeflaterEngine implements DeflaterConstants
if (DEBUGGING)
System.err.println("updateHash: "+strstart);
ins_h = (window[strstart] << HASH_SHIFT) ^ window[strstart + 1];
- }
+ }
/**
* Inserts the current string in the head hash and returns the previous
@@ -238,13 +238,13 @@ class DeflaterEngine implements DeflaterConstants
if (DEBUGGING)
{
- if (hash != (((window[strstart] << (2*HASH_SHIFT))
- ^ (window[strstart + 1] << HASH_SHIFT)
- ^ (window[strstart + 2])) & HASH_MASK))
- throw new InternalError("hash inconsistent: "+hash+"/"
- +window[strstart]+","
- +window[strstart+1]+","
- +window[strstart+2]+","+HASH_SHIFT);
+ if (hash != (((window[strstart] << (2*HASH_SHIFT))
+ ^ (window[strstart + 1] << HASH_SHIFT)
+ ^ (window[strstart + 2])) & HASH_MASK))
+ throw new InternalError("hash inconsistent: "+hash+"/"
+ +window[strstart]+","
+ +window[strstart+1]+","
+ +window[strstart+2]+","+HASH_SHIFT);
}
prev[strstart & WMASK] = match = head[hash];
@@ -259,22 +259,22 @@ class DeflaterEngine implements DeflaterConstants
matchStart -= WSIZE;
strstart -= WSIZE;
blockStart -= WSIZE;
-
+
/* Slide the hash table (could be avoided with 32 bit values
* at the expense of memory usage).
*/
- for (int i = 0; i < HASH_SIZE; i++)
+ for (int i = 0; i < HASH_SIZE; i++)
{
- int m = head[i] & 0xffff;
- head[i] = m >= WSIZE ? (short) (m - WSIZE) : 0;
+ int m = head[i] & 0xffff;
+ head[i] = m >= WSIZE ? (short) (m - WSIZE) : 0;
}
/* Slide the prev table.
*/
- for (int i = 0; i < WSIZE; i++)
+ for (int i = 0; i < WSIZE; i++)
{
- int m = prev[i] & 0xffff;
- prev[i] = m >= WSIZE ? (short) (m - WSIZE) : 0;
+ int m = prev[i] & 0xffff;
+ prev[i] = m >= WSIZE ? (short) (m - WSIZE) : 0;
}
}
@@ -298,30 +298,30 @@ class DeflaterEngine implements DeflaterConstants
*/
while (lookahead < DeflaterConstants.MIN_LOOKAHEAD && inputOff < inputEnd)
{
- int more = 2*WSIZE - lookahead - strstart;
-
- if (more > inputEnd - inputOff)
- more = inputEnd - inputOff;
-
- System.arraycopy(inputBuf, inputOff,
- window, strstart + lookahead, more);
- adler.update(inputBuf, inputOff, more);
- inputOff += more;
- totalIn += more;
- lookahead += more;
+ int more = 2*WSIZE - lookahead - strstart;
+
+ if (more > inputEnd - inputOff)
+ more = inputEnd - inputOff;
+
+ System.arraycopy(inputBuf, inputOff,
+ window, strstart + lookahead, more);
+ adler.update(inputBuf, inputOff, more);
+ inputOff += more;
+ totalIn += more;
+ lookahead += more;
}
- if (lookahead >= MIN_MATCH)
+ if (lookahead >= MIN_MATCH)
updateHash();
}
/**
- * Find the best (longest) string in the window matching the
+ * Find the best (longest) string in the window matching the
* string starting at strstart.
*
* Preconditions:
* strstart + MAX_MATCH <= window.length.
- *
+ *
*
* @param curMatch
*/
@@ -333,7 +333,7 @@ class DeflaterEngine implements DeflaterConstants
int match;
int best_end = this.strstart + matchLen;
int best_len = Math.max(matchLen, MIN_MATCH - 1);
-
+
int limit = Math.max(strstart - MAX_DIST, 0);
int strend = scan + MAX_MATCH - 1;
@@ -350,51 +350,51 @@ class DeflaterEngine implements DeflaterConstants
if (niceLength > lookahead)
niceLength = lookahead;
- if (DeflaterConstants.DEBUGGING
- && strstart > 2*WSIZE - MIN_LOOKAHEAD)
+ if (DeflaterConstants.DEBUGGING
+ && strstart > 2*WSIZE - MIN_LOOKAHEAD)
throw new InternalError("need lookahead");
-
+
do {
if (DeflaterConstants.DEBUGGING && curMatch >= strstart)
- throw new InternalError("future match");
+ throw new InternalError("future match");
if (window[curMatch + best_len] != scan_end
- || window[curMatch + best_len - 1] != scan_end1
- || window[curMatch] != window[scan]
- || window[curMatch+1] != window[scan + 1])
- continue;
+ || window[curMatch + best_len - 1] != scan_end1
+ || window[curMatch] != window[scan]
+ || window[curMatch+1] != window[scan + 1])
+ continue;
- match = curMatch + 2;
+ match = curMatch + 2;
scan += 2;
/* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258.
*/
while (window[++scan] == window[++match]
- && window[++scan] == window[++match]
- && window[++scan] == window[++match]
- && window[++scan] == window[++match]
- && window[++scan] == window[++match]
- && window[++scan] == window[++match]
- && window[++scan] == window[++match]
- && window[++scan] == window[++match]
- && scan < strend)
+ && window[++scan] == window[++match]
+ && window[++scan] == window[++match]
+ && window[++scan] == window[++match]
+ && window[++scan] == window[++match]
+ && window[++scan] == window[++match]
+ && window[++scan] == window[++match]
+ && window[++scan] == window[++match]
+ && scan < strend)
;
if (scan > best_end) {
-// if (DeflaterConstants.DEBUGGING && ins_h == 0)
-// System.err.println("Found match: "+curMatch+"-"+(scan-strstart));
- matchStart = curMatch;
- best_end = scan;
- best_len = scan - strstart;
- if (best_len >= niceLength)
- break;
-
- scan_end1 = window[best_end-1];
- scan_end = window[best_end];
+// if (DeflaterConstants.DEBUGGING && ins_h == 0)
+// System.err.println("Found match: "+curMatch+"-"+(scan-strstart));
+ matchStart = curMatch;
+ best_end = scan;
+ best_len = scan - strstart;
+ if (best_len >= niceLength)
+ break;
+
+ scan_end1 = window[best_end-1];
+ scan_end = window[best_end];
}
scan = strstart;
} while ((curMatch = (prev[curMatch & WMASK] & 0xffff)) > limit
- && --chainLength != 0);
+ && --chainLength != 0);
matchLen = Math.min(best_len, lookahead);
return matchLen >= MIN_MATCH;
@@ -417,13 +417,13 @@ class DeflaterEngine implements DeflaterConstants
length--;
while (--length > 0)
{
- insertString();
- strstart++;
+ insertString();
+ strstart++;
}
strstart += 2;
blockStart = strstart;
- }
-
+ }
+
private boolean deflateStored(boolean flush, boolean finish)
{
if (!flush && lookahead == 0)
@@ -434,25 +434,25 @@ class DeflaterEngine implements DeflaterConstants
int storedLen = strstart - blockStart;
- if ((storedLen >= DeflaterConstants.MAX_BLOCK_SIZE)
- /* Block is full */
- || (blockStart < WSIZE && storedLen >= MAX_DIST)
- /* Block may move out of window */
- || flush)
+ if ((storedLen >= DeflaterConstants.MAX_BLOCK_SIZE)
+ /* Block is full */
+ || (blockStart < WSIZE && storedLen >= MAX_DIST)
+ /* Block may move out of window */
+ || flush)
{
- boolean lastBlock = finish;
- if (storedLen > DeflaterConstants.MAX_BLOCK_SIZE)
- {
- storedLen = DeflaterConstants.MAX_BLOCK_SIZE;
- lastBlock = false;
- }
-
- if (DeflaterConstants.DEBUGGING)
- System.err.println("storedBlock["+storedLen+","+lastBlock+"]");
-
- huffman.flushStoredBlock(window, blockStart, storedLen, lastBlock);
- blockStart += storedLen;
- return !lastBlock;
+ boolean lastBlock = finish;
+ if (storedLen > DeflaterConstants.MAX_BLOCK_SIZE)
+ {
+ storedLen = DeflaterConstants.MAX_BLOCK_SIZE;
+ lastBlock = false;
+ }
+
+ if (DeflaterConstants.DEBUGGING)
+ System.err.println("storedBlock["+storedLen+","+lastBlock+"]");
+
+ huffman.flushStoredBlock(window, blockStart, storedLen, lastBlock);
+ blockStart += storedLen;
+ return !lastBlock;
}
return true;
}
@@ -464,78 +464,78 @@ class DeflaterEngine implements DeflaterConstants
while (lookahead >= MIN_LOOKAHEAD || flush)
{
- if (lookahead == 0)
- {
- /* We are flushing everything */
- huffman.flushBlock(window, blockStart, strstart - blockStart,
- finish);
- blockStart = strstart;
- return false;
- }
-
- if (strstart > 2 * WSIZE - MIN_LOOKAHEAD)
- {
- /* slide window, as findLongestMatch need this.
- * This should only happen when flushing and the window
- * is almost full.
- */
- slideWindow();
- }
-
- int hashHead;
- if (lookahead >= MIN_MATCH
- && (hashHead = insertString()) != 0
- && strategy != Deflater.HUFFMAN_ONLY
- && strstart - hashHead <= MAX_DIST
- && findLongestMatch(hashHead))
- {
- /* longestMatch sets matchStart and matchLen */
- if (DeflaterConstants.DEBUGGING)
- {
- for (int i = 0 ; i < matchLen; i++)
- {
- if (window[strstart+i] != window[matchStart + i])
- throw new InternalError();
- }
- }
- boolean full = huffman.tallyDist(strstart - matchStart, matchLen);
-
- lookahead -= matchLen;
- if (matchLen <= max_lazy && lookahead >= MIN_MATCH)
- {
- while (--matchLen > 0)
- {
- strstart++;
- insertString();
- }
- strstart++;
- }
- else
- {
- strstart += matchLen;
- if (lookahead >= MIN_MATCH - 1)
- updateHash();
- }
- matchLen = MIN_MATCH - 1;
- if (!full)
- continue;
- }
- else
- {
- /* No match found */
- huffman.tallyLit(window[strstart] & 0xff);
- strstart++;
- lookahead--;
- }
-
- if (huffman.isFull())
- {
- boolean lastBlock = finish && lookahead == 0;
- huffman.flushBlock(window, blockStart, strstart - blockStart,
- lastBlock);
- blockStart = strstart;
- return !lastBlock;
- }
+ if (lookahead == 0)
+ {
+ /* We are flushing everything */
+ huffman.flushBlock(window, blockStart, strstart - blockStart,
+ finish);
+ blockStart = strstart;
+ return false;
+ }
+
+ if (strstart > 2 * WSIZE - MIN_LOOKAHEAD)
+ {
+ /* slide window, as findLongestMatch need this.
+ * This should only happen when flushing and the window
+ * is almost full.
+ */
+ slideWindow();
+ }
+
+ int hashHead;
+ if (lookahead >= MIN_MATCH
+ && (hashHead = insertString()) != 0
+ && strategy != Deflater.HUFFMAN_ONLY
+ && strstart - hashHead <= MAX_DIST
+ && findLongestMatch(hashHead))
+ {
+ /* longestMatch sets matchStart and matchLen */
+ if (DeflaterConstants.DEBUGGING)
+ {
+ for (int i = 0 ; i < matchLen; i++)
+ {
+ if (window[strstart+i] != window[matchStart + i])
+ throw new InternalError();
+ }
+ }
+ boolean full = huffman.tallyDist(strstart - matchStart, matchLen);
+
+ lookahead -= matchLen;
+ if (matchLen <= max_lazy && lookahead >= MIN_MATCH)
+ {
+ while (--matchLen > 0)
+ {
+ strstart++;
+ insertString();
+ }
+ strstart++;
+ }
+ else
+ {
+ strstart += matchLen;
+ if (lookahead >= MIN_MATCH - 1)
+ updateHash();
+ }
+ matchLen = MIN_MATCH - 1;
+ if (!full)
+ continue;
+ }
+ else
+ {
+ /* No match found */
+ huffman.tallyLit(window[strstart] & 0xff);
+ strstart++;
+ lookahead--;
+ }
+
+ if (huffman.isFull())
+ {
+ boolean lastBlock = finish && lookahead == 0;
+ huffman.flushBlock(window, blockStart, strstart - blockStart,
+ lastBlock);
+ blockStart = strstart;
+ return !lastBlock;
+ }
}
return true;
}
@@ -547,127 +547,127 @@ class DeflaterEngine implements DeflaterConstants
while (lookahead >= MIN_LOOKAHEAD || flush)
{
- if (lookahead == 0)
- {
- if (prevAvailable)
- huffman.tallyLit(window[strstart-1] & 0xff);
- prevAvailable = false;
-
- /* We are flushing everything */
- if (DeflaterConstants.DEBUGGING && !flush)
- throw new InternalError("Not flushing, but no lookahead");
- huffman.flushBlock(window, blockStart, strstart - blockStart,
- finish);
- blockStart = strstart;
- return false;
- }
-
- if (strstart >= 2 * WSIZE - MIN_LOOKAHEAD)
- {
- /* slide window, as findLongestMatch need this.
- * This should only happen when flushing and the window
- * is almost full.
- */
- slideWindow();
- }
-
- int prevMatch = matchStart;
- int prevLen = matchLen;
- if (lookahead >= MIN_MATCH)
- {
- int hashHead = insertString();
- if (strategy != Deflater.HUFFMAN_ONLY
- && hashHead != 0 && strstart - hashHead <= MAX_DIST
- && findLongestMatch(hashHead))
- {
- /* longestMatch sets matchStart and matchLen */
-
- /* Discard match if too small and too far away */
- if (matchLen <= 5
- && (strategy == Deflater.FILTERED
- || (matchLen == MIN_MATCH
- && strstart - matchStart > TOO_FAR))) {
- matchLen = MIN_MATCH - 1;
- }
- }
- }
-
- /* previous match was better */
- if (prevLen >= MIN_MATCH && matchLen <= prevLen)
- {
- if (DeflaterConstants.DEBUGGING)
- {
- for (int i = 0 ; i < matchLen; i++)
- {
- if (window[strstart-1+i] != window[prevMatch + i])
- throw new InternalError();
- }
- }
- huffman.tallyDist(strstart - 1 - prevMatch, prevLen);
- prevLen -= 2;
- do
- {
- strstart++;
- lookahead--;
- if (lookahead >= MIN_MATCH)
- insertString();
- }
- while (--prevLen > 0);
- strstart ++;
- lookahead--;
- prevAvailable = false;
- matchLen = MIN_MATCH - 1;
- }
- else
- {
- if (prevAvailable)
- huffman.tallyLit(window[strstart-1] & 0xff);
- prevAvailable = true;
- strstart++;
- lookahead--;
- }
-
- if (huffman.isFull())
- {
- int len = strstart - blockStart;
- if (prevAvailable)
- len--;
- boolean lastBlock = (finish && lookahead == 0 && !prevAvailable);
- huffman.flushBlock(window, blockStart, len, lastBlock);
- blockStart += len;
- return !lastBlock;
- }
+ if (lookahead == 0)
+ {
+ if (prevAvailable)
+ huffman.tallyLit(window[strstart-1] & 0xff);
+ prevAvailable = false;
+
+ /* We are flushing everything */
+ if (DeflaterConstants.DEBUGGING && !flush)
+ throw new InternalError("Not flushing, but no lookahead");
+ huffman.flushBlock(window, blockStart, strstart - blockStart,
+ finish);
+ blockStart = strstart;
+ return false;
+ }
+
+ if (strstart >= 2 * WSIZE - MIN_LOOKAHEAD)
+ {
+ /* slide window, as findLongestMatch need this.
+ * This should only happen when flushing and the window
+ * is almost full.
+ */
+ slideWindow();
+ }
+
+ int prevMatch = matchStart;
+ int prevLen = matchLen;
+ if (lookahead >= MIN_MATCH)
+ {
+ int hashHead = insertString();
+ if (strategy != Deflater.HUFFMAN_ONLY
+ && hashHead != 0 && strstart - hashHead <= MAX_DIST
+ && findLongestMatch(hashHead))
+ {
+ /* longestMatch sets matchStart and matchLen */
+
+ /* Discard match if too small and too far away */
+ if (matchLen <= 5
+ && (strategy == Deflater.FILTERED
+ || (matchLen == MIN_MATCH
+ && strstart - matchStart > TOO_FAR))) {
+ matchLen = MIN_MATCH - 1;
+ }
+ }
+ }
+
+ /* previous match was better */
+ if (prevLen >= MIN_MATCH && matchLen <= prevLen)
+ {
+ if (DeflaterConstants.DEBUGGING)
+ {
+ for (int i = 0 ; i < matchLen; i++)
+ {
+ if (window[strstart-1+i] != window[prevMatch + i])
+ throw new InternalError();
+ }
+ }
+ huffman.tallyDist(strstart - 1 - prevMatch, prevLen);
+ prevLen -= 2;
+ do
+ {
+ strstart++;
+ lookahead--;
+ if (lookahead >= MIN_MATCH)
+ insertString();
+ }
+ while (--prevLen > 0);
+ strstart ++;
+ lookahead--;
+ prevAvailable = false;
+ matchLen = MIN_MATCH - 1;
+ }
+ else
+ {
+ if (prevAvailable)
+ huffman.tallyLit(window[strstart-1] & 0xff);
+ prevAvailable = true;
+ strstart++;
+ lookahead--;
+ }
+
+ if (huffman.isFull())
+ {
+ int len = strstart - blockStart;
+ if (prevAvailable)
+ len--;
+ boolean lastBlock = (finish && lookahead == 0 && !prevAvailable);
+ huffman.flushBlock(window, blockStart, len, lastBlock);
+ blockStart += len;
+ return !lastBlock;
+ }
}
return true;
- }
+ }
- public boolean deflate(boolean flush, boolean finish)
+ public boolean deflate(boolean flush, boolean finish)
{
boolean progress;
do
{
- fillWindow();
- boolean canFlush = flush && inputOff == inputEnd;
- if (DeflaterConstants.DEBUGGING)
- System.err.println("window: ["+blockStart+","+strstart+","
- +lookahead+"], "+comprFunc+","+canFlush);
- switch (comprFunc)
- {
- case DEFLATE_STORED:
- progress = deflateStored(canFlush, finish);
- break;
- case DEFLATE_FAST:
- progress = deflateFast(canFlush, finish);
- break;
- case DEFLATE_SLOW:
- progress = deflateSlow(canFlush, finish);
- break;
- default:
- throw new InternalError();
- }
+ fillWindow();
+ boolean canFlush = flush && inputOff == inputEnd;
+ if (DeflaterConstants.DEBUGGING)
+ System.err.println("window: ["+blockStart+","+strstart+","
+ +lookahead+"], "+comprFunc+","+canFlush);
+ switch (comprFunc)
+ {
+ case DEFLATE_STORED:
+ progress = deflateStored(canFlush, finish);
+ break;
+ case DEFLATE_FAST:
+ progress = deflateFast(canFlush, finish);
+ break;
+ case DEFLATE_SLOW:
+ progress = deflateSlow(canFlush, finish);
+ break;
+ default:
+ throw new InternalError();
+ }
}
while (pending.isFlushed() /* repeat while we have no pending output */
- && progress); /* and progress was made */
+ && progress); /* and progress was made */
return progress;
}
@@ -676,12 +676,12 @@ class DeflaterEngine implements DeflaterConstants
{
if (inputOff < inputEnd)
throw new IllegalStateException
- ("Old input was not completely processed");
+ ("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.
+ * check is very tricky: it also handles integer wrap around.
*/
if (0 > off || off > end || end > buf.length)
throw new ArrayIndexOutOfBoundsException();
diff --git a/libjava/classpath/java/util/zip/DeflaterHuffman.java b/libjava/classpath/java/util/zip/DeflaterHuffman.java
index 32c10b6de80..8da987e0fd9 100644
--- a/libjava/classpath/java/util/zip/DeflaterHuffman.java
+++ b/libjava/classpath/java/util/zip/DeflaterHuffman.java
@@ -44,7 +44,7 @@ package java.util.zip;
* to the split of deflate and setInput.
*
* @author Jochen Hoenicke
- * @date Jan 6, 2000
+ * @date Jan 6, 2000
*/
class DeflaterHuffman
{
@@ -79,7 +79,7 @@ class DeflaterHuffman
void reset() {
for (int i = 0; i < freqs.length; i++)
- freqs[i] = 0;
+ freqs[i] = 0;
codes = null;
length = null;
}
@@ -87,10 +87,10 @@ class DeflaterHuffman
final void writeSymbol(int code)
{
if (DeflaterConstants.DEBUGGING)
- {
- freqs[code]--;
-// System.err.print("writeSymbol("+freqs.length+","+code+"): ");
- }
+ {
+ freqs[code]--;
+// System.err.print("writeSymbol("+freqs.length+","+code+"): ");
+ }
pending.writeBits(codes[code] & 0xffff, length[code]);
}
@@ -98,13 +98,13 @@ class DeflaterHuffman
{
boolean empty = true;
for (int i = 0; i < freqs.length; i++)
- if (freqs[i] != 0)
- {
- System.err.println("freqs["+i+"] == "+freqs[i]);
- empty = false;
- }
+ if (freqs[i] != 0)
+ {
+ System.err.println("freqs["+i+"] == "+freqs[i]);
+ empty = false;
+ }
if (!empty)
- throw new InternalError();
+ throw new InternalError();
System.err.println("checkEmpty suceeded!");
}
@@ -120,31 +120,31 @@ class DeflaterHuffman
codes = new short[freqs.length];
if (DeflaterConstants.DEBUGGING)
- System.err.println("buildCodes: "+freqs.length);
- for (int bits = 0; bits < maxLength; bits++)
- {
- nextCode[bits] = code;
- code += bl_counts[bits] << (15 - bits);
- if (DeflaterConstants.DEBUGGING)
- System.err.println("bits: "+(bits+1)+" count: "+bl_counts[bits]
- +" nextCode: "+Integer.toHexString(code));
- }
+ System.err.println("buildCodes: "+freqs.length);
+ for (int bits = 0; bits < maxLength; bits++)
+ {
+ nextCode[bits] = code;
+ code += bl_counts[bits] << (15 - bits);
+ if (DeflaterConstants.DEBUGGING)
+ System.err.println("bits: "+(bits+1)+" count: "+bl_counts[bits]
+ +" nextCode: "+Integer.toHexString(code));
+ }
if (DeflaterConstants.DEBUGGING && code != 65536)
- throw new RuntimeException("Inconsistent bl_counts!");
-
+ throw new RuntimeException("Inconsistent bl_counts!");
+
for (int i=0; i < numCodes; i++)
- {
- int bits = length[i];
- if (bits > 0)
- {
- if (DeflaterConstants.DEBUGGING)
- System.err.println("codes["+i+"] = rev("
- +Integer.toHexString(nextCode[bits-1])+"),"
- +bits);
- codes[i] = bitReverse(nextCode[bits-1]);
- nextCode[bits-1] += 1 << (16 - bits);
- }
- }
+ {
+ int bits = length[i];
+ if (bits > 0)
+ {
+ if (DeflaterConstants.DEBUGGING)
+ System.err.println("codes["+i+"] = rev("
+ +Integer.toHexString(nextCode[bits-1])+"),"
+ +bits);
+ codes[i] = bitReverse(nextCode[bits-1]);
+ nextCode[bits-1] += 1 << (16 - bits);
+ }
+ }
}
private void buildLength(int childs[])
@@ -153,63 +153,63 @@ class DeflaterHuffman
int numNodes = childs.length / 2;
int numLeafs = (numNodes + 1) / 2;
int overflow = 0;
-
+
for (int i = 0; i < maxLength; i++)
- bl_counts[i] = 0;
+ bl_counts[i] = 0;
/* First calculate optimal bit lengths */
int lengths[] = new int[numNodes];
lengths[numNodes-1] = 0;
for (int i = numNodes - 1; i >= 0; i--)
- {
- if (childs[2*i+1] != -1)
- {
- int bitLength = lengths[i] + 1;
- if (bitLength > maxLength)
- {
- bitLength = maxLength;
- overflow++;
- }
- lengths[childs[2*i]] = lengths[childs[2*i+1]] = bitLength;
- }
- else
- {
- /* A leaf node */
- int bitLength = lengths[i];
- bl_counts[bitLength - 1]++;
- this.length[childs[2*i]] = (byte) lengths[i];
- }
- }
-
+ {
+ if (childs[2*i+1] != -1)
+ {
+ int bitLength = lengths[i] + 1;
+ if (bitLength > maxLength)
+ {
+ bitLength = maxLength;
+ overflow++;
+ }
+ lengths[childs[2*i]] = lengths[childs[2*i+1]] = bitLength;
+ }
+ else
+ {
+ /* A leaf node */
+ int bitLength = lengths[i];
+ bl_counts[bitLength - 1]++;
+ this.length[childs[2*i]] = (byte) lengths[i];
+ }
+ }
+
if (DeflaterConstants.DEBUGGING)
- {
- System.err.println("Tree "+freqs.length+" lengths:");
- for (int i=0; i < numLeafs; i++)
- System.err.println("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
- + " len: "+length[childs[2*i]]);
- }
-
+ {
+ System.err.println("Tree "+freqs.length+" lengths:");
+ for (int i=0; i < numLeafs; i++)
+ System.err.println("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
+ + " len: "+length[childs[2*i]]);
+ }
+
if (overflow == 0)
- return;
-
+ return;
+
int incrBitLen = maxLength - 1;
do
- {
- /* Find the first bit length which could increase: */
- while (bl_counts[--incrBitLen] == 0)
- ;
-
- /* Move this node one down and remove a corresponding
- * amount of overflow nodes.
- */
- do
- {
- bl_counts[incrBitLen]--;
- bl_counts[++incrBitLen]++;
- overflow -= 1 << (maxLength - 1 - incrBitLen);
- }
- while (overflow > 0 && incrBitLen < maxLength - 1);
- }
+ {
+ /* Find the first bit length which could increase: */
+ while (bl_counts[--incrBitLen] == 0)
+ ;
+
+ /* Move this node one down and remove a corresponding
+ * amount of overflow nodes.
+ */
+ do
+ {
+ bl_counts[incrBitLen]--;
+ bl_counts[++incrBitLen]++;
+ overflow -= 1 << (maxLength - 1 - incrBitLen);
+ }
+ while (overflow > 0 && incrBitLen < maxLength - 1);
+ }
while (overflow > 0);
/* We may have overshot above. Move some nodes from maxLength to
@@ -217,7 +217,7 @@ class DeflaterHuffman
*/
bl_counts[maxLength-1] += overflow;
bl_counts[maxLength-2] -= overflow;
-
+
/* Now recompute all bit lengths, scanning in increasing
* frequency. It is simpler to reconstruct all lengths instead of
* fixing only the wrong ones. This idea is taken from 'ar'
@@ -227,30 +227,30 @@ class DeflaterHuffman
* array.
*/
int nodePtr = 2 * numLeafs;
- for (int bits = maxLength; bits != 0; bits--)
- {
- int n = bl_counts[bits-1];
- while (n > 0)
- {
- int childPtr = 2*childs[nodePtr++];
- if (childs[childPtr + 1] == -1)
- {
- /* We found another leaf */
- length[childs[childPtr]] = (byte) bits;
- n--;
- }
- }
- }
+ for (int bits = maxLength; bits != 0; bits--)
+ {
+ int n = bl_counts[bits-1];
+ while (n > 0)
+ {
+ int childPtr = 2*childs[nodePtr++];
+ if (childs[childPtr + 1] == -1)
+ {
+ /* We found another leaf */
+ length[childs[childPtr]] = (byte) bits;
+ n--;
+ }
+ }
+ }
if (DeflaterConstants.DEBUGGING)
- {
- System.err.println("*** After overflow elimination. ***");
- for (int i=0; i < numLeafs; i++)
- System.err.println("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
- + " len: "+length[childs[2*i]]);
- }
+ {
+ System.err.println("*** After overflow elimination. ***");
+ for (int i=0; i < numLeafs; i++)
+ System.err.println("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
+ + " len: "+length[childs[2*i]]);
+ }
}
-
- void buildTree()
+
+ void buildTree()
{
int numSymbols = freqs.length;
@@ -266,123 +266,123 @@ class DeflaterHuffman
int heapLen = 0;
int maxCode = 0;
for (int n = 0; n < numSymbols; n++)
- {
- int freq = freqs[n];
- if (freq != 0)
- {
- /* Insert n into heap */
- int pos = heapLen++;
- int ppos;
- while (pos > 0 &&
- freqs[heap[ppos = (pos - 1) / 2]] > freq) {
- heap[pos] = heap[ppos];
- pos = ppos;
- }
- heap[pos] = n;
- maxCode = n;
- }
- }
-
+ {
+ int freq = freqs[n];
+ if (freq != 0)
+ {
+ /* Insert n into heap */
+ int pos = heapLen++;
+ int ppos;
+ while (pos > 0 &&
+ freqs[heap[ppos = (pos - 1) / 2]] > freq) {
+ heap[pos] = heap[ppos];
+ pos = ppos;
+ }
+ heap[pos] = n;
+ maxCode = n;
+ }
+ }
+
/* We could encode a single literal with 0 bits but then we
* don't see the literals. Therefore we force at least two
* literals to avoid this case. We don't care about order in
- * this case, both literals get a 1 bit code.
+ * this case, both literals get a 1 bit code.
*/
while (heapLen < 2)
- {
- int node = maxCode < 2 ? ++maxCode : 0;
- heap[heapLen++] = node;
- }
+ {
+ int node = maxCode < 2 ? ++maxCode : 0;
+ heap[heapLen++] = node;
+ }
numCodes = Math.max(maxCode + 1, minNumCodes);
-
+
int numLeafs = heapLen;
int[] childs = new int[4*heapLen - 2];
int[] values = new int[2*heapLen - 1];
int numNodes = numLeafs;
for (int i = 0; i < heapLen; i++)
- {
- int node = heap[i];
- childs[2*i] = node;
- childs[2*i+1] = -1;
- values[i] = freqs[node] << 8;
- heap[i] = i;
- }
-
+ {
+ int node = heap[i];
+ childs[2*i] = node;
+ childs[2*i+1] = -1;
+ values[i] = freqs[node] << 8;
+ heap[i] = i;
+ }
+
/* Construct the Huffman tree by repeatedly combining the least two
* frequent nodes.
*/
do
- {
- int first = heap[0];
- int last = heap[--heapLen];
-
- /* Propagate the hole to the leafs of the heap */
- int ppos = 0;
- int path = 1;
- while (path < heapLen)
- {
- if (path + 1 < heapLen
- && values[heap[path]] > values[heap[path+1]])
- path++;
-
- heap[ppos] = heap[path];
- ppos = path;
- path = path * 2 + 1;
- }
-
- /* Now propagate the last element down along path. Normally
- * it shouldn't go too deep.
- */
- int lastVal = values[last];
- while ((path = ppos) > 0
- && values[heap[ppos = (path - 1)/2]] > lastVal)
- heap[path] = heap[ppos];
- heap[path] = last;
-
-
- int second = heap[0];
-
- /* Create a new node father of first and second */
- last = numNodes++;
- childs[2*last] = first;
- childs[2*last+1] = second;
- int mindepth = Math.min(values[first] & 0xff, values[second] & 0xff);
- values[last] = lastVal = values[first] + values[second] - mindepth + 1;
-
- /* Again, propagate the hole to the leafs */
- ppos = 0;
- path = 1;
- while (path < heapLen)
- {
- if (path + 1 < heapLen
- && values[heap[path]] > values[heap[path+1]])
- path++;
-
- heap[ppos] = heap[path];
- ppos = path;
- path = ppos * 2 + 1;
- }
-
- /* Now propagate the new element down along path */
- while ((path = ppos) > 0
- && values[heap[ppos = (path - 1)/2]] > lastVal)
- heap[path] = heap[ppos];
- heap[path] = last;
- }
+ {
+ int first = heap[0];
+ int last = heap[--heapLen];
+
+ /* Propagate the hole to the leafs of the heap */
+ int ppos = 0;
+ int path = 1;
+ while (path < heapLen)
+ {
+ if (path + 1 < heapLen
+ && values[heap[path]] > values[heap[path+1]])
+ path++;
+
+ heap[ppos] = heap[path];
+ ppos = path;
+ path = path * 2 + 1;
+ }
+
+ /* Now propagate the last element down along path. Normally
+ * it shouldn't go too deep.
+ */
+ int lastVal = values[last];
+ while ((path = ppos) > 0
+ && values[heap[ppos = (path - 1)/2]] > lastVal)
+ heap[path] = heap[ppos];
+ heap[path] = last;
+
+
+ int second = heap[0];
+
+ /* Create a new node father of first and second */
+ last = numNodes++;
+ childs[2*last] = first;
+ childs[2*last+1] = second;
+ int mindepth = Math.min(values[first] & 0xff, values[second] & 0xff);
+ values[last] = lastVal = values[first] + values[second] - mindepth + 1;
+
+ /* Again, propagate the hole to the leafs */
+ ppos = 0;
+ path = 1;
+ while (path < heapLen)
+ {
+ if (path + 1 < heapLen
+ && values[heap[path]] > values[heap[path+1]])
+ path++;
+
+ heap[ppos] = heap[path];
+ ppos = path;
+ path = ppos * 2 + 1;
+ }
+
+ /* Now propagate the new element down along path */
+ while ((path = ppos) > 0
+ && values[heap[ppos = (path - 1)/2]] > lastVal)
+ heap[path] = heap[ppos];
+ heap[path] = last;
+ }
while (heapLen > 1);
-
+
if (heap[0] != childs.length / 2 - 1)
- throw new RuntimeException("Weird!");
-
+ throw new RuntimeException("Weird!");
+
buildLength(childs);
}
- int getEncodedLength()
+ int getEncodedLength()
{
int len = 0;
for (int i = 0; i < freqs.length; i++)
- len += freqs[i] * length[i];
+ len += freqs[i] * length[i];
return len;
}
@@ -391,46 +391,46 @@ class DeflaterHuffman
int min_count; /* min repeat count */
int count; /* repeat count of the current code */
int curlen = -1; /* length of current code */
-
+
int i = 0;
while (i < numCodes)
- {
- count = 1;
- int nextlen = length[i];
- if (nextlen == 0)
- {
- max_count = 138;
- min_count = 3;
- }
- else
- {
- max_count = 6;
- min_count = 3;
- if (curlen != nextlen)
- {
- blTree.freqs[nextlen]++;
- count = 0;
- }
- }
- curlen = nextlen;
- i++;
-
- while (i < numCodes && curlen == length[i])
- {
- i++;
- if (++count >= max_count)
- break;
- }
-
- if (count < min_count)
- blTree.freqs[curlen] += count;
- else if (curlen != 0)
- blTree.freqs[REP_3_6]++;
- else if (count <= 10)
- blTree.freqs[REP_3_10]++;
- else
- blTree.freqs[REP_11_138]++;
- }
+ {
+ count = 1;
+ int nextlen = length[i];
+ if (nextlen == 0)
+ {
+ max_count = 138;
+ min_count = 3;
+ }
+ else
+ {
+ max_count = 6;
+ min_count = 3;
+ if (curlen != nextlen)
+ {
+ blTree.freqs[nextlen]++;
+ count = 0;
+ }
+ }
+ curlen = nextlen;
+ i++;
+
+ while (i < numCodes && curlen == length[i])
+ {
+ i++;
+ if (++count >= max_count)
+ break;
+ }
+
+ if (count < min_count)
+ blTree.freqs[curlen] += count;
+ else if (curlen != 0)
+ blTree.freqs[REP_3_6]++;
+ else if (count <= 10)
+ blTree.freqs[REP_3_10]++;
+ else
+ blTree.freqs[REP_11_138]++;
+ }
}
void writeTree(Tree blTree)
@@ -439,58 +439,58 @@ class DeflaterHuffman
int min_count; /* min repeat count */
int count; /* repeat count of the current code */
int curlen = -1; /* length of current code */
-
+
int i = 0;
while (i < numCodes)
- {
- count = 1;
- int nextlen = length[i];
- if (nextlen == 0)
- {
- max_count = 138;
- min_count = 3;
- }
- else
- {
- max_count = 6;
- min_count = 3;
- if (curlen != nextlen)
- {
- blTree.writeSymbol(nextlen);
- count = 0;
- }
- }
- curlen = nextlen;
- i++;
-
- while (i < numCodes && curlen == length[i])
- {
- i++;
- if (++count >= max_count)
- break;
- }
-
- if (count < min_count)
- {
- while (count-- > 0)
- blTree.writeSymbol(curlen);
- }
- else if (curlen != 0)
- {
- blTree.writeSymbol(REP_3_6);
- pending.writeBits(count - 3, 2);
- }
- else if (count <= 10)
- {
- blTree.writeSymbol(REP_3_10);
- pending.writeBits(count - 3, 3);
- }
- else
- {
- blTree.writeSymbol(REP_11_138);
- pending.writeBits(count - 11, 7);
- }
- }
+ {
+ count = 1;
+ int nextlen = length[i];
+ if (nextlen == 0)
+ {
+ max_count = 138;
+ min_count = 3;
+ }
+ else
+ {
+ max_count = 6;
+ min_count = 3;
+ if (curlen != nextlen)
+ {
+ blTree.writeSymbol(nextlen);
+ count = 0;
+ }
+ }
+ curlen = nextlen;
+ i++;
+
+ while (i < numCodes && curlen == length[i])
+ {
+ i++;
+ if (++count >= max_count)
+ break;
+ }
+
+ if (count < min_count)
+ {
+ while (count-- > 0)
+ blTree.writeSymbol(curlen);
+ }
+ else if (curlen != 0)
+ {
+ blTree.writeSymbol(REP_3_6);
+ pending.writeBits(count - 3, 2);
+ }
+ else if (count <= 10)
+ {
+ blTree.writeSymbol(REP_3_10);
+ pending.writeBits(count - 3, 3);
+ }
+ else
+ {
+ blTree.writeSymbol(REP_11_138);
+ pending.writeBits(count - 11, 7);
+ }
+ }
}
}
@@ -514,9 +514,9 @@ class DeflaterHuffman
*/
static short bitReverse(int value) {
return (short) (bit4Reverse.charAt(value & 0xf) << 12
- | bit4Reverse.charAt((value >> 4) & 0xf) << 8
- | bit4Reverse.charAt((value >> 8) & 0xf) << 4
- | bit4Reverse.charAt(value >> 12));
+ | bit4Reverse.charAt((value >> 4) & 0xf) << 8
+ | bit4Reverse.charAt((value >> 8) & 0xf) << 4
+ | bit4Reverse.charAt(value >> 12));
}
static {
@@ -550,8 +550,8 @@ class DeflaterHuffman
staticDLength[i] = 5;
}
}
-
- public DeflaterHuffman(DeflaterPending pending)
+
+ public DeflaterHuffman(DeflaterPending pending)
{
this.pending = pending;
@@ -578,8 +578,8 @@ class DeflaterHuffman
int code = 257;
while (len >= 8)
{
- code += 4;
- len >>= 1;
+ code += 4;
+ len >>= 1;
}
return code + len;
}
@@ -588,8 +588,8 @@ class DeflaterHuffman
int code = 0;
while (distance >= 4)
{
- code += 2;
- distance >>= 1;
+ code += 2;
+ distance >>= 1;
}
return code + distance;
}
@@ -610,58 +610,58 @@ class DeflaterHuffman
}
public void compressBlock() {
- for (int i = 0; i < last_lit; i++)
+ for (int i = 0; i < last_lit; i++)
{
- int litlen = l_buf[i] & 0xff;
- int dist = d_buf[i];
- if (dist-- != 0)
- {
- if (DeflaterConstants.DEBUGGING)
- System.err.print("["+(dist+1)+","+(litlen+3)+"]: ");
-
- int lc = l_code(litlen);
- literalTree.writeSymbol(lc);
-
- int bits = (lc - 261) / 4;
- if (bits > 0 && bits <= 5)
- pending.writeBits(litlen & ((1 << bits) - 1), bits);
-
- int dc = d_code(dist);
- distTree.writeSymbol(dc);
-
- bits = dc / 2 - 1;
- if (bits > 0)
- pending.writeBits(dist & ((1 << bits) - 1), bits);
- }
- else
- {
- if (DeflaterConstants.DEBUGGING)
- {
- if (litlen > 32 && litlen < 127)
- System.err.print("("+(char)litlen+"): ");
- else
- System.err.print("{"+litlen+"}: ");
- }
- literalTree.writeSymbol(litlen);
- }
+ int litlen = l_buf[i] & 0xff;
+ int dist = d_buf[i];
+ if (dist-- != 0)
+ {
+ if (DeflaterConstants.DEBUGGING)
+ System.err.print("["+(dist+1)+","+(litlen+3)+"]: ");
+
+ int lc = l_code(litlen);
+ literalTree.writeSymbol(lc);
+
+ int bits = (lc - 261) / 4;
+ if (bits > 0 && bits <= 5)
+ pending.writeBits(litlen & ((1 << bits) - 1), bits);
+
+ int dc = d_code(dist);
+ distTree.writeSymbol(dc);
+
+ bits = dc / 2 - 1;
+ if (bits > 0)
+ pending.writeBits(dist & ((1 << bits) - 1), bits);
+ }
+ else
+ {
+ if (DeflaterConstants.DEBUGGING)
+ {
+ if (litlen > 32 && litlen < 127)
+ System.err.print("("+(char)litlen+"): ");
+ else
+ System.err.print("{"+litlen+"}: ");
+ }
+ literalTree.writeSymbol(litlen);
+ }
}
if (DeflaterConstants.DEBUGGING)
System.err.print("EOF: ");
literalTree.writeSymbol(EOF_SYMBOL);
if (DeflaterConstants.DEBUGGING)
{
- literalTree.checkEmpty();
- distTree.checkEmpty();
+ literalTree.checkEmpty();
+ distTree.checkEmpty();
}
}
- public void flushStoredBlock(byte[] stored,
- int stored_offset, int stored_len,
- boolean lastBlock) {
+ public void flushStoredBlock(byte[] stored,
+ int stored_offset, int stored_len,
+ boolean lastBlock) {
if (DeflaterConstants.DEBUGGING)
System.err.println("Flushing stored block "+ stored_len);
pending.writeBits((DeflaterConstants.STORED_BLOCK << 1)
- + (lastBlock ? 1 : 0), 3);
+ + (lastBlock ? 1 : 0), 3);
pending.alignToByte();
pending.writeShort(stored_len);
pending.writeShort(~stored_len);
@@ -670,7 +670,7 @@ class DeflaterHuffman
}
public void flushBlock(byte[] stored, int stored_offset, int stored_len,
- boolean lastBlock) {
+ boolean lastBlock) {
literalTree.freqs[EOF_SYMBOL]++;
/* Build trees */
@@ -687,8 +687,8 @@ class DeflaterHuffman
int blTreeCodes = 4;
for (int i = 18; i > blTreeCodes; i--)
{
- if (blTree.length[BL_ORDER[i]] > 0)
- blTreeCodes = i+1;
+ if (blTree.length[BL_ORDER[i]] > 0)
+ blTreeCodes = i+1;
}
int opt_len = 14 + blTreeCodes * 3 + blTree.getEncodedLength()
+ literalTree.getEncodedLength() + distTree.getEncodedLength()
@@ -701,36 +701,36 @@ class DeflaterHuffman
static_len += distTree.freqs[i] * staticDLength[i];
if (opt_len >= static_len)
{
- /* Force static trees */
- opt_len = static_len;
+ /* Force static trees */
+ opt_len = static_len;
}
if (stored_offset >= 0 && stored_len+4 < opt_len >> 3)
{
- /* Store Block */
- if (DeflaterConstants.DEBUGGING)
- System.err.println("Storing, since " + stored_len + " < " + opt_len
- + " <= " + static_len);
- flushStoredBlock(stored, stored_offset, stored_len, lastBlock);
+ /* Store Block */
+ if (DeflaterConstants.DEBUGGING)
+ System.err.println("Storing, since " + stored_len + " < " + opt_len
+ + " <= " + static_len);
+ flushStoredBlock(stored, stored_offset, stored_len, lastBlock);
}
else if (opt_len == static_len)
{
- /* Encode with static tree */
- pending.writeBits((DeflaterConstants.STATIC_TREES << 1)
- + (lastBlock ? 1 : 0), 3);
- literalTree.setStaticCodes(staticLCodes, staticLLength);
- distTree.setStaticCodes(staticDCodes, staticDLength);
- compressBlock();
- reset();
+ /* Encode with static tree */
+ pending.writeBits((DeflaterConstants.STATIC_TREES << 1)
+ + (lastBlock ? 1 : 0), 3);
+ literalTree.setStaticCodes(staticLCodes, staticLLength);
+ distTree.setStaticCodes(staticDCodes, staticDLength);
+ compressBlock();
+ reset();
}
else
{
- /* Encode with dynamic tree */
- pending.writeBits((DeflaterConstants.DYN_TREES << 1)
- + (lastBlock ? 1 : 0), 3);
- sendAllTrees(blTreeCodes);
- compressBlock();
- reset();
+ /* Encode with dynamic tree */
+ pending.writeBits((DeflaterConstants.DYN_TREES << 1)
+ + (lastBlock ? 1 : 0), 3);
+ sendAllTrees(blTreeCodes);
+ compressBlock();
+ reset();
}
}
@@ -739,14 +739,14 @@ class DeflaterHuffman
return last_lit == BUFSIZE;
}
- public final boolean tallyLit(int lit)
+ public final boolean tallyLit(int lit)
{
if (DeflaterConstants.DEBUGGING)
{
- if (lit > 32 && lit < 127)
- System.err.println("("+(char)lit+")");
- else
- System.err.println("{"+lit+"}");
+ if (lit > 32 && lit < 127)
+ System.err.println("("+(char)lit+")");
+ else
+ System.err.println("{"+lit+"}");
}
d_buf[last_lit] = 0;
l_buf[last_lit++] = (byte) lit;
@@ -754,7 +754,7 @@ class DeflaterHuffman
return last_lit == BUFSIZE;
}
- public final boolean tallyDist(int dist, int len)
+ public final boolean tallyDist(int dist, int len)
{
if (DeflaterConstants.DEBUGGING)
System.err.println("["+dist+","+len+"]");
diff --git a/libjava/classpath/java/util/zip/DeflaterOutputStream.java b/libjava/classpath/java/util/zip/DeflaterOutputStream.java
index 4321c0f2cae..6fd1c5cfb57 100644
--- a/libjava/classpath/java/util/zip/DeflaterOutputStream.java
+++ b/libjava/classpath/java/util/zip/DeflaterOutputStream.java
@@ -57,21 +57,21 @@ import java.io.OutputStream;
* finishing the stream.
*
* @author Tom Tromey, Jochen Hoenicke
- * @date Jan 11, 2001
+ * @date Jan 11, 2001
*/
public class DeflaterOutputStream extends FilterOutputStream
{
- /**
+ /**
* This buffer is used temporarily to retrieve the bytes from the
- * deflater and write them to the underlying output stream.
+ * deflater and write them to the underlying output stream.
*/
protected byte[] buf;
- /**
+ /**
* The deflater which is used to deflate the stream.
*/
protected Deflater def;
-
+
/**
* Deflates everything in the def's input buffers. This will call
* <code>def.deflate()</code> until all bytes from the input buffers
@@ -81,19 +81,19 @@ public class DeflaterOutputStream extends FilterOutputStream
{
while (! def.needsInput())
{
- int len = def.deflate(buf, 0, buf.length);
+ int len = def.deflate(buf, 0, buf.length);
- // System.err.println("DOS deflated " + len + " out of " + buf.length);
- if (len <= 0)
- break;
- out.write(buf, 0, len);
+ // System.err.println("DOS deflated " + len + " out of " + buf.length);
+ if (len <= 0)
+ break;
+ out.write(buf, 0, len);
}
if (! def.needsInput())
throw new InternalError("Can't deflate all input?");
}
- /**
+ /**
* Creates a new DeflaterOutputStream with a default Deflater and
* default buffer size.
* @param out the output stream where deflated output should be written.
@@ -103,7 +103,7 @@ public class DeflaterOutputStream extends FilterOutputStream
this(out, new Deflater(), 4096);
}
- /**
+ /**
* Creates a new DeflaterOutputStream with the given Deflater and
* default buffer size.
* @param out the output stream where deflated output should be written.
@@ -114,7 +114,7 @@ public class DeflaterOutputStream extends FilterOutputStream
this(out, defl, 4096);
}
- /**
+ /**
* Creates a new DeflaterOutputStream with the given Deflater and
* buffer size.
* @param out the output stream where deflated output should be written.
@@ -131,7 +131,7 @@ public class DeflaterOutputStream extends FilterOutputStream
def = defl;
}
- /**
+ /**
* Flushes the stream by calling flush() on the deflater and then
* on the underlying stream. This ensures that all bytes are
* flushed. This function doesn't work in Sun's JDK, but only in
@@ -147,17 +147,17 @@ public class DeflaterOutputStream extends FilterOutputStream
/**
* Finishes the stream by calling finish() on the deflater. This
* was the only way to ensure that all bytes are flushed in Sun's
- * JDK.
+ * JDK.
*/
public void finish() throws IOException
{
def.finish();
while (! def.finished())
{
- int len = def.deflate(buf, 0, buf.length);
- if (len <= 0)
- break;
- out.write(buf, 0, len);
+ int len = def.deflate(buf, 0, buf.length);
+ if (len <= 0)
+ break;
+ out.write(buf, 0, len);
}
if (! def.finished())
throw new InternalError("Can't deflate all input?");
@@ -165,7 +165,7 @@ public class DeflaterOutputStream extends FilterOutputStream
}
/**
- * Calls finish() and closes the stream.
+ * Calls finish() and closes the stream.
*/
public void close() throws IOException
{
diff --git a/libjava/classpath/java/util/zip/DeflaterPending.java b/libjava/classpath/java/util/zip/DeflaterPending.java
index f38212c352d..fabc2264e6e 100644
--- a/libjava/classpath/java/util/zip/DeflaterPending.java
+++ b/libjava/classpath/java/util/zip/DeflaterPending.java
@@ -41,7 +41,7 @@ package java.util.zip;
* This class stores the pending output of the Deflater.
*
* @author Jochen Hoenicke
- * @date Jan 5, 2000
+ * @date Jan 5, 2000
*/
class DeflaterPending extends PendingBuffer
@@ -51,4 +51,3 @@ class DeflaterPending extends PendingBuffer
super(DeflaterConstants.PENDING_BUF_SIZE);
}
}
-
diff --git a/libjava/classpath/java/util/zip/GZIPInputStream.java b/libjava/classpath/java/util/zip/GZIPInputStream.java
index f244810e787..ed99ee92c4b 100644
--- a/libjava/classpath/java/util/zip/GZIPInputStream.java
+++ b/libjava/classpath/java/util/zip/GZIPInputStream.java
@@ -7,7 +7,7 @@ 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
@@ -43,7 +43,7 @@ import java.io.IOException;
import java.io.InputStream;
/**
- * This filter stream is used to decompress a "GZIP" format stream.
+ * This filter stream is used to decompress a "GZIP" format stream.
* The "GZIP" format is described in RFC 1952.
*
* @author John Leuner
@@ -86,11 +86,11 @@ public class GZIPInputStream
/**
* The CRC-32 checksum value for uncompressed data.
*/
- protected CRC32 crc;
+ protected CRC32 crc;
/**
* Indicates whether or not the end of the stream has been reached.
- */
+ */
protected boolean eos;
/**
@@ -101,7 +101,7 @@ public class GZIPInputStream
/**
* Creates a GZIPInputStream with the default buffer size.
*
- * @param in The stream to read compressed data from
+ * @param in The stream to read compressed data from
* (in GZIP format).
*
* @throws IOException if an error occurs during an I/O operation.
@@ -115,7 +115,7 @@ public class GZIPInputStream
/**
* Creates a GZIPInputStream with the specified buffer size.
*
- * @param in The stream to read compressed data from
+ * @param in The stream to read compressed data from
* (in GZIP format).
* @param size The size of the buffer to use.
*
@@ -204,7 +204,7 @@ public class GZIPInputStream
throw new IOException("Error in GZIP header, bad magic code");
headCRC.update(magic);
headCRC.update(magic2);
-
+
/* 2. Check the compression type (must be 8) */
int CM = in.read();
if (CM != Deflater.DEFLATED)
@@ -216,32 +216,32 @@ public class GZIPInputStream
if (flags < 0)
throw new EOFException("Early EOF in GZIP header");
headCRC.update(flags);
-
+
/* This flag byte is divided into individual bits as follows:
-
- bit 0 FTEXT
- bit 1 FHCRC
- bit 2 FEXTRA
- bit 3 FNAME
- bit 4 FCOMMENT
- bit 5 reserved
- bit 6 reserved
- bit 7 reserved
+
+ bit 0 FTEXT
+ bit 1 FHCRC
+ bit 2 FEXTRA
+ bit 3 FNAME
+ bit 4 FCOMMENT
+ bit 5 reserved
+ bit 6 reserved
+ bit 7 reserved
*/
-
- /* 3.1 Check the reserved bits are zero */
+
+ /* 3.1 Check the reserved bits are zero */
if ((flags & 0xd0) != 0)
throw new IOException("Reserved flag bits in GZIP header != 0");
-
+
/* 4.-6. Skip the modification time, extra flags, and OS type */
for (int i=0; i< 6; i++)
{
int readByte = in.read();
if (readByte < 0)
- throw new EOFException("Early EOF in GZIP header");
+ throw new EOFException("Early EOF in GZIP header");
headCRC.update(readByte);
}
-
+
/* 7. Read extra field */
if ((flags & FEXTRA) != 0)
{
@@ -249,39 +249,39 @@ public class GZIPInputStream
for (int i=0; i< 2; i++)
{
int readByte = in.read();
- if (readByte < 0)
- throw new EOFException("Early EOF in GZIP header");
- headCRC.update(readByte);
+ if (readByte < 0)
+ throw new EOFException("Early EOF in GZIP header");
+ headCRC.update(readByte);
}
if (in.read() < 0 || in.read() < 0)
- throw new EOFException("Early EOF in GZIP header");
-
+ throw new EOFException("Early EOF in GZIP header");
+
int len1, len2, extraLen;
len1 = in.read();
len2 = in.read();
if ((len1 < 0) || (len2 < 0))
- throw new EOFException("Early EOF in GZIP header");
+ throw new EOFException("Early EOF in GZIP header");
headCRC.update(len1);
headCRC.update(len2);
extraLen = (len1 << 8) | len2;
for (int i = 0; i < extraLen;i++)
{
- int readByte = in.read();
- if (readByte < 0)
- throw new EOFException("Early EOF in GZIP header");
- headCRC.update(readByte);
+ int readByte = in.read();
+ if (readByte < 0)
+ throw new EOFException("Early EOF in GZIP header");
+ headCRC.update(readByte);
}
}
-
+
/* 8. Read file name */
if ((flags & FNAME) != 0)
{
int readByte;
while ( (readByte = in.read()) > 0)
- headCRC.update(readByte);
+ headCRC.update(readByte);
if (readByte < 0)
- throw new EOFException("Early EOF in GZIP file name");
+ throw new EOFException("Early EOF in GZIP file name");
headCRC.update(readByte);
}
@@ -296,7 +296,7 @@ public class GZIPInputStream
throw new EOFException("Early EOF in GZIP comment");
headCRC.update(readByte);
}
-
+
/* 10. Read header CRC */
if ((flags & FHCRC) != 0)
{
@@ -304,16 +304,16 @@ public class GZIPInputStream
int crcval = in.read();
if (crcval < 0)
throw new EOFException("Early EOF in GZIP header");
-
+
tempByte = in.read();
if (tempByte < 0)
throw new EOFException("Early EOF in GZIP header");
-
+
crcval = (crcval << 8) | tempByte;
if (crcval != ((int) headCRC.getValue() & 0xffff))
throw new IOException("Header CRC value mismatch");
}
-
+
readGZIPHeader = true;
//System.err.println("Read GZIP header");
}
@@ -330,7 +330,7 @@ public class GZIPInputStream
{
int count = in.read(footer, 8-needed, needed);
if (count <= 0)
- throw new EOFException("Early EOF in GZIP footer");
+ throw new EOFException("Early EOF in GZIP footer");
needed -= count; //Jewel Jan 16
}
@@ -338,9 +338,9 @@ public class GZIPInputStream
| ((footer[2] & 0xff) << 16) | (footer[3] << 24);
if (crcval != (int) crc.getValue())
throw new IOException("GZIP crc sum mismatch, theirs \""
- + Integer.toHexString(crcval)
- + "\" and ours \""
- + Integer.toHexString( (int) crc.getValue()));
+ + Integer.toHexString(crcval)
+ + "\" and ours \""
+ + Integer.toHexString( (int) crc.getValue()));
int total = (footer[4] & 0xff) | ((footer[5] & 0xff) << 8)
| ((footer[6] & 0xff) << 16) | (footer[7] << 24);
diff --git a/libjava/classpath/java/util/zip/GZIPOutputStream.java b/libjava/classpath/java/util/zip/GZIPOutputStream.java
index 5b7b827a9ff..0080ab645a7 100644
--- a/libjava/classpath/java/util/zip/GZIPOutputStream.java
+++ b/libjava/classpath/java/util/zip/GZIPOutputStream.java
@@ -7,7 +7,7 @@ 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
@@ -41,7 +41,7 @@ import java.io.IOException;
import java.io.OutputStream;
/**
- * This filter stream is used to compress a stream into a "GZIP" stream.
+ * This filter stream is used to compress a stream into a "GZIP" stream.
* The "GZIP" format is described in RFC 1952.
*
* @author John Leuner
@@ -64,8 +64,8 @@ public class GZIPOutputStream extends DeflaterOutputStream
/**
* Creates a GZIPOutputStream with the default buffer size
*
- * @param out The stream to read data (to be compressed) from
- *
+ * @param out The stream to read data (to be compressed) from
+ *
*/
public GZIPOutputStream(OutputStream out) throws IOException
{
@@ -75,8 +75,8 @@ public class GZIPOutputStream extends DeflaterOutputStream
/**
* Creates a GZIPOutputStream with the specified buffer size
*
- * @param out The stream to read compressed data from
- * @param size Size of the buffer to use
+ * @param out The stream to read compressed data from
+ * @param size Size of the buffer to use
*/
public GZIPOutputStream(OutputStream out, int size) throws IOException
{
@@ -85,25 +85,25 @@ public class GZIPOutputStream extends DeflaterOutputStream
int mod_time = (int) (System.currentTimeMillis() / 1000L);
byte[] gzipHeader =
{
- /* The two magic bytes */
- (byte) GZIPInputStream.GZIP_MAGIC,
- (byte) (GZIPInputStream.GZIP_MAGIC >> 8),
-
- /* The compression type */
- (byte) Deflater.DEFLATED,
-
+ /* The two magic bytes */
+ (byte) GZIPInputStream.GZIP_MAGIC,
+ (byte) (GZIPInputStream.GZIP_MAGIC >> 8),
+
+ /* The compression type */
+ (byte) Deflater.DEFLATED,
+
/* The flags (not set) */
- 0,
-
- /* The modification time */
- (byte) mod_time, (byte) (mod_time >> 8),
- (byte) (mod_time >> 16), (byte) (mod_time >> 24),
-
- /* The extra flags */
- 0,
-
- /* The OS type (unknown) */
- (byte) 255
+ 0,
+
+ /* The modification time */
+ (byte) mod_time, (byte) (mod_time >> 8),
+ (byte) (mod_time >> 16), (byte) (mod_time >> 24),
+
+ /* The extra flags */
+ 0,
+
+ /* The OS type (unknown) */
+ (byte) 255
};
out.write(gzipHeader);
@@ -134,18 +134,18 @@ public class GZIPOutputStream extends DeflaterOutputStream
int totalin = def.getTotalIn();
int crcval = (int) (crc.getValue() & 0xffffffff);
- // System.err.println("CRC val is " + Integer.toHexString( crcval ) + " and length " + Integer.toHexString(totalin));
-
- byte[] gzipFooter =
+ // System.err.println("CRC val is " + Integer.toHexString( crcval ) + " and length " + Integer.toHexString(totalin));
+
+ byte[] gzipFooter =
{
- (byte) crcval, (byte) (crcval >> 8),
- (byte) (crcval >> 16), (byte) (crcval >> 24),
+ (byte) crcval, (byte) (crcval >> 8),
+ (byte) (crcval >> 16), (byte) (crcval >> 24),
- (byte) totalin, (byte) (totalin >> 8),
- (byte) (totalin >> 16), (byte) (totalin >> 24)
+ (byte) totalin, (byte) (totalin >> 8),
+ (byte) (totalin >> 16), (byte) (totalin >> 24)
};
out.write(gzipFooter);
- // System.err.println("wrote GZIP trailer (" + gzipFooter.length + " bytes )");
+ // System.err.println("wrote GZIP trailer (" + gzipFooter.length + " bytes )");
}
}
diff --git a/libjava/classpath/java/util/zip/Inflater.java b/libjava/classpath/java/util/zip/Inflater.java
index f529dc691c6..0f094d66744 100644
--- a/libjava/classpath/java/util/zip/Inflater.java
+++ b/libjava/classpath/java/util/zip/Inflater.java
@@ -7,7 +7,7 @@ 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
@@ -43,7 +43,7 @@ package java.util.zip;
*/
/**
- * Inflater is used to decompress data that has been compressed according
+ * Inflater is used to decompress data that has been compressed according
* to the "deflate" standard described in rfc1950.
*
* The usage is as following. First you have to set some input with
@@ -51,10 +51,10 @@ package java.util.zip;
* inflate any bytes there may be three reasons:
* <ul>
* <li>needsInput() returns true because the input buffer is empty.
- * You have to provide more input with <code>setInput()</code>.
+ * You have to provide more input with <code>setInput()</code>.
* NOTE: needsInput() also returns true when, the stream is finished.
* </li>
- * <li>needsDictionary() returns true, you have to provide a preset
+ * <li>needsDictionary() returns true, you have to provide a preset
* dictionary with <code>setDictionary()</code>.</li>
* <li>finished() returns true, the inflater has finished.</li>
* </ul>
@@ -69,15 +69,15 @@ package java.util.zip;
public class Inflater
{
/* Copy lengths for literal codes 257..285 */
- private static final int CPLENS[] =
- {
+ private static final int CPLENS[] =
+ {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258
};
-
- /* Extra bits for literal codes 257..285 */
- private static final int CPLEXT[] =
- {
+
+ /* Extra bits for literal codes 257..285 */
+ private static final int CPLEXT[] =
+ {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0
};
@@ -88,11 +88,11 @@ public class Inflater
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577
};
-
+
/* Extra bits for distance codes */
private static final int CPDEXT[] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
- 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
+ 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13
};
@@ -122,10 +122,10 @@ public class Inflater
* Only valid if mode is DECODE_DICT or DECODE_CHKSUM.
*/
private int readAdler;
- /**
+ /**
* The number of bits needed to complete the current state. This
* is valid, if mode is DECODE_DICT, DECODE_CHKSUM,
- * DECODE_HUFFMAN_LENBITS or DECODE_HUFFMAN_DISTBITS.
+ * DECODE_HUFFMAN_LENBITS or DECODE_HUFFMAN_DISTBITS.
*/
private int neededBits;
private int repLength, repDist;
@@ -133,7 +133,7 @@ public class Inflater
/**
* True, if the last block flag was set in the last block of the
* inflated stream. This means that the stream ends after the
- * current block.
+ * current block.
*/
private boolean isLastBlock;
@@ -143,7 +143,7 @@ public class Inflater
private long totalOut;
/**
* The total number of bytes set with setInput(). This is not the
- * value returned by getTotalIn(), since this also includes the
+ * value returned by getTotalIn(), since this also includes the
* unprocessed input.
*/
private long totalIn;
@@ -198,7 +198,7 @@ public class Inflater
* for the Sun implementation). Exists only for compatibility
* with Sun's JDK, where the compressor allocates native memory.
* If you call any method (even reset) afterwards the behaviour is
- * <i>undefined</i>.
+ * <i>undefined</i>.
*/
public void end ()
{
@@ -214,7 +214,7 @@ public class Inflater
* Returns true, if the inflater has finished. This means, that no
* input is needed and no output can be produced.
*/
- public boolean finished()
+ public boolean finished()
{
return mode == FINISHED && outputWindow.getAvailable() == 0;
}
@@ -230,18 +230,18 @@ public class Inflater
{
return needsDictionary() ? readAdler : (int) adler.getValue();
}
-
+
/**
* Gets the number of unprocessed input. Useful, if the end of the
* stream is reached and you want to further process the bytes after
- * the deflate stream.
+ * the deflate stream.
* @return the number of bytes of the input which were not processed.
*/
public int getRemaining()
{
return input.getAvailableBytes();
}
-
+
/**
* Gets the total number of processed compressed input bytes.
* @return the total number of bytes of processed input bytes.
@@ -283,11 +283,11 @@ public class Inflater
/**
* Inflates the compressed stream to the output buffer. If this
* returns 0, you should check, whether needsDictionary(),
- * needsInput() or finished() returns true, to determine why no
+ * needsInput() or finished() returns true, to determine why no
* further output is produced.
* @param buf the output buffer.
* @return the number of bytes written to the buffer, 0 if no further
- * output can be produced.
+ * output can be produced.
* @exception DataFormatException if deflated stream is invalid.
* @exception IllegalArgumentException if buf has length 0.
*/
@@ -299,13 +299,13 @@ public class Inflater
/**
* Inflates the compressed stream to the output buffer. If this
* returns 0, you should check, whether needsDictionary(),
- * needsInput() or finished() returns true, to determine why no
+ * needsInput() or finished() returns true, to determine why no
* further output is produced.
* @param buf the output buffer.
* @param off the offset into buffer where the output should start.
* @param len the maximum length of the output.
* @return the number of bytes written to the buffer, 0 if no further
- * output can be produced.
+ * output can be produced.
* @exception DataFormatException if deflated stream is invalid.
* @exception IndexOutOfBoundsException if the off and/or len are wrong.
*/
@@ -351,7 +351,7 @@ public class Inflater
*
* <em>NOTE</em>: This method also returns true when the stream is finished.
*/
- public boolean needsInput ()
+ public boolean needsInput ()
{
return input.needsInput ();
}
@@ -381,7 +381,7 @@ public class Inflater
* @param buffer the dictionary.
* @exception IllegalStateException if no dictionary is needed.
* @exception IllegalArgumentException if the dictionary checksum is
- * wrong.
+ * wrong.
*/
public void setDictionary (byte[] buffer)
{
@@ -398,7 +398,7 @@ public class Inflater
* @param len the length of the dictionary.
* @exception IllegalStateException if no dictionary is needed.
* @exception IllegalArgumentException if the dictionary checksum is
- * wrong.
+ * wrong.
* @exception IndexOutOfBoundsException if the off and/or len are wrong.
*/
public void setDictionary (byte[] buffer, int off, int len)
@@ -420,7 +420,7 @@ public class Inflater
* @param buf the input.
* @exception IllegalStateException if no input is needed.
*/
- public void setInput (byte[] buf)
+ public void setInput (byte[] buf)
{
setInput (buf, 0, buf.length);
}
@@ -430,11 +430,11 @@ public class Inflater
* returns true.
* @param buf the input.
* @param off the offset into buffer where the input starts.
- * @param len the length of the input.
+ * @param len the length of the input.
* @exception IllegalStateException if no input is needed.
* @exception IndexOutOfBoundsException if the off and/or len are wrong.
*/
- public void setInput (byte[] buf, int off, int len)
+ public void setInput (byte[] buf, int off, int len)
{
input.setInput (buf, off, len);
totalIn += len;
@@ -442,7 +442,7 @@ public class Inflater
/**
* Decodes the deflate header.
- * @return false if more input is needed.
+ * @return false if more input is needed.
* @exception DataFormatException if header is invalid.
*/
private boolean decodeHeader () throws DataFormatException
@@ -451,48 +451,48 @@ public class Inflater
if (header < 0)
return false;
input.dropBits(16);
-
+
/* The header is written in "wrong" byte order */
header = ((header << 8) | (header >> 8)) & 0xffff;
if (header % 31 != 0)
throw new DataFormatException("Header checksum illegal");
-
+
if ((header & 0x0f00) != (Deflater.DEFLATED << 8))
throw new DataFormatException("Compression Method unknown");
- /* Maximum size of the backwards window in bits.
+ /* Maximum size of the backwards window in bits.
* We currently ignore this, but we could use it to make the
* inflater window more space efficient. On the other hand the
* full window (15 bits) is needed most times, anyway.
int max_wbits = ((header & 0x7000) >> 12) + 8;
*/
-
+
if ((header & 0x0020) == 0) // Dictionary flag?
{
- mode = DECODE_BLOCKS;
+ mode = DECODE_BLOCKS;
}
else
{
- mode = DECODE_DICT;
- neededBits = 32;
+ mode = DECODE_DICT;
+ neededBits = 32;
}
return true;
}
-
+
/**
* Decodes the dictionary checksum after the deflate header.
- * @return false if more input is needed.
+ * @return false if more input is needed.
*/
private boolean decodeDict ()
{
while (neededBits > 0)
{
- int dictByte = input.peekBits(8);
- if (dictByte < 0)
- return false;
- input.dropBits(8);
- readAdler = (readAdler << 8) | dictByte;
- neededBits -= 8;
+ int dictByte = input.peekBits(8);
+ if (dictByte < 0)
+ return false;
+ input.dropBits(8);
+ readAdler = (readAdler << 8) | dictByte;
+ neededBits -= 8;
}
return false;
}
@@ -501,226 +501,226 @@ public class Inflater
* Decodes the huffman encoded symbols in the input stream.
* @return false if more input is needed, true if output window is
* full or the current block ends.
- * @exception DataFormatException if deflated stream is invalid.
+ * @exception DataFormatException if deflated stream is invalid.
*/
private boolean decodeHuffman () throws DataFormatException
{
int free = outputWindow.getFreeSpace();
while (free >= 258)
{
- int symbol;
- switch (mode)
- {
- case DECODE_HUFFMAN:
- /* This is the inner loop so it is optimized a bit */
- while (((symbol = litlenTree.getSymbol(input)) & ~0xff) == 0)
- {
- outputWindow.write(symbol);
- if (--free < 258)
- return true;
- }
- if (symbol < 257)
- {
- if (symbol < 0)
- return false;
- else
- {
- /* symbol == 256: end of block */
- distTree = null;
- litlenTree = null;
- mode = DECODE_BLOCKS;
- return true;
- }
- }
-
- try
- {
- repLength = CPLENS[symbol - 257];
- neededBits = CPLEXT[symbol - 257];
- }
- catch (ArrayIndexOutOfBoundsException ex)
- {
- throw new DataFormatException("Illegal rep length code");
- }
- /* fall through */
- case DECODE_HUFFMAN_LENBITS:
- if (neededBits > 0)
- {
- mode = DECODE_HUFFMAN_LENBITS;
- int i = input.peekBits(neededBits);
- if (i < 0)
- return false;
- input.dropBits(neededBits);
- repLength += i;
- }
- mode = DECODE_HUFFMAN_DIST;
- /* fall through */
- case DECODE_HUFFMAN_DIST:
- symbol = distTree.getSymbol(input);
- if (symbol < 0)
- return false;
- try
- {
- repDist = CPDIST[symbol];
- neededBits = CPDEXT[symbol];
- }
- catch (ArrayIndexOutOfBoundsException ex)
- {
- throw new DataFormatException("Illegal rep dist code");
- }
- /* fall through */
- case DECODE_HUFFMAN_DISTBITS:
- if (neededBits > 0)
- {
- mode = DECODE_HUFFMAN_DISTBITS;
- int i = input.peekBits(neededBits);
- if (i < 0)
- return false;
- input.dropBits(neededBits);
- repDist += i;
- }
- outputWindow.repeat(repLength, repDist);
- free -= repLength;
- mode = DECODE_HUFFMAN;
- break;
- default:
- throw new IllegalStateException();
- }
+ int symbol;
+ switch (mode)
+ {
+ case DECODE_HUFFMAN:
+ /* This is the inner loop so it is optimized a bit */
+ while (((symbol = litlenTree.getSymbol(input)) & ~0xff) == 0)
+ {
+ outputWindow.write(symbol);
+ if (--free < 258)
+ return true;
+ }
+ if (symbol < 257)
+ {
+ if (symbol < 0)
+ return false;
+ else
+ {
+ /* symbol == 256: end of block */
+ distTree = null;
+ litlenTree = null;
+ mode = DECODE_BLOCKS;
+ return true;
+ }
+ }
+
+ try
+ {
+ repLength = CPLENS[symbol - 257];
+ neededBits = CPLEXT[symbol - 257];
+ }
+ catch (ArrayIndexOutOfBoundsException ex)
+ {
+ throw new DataFormatException("Illegal rep length code");
+ }
+ /* fall through */
+ case DECODE_HUFFMAN_LENBITS:
+ if (neededBits > 0)
+ {
+ mode = DECODE_HUFFMAN_LENBITS;
+ int i = input.peekBits(neededBits);
+ if (i < 0)
+ return false;
+ input.dropBits(neededBits);
+ repLength += i;
+ }
+ mode = DECODE_HUFFMAN_DIST;
+ /* fall through */
+ case DECODE_HUFFMAN_DIST:
+ symbol = distTree.getSymbol(input);
+ if (symbol < 0)
+ return false;
+ try
+ {
+ repDist = CPDIST[symbol];
+ neededBits = CPDEXT[symbol];
+ }
+ catch (ArrayIndexOutOfBoundsException ex)
+ {
+ throw new DataFormatException("Illegal rep dist code");
+ }
+ /* fall through */
+ case DECODE_HUFFMAN_DISTBITS:
+ if (neededBits > 0)
+ {
+ mode = DECODE_HUFFMAN_DISTBITS;
+ int i = input.peekBits(neededBits);
+ if (i < 0)
+ return false;
+ input.dropBits(neededBits);
+ repDist += i;
+ }
+ outputWindow.repeat(repLength, repDist);
+ free -= repLength;
+ mode = DECODE_HUFFMAN;
+ break;
+ default:
+ throw new IllegalStateException();
+ }
}
return true;
}
/**
* Decodes the adler checksum after the deflate stream.
- * @return false if more input is needed.
+ * @return false if more input is needed.
* @exception DataFormatException if checksum doesn't match.
*/
private boolean decodeChksum () throws DataFormatException
{
while (neededBits > 0)
{
- int chkByte = input.peekBits(8);
- if (chkByte < 0)
- return false;
- input.dropBits(8);
- readAdler = (readAdler << 8) | chkByte;
- neededBits -= 8;
+ int chkByte = input.peekBits(8);
+ if (chkByte < 0)
+ return false;
+ input.dropBits(8);
+ readAdler = (readAdler << 8) | chkByte;
+ neededBits -= 8;
}
if ((int) adler.getValue() != readAdler)
throw new DataFormatException("Adler chksum doesn't match: "
- +Integer.toHexString((int)adler.getValue())
- +" vs. "+Integer.toHexString(readAdler));
+ +Integer.toHexString((int)adler.getValue())
+ +" vs. "+Integer.toHexString(readAdler));
mode = FINISHED;
return false;
}
/**
* Decodes the deflated stream.
- * @return false if more input is needed, or if finished.
+ * @return false if more input is needed, or if finished.
* @exception DataFormatException if deflated stream is invalid.
*/
private boolean decode () throws DataFormatException
{
- switch (mode)
+ switch (mode)
{
case DECODE_HEADER:
- return decodeHeader();
+ return decodeHeader();
case DECODE_DICT:
- return decodeDict();
+ return decodeDict();
case DECODE_CHKSUM:
- return decodeChksum();
+ return decodeChksum();
case DECODE_BLOCKS:
- if (isLastBlock)
- {
- if (nowrap)
- {
- mode = FINISHED;
- return false;
- }
- else
- {
- input.skipToByteBoundary();
- neededBits = 32;
- mode = DECODE_CHKSUM;
- return true;
- }
- }
-
- int type = input.peekBits(3);
- if (type < 0)
- return false;
- input.dropBits(3);
-
- if ((type & 1) != 0)
- isLastBlock = true;
- switch (type >> 1)
- {
- case DeflaterConstants.STORED_BLOCK:
- input.skipToByteBoundary();
- mode = DECODE_STORED_LEN1;
- break;
- case DeflaterConstants.STATIC_TREES:
- litlenTree = InflaterHuffmanTree.defLitLenTree;
- distTree = InflaterHuffmanTree.defDistTree;
- mode = DECODE_HUFFMAN;
- break;
- case DeflaterConstants.DYN_TREES:
- dynHeader = new InflaterDynHeader();
- mode = DECODE_DYN_HEADER;
- break;
- default:
- throw new DataFormatException("Unknown block type "+type);
- }
- return true;
+ if (isLastBlock)
+ {
+ if (nowrap)
+ {
+ mode = FINISHED;
+ return false;
+ }
+ else
+ {
+ input.skipToByteBoundary();
+ neededBits = 32;
+ mode = DECODE_CHKSUM;
+ return true;
+ }
+ }
+
+ int type = input.peekBits(3);
+ if (type < 0)
+ return false;
+ input.dropBits(3);
+
+ if ((type & 1) != 0)
+ isLastBlock = true;
+ switch (type >> 1)
+ {
+ case DeflaterConstants.STORED_BLOCK:
+ input.skipToByteBoundary();
+ mode = DECODE_STORED_LEN1;
+ break;
+ case DeflaterConstants.STATIC_TREES:
+ litlenTree = InflaterHuffmanTree.defLitLenTree;
+ distTree = InflaterHuffmanTree.defDistTree;
+ mode = DECODE_HUFFMAN;
+ break;
+ case DeflaterConstants.DYN_TREES:
+ dynHeader = new InflaterDynHeader();
+ mode = DECODE_DYN_HEADER;
+ break;
+ default:
+ throw new DataFormatException("Unknown block type "+type);
+ }
+ return true;
case DECODE_STORED_LEN1:
- {
- if ((uncomprLen = input.peekBits(16)) < 0)
- return false;
- input.dropBits(16);
- mode = DECODE_STORED_LEN2;
- }
- /* fall through */
+ {
+ if ((uncomprLen = input.peekBits(16)) < 0)
+ return false;
+ input.dropBits(16);
+ mode = DECODE_STORED_LEN2;
+ }
+ /* fall through */
case DECODE_STORED_LEN2:
- {
- int nlen = input.peekBits(16);
- if (nlen < 0)
- return false;
- input.dropBits(16);
- if (nlen != (uncomprLen ^ 0xffff))
- throw new DataFormatException("broken uncompressed block");
- mode = DECODE_STORED;
- }
- /* fall through */
+ {
+ int nlen = input.peekBits(16);
+ if (nlen < 0)
+ return false;
+ input.dropBits(16);
+ if (nlen != (uncomprLen ^ 0xffff))
+ throw new DataFormatException("broken uncompressed block");
+ mode = DECODE_STORED;
+ }
+ /* fall through */
case DECODE_STORED:
- {
- int more = outputWindow.copyStored(input, uncomprLen);
- uncomprLen -= more;
- if (uncomprLen == 0)
- {
- mode = DECODE_BLOCKS;
- return true;
- }
- return !input.needsInput();
- }
+ {
+ int more = outputWindow.copyStored(input, uncomprLen);
+ uncomprLen -= more;
+ if (uncomprLen == 0)
+ {
+ mode = DECODE_BLOCKS;
+ return true;
+ }
+ return !input.needsInput();
+ }
case DECODE_DYN_HEADER:
- if (!dynHeader.decode(input))
- return false;
- litlenTree = dynHeader.buildLitLenTree();
- distTree = dynHeader.buildDistTree();
- mode = DECODE_HUFFMAN;
- /* fall through */
+ if (!dynHeader.decode(input))
+ return false;
+ litlenTree = dynHeader.buildLitLenTree();
+ distTree = dynHeader.buildDistTree();
+ mode = DECODE_HUFFMAN;
+ /* fall through */
case DECODE_HUFFMAN:
case DECODE_HUFFMAN_LENBITS:
case DECODE_HUFFMAN_DIST:
case DECODE_HUFFMAN_DISTBITS:
- return decodeHuffman();
+ return decodeHuffman();
case FINISHED:
- return false;
+ return false;
default:
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
+ }
}
}
diff --git a/libjava/classpath/java/util/zip/InflaterDynHeader.java b/libjava/classpath/java/util/zip/InflaterDynHeader.java
index bff84a894d8..64e08d6bbb5 100644
--- a/libjava/classpath/java/util/zip/InflaterDynHeader.java
+++ b/libjava/classpath/java/util/zip/InflaterDynHeader.java
@@ -49,12 +49,12 @@ class InflaterDynHeader
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;
@@ -63,127 +63,127 @@ class InflaterDynHeader
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;
- }
+ 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;
+ }
}
}
diff --git a/libjava/classpath/java/util/zip/InflaterHuffmanTree.java b/libjava/classpath/java/util/zip/InflaterHuffmanTree.java
index 6c9b2175d33..c12c732e0c7 100644
--- a/libjava/classpath/java/util/zip/InflaterHuffmanTree.java
+++ b/libjava/classpath/java/util/zip/InflaterHuffmanTree.java
@@ -40,37 +40,37 @@ package java.util.zip;
class InflaterHuffmanTree
{
private static final int MAX_BITLEN = 15;
-
+
private short[] tree;
static InflaterHuffmanTree defLitLenTree, defDistTree;
static
{
- try
+ 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);
- }
+ 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");
+ throw new InternalError
+ ("InflaterHuffmanTree: static tree length illegal");
}
}
@@ -83,31 +83,31 @@ class InflaterHuffmanTree
{
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 bits = codeLengths[i];
+ if (bits > 0)
+ blCount[bits]++;
}
int code = 0;
int treeSize = 512;
for (int bits = 1; bits <= MAX_BITLEN; bits++)
{
- nextCode[bits] = code;
- 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);
- }
+ nextCode[bits] = code;
+ 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)
throw new DataFormatException("Code lengths don't add up properly.");
@@ -119,46 +119,46 @@ class InflaterHuffmanTree
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);
- }
+ 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));
+ 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));
}
}
@@ -173,45 +173,45 @@ class InflaterHuffmanTree
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;
- }
+ 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;
+ 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;
}
}
}
diff --git a/libjava/classpath/java/util/zip/InflaterInputStream.java b/libjava/classpath/java/util/zip/InflaterInputStream.java
index 08c1fd75a0b..1c5e9f2dd6c 100644
--- a/libjava/classpath/java/util/zip/InflaterInputStream.java
+++ b/libjava/classpath/java/util/zip/InflaterInputStream.java
@@ -8,7 +8,7 @@ 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
@@ -57,17 +57,17 @@ import java.io.InputStream;
public class InflaterInputStream extends FilterInputStream
{
/**
- * Decompressor for this filter
+ * Decompressor for this filter
*/
protected Inflater inf;
/**
- * Byte array used as a buffer
+ * Byte array used as a buffer
*/
protected byte[] buf;
/**
- * Size of buffer
+ * Size of buffer
*/
protected int len;
@@ -81,7 +81,7 @@ public class InflaterInputStream extends FilterInputStream
*
* @param in the InputStream to read bytes from
*/
- public InflaterInputStream(InputStream in)
+ public InflaterInputStream(InputStream in)
{
this(in, new Inflater(), 4096);
}
@@ -93,7 +93,7 @@ public class InflaterInputStream extends FilterInputStream
* @param in the InputStream to read bytes from
* @param inf the decompressor used to decompress data read from in
*/
- public InflaterInputStream(InputStream in, Inflater inf)
+ public InflaterInputStream(InputStream in, Inflater inf)
{
this(in, inf, 4096);
}
@@ -106,7 +106,7 @@ public class InflaterInputStream extends FilterInputStream
* @param inf the decompressor used to decompress data read from in
* @param size size of the buffer to use
*/
- public InflaterInputStream(InputStream in, Inflater inf, int size)
+ public InflaterInputStream(InputStream in, Inflater inf, int size)
{
super(in);
@@ -116,7 +116,7 @@ public class InflaterInputStream extends FilterInputStream
throw new NullPointerException("inf may not be null");
if (size < 0)
throw new IllegalArgumentException("size may not be negative");
-
+
this.inf = inf;
this.buf = new byte [size];
}
@@ -151,12 +151,12 @@ public class InflaterInputStream extends FilterInputStream
{
if (in == null)
throw new ZipException ("InflaterInputStream is closed");
-
+
len = in.read(buf, 0, buf.length);
if (len < 0)
throw new ZipException("Deflated stream ends early.");
-
+
inf.setInput(buf, 0, len);
}
@@ -166,7 +166,7 @@ public class InflaterInputStream extends FilterInputStream
* The byte is in the lower 8 bits of the int.
*/
public int read() throws IOException
- {
+ {
int nread = read(onebytebuffer, 0, 1);
if (nread > 0)
return onebytebuffer[0] & 0xff;
@@ -192,27 +192,27 @@ public class InflaterInputStream extends FilterInputStream
int count = 0;
while (count == 0)
{
- if (inf.needsInput())
- fill();
-
- try
- {
- count = inf.inflate(b, off, len);
- if (count == 0)
- {
- if (this.len == -1)
- {
- // Couldn't get any more data to feed to the Inflater
- return -1;
- }
- if (inf.needsDictionary())
- throw new ZipException("Inflater needs Dictionary");
- }
- }
- catch (DataFormatException dfe)
- {
- throw new ZipException(dfe.getMessage());
- }
+ if (inf.needsInput())
+ fill();
+
+ try
+ {
+ count = inf.inflate(b, off, len);
+ if (count == 0)
+ {
+ if (this.len == -1)
+ {
+ // Couldn't get any more data to feed to the Inflater
+ return -1;
+ }
+ if (inf.needsDictionary())
+ throw new ZipException("Inflater needs Dictionary");
+ }
+ }
+ catch (DataFormatException dfe)
+ {
+ throw new ZipException(dfe.getMessage());
+ }
}
return count;
}
@@ -238,12 +238,12 @@ public class InflaterInputStream extends FilterInputStream
long skipped = 0L;
while (n > 0L)
{
- int numread = read(tmpbuf, 0, buflen);
- if (numread <= 0)
- break;
- n -= numread;
- skipped += numread;
- buflen = (int) Math.min(n, 2048);
+ int numread = read(tmpbuf, 0, buflen);
+ if (numread <= 0)
+ break;
+ n -= numread;
+ skipped += numread;
+ buflen = (int) Math.min(n, 2048);
}
return skipped;
diff --git a/libjava/classpath/java/util/zip/OutputWindow.java b/libjava/classpath/java/util/zip/OutputWindow.java
index 1f082a9faa4..59dadb5f320 100644
--- a/libjava/classpath/java/util/zip/OutputWindow.java
+++ b/libjava/classpath/java/util/zip/OutputWindow.java
@@ -67,9 +67,9 @@ class OutputWindow
{
while (len-- > 0)
{
- window[window_end++] = window[rep_start++];
- window_end &= WINDOW_MASK;
- rep_start &= WINDOW_MASK;
+ window[window_end++] = window[rep_start++];
+ window_end &= WINDOW_MASK;
+ rep_start &= WINDOW_MASK;
}
}
@@ -82,18 +82,18 @@ class OutputWindow
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++];
- }
+ 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);
@@ -101,16 +101,16 @@ class OutputWindow
public int copyStored(StreamManipulator input, int len)
{
- len = Math.min(Math.min(len, WINDOW_SIZE - window_filled),
- input.getAvailableBytes());
+ 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);
+ 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);
@@ -127,8 +127,8 @@ class OutputWindow
if (len > WINDOW_SIZE)
{
- offset += len - WINDOW_SIZE;
- len = WINDOW_SIZE;
+ offset += len - WINDOW_SIZE;
+ len = WINDOW_SIZE;
}
System.arraycopy(dict, offset, window, 0, len);
window_end = len & WINDOW_MASK;
@@ -157,10 +157,10 @@ class OutputWindow
if (tailLen > 0)
{
- System.arraycopy(window, WINDOW_SIZE - tailLen,
- output, offset, tailLen);
- offset += tailLen;
- len = copy_end;
+ 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;
@@ -173,6 +173,3 @@ class OutputWindow
window_filled = window_end = 0;
}
}
-
-
-
diff --git a/libjava/classpath/java/util/zip/PendingBuffer.java b/libjava/classpath/java/util/zip/PendingBuffer.java
index 9079b9804b7..50f561f49a3 100644
--- a/libjava/classpath/java/util/zip/PendingBuffer.java
+++ b/libjava/classpath/java/util/zip/PendingBuffer.java
@@ -40,12 +40,12 @@ 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
+ * It allows you to write bits as well as bytes
*
* Based on DeflaterPending.java
*
* @author Jochen Hoenicke
- * @date Jan 5, 2000
+ * @date Jan 5, 2000
*/
class PendingBuffer
@@ -71,14 +71,14 @@ class PendingBuffer
start = end = bitCount = 0;
}
- public final void writeByte(int b)
+ public final void writeByte(int b)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) b;
}
- public final void writeShort(int s)
+ public final void writeShort(int s)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
@@ -86,7 +86,7 @@ class PendingBuffer
buf[end++] = (byte) (s >> 8);
}
- public final void writeInt(int s)
+ public final void writeInt(int s)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
@@ -96,7 +96,7 @@ class PendingBuffer
buf[end++] = (byte) (s >> 24);
}
- public final void writeBlock(byte[] block, int offset, int len)
+ public final void writeBlock(byte[] block, int offset, int len)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
@@ -113,9 +113,9 @@ class PendingBuffer
throw new IllegalStateException();
if (bitCount > 0)
{
- buf[end++] = (byte) bits;
- if (bitCount > 8)
- buf[end++] = (byte) (bits >>> 8);
+ buf[end++] = (byte) bits;
+ if (bitCount > 8)
+ buf[end++] = (byte) (bits >>> 8);
}
bits = 0;
bitCount = 0;
@@ -161,28 +161,28 @@ class PendingBuffer
public final int flush(byte[] output, int offset, int length) {
if (bitCount >= 8)
{
- buf[end++] = (byte) bits;
- bits >>>= 8;
- 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;
+ length = end - start;
+ System.arraycopy(buf, start, output, offset, length);
+ start = 0;
+ end = 0;
}
else
{
- System.arraycopy(buf, start, output, offset, length);
- start += length;
+ 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
*/
@@ -197,4 +197,3 @@ class PendingBuffer
}
-
diff --git a/libjava/classpath/java/util/zip/StreamManipulator.java b/libjava/classpath/java/util/zip/StreamManipulator.java
index 57d15ae283b..105d807e4bf 100644
--- a/libjava/classpath/java/util/zip/StreamManipulator.java
+++ b/libjava/classpath/java/util/zip/StreamManipulator.java
@@ -46,7 +46,7 @@ package java.util.zip;
* 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
+ * 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.
*
@@ -66,17 +66,17 @@ class StreamManipulator
* 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;
+ 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);
}
@@ -94,7 +94,7 @@ class StreamManipulator
/**
* 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.
+ * @return the value of the bits, or -1 if not enough bits available.
*/
public final int getBits(int n)
{
@@ -114,7 +114,7 @@ class StreamManipulator
}
/**
- * Gets the number of bytes available.
+ * Gets the number of bytes available.
* @return the number of bytes available.
*/
public final int getAvailableBytes()
@@ -141,24 +141,24 @@ class StreamManipulator
* 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.
+ * @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)
+ 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++;
+ output[offset++] = (byte) buffer;
+ buffer >>>= 8;
+ bits_in_buffer -= 8;
+ length--;
+ count++;
}
if (length == 0)
return count;
@@ -171,9 +171,9 @@ class StreamManipulator
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;
+ /* We always want an even number of bytes in input, see peekBits */
+ buffer = (window[window_start++] & 0xff);
+ bits_in_buffer = 8;
}
return count + length;
}
@@ -191,26 +191,25 @@ class StreamManipulator
{
if (window_start < window_end)
throw new IllegalStateException
- ("Old input was not completely processed");
+ ("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.
+ * 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;
+ /* 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;
}
}
-
diff --git a/libjava/classpath/java/util/zip/ZipConstants.java b/libjava/classpath/java/util/zip/ZipConstants.java
index bdf94506ba2..69f589a3166 100644
--- a/libjava/classpath/java/util/zip/ZipConstants.java
+++ b/libjava/classpath/java/util/zip/ZipConstants.java
@@ -91,4 +91,3 @@ interface ZipConstants
int ENDOFF = 16;
int ENDCOM = 20;
}
-
diff --git a/libjava/classpath/java/util/zip/ZipEntry.java b/libjava/classpath/java/util/zip/ZipEntry.java
index a6d01af5ff6..73afc893b6c 100644
--- a/libjava/classpath/java/util/zip/ZipEntry.java
+++ b/libjava/classpath/java/util/zip/ZipEntry.java
@@ -46,7 +46,7 @@ import java.util.Calendar;
* 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
+ * @author Jochen Hoenicke
*/
public class ZipEntry implements ZipConstants, Cloneable
{
@@ -196,7 +196,7 @@ public class ZipEntry implements ZipConstants, Cloneable
/**
* Returns the entry name. The path components in the entry are
- * always separated by slashes ('/').
+ * always separated by slashes ('/').
*/
public String getName()
{
@@ -241,7 +241,7 @@ public class ZipEntry implements ZipConstants, Cloneable
time = cal.getTimeInMillis();
known |= KNOWN_TIME;
return time;
- }
+ }
catch (RuntimeException ex)
{
/* Ignore illegal time stamp */
@@ -260,7 +260,7 @@ public class ZipEntry implements ZipConstants, Cloneable
public void setSize(long size)
{
if ((size & 0xffffffff00000000L) != 0)
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException();
this.size = (int) size;
this.known |= KNOWN_SIZE;
}
@@ -298,7 +298,7 @@ public class ZipEntry implements ZipConstants, Cloneable
public void setCrc(long crc)
{
if ((crc & 0xffffffff00000000L) != 0)
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException();
this.crc = (int) crc;
this.known |= KNOWN_CRC;
}
@@ -317,18 +317,18 @@ public class ZipEntry implements ZipConstants, Cloneable
* supported.
* @exception IllegalArgumentException if method is not supported.
* @see ZipOutputStream#DEFLATED
- * @see ZipOutputStream#STORED
+ * @see ZipOutputStream#STORED
*/
public void setMethod(int method)
{
if (method != ZipOutputStream.STORED
- && method != ZipOutputStream.DEFLATED)
- throw new IllegalArgumentException();
+ && method != ZipOutputStream.DEFLATED)
+ throw new IllegalArgumentException();
this.method = (byte) method;
}
/**
- * Gets the compression method.
+ * Gets the compression method.
* @return the compression method or -1 if unknown.
*/
public int getMethod()
@@ -342,10 +342,10 @@ public class ZipEntry implements ZipConstants, Cloneable
*/
public void setExtra(byte[] extra)
{
- if (extra == null)
+ if (extra == null)
{
- this.extra = null;
- return;
+ this.extra = null;
+ return;
}
if (extra.length > 0xffff)
throw new IllegalArgumentException();
@@ -360,38 +360,38 @@ public class ZipEntry implements ZipConstants, Cloneable
if (extra == null)
{
- known |= KNOWN_EXTRA;
- return;
+ known |= KNOWN_EXTRA;
+ return;
}
try
{
- int pos = 0;
- while (pos < extra.length)
- {
- int sig = (extra[pos++] & 0xff)
- | (extra[pos++] & 0xff) << 8;
- int len = (extra[pos++] & 0xff)
- | (extra[pos++] & 0xff) << 8;
- if (sig == 0x5455)
- {
- /* extended time stamp */
- int flags = extra[pos];
- if ((flags & 1) != 0)
- {
- long time = ((extra[pos+1] & 0xff)
- | (extra[pos+2] & 0xff) << 8
- | (extra[pos+3] & 0xff) << 16
- | (extra[pos+4] & 0xff) << 24);
- setTime(time*1000);
- }
- }
- pos += len;
- }
+ int pos = 0;
+ while (pos < extra.length)
+ {
+ int sig = (extra[pos++] & 0xff)
+ | (extra[pos++] & 0xff) << 8;
+ int len = (extra[pos++] & 0xff)
+ | (extra[pos++] & 0xff) << 8;
+ if (sig == 0x5455)
+ {
+ /* extended time stamp */
+ int flags = extra[pos];
+ if ((flags & 1) != 0)
+ {
+ long time = ((extra[pos+1] & 0xff)
+ | (extra[pos+2] & 0xff) << 8
+ | (extra[pos+3] & 0xff) << 16
+ | (extra[pos+4] & 0xff) << 24);
+ setTime(time*1000);
+ }
+ }
+ pos += len;
+ }
}
catch (ArrayIndexOutOfBoundsException ex)
{
- /* be lenient */
+ /* be lenient */
}
known |= KNOWN_EXTRA;
@@ -429,7 +429,7 @@ public class ZipEntry implements ZipConstants, Cloneable
/**
* Gets true, if the entry is a directory. This is solely
- * determined by the name, a trailing slash '/' marks a directory.
+ * determined by the name, a trailing slash '/' marks a directory.
*/
public boolean isDirectory()
{
diff --git a/libjava/classpath/java/util/zip/ZipFile.java b/libjava/classpath/java/util/zip/ZipFile.java
index 7cf7007ed8f..3963bcb1eb5 100644
--- a/libjava/classpath/java/util/zip/ZipFile.java
+++ b/libjava/classpath/java/util/zip/ZipFile.java
@@ -106,19 +106,19 @@ public class ZipFile implements ZipConstants
*
* @return the newly open RandomAccessFile, never null
*/
- private RandomAccessFile openFile(String name,
- File file)
+ private RandomAccessFile openFile(String name,
+ File file)
throws ZipException, IOException
- {
- try
+ {
+ try
{
- return
+ return
(name != null)
? new RandomAccessFile(name, "r")
: new RandomAccessFile(file, "r");
}
catch (FileNotFoundException f)
- {
+ {
ZipException ze = new ZipException(f.getMessage());
ze.initCause(f);
throw ze;
@@ -130,7 +130,7 @@ public class ZipFile implements ZipConstants
* Opens a Zip file with the given name for reading.
* @exception IOException if a i/o error occured.
* @exception ZipException if the file doesn't contain a valid zip
- * archive.
+ * archive.
*/
public ZipFile(String name) throws ZipException, IOException
{
@@ -143,7 +143,7 @@ public class ZipFile implements ZipConstants
* Opens a Zip file reading the given File.
* @exception IOException if a i/o error occured.
* @exception ZipException if the file doesn't contain a valid zip
- * archive.
+ * archive.
*/
public ZipFile(File file) throws ZipException, IOException
{
@@ -158,7 +158,7 @@ public class ZipFile implements ZipConstants
* If the OPEN_DELETE mode is specified, the zip file will be deleted at
* some time moment after it is opened. It will be deleted before the zip
* file is closed or the Virtual Machine exits.
- *
+ *
* The contents of the zip file will be accessible until it is closed.
*
* @since JDK1.3
@@ -166,7 +166,7 @@ public class ZipFile implements ZipConstants
*
* @exception IOException if a i/o error occured.
* @exception ZipException if the file doesn't contain a valid zip
- * archive.
+ * archive.
*/
public ZipFile(File file, int mode) throws ZipException, IOException
{
@@ -183,7 +183,7 @@ public class ZipFile implements ZipConstants
{
boolean valid = false;
- try
+ try
{
byte[] buf = new byte[4];
raf.readFully(buf);
@@ -195,18 +195,18 @@ public class ZipFile implements ZipConstants
}
catch (IOException _)
{
- }
+ }
if (!valid)
{
try
{
- raf.close();
+ raf.close();
}
catch (IOException _)
{
}
- throw new ZipException("Not a valid zip file");
+ throw new ZipException("Not a valid zip file");
}
}
@@ -225,11 +225,11 @@ public class ZipFile implements ZipConstants
* while holding the lock on <code>raf</code>.
*
* @exception IOException if a i/o error occured.
- * @exception ZipException if the central directory is malformed
+ * @exception ZipException if the central directory is malformed
*/
private void readEntries() throws ZipException, IOException
{
- /* Search for the End Of Central Directory. When a zip comment is
+ /* Search for the End Of Central Directory. When a zip comment is
* present the directory may start earlier.
* Note that a comment has a maximum length of 64K, so that is the
* maximum we search backwards.
@@ -239,13 +239,13 @@ public class ZipFile implements ZipConstants
long top = Math.max(0, pos - 65536);
do
{
- if (pos < top)
- throw new ZipException
- ("central directory not found, probably not a zip file: " + name);
- inp.seek(pos--);
+ if (pos < top)
+ throw new ZipException
+ ("central directory not found, probably not a zip file: " + name);
+ inp.seek(pos--);
}
while (inp.readLeInt() != ENDSIG);
-
+
if (inp.skip(ENDTOT - ENDNRD) != ENDTOT - ENDNRD)
throw new EOFException(name);
int count = inp.readLeShort();
@@ -255,43 +255,43 @@ public class ZipFile implements ZipConstants
entries = new LinkedHashMap<String, ZipEntry> (count+count/2);
inp.seek(centralOffset);
-
+
for (int i = 0; i < count; i++)
{
- if (inp.readLeInt() != CENSIG)
- throw new ZipException("Wrong Central Directory signature: " + name);
+ if (inp.readLeInt() != CENSIG)
+ throw new ZipException("Wrong Central Directory signature: " + name);
inp.skip(6);
- int method = inp.readLeShort();
- int dostime = inp.readLeInt();
- int crc = inp.readLeInt();
- int csize = inp.readLeInt();
- int size = inp.readLeInt();
- int nameLen = inp.readLeShort();
- int extraLen = inp.readLeShort();
- int commentLen = inp.readLeShort();
+ int method = inp.readLeShort();
+ int dostime = inp.readLeInt();
+ int crc = inp.readLeInt();
+ int csize = inp.readLeInt();
+ int size = inp.readLeInt();
+ int nameLen = inp.readLeShort();
+ int extraLen = inp.readLeShort();
+ int commentLen = inp.readLeShort();
inp.skip(8);
- int offset = inp.readLeInt();
- String name = inp.readString(nameLen);
-
- ZipEntry entry = new ZipEntry(name);
- entry.setMethod(method);
- entry.setCrc(crc & 0xffffffffL);
- entry.setSize(size & 0xffffffffL);
- entry.setCompressedSize(csize & 0xffffffffL);
- entry.setDOSTime(dostime);
- if (extraLen > 0)
- {
- byte[] extra = new byte[extraLen];
- inp.readFully(extra);
- entry.setExtra(extra);
- }
- if (commentLen > 0)
- {
+ int offset = inp.readLeInt();
+ String name = inp.readString(nameLen);
+
+ ZipEntry entry = new ZipEntry(name);
+ entry.setMethod(method);
+ entry.setCrc(crc & 0xffffffffL);
+ entry.setSize(size & 0xffffffffL);
+ entry.setCompressedSize(csize & 0xffffffffL);
+ entry.setDOSTime(dostime);
+ if (extraLen > 0)
+ {
+ byte[] extra = new byte[extraLen];
+ inp.readFully(extra);
+ entry.setExtra(extra);
+ }
+ if (commentLen > 0)
+ {
entry.setComment(inp.readString(commentLen));
- }
- entry.offset = offset;
- entries.put(name, entry);
+ }
+ entry.offset = offset;
+ entries.put(name, entry);
}
}
@@ -299,7 +299,7 @@ public class ZipFile implements ZipConstants
* Closes the ZipFile. This also closes all input streams given by
* this class. After this is called, no further method should be
* called.
- *
+ *
* @exception IOException if a i/o error occured.
*/
public void close() throws IOException
@@ -310,9 +310,9 @@ public class ZipFile implements ZipConstants
synchronized (raf)
{
- closed = true;
- entries = null;
- raf.close();
+ closed = true;
+ entries = null;
+ raf.close();
}
}
@@ -333,14 +333,14 @@ public class ZipFile implements ZipConstants
public Enumeration<? extends ZipEntry> entries()
{
checkClosed();
-
+
try
{
- return new ZipEntryEnumeration(getEntries().values().iterator());
+ return new ZipEntryEnumeration(getEntries().values().iterator());
}
catch (IOException ioe)
{
- return new EmptyEnumeration<ZipEntry>();
+ return new EmptyEnumeration<ZipEntry>();
}
}
@@ -354,12 +354,12 @@ public class ZipFile implements ZipConstants
{
synchronized(raf)
{
- checkClosed();
+ checkClosed();
- if (entries == null)
- readEntries();
+ if (entries == null)
+ readEntries();
- return entries;
+ return entries;
}
}
@@ -378,16 +378,16 @@ public class ZipFile implements ZipConstants
try
{
- LinkedHashMap<String, ZipEntry> entries = getEntries();
- ZipEntry entry = entries.get(name);
+ LinkedHashMap<String, ZipEntry> entries = getEntries();
+ ZipEntry entry = entries.get(name);
// If we didn't find it, maybe it's a directory.
if (entry == null && !name.endsWith("/"))
- entry = entries.get(name + '/');
- return entry != null ? new ZipEntry(entry, name) : null;
+ entry = entries.get(name + '/');
+ return entry != null ? new ZipEntry(entry, name) : null;
}
catch (IOException ioe)
{
- return null;
+ return null;
}
}
@@ -411,7 +411,7 @@ public class ZipFile implements ZipConstants
*
* @exception IllegalStateException when the ZipFile has already been closed
* @exception IOException if a i/o error occured.
- * @exception ZipException if the Zip archive is malformed.
+ * @exception ZipException if the Zip archive is malformed.
*/
public InputStream getInputStream(ZipEntry entry) throws IOException
{
@@ -446,7 +446,7 @@ public class ZipFile implements ZipConstants
switch (method)
{
case ZipOutputStream.STORED:
- return inp;
+ return inp;
case ZipOutputStream.DEFLATED:
inp.addDummyByte();
final Inflater inf = new Inflater(true);
@@ -463,10 +463,10 @@ public class ZipFile implements ZipConstants
}
};
default:
- throw new ZipException("Unknown compression method " + method);
+ throw new ZipException("Unknown compression method " + method);
}
}
-
+
/**
* Returns the (path) name of this zip file.
*/
@@ -483,17 +483,17 @@ public class ZipFile implements ZipConstants
public int size()
{
checkClosed();
-
+
try
{
- return getEntries().size();
+ return getEntries().size();
}
catch (IOException ioe)
{
- return 0;
+ return 0;
}
}
-
+
private static class ZipEntryEnumeration implements Enumeration<ZipEntry>
{
private final Iterator<ZipEntry> elements;
@@ -511,7 +511,7 @@ public class ZipFile implements ZipConstants
public ZipEntry nextElement()
{
/* We return a clone, just to be safe that the user doesn't
- * change the entry.
+ * change the entry.
*/
return (ZipEntry) (elements.next().clone());
}
@@ -525,7 +525,7 @@ public class ZipFile implements ZipConstants
private static final Charset UTF8CHARSET = Charset.forName("UTF-8");
/**
- * The actual UTF-8 decoder. Created on demand.
+ * The actual UTF-8 decoder. Created on demand.
*/
private CharsetDecoder utf8Decoder;
@@ -572,37 +572,37 @@ public class ZipFile implements ZipConstants
}
}
}
-
+
public int available()
{
long amount = end - (bufferOffset + pos);
if (amount > Integer.MAX_VALUE)
- return Integer.MAX_VALUE;
+ return Integer.MAX_VALUE;
return (int) amount;
}
-
+
public int read() throws IOException
{
if (bufferOffset + pos >= end + dummyByteCount)
- return -1;
+ return -1;
if (pos == buffer.length)
{
bufferOffset += buffer.length;
pos = 0;
fillBuffer();
}
-
+
return buffer[pos++] & 0xFF;
}
public int read(byte[] b, int off, int len) throws IOException
{
if (len > end + dummyByteCount - (bufferOffset + pos))
- {
- len = (int) (end + dummyByteCount - (bufferOffset + pos));
- if (len == 0)
- return -1;
- }
+ {
+ len = (int) (end + dummyByteCount - (bufferOffset + pos));
+ if (len == 0)
+ return -1;
+ }
int totalBytesRead = Math.min(buffer.length - pos, len);
System.arraycopy(buffer, pos, b, off, totalBytesRead);
@@ -622,16 +622,16 @@ public class ZipFile implements ZipConstants
len -= remain;
totalBytesRead += remain;
}
-
+
return totalBytesRead;
}
public long skip(long amount) throws IOException
{
if (amount < 0)
- return 0;
+ return 0;
if (amount > end - (bufferOffset + pos))
- amount = end - (bufferOffset + pos);
+ amount = end - (bufferOffset + pos);
seek(bufferOffset + pos + amount);
return amount;
}
diff --git a/libjava/classpath/java/util/zip/ZipInputStream.java b/libjava/classpath/java/util/zip/ZipInputStream.java
index df44bb3e808..3eae026da9d 100644
--- a/libjava/classpath/java/util/zip/ZipInputStream.java
+++ b/libjava/classpath/java/util/zip/ZipInputStream.java
@@ -82,9 +82,9 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
{
if (avail <= 0)
{
- fillBuf();
- if (avail <= 0)
- return -1;
+ fillBuf();
+ if (avail <= 0)
+ return -1;
}
if (length > avail)
length = avail;
@@ -92,28 +92,28 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
avail -= length;
return length;
}
-
+
private void readFully(byte[] out) throws IOException
{
int off = 0;
int len = out.length;
while (len > 0)
{
- int count = readBuf(out, off, len);
- if (count == -1)
- throw new EOFException();
- off += count;
- len -= count;
+ int count = readBuf(out, off, len);
+ if (count == -1)
+ throw new EOFException();
+ off += count;
+ len -= count;
}
}
-
+
private int readLeByte() throws IOException
{
if (avail <= 0)
{
- fillBuf();
- if (avail <= 0)
- throw new ZipException("EOF in header");
+ fillBuf();
+ if (avail <= 0)
+ throw new ZipException("EOF in header");
}
return buf[len - avail--] & 0xff;
}
@@ -121,7 +121,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
/**
* Read an unsigned short in little endian byte order.
*/
- private int readLeShort() throws IOException
+ private int readLeShort() throws IOException
{
return readLeByte() | (readLeByte() << 8);
}
@@ -129,7 +129,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
/**
* Read an int in little endian byte order.
*/
- private int readLeInt() throws IOException
+ private int readLeInt() throws IOException
{
return readLeShort() | (readLeShort() << 16);
}
@@ -148,13 +148,13 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
int header = readLeInt();
if (header == CENSIG)
{
- /* Central Header reached. */
- close();
- return null;
+ /* Central Header reached. */
+ close();
+ return null;
}
if (header != LOCSIG)
throw new ZipException("Wrong Local header signature: "
- + Integer.toHexString(header));
+ + Integer.toHexString(header));
/* skip version */
readLeShort();
flags = readLeShort();
@@ -175,36 +175,36 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
String name;
try
{
- name = new String(buffer, "UTF-8");
+ name = new String(buffer, "UTF-8");
}
catch (UnsupportedEncodingException uee)
{
- throw new AssertionError(uee);
+ throw new AssertionError(uee);
}
-
+
entry = createZipEntry(name);
entryAtEOF = false;
entry.setMethod(method);
if ((flags & 8) == 0)
{
- entry.setCrc(crc & 0xffffffffL);
- entry.setSize(size & 0xffffffffL);
- entry.setCompressedSize(csize & 0xffffffffL);
+ entry.setCrc(crc & 0xffffffffL);
+ entry.setSize(size & 0xffffffffL);
+ entry.setCompressedSize(csize & 0xffffffffL);
}
entry.setDOSTime(dostime);
if (extraLen > 0)
{
- byte[] extra = new byte[extraLen];
- readFully(extra);
- entry.setExtra(extra);
+ byte[] extra = new byte[extraLen];
+ readFully(extra);
+ entry.setExtra(extra);
}
if (method == ZipOutputStream.DEFLATED && avail > 0)
{
- System.arraycopy(buf, len - avail, buf, 0, avail);
- len = avail;
- avail = 0;
- inf.setInput(buf, 0, len);
+ System.arraycopy(buf, len - avail, buf, 0, avail);
+ len = avail;
+ avail = 0;
+ inf.setInput(buf, 0, len);
}
return entry;
}
@@ -232,33 +232,33 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
if (method == ZipOutputStream.DEFLATED)
{
- if ((flags & 8) != 0)
- {
- /* We don't know how much we must skip, read until end. */
- byte[] tmp = new byte[2048];
- while (read(tmp) > 0)
- ;
-
- /* read will close this entry */
- return;
- }
- csize -= inf.getTotalIn();
- avail = inf.getRemaining();
+ if ((flags & 8) != 0)
+ {
+ /* We don't know how much we must skip, read until end. */
+ byte[] tmp = new byte[2048];
+ while (read(tmp) > 0)
+ ;
+
+ /* read will close this entry */
+ return;
+ }
+ csize -= inf.getTotalIn();
+ avail = inf.getRemaining();
}
if (avail > csize && csize >= 0)
avail -= csize;
else
{
- csize -= avail;
- avail = 0;
- while (csize != 0)
- {
- long skipped = in.skip(csize & 0xffffffffL);
- if (skipped <= 0)
- throw new ZipException("zip archive ends early.");
- csize -= skipped;
- }
+ csize -= avail;
+ avail = 0;
+ while (csize != 0)
+ {
+ long skipped = in.skip(csize & 0xffffffffL);
+ if (skipped <= 0)
+ throw new ZipException("zip archive ends early.");
+ csize -= skipped;
+ }
}
size = 0;
@@ -307,40 +307,40 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
switch (method)
{
case ZipOutputStream.DEFLATED:
- len = super.read(b, off, len);
- if (len < 0)
- {
- if (!inf.finished())
- throw new ZipException("Inflater not finished!?");
- avail = inf.getRemaining();
- if ((flags & 8) != 0)
- readDataDescr();
-
- if (inf.getTotalIn() != csize
- || inf.getTotalOut() != size)
- throw new ZipException("size mismatch: "+csize+";"+size+" <-> "+inf.getTotalIn()+";"+inf.getTotalOut());
- inf.reset();
- finished = true;
- }
- break;
-
+ len = super.read(b, off, len);
+ if (len < 0)
+ {
+ if (!inf.finished())
+ throw new ZipException("Inflater not finished!?");
+ avail = inf.getRemaining();
+ if ((flags & 8) != 0)
+ readDataDescr();
+
+ if (inf.getTotalIn() != csize
+ || inf.getTotalOut() != size)
+ throw new ZipException("size mismatch: "+csize+";"+size+" <-> "+inf.getTotalIn()+";"+inf.getTotalOut());
+ inf.reset();
+ finished = true;
+ }
+ break;
+
case ZipOutputStream.STORED:
- if (len > csize && csize >= 0)
- len = csize;
-
- len = readBuf(b, off, len);
- if (len > 0)
- {
- csize -= len;
- size -= len;
- }
-
- if (csize == 0)
- finished = true;
- else if (len < 0)
- throw new ZipException("EOF in stored block");
- break;
+ if (len > csize && csize >= 0)
+ len = csize;
+
+ len = readBuf(b, off, len);
+ if (len > 0)
+ {
+ csize -= len;
+ size -= len;
+ }
+
+ if (csize == 0)
+ finished = true;
+ else if (len < 0)
+ throw new ZipException("EOF in stored block");
+ break;
}
if (len > 0)
@@ -348,11 +348,11 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
if (finished)
{
- if ((crc.getValue() & 0xffffffffL) != entry.getCrc())
- throw new ZipException("CRC mismatch");
- crc.reset();
- entry = null;
- entryAtEOF = true;
+ if ((crc.getValue() & 0xffffffffL) != entry.getCrc())
+ throw new ZipException("CRC mismatch");
+ crc.reset();
+ entry = null;
+ entryAtEOF = true;
}
return len;
}
@@ -374,7 +374,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
* to new ZipEntry(name).
* @param name the name of the zip entry.
*/
- protected ZipEntry createZipEntry(String name)
+ protected ZipEntry createZipEntry(String name)
{
return new ZipEntry(name);
}
diff --git a/libjava/classpath/java/util/zip/ZipOutputStream.java b/libjava/classpath/java/util/zip/ZipOutputStream.java
index d292f7d40e2..bc1c3e99c52 100644
--- a/libjava/classpath/java/util/zip/ZipOutputStream.java
+++ b/libjava/classpath/java/util/zip/ZipOutputStream.java
@@ -54,7 +54,7 @@ import java.util.Vector;
*
* This class is not thread safe.
*
- * @author Jochen Hoenicke
+ * @author Jochen Hoenicke
*/
public class ZipOutputStream extends DeflaterOutputStream implements ZipConstants
{
@@ -79,7 +79,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
* Compression method. This method doesn't compress at all.
*/
public static final int STORED = 0;
-
+
/**
* Compression method. This method uses the Deflater.
*/
@@ -105,17 +105,17 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
byte[] commentBytes;
try
{
- commentBytes = comment.getBytes("UTF-8");
+ commentBytes = comment.getBytes("UTF-8");
}
catch (UnsupportedEncodingException uee)
{
- throw new AssertionError(uee);
+ throw new AssertionError(uee);
}
if (commentBytes.length > 0xffff)
throw new IllegalArgumentException("Comment too long.");
zipComment = commentBytes;
}
-
+
/**
* Sets default compression method. If the Zip entry specifies
* another method its method takes precedence.
@@ -133,7 +133,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
/**
* Sets default compression level. The new level will be activated
- * immediately.
+ * immediately.
* @exception IllegalArgumentException if level is not supported.
* @see Deflater
*/
@@ -141,11 +141,11 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
{
def.setLevel(level);
}
-
+
/**
* Write an unsigned short in little endian byte order.
*/
- private void writeLeShort(int value) throws IOException
+ private void writeLeShort(int value) throws IOException
{
out.write(value & 0xff);
out.write((value >> 8) & 0xff);
@@ -154,7 +154,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
/**
* Write an int in little endian byte order.
*/
- private void writeLeInt(int value) throws IOException
+ private void writeLeInt(int value) throws IOException
{
writeLeShort(value);
writeLeShort(value >> 16);
@@ -192,27 +192,27 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
if (method == STORED)
{
- if (entry.getCompressedSize() >= 0)
- {
- if (entry.getSize() < 0)
- entry.setSize(entry.getCompressedSize());
- else if (entry.getSize() != entry.getCompressedSize())
- throw new ZipException
- ("Method STORED, but compressed size != size");
- }
- else
- entry.setCompressedSize(entry.getSize());
-
- if (entry.getSize() < 0)
- throw new ZipException("Method STORED, but size not set");
- if (entry.getCrc() < 0)
- throw new ZipException("Method STORED, but crc not set");
+ if (entry.getCompressedSize() >= 0)
+ {
+ if (entry.getSize() < 0)
+ entry.setSize(entry.getCompressedSize());
+ else if (entry.getSize() != entry.getCompressedSize())
+ throw new ZipException
+ ("Method STORED, but compressed size != size");
+ }
+ else
+ entry.setCompressedSize(entry.getSize());
+
+ if (entry.getSize() < 0)
+ throw new ZipException("Method STORED, but size not set");
+ if (entry.getCrc() < 0)
+ throw new ZipException("Method STORED, but crc not set");
}
else if (method == DEFLATED)
{
- if (entry.getCompressedSize() < 0
- || entry.getSize() < 0 || entry.getCrc() < 0)
- flags |= 8;
+ if (entry.getCompressedSize() < 0
+ || entry.getSize() < 0 || entry.getCrc() < 0)
+ flags |= 8;
}
if (curEntry != null)
@@ -228,30 +228,30 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
/* Write the local file header */
writeLeInt(LOCSIG);
writeLeShort(method == STORED
- ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
+ ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
writeLeShort(flags);
writeLeShort(method);
writeLeInt(entry.getDOSTime());
if ((flags & 8) == 0)
{
- writeLeInt((int)entry.getCrc());
- writeLeInt((int)entry.getCompressedSize());
- writeLeInt((int)entry.getSize());
+ writeLeInt((int)entry.getCrc());
+ writeLeInt((int)entry.getCompressedSize());
+ writeLeInt((int)entry.getSize());
}
else
{
- writeLeInt(0);
- writeLeInt(0);
- writeLeInt(0);
+ writeLeInt(0);
+ writeLeInt(0);
+ writeLeInt(0);
}
byte[] name;
try
{
- name = entry.getName().getBytes("UTF-8");
+ name = entry.getName().getBytes("UTF-8");
}
catch (UnsupportedEncodingException uee)
{
- throw new AssertionError(uee);
+ throw new AssertionError(uee);
}
if (name.length > 0xffff)
throw new ZipException("Name too long.");
@@ -294,31 +294,31 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
curEntry.setSize(size);
else if (curEntry.getSize() != size)
throw new ZipException("size was "+size
- +", but I expected "+curEntry.getSize());
+ +", but I expected "+curEntry.getSize());
if (curEntry.getCompressedSize() < 0)
curEntry.setCompressedSize(csize);
else if (curEntry.getCompressedSize() != csize)
throw new ZipException("compressed size was "+csize
- +", but I expected "+curEntry.getSize());
+ +", but I expected "+curEntry.getSize());
if (curEntry.getCrc() < 0)
curEntry.setCrc(crc.getValue());
else if (curEntry.getCrc() != crc.getValue())
throw new ZipException("crc was " + Long.toHexString(crc.getValue())
- + ", but I expected "
- + Long.toHexString(curEntry.getCrc()));
+ + ", but I expected "
+ + Long.toHexString(curEntry.getCrc()));
offset += csize;
/* Now write the data descriptor entry if needed. */
if (curMethod == DEFLATED && (curEntry.flags & 8) != 0)
{
- writeLeInt(EXTSIG);
- writeLeInt((int)curEntry.getCrc());
- writeLeInt((int)curEntry.getCompressedSize());
- writeLeInt((int)curEntry.getSize());
- offset += EXTHDR;
+ writeLeInt(EXTSIG);
+ writeLeInt((int)curEntry.getCrc());
+ writeLeInt((int)curEntry.getCompressedSize());
+ writeLeInt((int)curEntry.getSize());
+ offset += EXTHDR;
}
entries.addElement(curEntry);
@@ -338,12 +338,12 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
switch (curMethod)
{
case DEFLATED:
- super.write(b, off, len);
- break;
-
+ super.write(b, off, len);
+ break;
+
case STORED:
- out.write(b, off, len);
- break;
+ out.write(b, off, len);
+ break;
}
crc.update(b, off, len);
@@ -364,65 +364,65 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
int numEntries = 0;
int sizeEntries = 0;
-
+
Enumeration e = entries.elements();
while (e.hasMoreElements())
{
- ZipEntry entry = (ZipEntry) e.nextElement();
-
- int method = entry.getMethod();
- writeLeInt(CENSIG);
- writeLeShort(method == STORED
- ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
- writeLeShort(method == STORED
- ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
- writeLeShort(entry.flags);
- writeLeShort(method);
- writeLeInt(entry.getDOSTime());
- writeLeInt((int)entry.getCrc());
- writeLeInt((int)entry.getCompressedSize());
- writeLeInt((int)entry.getSize());
-
- byte[] name;
- try
- {
- name = entry.getName().getBytes("UTF-8");
- }
- catch (UnsupportedEncodingException uee)
- {
- throw new AssertionError(uee);
- }
- if (name.length > 0xffff)
- throw new ZipException("Name too long.");
- byte[] extra = entry.getExtra();
- if (extra == null)
- extra = new byte[0];
- String str = entry.getComment();
- byte[] comment;
- try
- {
- comment = str != null ? str.getBytes("UTF-8") : new byte[0];
- }
- catch (UnsupportedEncodingException uee)
- {
- throw new AssertionError(uee);
- }
- if (comment.length > 0xffff)
- throw new ZipException("Comment too long.");
-
- writeLeShort(name.length);
- writeLeShort(extra.length);
- writeLeShort(comment.length);
- writeLeShort(0); /* disk number */
- writeLeShort(0); /* internal file attr */
- writeLeInt(0); /* external file attr */
- writeLeInt(entry.offset);
-
- out.write(name);
- out.write(extra);
- out.write(comment);
- numEntries++;
- sizeEntries += CENHDR + name.length + extra.length + comment.length;
+ ZipEntry entry = (ZipEntry) e.nextElement();
+
+ int method = entry.getMethod();
+ writeLeInt(CENSIG);
+ writeLeShort(method == STORED
+ ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
+ writeLeShort(method == STORED
+ ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);
+ writeLeShort(entry.flags);
+ writeLeShort(method);
+ writeLeInt(entry.getDOSTime());
+ writeLeInt((int)entry.getCrc());
+ writeLeInt((int)entry.getCompressedSize());
+ writeLeInt((int)entry.getSize());
+
+ byte[] name;
+ try
+ {
+ name = entry.getName().getBytes("UTF-8");
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
+ if (name.length > 0xffff)
+ throw new ZipException("Name too long.");
+ byte[] extra = entry.getExtra();
+ if (extra == null)
+ extra = new byte[0];
+ String str = entry.getComment();
+ byte[] comment;
+ try
+ {
+ comment = str != null ? str.getBytes("UTF-8") : new byte[0];
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ throw new AssertionError(uee);
+ }
+ if (comment.length > 0xffff)
+ throw new ZipException("Comment too long.");
+
+ writeLeShort(name.length);
+ writeLeShort(extra.length);
+ writeLeShort(comment.length);
+ writeLeShort(0); /* disk number */
+ writeLeShort(0); /* internal file attr */
+ writeLeInt(0); /* external file attr */
+ writeLeInt(entry.offset);
+
+ out.write(name);
+ out.write(extra);
+ out.write(comment);
+ numEntries++;
+ sizeEntries += CENHDR + name.length + extra.length + comment.length;
}
writeLeInt(ENDSIG);
OpenPOWER on IntegriCloud