From 4f9533c7722fa07511a94d005227961f4a4dec23 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@gcc.gnu.org>
Date: Thu, 18 May 2006 17:29:21 +0000
Subject: Imported GNU Classpath 0.90

       Imported GNU Classpath 0.90
       * scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale.

       * sources.am: Regenerated.
       * gcj/javaprims.h: Regenerated.
       * Makefile.in: Regenerated.
       * gcj/Makefile.in: Regenerated.
       * include/Makefile.in: Regenerated.
       * testsuite/Makefile.in: Regenerated.

       * gnu/java/lang/VMInstrumentationImpl.java: New override.
       * gnu/java/net/local/LocalSocketImpl.java: Likewise.
       * gnu/classpath/jdwp/VMMethod.java: Likewise.
       * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest
       interface.
       * java/lang/Thread.java: Add UncaughtExceptionHandler.
       * java/lang/reflect/Method.java: Implements GenericDeclaration and
       isSynthetic(),
       * java/lang/reflect/Field.java: Likewise.
       * java/lang/reflect/Constructor.java
       * java/lang/Class.java: Implements Type, GenericDeclaration,
       getSimpleName() and getEnclosing*() methods.
       * java/lang/Class.h: Add new public methods.
       * java/lang/Math.java: Add signum(), ulp() and log10().
       * java/lang/natMath.cc (log10): New function.
       * java/security/VMSecureRandom.java: New override.
       * java/util/logging/Logger.java: Updated to latest classpath
       version.
       * java/util/logging/LogManager.java: New override.

From-SVN: r113887
---
 libjava/classpath/java/util/zip/ZipFile.java | 60 +++++++++++++++++++++++++---
 1 file changed, 55 insertions(+), 5 deletions(-)

(limited to 'libjava/classpath/java/util/zip/ZipFile.java')

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;
     }
 
-- 
cgit v1.1