This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new b634fafadd Better method names and update Javadoc
b634fafadd is described below
commit b634fafadd64b00063797b11eb424087fe1c6867
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 4ed182411c..df6c17c217 100644
--- a/java/org/apache/catalina/servlets/DefaultServlet.java
+++ b/java/org/apache/catalina/servlets/DefaultServlet.java
@@ -2067,7 +2067,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() : ""));
}
@@ -2597,8 +2597,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
@@ -2610,7 +2610,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();
@@ -2623,8 +2623,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
@@ -2642,7 +2642,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();
@@ -2655,8 +2655,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
@@ -2670,7 +2669,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();
@@ -2684,8 +2683,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
@@ -2719,7 +2717,7 @@ public class DefaultServlet extends HttpServlet {
ostream.println();
// Printing content
- exception = copyRange(istream, ostream, start, end);
+ exception = copyNoThrow(istream, ostream, start, end);
}
}
@@ -2735,15 +2733,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;
@@ -2766,16 +2780,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];
@@ -2797,8 +2827,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
@@ -2806,8 +2836,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]