src/main/java/org/apache/sling/api/servlets/SlingJakartaSafeMethodsServlet.java [483:569]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            super(wrappedResponse);
            noBody = new NoBodyOutputStream();
        }

        /**
         * Called at the end of request processing to ensure the content length
         * is set. If the processor already set the length, this method does not
         * do anything. Otherwise the number of bytes written through the
         * null-output is set on the response.
         */
        void setContentLength() {
            if (!didSetContentLength) {
                setContentLength(noBody.getContentLength());
            }
        }

        /**
         * Overwrite this to prevent setting the content length at the end of
         * the request through {@link #setContentLength()}
         */
        @Override
        public void setContentLength(int len) {
            super.setContentLength(len);
            didSetContentLength = true;
        }

        /**
         * Just return the null output stream and don't check whether a writer
         * has already been acquired.
         */
        @Override
        public ServletOutputStream getOutputStream() {
            return noBody;
        }

        /**
         * Just return the writer to the null output stream and don't check
         * whether an output stram has already been acquired.
         */
        @Override
        public PrintWriter getWriter() throws UnsupportedEncodingException {
            if (writer == null) {
                OutputStreamWriter w;

                w = new OutputStreamWriter(noBody, getCharacterEncoding());
                writer = new PrintWriter(w);
            }
            return writer;
        }
    }

    /**
     * Simple ServletOutputStream which just does not write but counts the bytes
     * written through it. This class is used by the NoBodyResponse.
     */
    private class NoBodyOutputStream extends ServletOutputStream {

        private int contentLength = 0;

        /**
         * @return the number of bytes "written" through this stream
         */
        int getContentLength() {
            return contentLength;
        }

        @Override
        public void write(int b) {
            contentLength++;
        }

        @Override
        public void write(byte buf[], int offset, int len) {
            if (len >= 0) {
                contentLength += len;
            } else {
                throw new IndexOutOfBoundsException();
            }
        }

        @Override
        public boolean isReady() {
            return true;
        }

        @Override
        public void setWriteListener(WriteListener writeListener) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



src/main/java/org/apache/sling/api/servlets/SlingSafeMethodsServlet.java [477:563]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            super(wrappedResponse);
            noBody = new NoBodyOutputStream();
        }

        /**
         * Called at the end of request processing to ensure the content length
         * is set. If the processor already set the length, this method does not
         * do anything. Otherwise the number of bytes written through the
         * null-output is set on the response.
         */
        void setContentLength() {
            if (!didSetContentLength) {
                setContentLength(noBody.getContentLength());
            }
        }

        /**
         * Overwrite this to prevent setting the content length at the end of
         * the request through {@link #setContentLength()}
         */
        @Override
        public void setContentLength(int len) {
            super.setContentLength(len);
            didSetContentLength = true;
        }

        /**
         * Just return the null output stream and don't check whether a writer
         * has already been acquired.
         */
        @Override
        public ServletOutputStream getOutputStream() {
            return noBody;
        }

        /**
         * Just return the writer to the null output stream and don't check
         * whether an output stram has already been acquired.
         */
        @Override
        public PrintWriter getWriter() throws UnsupportedEncodingException {
            if (writer == null) {
                OutputStreamWriter w;

                w = new OutputStreamWriter(noBody, getCharacterEncoding());
                writer = new PrintWriter(w);
            }
            return writer;
        }
    }

    /**
     * Simple ServletOutputStream which just does not write but counts the bytes
     * written through it. This class is used by the NoBodyResponse.
     */
    private class NoBodyOutputStream extends ServletOutputStream {

        private int contentLength = 0;

        /**
         * @return the number of bytes "written" through this stream
         */
        int getContentLength() {
            return contentLength;
        }

        @Override
        public void write(int b) {
            contentLength++;
        }

        @Override
        public void write(byte buf[], int offset, int len) {
            if (len >= 0) {
                contentLength += len;
            } else {
                throw new IndexOutOfBoundsException();
            }
        }

        @Override
        public boolean isReady() {
            return true;
        }

        @Override
        public void setWriteListener(WriteListener writeListener) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



