diff options
Diffstat (limited to 'libjava/classpath/java/util/zip')
-rw-r--r-- | libjava/classpath/java/util/zip/Deflater.java | 1 | ||||
-rw-r--r-- | libjava/classpath/java/util/zip/DeflaterEngine.java | 5 | ||||
-rw-r--r-- | libjava/classpath/java/util/zip/GZIPInputStream.java | 2 | ||||
-rw-r--r-- | libjava/classpath/java/util/zip/Inflater.java | 1 | ||||
-rw-r--r-- | libjava/classpath/java/util/zip/ZipConstants.java | 3 | ||||
-rw-r--r-- | libjava/classpath/java/util/zip/ZipFile.java | 60 |
6 files changed, 59 insertions, 13 deletions
diff --git a/libjava/classpath/java/util/zip/Deflater.java b/libjava/classpath/java/util/zip/Deflater.java index 7bc1a19..a4ec0e6 100644 --- a/libjava/classpath/java/util/zip/Deflater.java +++ b/libjava/classpath/java/util/zip/Deflater.java @@ -221,7 +221,6 @@ public class Deflater * where the compressor allocates native memory. * If you call any method (even reset) afterwards the behaviour is * <i>undefined</i>. - * @deprecated Just clear all references to deflater instead. */ public void end() { diff --git a/libjava/classpath/java/util/zip/DeflaterEngine.java b/libjava/classpath/java/util/zip/DeflaterEngine.java index 3eea7c2..f79e477 100644 --- a/libjava/classpath/java/util/zip/DeflaterEngine.java +++ b/libjava/classpath/java/util/zip/DeflaterEngine.java @@ -497,7 +497,7 @@ class DeflaterEngine implements DeflaterConstants throw new InternalError(); } } - huffman.tallyDist(strstart - matchStart, matchLen); + boolean full = huffman.tallyDist(strstart - matchStart, matchLen); lookahead -= matchLen; if (matchLen <= max_lazy && lookahead >= MIN_MATCH) @@ -516,7 +516,8 @@ class DeflaterEngine implements DeflaterConstants updateHash(); } matchLen = MIN_MATCH - 1; - continue; + if (!full) + continue; } else { diff --git a/libjava/classpath/java/util/zip/GZIPInputStream.java b/libjava/classpath/java/util/zip/GZIPInputStream.java index 2cea755..f244810 100644 --- a/libjava/classpath/java/util/zip/GZIPInputStream.java +++ b/libjava/classpath/java/util/zip/GZIPInputStream.java @@ -207,7 +207,7 @@ public class GZIPInputStream /* 2. Check the compression type (must be 8) */ int CM = in.read(); - if (CM != 8) + if (CM != Deflater.DEFLATED) throw new IOException("Error in GZIP header, data not in deflate format"); headCRC.update(CM); diff --git a/libjava/classpath/java/util/zip/Inflater.java b/libjava/classpath/java/util/zip/Inflater.java index 76de891..f1616d6 100644 --- a/libjava/classpath/java/util/zip/Inflater.java +++ b/libjava/classpath/java/util/zip/Inflater.java @@ -199,7 +199,6 @@ public class Inflater * with Sun's JDK, where the compressor allocates native memory. * If you call any method (even reset) afterwards the behaviour is * <i>undefined</i>. - * @deprecated Just clear all references to inflater instead. */ public void end () { diff --git a/libjava/classpath/java/util/zip/ZipConstants.java b/libjava/classpath/java/util/zip/ZipConstants.java index 6d66419..bdf9450 100644 --- a/libjava/classpath/java/util/zip/ZipConstants.java +++ b/libjava/classpath/java/util/zip/ZipConstants.java @@ -85,9 +85,6 @@ interface ZipConstants long ENDSIG = 'P'|('K'<<8)|(5<<16)|(6<<24); int ENDHDR = 22; - /* The following two fields are missing in SUN JDK */ - int ENDNRD = 4; - int ENDDCD = 6; int ENDSUB = 8; int ENDTOT = 10; int ENDSIZ = 12; diff --git a/libjava/classpath/java/util/zip/ZipFile.java b/libjava/classpath/java/util/zip/ZipFile.java index 7307ee9..b849551 100644 --- a/libjava/classpath/java/util/zip/ZipFile.java +++ b/libjava/classpath/java/util/zip/ZipFile.java @@ -43,6 +43,7 @@ import gnu.java.util.EmptyEnumeration; import java.io.EOFException; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile; @@ -75,6 +76,11 @@ public class ZipFile implements ZipConstants */ public static final int OPEN_DELETE = 0x4; + /** + * This field isn't defined in the JDK's ZipConstants, but should be. + */ + static final int ENDNRD = 4; + // Name of this zip file. private final String name; @@ -86,6 +92,37 @@ public class ZipFile implements ZipConstants private boolean closed = false; + + /** + * Helper function to open RandomAccessFile and throw the proper + * ZipException in case opening the file fails. + * + * @param name the file name, or null if file is provided + * + * @param file the file, or null if name is provided + * + * @return the newly open RandomAccessFile, never null + */ + private RandomAccessFile openFile(String name, + File file) + throws ZipException, IOException + { + try + { + 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; + } + } + + /** * Opens a Zip file with the given name for reading. * @exception IOException if a i/o error occured. @@ -94,7 +131,7 @@ public class ZipFile implements ZipConstants */ public ZipFile(String name) throws ZipException, IOException { - this.raf = new RandomAccessFile(name, "r"); + this.raf = openFile(name,null); this.name = name; checkZipFile(); } @@ -107,7 +144,7 @@ public class ZipFile implements ZipConstants */ public ZipFile(File file) throws ZipException, IOException { - this.raf = new RandomAccessFile(file, "r"); + this.raf = openFile(null,file); this.name = file.getPath(); checkZipFile(); } @@ -134,7 +171,7 @@ public class ZipFile implements ZipConstants throw new IllegalArgumentException("invalid mode"); if ((mode & OPEN_DELETE) != 0) file.deleteOnExit(); - this.raf = new RandomAccessFile(file, "r"); + this.raf = openFile(null,file); this.name = file.getPath(); checkZipFile(); } @@ -408,7 +445,19 @@ public class ZipFile implements ZipConstants case ZipOutputStream.STORED: return inp; case ZipOutputStream.DEFLATED: - return new InflaterInputStream(inp, new Inflater(true)); + final Inflater inf = new Inflater(true); + final int sz = (int) entry.getSize(); + return new InflaterInputStream(inp, inf) + { + public int available() throws IOException + { + if (sz == -1) + return super.available(); + if (super.available() != 0) + return sz - inf.getTotalOut(); + return 0; + } + }; default: throw new ZipException("Unknown compression method " + method); } @@ -514,6 +563,7 @@ public class ZipFile implements ZipConstants pos = 0; fillBuffer(); } + return buffer[pos++] & 0xFF; } @@ -544,7 +594,7 @@ public class ZipFile implements ZipConstants len -= remain; totalBytesRead += remain; } - + return totalBytesRead; } |