/*\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
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
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
/**\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
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
\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
\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
// 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
* @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
// 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
// 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
\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
return null;\r
}\r
\r
- result.addElement(currentRange);\r
+ result.add(currentRange);\r
}\r
\r
return result;\r
}\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
* 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
* 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
* 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
* 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
*\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
*\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
* @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
* @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
* @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
* @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
fileEncoding);\r
}\r
\r
- Range currentRange = (Range) ranges.nextElement();\r
+ Range currentRange = (Range) ranges.next();\r
\r
// Writing MIME header.\r
writer.println();\r
* @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
* @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
* @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
* @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
// ------------------------------------------------------ Range Inner Class\r
\r
\r
- private class Range {\r
+ protected class Range {\r
\r
public long start;\r
public long end;\r