This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 2067b4d9e0 Better method names and update Javadoc
2067b4d9e0 is described below
commit 2067b4d9e0e83b202a2e5d4a9971829cf8277230
Author: Mark Thomas <[email protected]>
AuthorDate: Wed May 27 10:29:47 2026 +0100
Better method names and update Javadoc
Based on PR #1011 by Chenjp
---
.../apache/catalina/servlets/DefaultServlet.java | 87 +++++++++++++++++-----
1 file changed, 68 insertions(+), 19 deletions(-)
diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java
b/java/org/apache/catalina/servlets/DefaultServlet.java
index 3523545948..a28f6ab51c 100644
--- a/java/org/apache/catalina/servlets/DefaultServlet.java
+++ b/java/org/apache/catalina/servlets/DefaultServlet.java
@@ -2028,7 +2028,7 @@ public class DefaultServlet extends HttpServlet {
} else {
reader = new InputStreamReader(is);
}
- IOException e = copyRange(reader, new PrintWriter(buffer));
+ IOException e = copyNoThrow(reader, new
PrintWriter(buffer));
if (debug > 10) {
log("readme '" + readmeFile + "' output error: " + ((e
!= null) ? e.getMessage() : ""));
}
@@ -2525,8 +2525,8 @@ public class DefaultServlet extends HttpServlet {
/**
- * Copy the contents of the specified input stream to the specified output
stream, and ensure that both streams are
- * closed before returning (even in the face of an exception).
+ * Copy the contents of the specified input stream to the specified output
stream, and ensure that the input stream
+ * is closed before returning (even in the face of an exception).
*
* @param is The input stream to read the source resource from
* @param ostream The output stream to write to
@@ -2538,7 +2538,7 @@ public class DefaultServlet extends HttpServlet {
InputStream istream = new BufferedInputStream(is, input);
// Copy the input stream to the output stream
- IOException exception = copyRange(istream, ostream);
+ IOException exception = copyNoThrow(istream, ostream);
// Clean up the input stream
istream.close();
@@ -2551,8 +2551,8 @@ public class DefaultServlet extends HttpServlet {
/**
- * Copy the contents of the specified input stream to the specified output
stream, and ensure that both streams are
- * closed before returning (even in the face of an exception).
+ * Copy the contents of the specified input stream to the specified output
stream, and ensure that the input stream
+ * is closed before returning (even in the face of an exception).
*
* @param is The input stream to read the source resource from
* @param writer The writer to write to
@@ -2570,7 +2570,7 @@ public class DefaultServlet extends HttpServlet {
}
// Copy the input stream to the output stream
- IOException exception = copyRange(reader, writer);
+ IOException exception = copyNoThrow(reader, writer);
// Clean up the reader
reader.close();
@@ -2583,8 +2583,7 @@ public class DefaultServlet extends HttpServlet {
/**
- * Copy the contents of the specified input stream to the specified output
stream, and ensure that both streams are
- * closed before returning (even in the face of an exception).
+ * Copy the contents of the specified resource to the specified output
stream.
*
* @param resource The source resource
* @param length the resource length
@@ -2598,7 +2597,7 @@ public class DefaultServlet extends HttpServlet {
InputStream resourceInputStream = resource.getInputStream();
InputStream istream = new BufferedInputStream(resourceInputStream,
input);
- IOException exception = copyRange(istream, ostream, getStart(range,
length), getEnd(range, length));
+ IOException exception = copyNoThrow(istream, ostream, getStart(range,
length), getEnd(range, length));
// Clean up the input stream
istream.close();
@@ -2612,8 +2611,7 @@ public class DefaultServlet extends HttpServlet {
/**
- * Copy the contents of the specified input stream to the specified output
stream, and ensure that both streams are
- * closed before returning (even in the face of an exception).
+ * Copy the selected contents of the specified resource to the specified
output stream.
*
* @param resource The source resource
* @param length the resource length
@@ -2647,7 +2645,7 @@ public class DefaultServlet extends HttpServlet {
ostream.println();
// Printing content
- exception = copyRange(istream, ostream, start, end);
+ exception = copyNoThrow(istream, ostream, start, end);
}
}
@@ -2663,15 +2661,31 @@ public class DefaultServlet extends HttpServlet {
/**
- * Copy the contents of the specified input stream to the specified output
stream, and ensure that both streams are
- * closed before returning (even in the face of an exception).
+ * Copy the contents of the specified input stream to the specified output
stream and return, rather than throw, any
+ * IOException that occurs.
*
* @param istream The input stream to read from
* @param ostream The output stream to write to
*
* @return Exception which occurred during processing
+ *
+ * @deprecated Will be removed in Tomcat 12. Use {@link
#copyNoThrow(InputStream, ServletOutputStream)}
*/
+ @Deprecated
protected IOException copyRange(InputStream istream, ServletOutputStream
ostream) {
+ return copyNoThrow(istream, ostream);
+ }
+
+ /**
+ * Copy the contents of the specified input stream to the specified output
stream and return, rather than throw, any
+ * IOException that occurs.
+ *
+ * @param istream The input stream to read from
+ * @param ostream The output stream to write to
+ *
+ * @return Exception which occurred during processing
+ */
+ protected IOException copyNoThrow(InputStream istream, ServletOutputStream
ostream) {
// Copy the input stream to the output stream
IOException exception = null;
@@ -2694,16 +2708,32 @@ public class DefaultServlet extends HttpServlet {
/**
- * Copy the contents of the specified input stream to the specified output
stream, and ensure that both streams are
- * closed before returning (even in the face of an exception).
+ * Copy the contents of the specified reader to the specified writer and
return, rather than throw, any IOException
+ * that occurs.
*
* @param reader The reader to read from
* @param writer The writer to write to
*
* @return Exception which occurred during processing
+ *
+ * @deprecated Will be removed in Tomcat 12. Use {@link
#copyNoThrow(Reader, PrintWriter)}
*/
+ @Deprecated
protected IOException copyRange(Reader reader, PrintWriter writer) {
+ return copyNoThrow(reader, writer);
+ }
+
+ /**
+ * Copy the contents of the specified reader to the specified writer and
return, rather than throw, any IOException
+ * that occurs.
+ *
+ * @param reader The reader to read from
+ * @param writer The writer to write to
+ *
+ * @return Exception which occurred during processing
+ */
+ protected IOException copyNoThrow(Reader reader, PrintWriter writer) {
// Copy the input stream to the output stream
IOException exception = null;
char[] buffer = new char[input];
@@ -2725,8 +2755,8 @@ public class DefaultServlet extends HttpServlet {
/**
- * Copy the contents of the specified input stream to the specified output
stream, and ensure that both streams are
- * closed before returning (even in the face of an exception).
+ * Copy the selected contents of the specified input stream to the
specified output stream, and return, rather than
+ * throw, any IOException that occurs.
*
* @param istream The input stream to read from
* @param ostream The output stream to write to
@@ -2734,8 +2764,27 @@ public class DefaultServlet extends HttpServlet {
* @param end End of the range which will be copied
*
* @return Exception which occurred during processing
+ *
+ * @deprecated Will be removed in Tomcat 12. Use {@link
#copyNoThrow(InputStream, ServletOutputStream, long, long)}
*/
+ @Deprecated
protected IOException copyRange(InputStream istream, ServletOutputStream
ostream, long start, long end) {
+ return copyNoThrow(istream, ostream, start, end);
+ }
+
+
+ /**
+ * Copy the selected contents of the specified input stream to the
specified output stream, and return, rather than
+ * throw, any IOException that occurs.
+ *
+ * @param istream The input stream to read from
+ * @param ostream The output stream to write to
+ * @param start Start of the range which will be copied
+ * @param end End of the range which will be copied
+ *
+ * @return Exception which occurred during processing
+ */
+ protected IOException copyNoThrow(InputStream istream, ServletOutputStream
ostream, long start, long end) {
if (debug > 10) {
log("Serving bytes: " + start + "-" + end);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]