- Switch to ArrayList.
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 13 Apr 2006 11:18:26 +0000 (11:18 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 13 Apr 2006 11:18:26 +0000 (11:18 +0000)
- private -> protected.
- Use a marker constant for full range, because null indicates an error or no content.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@393783 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/servlets/DefaultServlet.java

index 480c57b..ddb4370 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * Copyright 1999,2004 The Apache Software Foundation.\r
+ * Copyright 1999,2004-2006 The Apache Software Foundation.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -32,9 +32,9 @@ import java.io.RandomAccessFile;
 import java.io.Reader;\r
 import java.io.StringReader;\r
 import java.io.StringWriter;\r
-import java.util.Enumeration;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
 import java.util.StringTokenizer;\r
-import java.util.Vector;\r
 \r
 import javax.naming.InitialContext;\r
 import javax.naming.NameClassPair;\r
@@ -152,6 +152,12 @@ public class DefaultServlet
     protected int sendfileSize = 48 * 1024;\r
     \r
     \r
+    /**\r
+     * Full range marker.\r
+     */\r
+    protected static ArrayList FULL = new ArrayList();\r
+    \r
+    \r
     // ----------------------------------------------------- Static Initializer\r
 \r
 \r
@@ -190,7 +196,7 @@ public class DefaultServlet
     /**\r
      * Size of file transfer buffer in bytes.\r
      */\r
-    private static final int BUFFER_SIZE = 4096;\r
+    protected static final int BUFFER_SIZE = 4096;\r
 \r
 \r
     // --------------------------------------------------------- Public Methods\r
@@ -732,7 +738,7 @@ public class DefaultServlet
             cacheEntry.attributes.setMimeType(contentType);\r
         }\r
 \r
-        Vector ranges = null;\r
+        ArrayList ranges = null;\r
         long contentLength = -1L;\r
 \r
         if (cacheEntry.context != null) {\r
@@ -791,9 +797,10 @@ public class DefaultServlet
 \r
         }\r
 \r
-        if ( (cacheEntry.context != null) ||\r
-             ( ((ranges == null) || (ranges.isEmpty()))\r
-               && (request.getHeader("Range") == null) ) ) {\r
+        if ( (cacheEntry.context != null) \r
+                || ( ((ranges == null) || (ranges.isEmpty()))\r
+                        && (request.getHeader("Range") == null) )\r
+                || (ranges == FULL) ) {\r
 \r
             // Set the appropriate output headers\r
             if (contentType != null) {\r
@@ -851,7 +858,7 @@ public class DefaultServlet
 \r
             if (ranges.size() == 1) {\r
 \r
-                Range range = (Range) ranges.elementAt(0);\r
+                Range range = (Range) ranges.get(0);\r
                 response.addHeader("Content-Range", "bytes "\r
                                    + range.start\r
                                    + "-" + range.end + "/"\r
@@ -897,10 +904,10 @@ public class DefaultServlet
                         // Silent catch\r
                     }\r
                     if (ostream != null) {\r
-                        copy(cacheEntry, ostream, ranges.elements(),\r
+                        copy(cacheEntry, ostream, ranges.iterator(),\r
                              contentType);\r
                     } else {\r
-                        copy(cacheEntry, writer, ranges.elements(),\r
+                        copy(cacheEntry, writer, ranges.iterator(),\r
                              contentType);\r
                     }\r
                 }\r
@@ -980,7 +987,7 @@ public class DefaultServlet
      * @param response The servlet response we are creating\r
      * @return Vector of ranges\r
      */\r
-    protected Vector parseRange(HttpServletRequest request,\r
+    protected ArrayList parseRange(HttpServletRequest request,\r
                                 HttpServletResponse response,\r
                                 ResourceAttributes resourceAttributes)\r
         throws IOException {\r
@@ -1005,7 +1012,7 @@ public class DefaultServlet
                 // If the ETag the client gave does not match the entity\r
                 // etag, then the entire entity is returned.\r
                 if (!eTag.equals(headerValue.trim()))\r
-                    return null;\r
+                    return FULL;\r
 \r
             } else {\r
 \r
@@ -1013,7 +1020,7 @@ public class DefaultServlet
                 // the last modification date of the entity, the entire entity\r
                 // is returned.\r
                 if (lastModified > (headerValueTime + 1000))\r
-                    return null;\r
+                    return FULL;\r
 \r
             }\r
 \r
@@ -1042,7 +1049,7 @@ public class DefaultServlet
 \r
         // Vector which will contain all the ranges which are successfully\r
         // parsed.\r
-        Vector result = new Vector();\r
+        ArrayList result = new ArrayList();\r
         StringTokenizer commaTokenizer = new StringTokenizer(rangeHeader, ",");\r
 \r
         // Parsing the range list\r
@@ -1105,7 +1112,7 @@ public class DefaultServlet
                 return null;\r
             }\r
 \r
-            result.addElement(currentRange);\r
+            result.add(currentRange);\r
         }\r
 \r
         return result;\r
@@ -1510,13 +1517,13 @@ public class DefaultServlet
     }\r
 \r
 \r
-    // -------------------------------------------------------- Private Methods\r
+    // -------------------------------------------------------- protected Methods\r
 \r
 \r
     /**\r
      * Check if sendfile can be used.\r
      */\r
-    private boolean checkSendfile(HttpServletRequest request,\r
+    protected boolean checkSendfile(HttpServletRequest request,\r
                                   HttpServletResponse response,\r
                                   CacheEntry entry,\r
                                   long length, Range range) {\r
@@ -1553,7 +1560,7 @@ public class DefaultServlet
      * and false if the condition is not satisfied, in which case request\r
      * processing is stopped\r
      */\r
-    private boolean checkIfMatch(HttpServletRequest request,\r
+    protected boolean checkIfMatch(HttpServletRequest request,\r
                                  HttpServletResponse response,\r
                                  ResourceAttributes resourceAttributes)\r
         throws IOException {\r
@@ -1598,7 +1605,7 @@ public class DefaultServlet
      * and false if the condition is not satisfied, in which case request\r
      * processing is stopped\r
      */\r
-    private boolean checkIfModifiedSince(HttpServletRequest request,\r
+    protected boolean checkIfModifiedSince(HttpServletRequest request,\r
                                          HttpServletResponse response,\r
                                          ResourceAttributes resourceAttributes)\r
         throws IOException {\r
@@ -1635,7 +1642,7 @@ public class DefaultServlet
      * and false if the condition is not satisfied, in which case request\r
      * processing is stopped\r
      */\r
-    private boolean checkIfNoneMatch(HttpServletRequest request,\r
+    protected boolean checkIfNoneMatch(HttpServletRequest request,\r
                                      HttpServletResponse response,\r
                                      ResourceAttributes resourceAttributes)\r
         throws IOException {\r
@@ -1693,7 +1700,7 @@ public class DefaultServlet
      * and false if the condition is not satisfied, in which case request\r
      * processing is stopped\r
      */\r
-    private boolean checkIfUnmodifiedSince(HttpServletRequest request,\r
+    protected boolean checkIfUnmodifiedSince(HttpServletRequest request,\r
                                            HttpServletResponse response,\r
                                            ResourceAttributes resourceAttributes)\r
         throws IOException {\r
@@ -1726,7 +1733,7 @@ public class DefaultServlet
      *\r
      * @exception IOException if an input/output error occurs\r
      */\r
-    private void copy(CacheEntry cacheEntry, InputStream is,\r
+    protected void copy(CacheEntry cacheEntry, InputStream is,\r
                       ServletOutputStream ostream)\r
         throws IOException {\r
 \r
@@ -1776,7 +1783,7 @@ public class DefaultServlet
      *\r
      * @exception IOException if an input/output error occurs\r
      */\r
-    private void copy(CacheEntry cacheEntry, InputStream is, PrintWriter writer)\r
+    protected void copy(CacheEntry cacheEntry, InputStream is, PrintWriter writer)\r
         throws IOException {\r
 \r
         IOException exception = null;\r
@@ -1823,7 +1830,7 @@ public class DefaultServlet
      * @param range Range the client wanted to retrieve\r
      * @exception IOException if an input/output error occurs\r
      */\r
-    private void copy(CacheEntry cacheEntry, ServletOutputStream ostream,\r
+    protected void copy(CacheEntry cacheEntry, ServletOutputStream ostream,\r
                       Range range)\r
         throws IOException {\r
 \r
@@ -1858,7 +1865,7 @@ public class DefaultServlet
      * @param range Range the client wanted to retrieve\r
      * @exception IOException if an input/output error occurs\r
      */\r
-    private void copy(CacheEntry cacheEntry, PrintWriter writer,\r
+    protected void copy(CacheEntry cacheEntry, PrintWriter writer,\r
                       Range range)\r
         throws IOException {\r
 \r
@@ -1901,19 +1908,19 @@ public class DefaultServlet
      * @param contentType Content type of the resource\r
      * @exception IOException if an input/output error occurs\r
      */\r
-    private void copy(CacheEntry cacheEntry, ServletOutputStream ostream,\r
-                      Enumeration ranges, String contentType)\r
+    protected void copy(CacheEntry cacheEntry, ServletOutputStream ostream,\r
+                      Iterator ranges, String contentType)\r
         throws IOException {\r
 \r
         IOException exception = null;\r
 \r
-        while ( (exception == null) && (ranges.hasMoreElements()) ) {\r
+        while ( (exception == null) && (ranges.hasNext()) ) {\r
 \r
             InputStream resourceInputStream = cacheEntry.resource.streamContent();\r
             InputStream istream =\r
                 new BufferedInputStream(resourceInputStream, input);\r
 \r
-            Range currentRange = (Range) ranges.nextElement();\r
+            Range currentRange = (Range) ranges.next();\r
 \r
             // Writing MIME header.\r
             ostream.println();\r
@@ -1958,13 +1965,13 @@ public class DefaultServlet
      * @param contentType Content type of the resource\r
      * @exception IOException if an input/output error occurs\r
      */\r
-    private void copy(CacheEntry cacheEntry, PrintWriter writer,\r
-                      Enumeration ranges, String contentType)\r
+    protected void copy(CacheEntry cacheEntry, PrintWriter writer,\r
+                      Iterator ranges, String contentType)\r
         throws IOException {\r
 \r
         IOException exception = null;\r
 \r
-        while ( (exception == null) && (ranges.hasMoreElements()) ) {\r
+        while ( (exception == null) && (ranges.hasNext()) ) {\r
 \r
             InputStream resourceInputStream = cacheEntry.resource.streamContent();\r
             \r
@@ -1976,7 +1983,7 @@ public class DefaultServlet
                                                fileEncoding);\r
             }\r
 \r
-            Range currentRange = (Range) ranges.nextElement();\r
+            Range currentRange = (Range) ranges.next();\r
 \r
             // Writing MIME header.\r
             writer.println();\r
@@ -2019,7 +2026,7 @@ public class DefaultServlet
      * @param ostream The output stream to write to\r
      * @return Exception which occurred during processing\r
      */\r
-    private IOException copyRange(InputStream istream,\r
+    protected IOException copyRange(InputStream istream,\r
                                   ServletOutputStream ostream) {\r
 \r
         // Copy the input stream to the output stream\r
@@ -2052,7 +2059,7 @@ public class DefaultServlet
      * @param writer The writer to write to\r
      * @return Exception which occurred during processing\r
      */\r
-    private IOException copyRange(Reader reader, PrintWriter writer) {\r
+    protected IOException copyRange(Reader reader, PrintWriter writer) {\r
 \r
         // Copy the input stream to the output stream\r
         IOException exception = null;\r
@@ -2086,7 +2093,7 @@ public class DefaultServlet
      * @param end End of the range which will be copied\r
      * @return Exception which occurred during processing\r
      */\r
-    private IOException copyRange(InputStream istream,\r
+    protected IOException copyRange(InputStream istream,\r
                                   ServletOutputStream ostream,\r
                                   long start, long end) {\r
 \r
@@ -2138,7 +2145,7 @@ public class DefaultServlet
      * @param end End of the range which will be copied\r
      * @return Exception which occurred during processing\r
      */\r
-    private IOException copyRange(Reader reader, PrintWriter writer,\r
+    protected IOException copyRange(Reader reader, PrintWriter writer,\r
                                   long start, long end) {\r
 \r
         try {\r
@@ -2179,7 +2186,7 @@ public class DefaultServlet
     // ------------------------------------------------------ Range Inner Class\r
 \r
 \r
-    private class Range {\r
+    protected class Range {\r
 \r
         public long start;\r
         public long end;\r