This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new f314161e96 Better method names and update Javadoc
f314161e96 is described below

commit f314161e965b576cff00ad8fb39adae2c1dd5dca
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 5d88fc2a82..6868717fff 100644
--- a/java/org/apache/catalina/servlets/DefaultServlet.java
+++ b/java/org/apache/catalina/servlets/DefaultServlet.java
@@ -2043,7 +2043,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() : ""));
                     }
@@ -2540,8 +2540,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
@@ -2553,7 +2553,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();
@@ -2566,8 +2566,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
@@ -2585,7 +2585,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();
@@ -2598,8 +2598,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
@@ -2613,7 +2612,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();
@@ -2627,8 +2626,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
@@ -2662,7 +2660,7 @@ public class DefaultServlet extends HttpServlet {
                 ostream.println();
 
                 // Printing content
-                exception = copyRange(istream, ostream, start, end);
+                exception = copyNoThrow(istream, ostream, start, end);
             }
         }
 
@@ -2678,15 +2676,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;
@@ -2709,16 +2723,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];
@@ -2740,8 +2770,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
@@ -2749,8 +2779,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]

Reply via email to