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 b39be711fd Refactor to reduce code duplication
b39be711fd is described below
commit b39be711fd5e1b5aa4840378c765e94dc353d144
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 9228496a43..b14279eebe 100644
--- a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
+++ b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
@@ -999,9 +999,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) {
@@ -1012,9 +1010,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();
}
@@ -1042,9 +1038,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.
@@ -1065,6 +1059,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();
@@ -1090,9 +1090,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();
}
@@ -1120,9 +1118,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);
@@ -1141,6 +1137,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]