This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 2cb05275ad Refactor to reduce code duplication
2cb05275ad is described below
commit 2cb05275ad007543b2f5387261b7d661e9ee6b27
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 1dae971631..8f3a56dc6b 100644
--- a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
+++ b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
@@ -1000,9 +1000,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) {
@@ -1013,9 +1011,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();
}
@@ -1043,9 +1039,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.
@@ -1066,6 +1060,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();
@@ -1091,9 +1091,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();
}
@@ -1121,9 +1119,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);
@@ -1142,6 +1138,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]