Author: ssmiweve
Date: 2008-12-22 21:17:34 +0100 (Mon, 22 Dec 2008)
New Revision: 7111

Modified:
   
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/HTTPClient.java
   
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/JarFileFactory.java
   
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/JarURLConnection.java
   
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/URLJarFile.java
Log:
Issue SKER5029:  (Upgrade sun java classes that are patched in Sesat 
HttpClient) 


Modified: 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/HTTPClient.java
===================================================================
--- 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/HTTPClient.java 
    2008-12-17 20:16:44 UTC (rev 7110)
+++ 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/HTTPClient.java 
    2008-12-22 20:17:34 UTC (rev 7111)
@@ -32,6 +32,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.RandomAccessFile;
 import java.net.ConnectException;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
@@ -40,6 +41,8 @@
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
 import java.net.JarURLConnection;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -50,8 +53,9 @@
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import sun.net.www.protocol.jar.URLJarFile;
-import sun.net.www.protocol.jar.URLJarFileCallBack;
+import no.sesat.search.http.protocol.jar.URLJarFile;
+import no.sesat.search.http.protocol.jar.URLJarFile.URLJarFileCloseController;
+import no.sesat.search.http.protocol.jar.URLJarFileCallBack;
 
 /**
  * Utility class to fetch URLs and return them as either BufferedReaders or 
XML documents.
@@ -513,7 +517,7 @@
             private int BUF_SIZE = 2048;
 
             @SuppressWarnings(value = "unchecked")
-            public JarFile retrieve(final URL url) throws IOException {
+            public JarFile retrieve(final URL url, final 
URLJarFileCloseController closeController) throws IOException {
 
                 // next to verbose copy from URLJarFile
                 JarFile result = null;
@@ -528,35 +532,53 @@
                 final InputStream in = connection.getInputStream();
 
                 try {
-                    result = (JarFile) AccessController.doPrivileged(new 
PrivilegedExceptionAction() {
+
+                result = (JarFile)
+                        // the following anonymous class is modified from 
URLJarFile to use java.nio
+                    AccessController.doPrivileged(new 
PrivilegedExceptionAction() {
                         public Object run() throws IOException {
-                            OutputStream     out = null;
+
                             File tmpFile = null;
                             try {
-                                tmpFile = File.createTempFile("jar_cache", 
null);
+                                tmpFile = 
File.createTempFile("jar_sesat-httpclient_cache", null);
                                 tmpFile.deleteOnExit();
-                                out  = new FileOutputStream(tmpFile);
-                                int read = 0;
-                                byte[] buf = new byte[BUF_SIZE];
-                                while ((read = in.read(buf)) != -1) {
-                                    out.write(buf, 0, read);
+
+                                RandomAccessFile fileAccess = null;
+                                FileChannel channel = null;
+
+                                try{
+
+                                    fileAccess = new RandomAccessFile(tmpFile, 
"rws");
+                                    channel = fileAccess.getChannel();
+
+                                    channel.lock();
+
+                                    final byte[] buf = new byte[BUF_SIZE];
+                                    final ByteBuffer nioBuf = 
ByteBuffer.wrap(buf);
+
+                                    while (in.read(buf) != -1) {
+                                        channel.write(nioBuf);
+                                    }
+
+                                }finally{
+                                    if(null != channel){ channel.close(); }
+                                    if(null != fileAccess){ 
fileAccess.close(); }
+                                    if(null != in){ in.close(); }
                                 }
-                                out.close();
-                                out = null;
-                                return new URLJarFile(tmpFile);
 
+                                return new URLJarFile(tmpFile, 
closeController);
+
                             } catch (IOException e) {
                                 if (tmpFile != null) {
                                     tmpFile.delete();
                                 }
                                 throw e;
-                            } finally {
-                                if (in != null) {
-                                    in.close();
+                            } catch(RuntimeException rte){
+                                if (tmpFile != null) {
+                                    tmpFile.delete();
                                 }
-                                if (out != null) {
-                                    out.close();
-                                }
+                                LOG.error("failed writing 
jar_sesat-httpclient_cache file", rte);
+                                throw rte;
                             }
                         }
                     });

Modified: 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/JarFileFactory.java
===================================================================
--- 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/JarFileFactory.java
    2008-12-17 20:16:44 UTC (rev 7110)
+++ 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/JarFileFactory.java
    2008-12-22 20:17:34 UTC (rev 7111)
@@ -1,8 +1,28 @@
 /*
- * @(#)JarFileFactory.java     1.37 06/02/27
+ * PATCHED TO ADDRESS 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6270774
  *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
  */
 
 package no.sesat.search.http.protocol.jar;
@@ -11,15 +31,17 @@
 import java.net.*;
 import java.util.*;
 import java.util.jar.*;
+import java.util.zip.ZipFile;
 import java.security.Permission;
 
 /* A factory for cached JAR file. This class is used to both retrieve
  * and cache Jar files.
  *
- *
+ * @author Benjamin Renaud
  * @since JDK1.2
  */
 class JarFileFactory implements URLJarFile.URLJarFileCloseController {
+
     /* the url to file cache */
     private static HashMap fileCache = new HashMap();
 
@@ -27,48 +49,51 @@
     private static HashMap urlCache = new HashMap();
 
     URLConnection getConnection(JarFile jarFile) throws IOException {
-        URL u = (URL) urlCache.get(jarFile);
-        if (u != null) {
+        URL u = (URL)urlCache.get(jarFile);
+        if (u != null)
             return u.openConnection();
-        }
+
         return null;
     }
 
     public JarFile get(URL url) throws IOException {
-        return get(url, null);
+        return get(url, true);
     }
 
-    JarFile get(URL url, JarURLConnection parentConnection) throws IOException 
{
+    JarFile get(URL url, boolean useCaches) throws IOException {
+        return get(url, useCaches, null);
+    }
 
+    JarFile get(URL url, boolean useCaches, JarURLConnection parentConnection) 
throws IOException {
+
         JarFile result = null;
         JarFile local_result = null;
 
-        if (null == parentConnection || parentConnection.getUseCaches()) {
+        if (useCaches) {
             synchronized (this) {
                 result = getCachedJarFile(url);
             }
             if (result == null) {
-                local_result = URLJarFile.getJarFile(url, parentConnection);
+                local_result = URLJarFile.getJarFile(url, this, 
parentConnection);
                 synchronized (this) {
                     result = getCachedJarFile(url);
                     if (result == null) {
                         fileCache.put(url, local_result);
                         urlCache.put(local_result, url);
                         result = local_result;
-
-                    }else {
+                    } else {
                         if (local_result != null) {
                             local_result.close();
                         }
                     }
                 }
             }
-        }else {
-            result = URLJarFile.getJarFile(url, parentConnection);
+        } else {
+            result = URLJarFile.getJarFile(url, this, parentConnection);
         }
-        if (result == null) {
+        if (result == null)
             throw new FileNotFoundException(url.toString());
-        }
+
         return result;
     }
 
@@ -79,13 +104,14 @@
      */
     public void close(JarFile jarFile) {
         URL urlRemoved = (URL) urlCache.remove(jarFile);
-        if (urlRemoved != null) {
-            fileCache.remove(urlRemoved);
+        if( urlRemoved != null) {
+                fileCache.remove(urlRemoved);
         }
     }
 
+
     private JarFile getCachedJarFile(URL url) {
-        JarFile result = (JarFile) fileCache.get(url);
+        JarFile result = (JarFile)fileCache.get(url);
 
         /* if the JAR file is cached, the permission will always be there */
         if (result != null) {
@@ -95,17 +121,17 @@
                 if (sm != null) {
                     try {
                         sm.checkPermission(perm);
-                    }
-                    catch (SecurityException se) {
+                    } catch (SecurityException se) {
                         // fallback to checkRead/checkConnect for pre 1.2
                         // security managers
-                        if ((perm instanceof java.io.FilePermission) && 
perm.getActions().indexOf("read") != -1) {
+                        if ((perm instanceof java.io.FilePermission) &&
+                            perm.getActions().indexOf("read") != -1) {
                             sm.checkRead(perm.getName());
-                        }
-                        else if ((perm instanceof java.net.SocketPermission) 
&& perm.getActions().indexOf("connect") != -1) {
+                        } else if ((perm instanceof
+                            java.net.SocketPermission) &&
+                            perm.getActions().indexOf("connect") != -1) {
                             sm.checkConnect(url.getHost(), url.getPort());
-                        }
-                        else {
+                        } else {
                             throw se;
                         }
                     }
@@ -118,11 +144,9 @@
     private Permission getPermission(JarFile jarFile) {
         try {
             URLConnection uc = getConnection(jarFile);
-            if (uc != null) {
+            if (uc != null)
                 return uc.getPermission();
-            }
-        }
-        catch (IOException ioe) {
+        } catch (IOException ioe) {
             // gulp
         }
 

Modified: 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/JarURLConnection.java
===================================================================
--- 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/JarURLConnection.java
  2008-12-17 20:16:44 UTC (rev 7110)
+++ 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/JarURLConnection.java
  2008-12-22 20:17:34 UTC (rev 7111)
@@ -1,11 +1,32 @@
 /*
- * @(#)JarURLConnection.java   1.31 06/08/14
+ * PATCHED TO ADDRESS 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6270774
  *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
  */
 
 package no.sesat.search.http.protocol.jar;
+import sun.net.www.protocol.jar.*;
 
 import java.io.InputStream;
 import java.io.IOException;
@@ -14,23 +35,26 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.MalformedURLException;
+import java.net.UnknownServiceException;
+import java.util.Enumeration;
 import java.util.Map;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
+import java.util.jar.Manifest;
 import java.security.Permission;
-import sun.net.www.protocol.jar.Handler;
 
 /**
- *
+ * @author Benjamin Renaud
  * @since 1.2
  */
 public class JarURLConnection extends java.net.JarURLConnection {
+
     private static final boolean debug = false;
 
     /* the Jar file factory. It handles both retrieval and caching.
      */
-    static JarFileFactory factory = new JarFileFactory();
+    private static JarFileFactory factory = new JarFileFactory();
 
     /* the url for the Jar file */
     private URL jarFileURL;
@@ -55,8 +79,8 @@
     /* the content type for this connection */
     private String contentType;
 
-
-    public JarURLConnection(URL url, Handler handler) throws 
MalformedURLException, IOException {
+    public JarURLConnection(URL url, Handler handler)
+    throws MalformedURLException, IOException {
         super(url);
 
         jarFileURL = getJarFileURL();
@@ -69,26 +93,23 @@
         return jarFile;
     }
 
-    @Override
     public JarEntry getJarEntry() throws IOException {
         connect();
         return jarEntry;
     }
 
-    @Override
     public Permission getPermission() throws IOException {
         return jarFileURLConnection.getPermission();
     }
+
     class JarURLInputStream extends java.io.FilterInputStream {
-        JarURLInputStream(InputStream src) {
-            super(src);
+        JarURLInputStream (InputStream src) {
+            super (src);
         }
-
-        public void close() throws IOException {
+        public void close () throws IOException {
             try {
                 super.close();
-            }
-            finally {
+            } finally {
                 if (!getUseCaches()) {
                     jarFile.close();
                 }
@@ -96,10 +117,12 @@
         }
     }
 
+
+
     public void connect() throws IOException {
         if (!connected) {
             /* the factory call will do the security checks */
-            jarFile = factory.get(getJarFileURL(), this);
+            jarFile = factory.get(getJarFileURL(), getUseCaches(), this);
 
             /* we also ask the factory the permission that was required
              * to get the jarFile, and set it as our permission.
@@ -108,24 +131,24 @@
                 jarFileURLConnection = factory.getConnection(jarFile);
             }
 
-            if (entryName != null) {
-                jarEntry = (JarEntry) jarFile.getEntry(entryName);
+            if ((entryName != null)) {
+                jarEntry = (JarEntry)jarFile.getEntry(entryName);
                 if (jarEntry == null) {
                     try {
                         if (!getUseCaches()) {
                             jarFile.close();
                         }
+                    } catch (Exception e) {
                     }
-                    catch (Exception e) {
-                    }
-                    throw new FileNotFoundException("JAR entry " + entryName + 
" not found in " + jarFile.getName());
+                    throw new FileNotFoundException("JAR entry " + entryName +
+                                                    " not found in " +
+                                                    jarFile.getName());
                 }
             }
             connected = true;
         }
     }
 
-    @Override
     public InputStream getInputStream() throws IOException {
         connect();
 
@@ -133,17 +156,17 @@
 
         if (entryName == null) {
             throw new IOException("no entry name specified");
-        }
-        else {
+        } else {
             if (jarEntry == null) {
-                throw new FileNotFoundException("JAR entry " + entryName + " 
not found in " + jarFile.getName());
+                throw new FileNotFoundException("JAR entry " + entryName +
+                                                " not found in " +
+                                                jarFile.getName());
             }
-            result = new JarURLInputStream(jarFile.getInputStream(jarEntry));
+            result = new JarURLInputStream (jarFile.getInputStream(jarEntry));
         }
         return result;
     }
 
-    @Override
     public int getContentLength() {
         int result = -1;
         try {
@@ -151,45 +174,39 @@
             if (jarEntry == null) {
                 /* if the URL referes to an archive */
                 result = jarFileURLConnection.getContentLength();
-            }
-            else {
+            } else {
                 /* if the URL referes to an archive entry */
-                result = (int) getJarEntry().getSize();
+                result = (int)getJarEntry().getSize();
             }
+        } catch (IOException e) {
         }
-        catch (IOException e) {
-        }
         return result;
     }
 
-    @Override
     public Object getContent() throws IOException {
         Object result = null;
 
         connect();
         if (entryName == null) {
             result = jarFile;
-        }
-        else {
+        } else {
             result = super.getContent();
         }
         return result;
     }
 
-    @Override
     public String getContentType() {
         if (contentType == null) {
             if (entryName == null) {
                 contentType = "x-java/jar";
-            }
-            else {
+            } else {
                 try {
                     connect();
                     InputStream in = jarFile.getInputStream(jarEntry);
-                    contentType = guessContentTypeFromStream(new 
BufferedInputStream(in));
+                    contentType = guessContentTypeFromStream(
+                                        new BufferedInputStream(in));
                     in.close();
-                }
-                catch (IOException e) {
+                } catch (IOException e) {
                     // don't do anything
                 }
             }
@@ -203,7 +220,6 @@
         return contentType;
     }
 
-    @Override
     public String getHeaderField(String name) {
         return jarFileURLConnection.getHeaderField(name);
     }
@@ -215,7 +231,6 @@
      *                  (e.g., "<code>accept</code>").
      * @param   value   the value associated with it.
      */
-    @Override
     public void setRequestProperty(String key, String value) {
         jarFileURLConnection.setRequestProperty(key, value);
     }
@@ -227,7 +242,6 @@
      * @return  the value of the named general request property for this
      *           connection.
      */
-    @Override
     public String getRequestProperty(String key) {
         return jarFileURLConnection.getRequestProperty(key);
     }
@@ -241,7 +255,6 @@
      *                  (e.g., "<code>accept</code>").
      * @param   value   the value associated with it.
      */
-    @Override
     public void addRequestProperty(String key, String value) {
         jarFileURLConnection.addRequestProperty(key, value);
     }
@@ -256,8 +269,7 @@
      *
      * @return  a Map of the general request properties for this connection.
      */
-    @Override
-    public Map<String, List<String>> getRequestProperties() {
+    public Map<String,List<String>> getRequestProperties() {
         return jarFileURLConnection.getRequestProperties();
     }
 
@@ -268,7 +280,6 @@
      * @param   allowuserinteraction   the new value.
      * @see     java.net.URLConnection#allowUserInteraction
      */
-    @Override
     public void setAllowUserInteraction(boolean allowuserinteraction) {
         jarFileURLConnection.setAllowUserInteraction(allowuserinteraction);
     }
@@ -281,7 +292,6 @@
      *          this object.
      * @see     java.net.URLConnection#allowUserInteraction
      */
-    @Override
     public boolean getAllowUserInteraction() {
         return jarFileURLConnection.getAllowUserInteraction();
     }
@@ -289,6 +299,7 @@
     /*
      * cache control
      */
+
     /**
      * Sets the value of the <code>useCaches</code> field of this
      * <code>URLConnection</code> to the specified value.
@@ -303,7 +314,6 @@
      *
      * @see     java.net.URLConnection#useCaches
      */
-    @Override
     public void setUseCaches(boolean usecaches) {
         jarFileURLConnection.setUseCaches(usecaches);
     }
@@ -316,7 +326,6 @@
      *          <code>useCaches</code> field.
      * @see     java.net.URLConnection#useCaches
      */
-    @Override
     public boolean getUseCaches() {
         return jarFileURLConnection.getUseCaches();
     }
@@ -328,24 +337,22 @@
      * @param   value   the new value.
      * @see     java.net.URLConnection#ifModifiedSince
      */
-    @Override
     public void setIfModifiedSince(long ifmodifiedsince) {
         jarFileURLConnection.setIfModifiedSince(ifmodifiedsince);
     }
 
-    /**
+   /**
      * Sets the default value of the <code>useCaches</code> field to the
      * specified value.
      *
      * @param   defaultusecaches   the new value.
      * @see     java.net.URLConnection#useCaches
      */
-    @Override
     public void setDefaultUseCaches(boolean defaultusecaches) {
         jarFileURLConnection.setDefaultUseCaches(defaultusecaches);
     }
 
-    /**
+   /**
      * Returns the default value of a <code>URLConnection</code>'s
      * <code>useCaches</code> flag.
      * <p>
@@ -357,7 +364,6 @@
      *          <code>useCaches</code> flag.
      * @see     java.net.URLConnection#useCaches
      */
-    @Override
     public boolean getDefaultUseCaches() {
         return jarFileURLConnection.getDefaultUseCaches();
     }

Modified: 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/URLJarFile.java
===================================================================
--- 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/URLJarFile.java
        2008-12-17 20:16:44 UTC (rev 7110)
+++ 
branches/2.18/httpclient-api/src/main/java/no/sesat/search/http/protocol/jar/URLJarFile.java
        2008-12-22 20:17:34 UTC (rev 7111)
@@ -1,10 +1,29 @@
 /*
- * @(#)URLJarFile.java 1.11 06/02/27
+ * PATCHED TO ADDRESS 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6270774
  *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ * Copyright 2001-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
  */
-
 package no.sesat.search.http.protocol.jar;
 
 import java.io.*;
@@ -16,13 +35,14 @@
 import java.security.CodeSigner;
 import java.security.cert.Certificate;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedActionException;
 import sun.net.www.ParseUtil;
-import sun.net.www.protocol.jar.URLJarFileCallBack;
 
 /* URL jar file is a common JarFile subtype used for JarURLConnection */
 public class URLJarFile extends JarFile {
+
     /*
      * Interface to be able to call retrieve() in plugin if
      * this variable is set.
@@ -35,21 +55,18 @@
     private static int BUF_SIZE = 2048;
 
     private Manifest superMan;
-
     private Attributes superAttr;
-
     private Map superEntries;
 
     static JarFile getJarFile(URL url) throws IOException {
-        return getJarFile(url, null);
+        return getJarFile(url, null, null);
     }
 
-    static JarFile getJarFile(URL url, JarURLConnection parentConnection) 
throws IOException {
-        if (isFileURL(url)) {
-            return new URLJarFile(url, parentConnection.factory);
-        }
+    static JarFile getJarFile(URL url, URLJarFileCloseController 
closeController, final JarURLConnection parentConnection) throws IOException {
+        if (isFileURL(url))
+            return new URLJarFile(url, closeController);
         else {
-            return retrieve(url, parentConnection);
+            return retrieve(url, closeController, parentConnection);
         }
     }
 
@@ -82,9 +99,9 @@
              * 'file:' URLs can be accessible through ftp.
              */
             String host = url.getHost();
-            if (host == null || host.equals("") || host.equals("~") || 
host.equalsIgnoreCase("localhost")) {
+            if (host == null || host.equals("") || host.equals("~") ||
+                host.equalsIgnoreCase("localhost"))
                 return true;
-            }
         }
         return false;
     }
@@ -92,7 +109,6 @@
     /*
      * close the jar file.
      */
-    @Override
     protected void finalize() throws IOException {
         close();
     }
@@ -106,21 +122,19 @@
      *         <code>null</code> if not found
      * @see java.util.zip.ZipEntry
      */
-    @Override
     public ZipEntry getEntry(String name) {
         ZipEntry ze = super.getEntry(name);
         if (ze != null) {
-            if (ze instanceof JarEntry) {
-                return new URLJarFileEntry((JarEntry) ze);
-            }
-            else {
-                throw new InternalError(super.getClass() + " returned 
unexpected entry type " + ze.getClass());
-            }
+            if (ze instanceof JarEntry)
+                return new URLJarFileEntry((JarEntry)ze);
+            else
+                throw new InternalError(super.getClass() +
+                                        " returned unexpected entry type " +
+                                        ze.getClass());
         }
         return null;
     }
 
-    @Override
     public Manifest getManifest() throws IOException {
 
         if (!isSuperMan()) {
@@ -129,7 +143,7 @@
 
         Manifest man = new Manifest();
         Attributes attr = man.getMainAttributes();
-        attr.putAll((Map) superAttr.clone());
+        attr.putAll((Map)superAttr.clone());
 
         // now deep copy the manifest entries
         if (superEntries != null) {
@@ -137,7 +151,7 @@
             Iterator it = superEntries.keySet().iterator();
             while (it.hasNext()) {
                 Object key = it.next();
-                Attributes at = (Attributes) superEntries.get(key);
+                Attributes at = (Attributes)superEntries.get(key);
                 entries.put(key, at.clone());
             }
         }
@@ -146,10 +160,9 @@
     }
 
     /* If close controller is set the notify the controller about the pending 
close */
-    @Override
     public void close() throws IOException {
         if (closeController != null) {
-            closeController.close(this);
+                closeController.close(this);
         }
         super.close();
     }
@@ -165,10 +178,8 @@
             superAttr = superMan.getMainAttributes();
             superEntries = superMan.getEntries();
             return true;
-        }
-        else {
+        } else
             return false;
-        }
     }
 
     /**
@@ -176,25 +187,26 @@
      * cached JAR file object.
      */
     private static JarFile retrieve(final URL url) throws IOException {
-        return retrieve(url, null);
+        return retrieve(url, null, null);
     }
 
     /**
      * Given a URL, retrieves a JAR file, caches it to disk, and creates a
      * cached JAR file object.
      */
-    private static JarFile retrieve(
-            final URL url,
-            final JarURLConnection parentConnection) throws IOException {
+     private static JarFile retrieve(final URL url, final 
URLJarFileCloseController closeController, final JarURLConnection 
parentConnection) throws IOException {
         /*
          * See if interface is set, then call retrieve function of the class
          * that implements URLJarFileCallBack interface (sun.plugin - to
          * handle the cache failure for JARJAR file.)
          */
-        if (callback != null) {
-            return callback.retrieve(url);
+        if (callback != null)
+        {
+            return callback.retrieve(url, closeController);
+        }
 
-        }else {
+        else
+        {
 
             JarFile result = null;
 
@@ -212,39 +224,39 @@
             final InputStream in = connection.getInputStream();
 
             try {
-                result = (JarFile) AccessController.doPrivileged(new 
PrivilegedExceptionAction() {
-                    public Object run() throws IOException {
-                        OutputStream out = null;
-                        File tmpFile = null;
-                        try {
-                            tmpFile = File.createTempFile("jar_cache", null);
-                            tmpFile.deleteOnExit();
-                            out  = new FileOutputStream(tmpFile);
-                            int read = 0;
-                            byte[] buf = new byte[BUF_SIZE];
-                            while ((read = in.read(buf)) != -1) {
-                                out.write(buf, 0, read);
+                result = (JarFile)
+                    AccessController.doPrivileged(new 
PrivilegedExceptionAction() {
+                        public Object run() throws IOException {
+                            OutputStream out = null;
+                            File tmpFile = null;
+                            try {
+                                tmpFile = File.createTempFile("jar_cache", 
null);
+                                tmpFile.deleteOnExit();
+                                out  = new FileOutputStream(tmpFile);
+                                int read = 0;
+                                byte[] buf = new byte[BUF_SIZE];
+                                while ((read = in.read(buf)) != -1) {
+                                    out.write(buf, 0, read);
+                                }
+                                out.close();
+                                out = null;
+                                return new URLJarFile(tmpFile, 
closeController);
+                            } catch (IOException e) {
+                                if (tmpFile != null) {
+                                    tmpFile.delete();
+                                }
+                                throw e;
+                            } finally {
+                                if (in != null) {
+                                    in.close();
+                                }
+                                if (out != null) {
+                                    out.close();
+                                }
                             }
-                            out.close();
-                            out = null;
-                            return new URLJarFile(tmpFile, null != 
parentConnection.factory ? parentConnection.factory : null);
-                        } catch (IOException e) {
-                            if (tmpFile != null) {
-                                tmpFile.delete();
-                            }
-                            throw e;
-                        } finally {
-                            if (in != null) {
-                            in.close();
-                            }
-                            if (out != null) {
-                            out.close();
-                            }
                         }
-                    }
-                   });
-
-            }catch (PrivilegedActionException pae) {
+                    });
+            } catch (PrivilegedActionException pae) {
                 throw (IOException) pae.getException();
             }
 
@@ -256,42 +268,40 @@
      * Set the call back interface to call retrive function in sun.plugin
      * package if plugin is running.
      */
-    public static void setCallBack(URLJarFileCallBack cb) {
+    public static void setCallBack(URLJarFileCallBack cb)
+    {
         callback = cb;
     }
 
+
     private class URLJarFileEntry extends JarEntry {
         private JarEntry je;
 
         URLJarFileEntry(JarEntry je) {
             super(je);
-            this.je = je;
+            this.je=je;
         }
 
-        @Override
         public Attributes getAttributes() throws IOException {
             if (URLJarFile.this.isSuperMan()) {
                 Map e = URLJarFile.this.superEntries;
                 if (e != null) {
-                    Attributes a = (Attributes) e.get(getName());
-                    if (a != null) {
-                        return (Attributes) a.clone();
-                    }
+                    Attributes a = (Attributes)e.get(getName());
+                    if (a != null)
+                        return  (Attributes)a.clone();
                 }
             }
             return null;
         }
 
-        @Override
         public java.security.cert.Certificate[] getCertificates() {
             Certificate[] certs = je.getCertificates();
-            return certs == null ? null : (Certificate[]) certs.clone();
+            return certs == null? null: certs.clone();
         }
 
-        @Override
         public CodeSigner[] getCodeSigners() {
             CodeSigner[] csg = je.getCodeSigners();
-            return csg == null ? null : (CodeSigner[]) csg.clone();
+            return csg == null? null: csg.clone();
         }
     }
 

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to