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

markt 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 15df1972cd Refactor to reduce code duplication
15df1972cd is described below

commit 15df1972cdd64a2668c3ed7e24714fef4b5bd123
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Jan 14 08:05:39 2026 +0000

    Refactor to reduce code duplication
---
 .../tomcat/websocket/WsRemoteEndpointImplBase.java | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java 
b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
index 14efbeaf5a..e83a052822 100644
--- a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
+++ b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
@@ -978,9 +978,7 @@ public abstract class WsRemoteEndpointImplBase implements 
RemoteEndpoint {
 
         @Override
         public void write(int b) throws IOException {
-            if (closed) {
-                throw new 
IllegalStateException(sm.getString("wsRemoteEndpoint.closedOutputStream"));
-            }
+            checkOpen();
 
             used = true;
             if (buffer.remaining() == 0) {
@@ -991,9 +989,7 @@ public abstract class WsRemoteEndpointImplBase implements 
RemoteEndpoint {
 
         @Override
         public void write(byte[] b, int off, int len) throws IOException {
-            if (closed) {
-                throw new 
IllegalStateException(sm.getString("wsRemoteEndpoint.closedOutputStream"));
-            }
+            checkOpen();
             if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > 
b.length) || ((off + len) < 0)) {
                 throw new IndexOutOfBoundsException();
             }
@@ -1021,9 +1017,7 @@ public abstract class WsRemoteEndpointImplBase implements 
RemoteEndpoint {
 
         @Override
         public void flush() throws IOException {
-            if (closed) {
-                throw new 
IllegalStateException(sm.getString("wsRemoteEndpoint.closedOutputStream"));
-            }
+            checkOpen();
 
             // Optimisation. If there is no data to flush then do not send an
             // empty message.
@@ -1044,6 +1038,12 @@ public abstract class WsRemoteEndpointImplBase 
implements RemoteEndpoint {
             doWrite(true);
         }
 
+        private void checkOpen() {
+            if (closed) {
+                throw new 
IllegalStateException(sm.getString("wsRemoteEndpoint.closedOutputStream"));
+            }
+        }
+
         private void doWrite(boolean last) throws IOException {
             if (used) {
                 buffer.flip();
@@ -1069,9 +1069,7 @@ public abstract class WsRemoteEndpointImplBase implements 
RemoteEndpoint {
 
         @Override
         public void write(char[] cbuf, int off, int len) throws IOException {
-            if (closed) {
-                throw new 
IllegalStateException(sm.getString("wsRemoteEndpoint.closedWriter"));
-            }
+            checkOpen();
             if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) 
> cbuf.length) || ((off + len) < 0)) {
                 throw new IndexOutOfBoundsException();
             }
@@ -1099,9 +1097,7 @@ public abstract class WsRemoteEndpointImplBase implements 
RemoteEndpoint {
 
         @Override
         public void flush() throws IOException {
-            if (closed) {
-                throw new 
IllegalStateException(sm.getString("wsRemoteEndpoint.closedWriter"));
-            }
+            checkOpen();
 
             if (buffer.position() > 0) {
                 doWrite(false);
@@ -1120,6 +1116,12 @@ public abstract class WsRemoteEndpointImplBase 
implements RemoteEndpoint {
             doWrite(true);
         }
 
+        private void checkOpen() {
+            if (closed) {
+                throw new 
IllegalStateException(sm.getString("wsRemoteEndpoint.closedWriter"));
+            }
+        }
+
         private void doWrite(boolean last) throws IOException {
             if (used) {
                 buffer.flip();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to