harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r822242 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
Date Tue, 06 Oct 2009 12:27:29 GMT
Author: tellison
Date: Tue Oct  6 12:27:28 2009
New Revision: 822242

URL: http://svn.apache.org/viewvc?rev=822242&view=rev
Log:
Tidy-up comments, formatting, and unnecessary else's.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java?rev=822242&r1=822241&r2=822242&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
Tue Oct  6 12:27:28 2009
@@ -43,7 +43,7 @@
 import org.apache.harmony.luni.util.Util;
 
 /**
- * This subclass extends <code>URLConnection</code>.
+ * This subclass extends {@code URLConnection}.
  * <p>
  * 
  * This class is responsible for connecting and retrieving resources from a Jar
@@ -60,17 +60,19 @@
     private JarFile jarFile;
 
     private JarEntry jarEntry;
-    
-    private boolean closed;
 
+    private boolean closed;
 
     /**
      * @param url
      *            the URL of the JAR
-     * @throws java.net.MalformedURLException
+     * @throws MalformedURLException
      *             if the URL is malformed
+     * @throws IOException
+     *             if there is a problem opening the connection.
      */
-    public JarURLConnectionImpl(java.net.URL url) throws MalformedURLException, IOException
{
+    public JarURLConnectionImpl(URL url) throws MalformedURLException,
+            IOException {
         super(url);
         jarFileURL = getJarFileURL();
         jarFileURLConnection = jarFileURL.openConnection();
@@ -89,7 +91,7 @@
     }
 
     /**
-     * Answers the Jar file refered by this <code>URLConnection</code>
+     * Answers the Jar file referred by this {@code URLConnection}.
      * 
      * @return the JAR file referenced by this connection
      * 
@@ -104,7 +106,7 @@
     }
 
     /**
-     * Answers the Jar file refered by this <code>URLConnection</code>
+     * Answers the Jar file referred by this {@code URLConnection}
      * 
      * @throws IOException
      *             if an IO error occurs while connecting to the resource.
@@ -112,22 +114,22 @@
     private void findJarFile() throws IOException {
         JarFile jar = null;
         if (getUseCaches()) {
-            synchronized(jarCache){
+            synchronized (jarCache) {
                 jarFile = jarCache.get(jarFileURL);
             }
             if (jarFile == null) {
                 jar = openJarFile();
-                synchronized(jarCache){
+                synchronized (jarCache) {
                     jarFile = jarCache.get(jarFileURL);
-                    if (jarFile == null){
+                    if (jarFile == null) {
                         jarCache.put(jarFileURL, jar);
-                        jarFile = jar; 
-                    }else{
+                        jarFile = jar;
+                    } else {
                         jar.close();
                     }
                 }
             }
-        }else{
+        } else {
             jarFile = openJarFile();
         }
 
@@ -136,38 +138,42 @@
         }
     }
 
+    @SuppressWarnings("nls")
     JarFile openJarFile() throws IOException {
         JarFile jar = null;
-        if (jarFileURL.getProtocol().equals("file")) { //$NON-NLS-1$
+        if (jarFileURL.getProtocol().equals("file")) {
             jar = new JarFile(new File(Util.decode(jarFileURL.getFile(), false,
                     "UTF-8")), true, ZipFile.OPEN_READ);
         } else {
             final InputStream is = jarFileURL.openConnection().getInputStream();
             try {
                 jar = AccessController
-                    .doPrivileged(new PrivilegedAction<JarFile>() {
-                        public JarFile run() {
-                            try {
-                                File tempJar = File.createTempFile("hyjar_", //$NON-NLS-1$
-                                        ".tmp", null); //$NON-NLS-1$
-                                tempJar.deleteOnExit();
-                                FileOutputStream fos = new FileOutputStream(
-                                        tempJar);
-                                byte[] buf = new byte[4096];
-                                int nbytes = 0;
-                                while ((nbytes = is.read(buf)) > -1) {
-                                    fos.write(buf, 0, nbytes);
+                        .doPrivileged(new PrivilegedAction<JarFile>() {
+                            public JarFile run() {
+                                try {
+                                    File tempJar = File.createTempFile(
+                                            "hyjar_", ".tmp", null);
+                                    tempJar.deleteOnExit();
+                                    FileOutputStream fos = new FileOutputStream(
+                                            tempJar);
+                                    byte[] buf = new byte[4096];
+                                    int nbytes = 0;
+                                    while ((nbytes = is.read(buf)) > -1) {
+                                        fos.write(buf, 0, nbytes);
+                                    }
+                                    fos.close();
+                                    return new JarFile(tempJar, true,
+                                            ZipFile.OPEN_READ
+                                                    | ZipFile.OPEN_DELETE);
+                                } catch (IOException e) {
+                                    return null;
                                 }
-                                fos.close();
-                                return new JarFile(tempJar, 
-                                        true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE); 
-                            } catch (IOException e) {
-                                return null;
                             }
-                        }
-                    });
+                        });
             } finally {
-                if (is != null) is.close();
+                if (is != null) {
+                    is.close();
+                }
             }
         }
 
@@ -175,10 +181,10 @@
     }
 
     /**
-     * Answers the JarEntry of the entry referenced by this
-     * <code>URLConnection</code>.
+     * Answers the JarEntry of the entry referenced by this {@code
+     * URLConnection}.
      * 
-     * @return java.util.jar.JarEntry the JarEntry referenced
+     * @return the JarEntry referenced
      * 
      * @throws IOException
      *             if an IO error occurs while getting the entry
@@ -191,8 +197,8 @@
     }
 
     /**
-     * Look up the JarEntry of the entry referenced by this
-     * <code>URLConnection</code>.
+     * Look up the JarEntry of the entry referenced by this {@code
+     * URLConnection}.
      */
     private void findJarEntry() throws IOException {
         if (getEntryName() == null) {
@@ -214,15 +220,16 @@
      */
     @Override
     public InputStream getInputStream() throws IOException {
-
         if (closed) {
-            throw new IllegalStateException(Msg.getString("KA027"));
+            // KA027=Inputstream of the JarURLConnection has been closed
+            throw new IllegalStateException(Msg.getString("KA027")); //$NON-NLS-1$
         }
         connect();
         if (jarInput != null) {
             return jarInput;
         }
         if (jarEntry == null) {
+            // K00fc=Jar entry not specified
             throw new IOException(Msg.getString("K00fc")); //$NON-NLS-1$
         }
         return jarInput = new JarURLConnectionInputStream(jarFile
@@ -230,10 +237,10 @@
     }
 
     /**
-     * Answers the content type of the resource.
-     * For jar file itself "x-java/jar" should be returned,
-     * for jar entries the content type of the entry should be returned.
-     * Returns non-null results ("content/unknown" for unknown types).
+     * Answers the content type of the resource. For jar file itself
+     * "x-java/jar" should be returned, for jar entries the content type of the
+     * entry should be returned. Returns non-null results ("content/unknown" for
+     * unknown types).
      * 
      * @return the content type
      */
@@ -242,31 +249,30 @@
         if (url.getFile().endsWith("!/")) { //$NON-NLS-1$
             // the type for jar file itself is always "x-java/jar"
             return "x-java/jar"; //$NON-NLS-1$
-        } else {
-            String cType = null;
-            String entryName = getEntryName();
+        }
+        String cType = null;
+        String entryName = getEntryName();
 
-            if (entryName != null) {
-                // if there is an Jar Entry, get the content type from the name
-                cType = guessContentTypeFromName(entryName);
-            } else {
-                try {
-                    connect();
-                    cType = jarFileURLConnection.getContentType();
-                } catch (IOException ioe) {
-                    // Ignore
-                }
-            }
-            if (cType == null) {
-                cType = "content/unknown"; //$NON-NLS-1$
+        if (entryName != null) {
+            // if there is an Jar Entry, get the content type from the name
+            cType = guessContentTypeFromName(entryName);
+        } else {
+            try {
+                connect();
+                cType = jarFileURLConnection.getContentType();
+            } catch (IOException ioe) {
+                // Ignore
             }
-            return cType;
         }
+        if (cType == null) {
+            cType = "content/unknown"; //$NON-NLS-1$
+        }
+        return cType;
     }
 
     /**
      * Answers the content length of the resource. Test cases reveal that if the
-     * URL is refering to a Jar file, this method answers a content-length
+     * URL is referring to a Jar file, this method answers a content-length
      * returned by URLConnection. For jar entry it should return it's size.
      * Otherwise, it will return -1.
      * 
@@ -278,25 +284,24 @@
             connect();
             if (jarEntry == null) {
                 return jarFileURLConnection.getContentLength();
-            } else {
-                return (int) getJarEntry().getSize();
             }
+            return (int) getJarEntry().getSize();
         } catch (IOException e) {
-            //Ignored
+            // Ignored
         }
         return -1;
     }
 
     /**
-     * Answers the object pointed by this <code>URL</code>. If this
-     * URLConnection is pointing to a Jar File (no Jar Entry), this method will
-     * return a <code>JarFile</code> If there is a Jar Entry, it will return
-     * the object corresponding to the Jar entry content type.
+     * Answers the object pointed by this {@code URL}. If this URLConnection is
+     * pointing to a Jar File (no Jar Entry), this method will return a {@code
+     * JarFile} If there is a Jar Entry, it will return the object corresponding
+     * to the Jar entry content type.
      * 
      * @return a non-null object
      * 
      * @throws IOException
-     *             if an IO error occured
+     *             if an IO error occurred
      * 
      * @see ContentHandler
      * @see ContentHandlerFactory
@@ -355,9 +360,9 @@
      */
     public static void closeCachedFiles() {
         Set<Map.Entry<URL, JarFile>> s = jarCache.entrySet();
-        synchronized(jarCache){
+        synchronized (jarCache) {
             Iterator<Map.Entry<URL, JarFile>> i = s.iterator();
-            while(i.hasNext()){
+            while (i.hasNext()) {
                 try {
                     ZipFile zip = i.next().getValue();
                     if (zip != null) {
@@ -367,7 +372,7 @@
                     // Ignored
                 }
             }
-       }
+        }
     }
 
     private class JarURLConnectionInputStream extends FilterInputStream {



Mime
View raw message