This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new eba521e705 Refactor to reduce code duplication
eba521e705 is described below
commit eba521e7058161cddf7e22233cbd11a2fda26800
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 1e8d2bd458..1b1b45bb51 100644
--- a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
+++ b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
@@ -988,9 +988,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) {
@@ -1001,9 +999,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();
}
@@ -1031,9 +1027,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.
@@ -1054,6 +1048,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();
@@ -1079,9 +1079,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();
}
@@ -1109,9 +1107,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);
@@ -1130,6 +1126,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]