Skip to content

Commit 0265b90

Browse files
committed
Add static methods for SockJsFrame creation and remove duplicates
Signed-off-by: KNU-K <[email protected]>
1 parent ef243d4 commit 0265b90

File tree

1 file changed

+25
-27
lines changed
  • spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame

1 file changed

+25
-27
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.web.socket.sockjs.frame;
1818

19+
1920
import java.nio.charset.Charset;
2021
import java.nio.charset.StandardCharsets;
2122
import org.jspecify.annotations.Nullable;
@@ -80,6 +81,30 @@ else if (content.charAt(0) == 'c') {
8081
}
8182
}
8283

84+
public static SockJsFrame openFrame() {
85+
return OPEN_FRAME;
86+
}
87+
88+
public static SockJsFrame heartbeatFrame() {
89+
return HEARTBEAT_FRAME;
90+
}
91+
92+
public static SockJsFrame messageFrame(SockJsMessageCodec codec, String... messages) {
93+
String encoded = codec.encode(messages);
94+
return new SockJsFrame(encoded);
95+
}
96+
97+
public static SockJsFrame closeFrameGoAway() {
98+
return CLOSE_GO_AWAY_FRAME;
99+
}
100+
101+
public static SockJsFrame closeFrameAnotherConnectionOpen() {
102+
return CLOSE_ANOTHER_CONNECTION_OPEN_FRAME;
103+
}
104+
105+
public static SockJsFrame closeFrame(int code, @Nullable String reason) {
106+
return new SockJsFrame("c[" + code + ",\"" + (reason != null ? reason : "") + "\"]");
107+
}
83108

84109
/**
85110
* Return the SockJS frame type.
@@ -116,7 +141,6 @@ public byte[] getContentBytes() {
116141
}
117142
}
118143

119-
120144
@Override
121145
public boolean equals(@Nullable Object other) {
122146
return (this == other || (other instanceof SockJsFrame that &&
@@ -151,30 +175,4 @@ public String toString() {
151175
return "SockJsFrame content='" + sb + "'";
152176
}
153177

154-
155-
public static SockJsFrame openFrame() {
156-
return OPEN_FRAME;
157-
}
158-
159-
public static SockJsFrame heartbeatFrame() {
160-
return HEARTBEAT_FRAME;
161-
}
162-
163-
public static SockJsFrame messageFrame(SockJsMessageCodec codec, String... messages) {
164-
String encoded = codec.encode(messages);
165-
return new SockJsFrame(encoded);
166-
}
167-
168-
public static SockJsFrame closeFrameGoAway() {
169-
return CLOSE_GO_AWAY_FRAME;
170-
}
171-
172-
public static SockJsFrame closeFrameAnotherConnectionOpen() {
173-
return CLOSE_ANOTHER_CONNECTION_OPEN_FRAME;
174-
}
175-
176-
public static SockJsFrame closeFrame(int code, @Nullable String reason) {
177-
return new SockJsFrame("c[" + code + ",\"" + (reason != null ? reason : "") + "\"]");
178-
}
179-
180178
}

0 commit comments

Comments
 (0)