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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 8eb557e  No need for these internal classes to be package visible.
8eb557e is described below

commit 8eb557efc3d76bfc2670a652999c4cb093631b80
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 3 17:41:53 2021 +0100

    No need for these internal classes to be package visible.
    
    While the (removed in this commit) comments indicate that
    NoBodyOutputStream and NoBodyResponse were intended to be private to
    HttpServlet, there were implemented as package private. Refactor so they
    are private to HttpServlet.
---
 java/javax/servlet/http/HttpServlet.java | 245 +++++++++++++++----------------
 1 file changed, 118 insertions(+), 127 deletions(-)

diff --git a/java/javax/servlet/http/HttpServlet.java 
b/java/javax/servlet/http/HttpServlet.java
index 1b252a2..16c346d 100644
--- a/java/javax/servlet/http/HttpServlet.java
+++ b/java/javax/servlet/http/HttpServlet.java
@@ -756,167 +756,158 @@ public abstract class HttpServlet extends 
GenericServlet {
         }
         service(request, response);
     }
-}
 
 
-/*
- * A response wrapper for use in (dumb) "HEAD" support.
- * This just swallows that body, counting the bytes in order to set
- * the content length appropriately.  All other methods delegate to the
- * wrapped HTTP Servlet Response object.
- */
-// file private
-class NoBodyResponse extends HttpServletResponseWrapper {
-    private final NoBodyOutputStream noBody;
-    private PrintWriter writer;
-    private boolean didSetContentLength;
-
-    // file private
-    NoBodyResponse(HttpServletResponse r) {
-        super(r);
-        noBody = new NoBodyOutputStream(this);
-    }
+    /*
+     * A response wrapper for use in (dumb) "HEAD" support.
+     * This just swallows that body, counting the bytes in order to set
+     * the content length appropriately.  All other methods delegate to the
+     * wrapped HTTP Servlet Response object.
+     */
+    private static class NoBodyResponse extends HttpServletResponseWrapper {
+        private final NoBodyOutputStream noBody;
+        private PrintWriter writer;
+        private boolean didSetContentLength;
+
+        private NoBodyResponse(HttpServletResponse r) {
+            super(r);
+            noBody = new NoBodyOutputStream(this);
+        }
 
-    // file private
-    void setContentLength() {
-        if (!didSetContentLength) {
-            if (writer != null) {
-                writer.flush();
+        private void setContentLength() {
+            if (!didSetContentLength) {
+                if (writer != null) {
+                    writer.flush();
+                }
+                super.setContentLength(noBody.getContentLength());
             }
-            super.setContentLength(noBody.getContentLength());
         }
-    }
 
 
-    // SERVLET RESPONSE interface methods
-
-    @Override
-    public void setContentLength(int len) {
-        super.setContentLength(len);
-        didSetContentLength = true;
-    }
+        @Override
+        public void setContentLength(int len) {
+            super.setContentLength(len);
+            didSetContentLength = true;
+        }
 
-    @Override
-    public void setContentLengthLong(long len) {
-        super.setContentLengthLong(len);
-        didSetContentLength = true;
-    }
+        @Override
+        public void setContentLengthLong(long len) {
+            super.setContentLengthLong(len);
+            didSetContentLength = true;
+        }
 
-    @Override
-    public void setHeader(String name, String value) {
-        super.setHeader(name, value);
-        checkHeader(name);
-    }
+        @Override
+        public void setHeader(String name, String value) {
+            super.setHeader(name, value);
+            checkHeader(name);
+        }
 
-    @Override
-    public void addHeader(String name, String value) {
-        super.addHeader(name, value);
-        checkHeader(name);
-    }
+        @Override
+        public void addHeader(String name, String value) {
+            super.addHeader(name, value);
+            checkHeader(name);
+        }
 
-    @Override
-    public void setIntHeader(String name, int value) {
-        super.setIntHeader(name, value);
-        checkHeader(name);
-    }
+        @Override
+        public void setIntHeader(String name, int value) {
+            super.setIntHeader(name, value);
+            checkHeader(name);
+        }
 
-    @Override
-    public void addIntHeader(String name, int value) {
-        super.addIntHeader(name, value);
-        checkHeader(name);
-    }
+        @Override
+        public void addIntHeader(String name, int value) {
+            super.addIntHeader(name, value);
+            checkHeader(name);
+        }
 
-    private void checkHeader(String name) {
-        if ("content-length".equalsIgnoreCase(name)) {
-            didSetContentLength = true;
+        private void checkHeader(String name) {
+            if ("content-length".equalsIgnoreCase(name)) {
+                didSetContentLength = true;
+            }
         }
-    }
 
-    @Override
-    public ServletOutputStream getOutputStream() throws IOException {
-        return noBody;
-    }
+        @Override
+        public ServletOutputStream getOutputStream() throws IOException {
+            return noBody;
+        }
 
-    @Override
-    public PrintWriter getWriter() throws UnsupportedEncodingException {
+        @Override
+        public PrintWriter getWriter() throws UnsupportedEncodingException {
 
-        if (writer == null) {
-            OutputStreamWriter w;
+            if (writer == null) {
+                OutputStreamWriter w;
 
-            w = new OutputStreamWriter(noBody, getCharacterEncoding());
-            writer = new PrintWriter(w);
+                w = new OutputStreamWriter(noBody, getCharacterEncoding());
+                writer = new PrintWriter(w);
+            }
+            return writer;
         }
-        return writer;
     }
-}
 
 
-/*
- * Servlet output stream that gobbles up all its data.
- */
+    /*
+     * Servlet output stream that gobbles up all its data.
+     */
+    private static class NoBodyOutputStream extends ServletOutputStream {
 
-// file private
-class NoBodyOutputStream extends ServletOutputStream {
+        private static final String LSTRING_FILE = 
"javax.servlet.http.LocalStrings";
+        private static final ResourceBundle lStrings = 
ResourceBundle.getBundle(LSTRING_FILE);
 
-    private static final String LSTRING_FILE = 
"javax.servlet.http.LocalStrings";
-    private static final ResourceBundle lStrings = 
ResourceBundle.getBundle(LSTRING_FILE);
+        private final HttpServletResponse response;
+        private boolean flushed = false;
+        private int contentLength = 0;
 
-    private final HttpServletResponse response;
-    private boolean flushed = false;
-    private int contentLength = 0;
+        private NoBodyOutputStream(HttpServletResponse response) {
+            this.response = response;
+        }
 
-    // file private
-    NoBodyOutputStream(HttpServletResponse response) {
-        this.response = response;
-    }
+        private int getContentLength() {
+            return contentLength;
+        }
 
-    // file private
-    int getContentLength() {
-        return contentLength;
-    }
+        @Override
+        public void write(int b) throws IOException {
+            contentLength++;
+            checkCommit();
+        }
 
-    @Override
-    public void write(int b) throws IOException {
-        contentLength++;
-        checkCommit();
-    }
+        @Override
+        public void write(byte buf[], int offset, int len) throws IOException {
+            if (buf == null) {
+                throw new NullPointerException(
+                        lStrings.getString("err.io.nullArray"));
+            }
 
-    @Override
-    public void write(byte buf[], int offset, int len) throws IOException {
-        if (buf == null) {
-            throw new NullPointerException(
-                    lStrings.getString("err.io.nullArray"));
-        }
+            if (offset < 0 || len < 0 || offset+len > buf.length) {
+                String msg = lStrings.getString("err.io.indexOutOfBounds");
+                Object[] msgArgs = new Object[3];
+                msgArgs[0] = Integer.valueOf(offset);
+                msgArgs[1] = Integer.valueOf(len);
+                msgArgs[2] = Integer.valueOf(buf.length);
+                msg = MessageFormat.format(msg, msgArgs);
+                throw new IndexOutOfBoundsException(msg);
+            }
 
-        if (offset < 0 || len < 0 || offset+len > buf.length) {
-            String msg = lStrings.getString("err.io.indexOutOfBounds");
-            Object[] msgArgs = new Object[3];
-            msgArgs[0] = Integer.valueOf(offset);
-            msgArgs[1] = Integer.valueOf(len);
-            msgArgs[2] = Integer.valueOf(buf.length);
-            msg = MessageFormat.format(msg, msgArgs);
-            throw new IndexOutOfBoundsException(msg);
+            contentLength += len;
+            checkCommit();
         }
 
-        contentLength += len;
-        checkCommit();
-    }
-
-    @Override
-    public boolean isReady() {
-        // TODO SERVLET 3.1
-        return false;
-    }
+        @Override
+        public boolean isReady() {
+            // TODO SERVLET 3.1
+            return false;
+        }
 
-    @Override
-    public void setWriteListener(javax.servlet.WriteListener listener) {
-        // TODO SERVLET 3.1
-    }
+        @Override
+        public void setWriteListener(javax.servlet.WriteListener listener) {
+            // TODO SERVLET 3.1
+        }
 
-    private void checkCommit() throws IOException {
-        if (!flushed && contentLength > response.getBufferSize()) {
-            response.flushBuffer();
-            flushed = true;
+        private void checkCommit() throws IOException {
+            if (!flushed && contentLength > response.getBufferSize()) {
+                response.flushBuffer();
+                flushed = true;
+            }
         }
     }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to