]> WPIA git - gigi.git/blobdiff - lib/jetty/org/eclipse/jetty/util/resource/URLResource.java
updating jetty to jetty-9.2.16.v2016040
[gigi.git] / lib / jetty / org / eclipse / jetty / util / resource / URLResource.java
index b696817e50b0d6a0012eca310c7cf96c99f5cb8f..5bba2c4726570a4bfbf5ed58b6a6dd60eaa2161b 100644 (file)
@@ -1,6 +1,6 @@
 //
 //  ========================================================================
 //
 //  ========================================================================
-//  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+//  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
 //  ------------------------------------------------------------------------
 //  All rights reserved. This program and the accompanying materials
 //  are made available under the terms of the Eclipse Public License v1.0
 //  ------------------------------------------------------------------------
 //  All rights reserved. This program and the accompanying materials
 //  are made available under the terms of the Eclipse Public License v1.0
@@ -197,13 +197,33 @@ public class URLResource extends Resource
         return _url.toExternalForm();
     }
 
         return _url.toExternalForm();
     }
 
+    
     /* ------------------------------------------------------------ */
     /**
     /* ------------------------------------------------------------ */
     /**
-     * Returns an input stream to the resource
+     * Returns an input stream to the resource. The underlying 
+     * url connection will be nulled out to prevent re-use.
      */
     @Override
     public synchronized InputStream getInputStream()
         throws java.io.IOException
      */
     @Override
     public synchronized InputStream getInputStream()
         throws java.io.IOException
+    {
+        return getInputStream (true); //backwards compatibility
+    }
+    
+    
+    /* ------------------------------------------------------------ */
+    /**
+     * Returns an input stream to the resource, optionally nulling
+     * out the underlying url connection. If the connection is not
+     * nulled out, a subsequent call to getInputStream() may return
+     * an existing and already in-use input stream - this depends on
+     * the url protocol. Eg JarURLConnection does not reuse inputstreams.
+     * 
+     * @param resetConnection if true the connection field is set to null
+     */
+    protected synchronized InputStream getInputStream(boolean resetConnection)
+        throws java.io.IOException
     {
         if (!checkConnection())
             throw new IOException( "Invalid resource");
     {
         if (!checkConnection())
             throw new IOException( "Invalid resource");
@@ -220,7 +240,11 @@ public class URLResource extends Resource
         }
         finally
         {
         }
         finally
         {
-            _connection=null;
+            if (resetConnection)
+            {
+                _connection=null;
+                if (LOG.isDebugEnabled()) LOG.debug("Connection nulled");
+            }
         }
     }
 
         }
     }
 
@@ -277,7 +301,7 @@ public class URLResource extends Resource
 
         path = URIUtil.canonicalPath(path);
 
 
         path = URIUtil.canonicalPath(path);
 
-        return newResource(URIUtil.addPaths(_url.toExternalForm(),path));
+        return newResource(URIUtil.addPaths(_url.toExternalForm(),URIUtil.encodePath(path)), _useCaches);
     }
 
     /* ------------------------------------------------------------ */
     }
 
     /* ------------------------------------------------------------ */