-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Enhance toString method in SockJsFrame #35510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
fb8ae80
ef243d4
0265b90
55a6b27
b8ccc8d
318bda4
c5facc7
5dd868b
c59bcbc
b32958e
c784f0a
c4e97d1
2e26f11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import org.springframework.util.Assert; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| /** | ||
| * Represents a SockJS frame. Provides factory methods to create SockJS frames. | ||
|
|
@@ -83,7 +82,6 @@ else if (content.charAt(0) == 'c') { | |
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Return the SockJS frame type. | ||
| */ | ||
|
|
@@ -119,7 +117,6 @@ public byte[] getContentBytes() { | |
| } | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public boolean equals(@Nullable Object other) { | ||
| return (this == other || (other instanceof SockJsFrame that && | ||
|
|
@@ -133,15 +130,27 @@ public int hashCode() { | |
|
|
||
| @Override | ||
| public String toString() { | ||
| String result = this.content; | ||
| if (result.length() > 80) { | ||
| result = result.substring(0, 80) + "...(truncated)"; | ||
| int maxLen = 80; | ||
| int contentLength = this.content.length(); | ||
| int len = Math.min(contentLength, maxLen); | ||
|
|
||
| StringBuilder sb = new StringBuilder(len + 20); | ||
polyglot-k marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for (int i = 0; i < len; i++) { | ||
| char c = this.content.charAt(i); | ||
| switch (c){ | ||
| case '\n' -> sb.append("\\n"); | ||
| case '\r' -> sb.append("\\r"); | ||
| default -> sb.append(c); | ||
| } | ||
| } | ||
| result = StringUtils.replace(result, "\n", "\\n"); | ||
| result = StringUtils.replace(result, "\r", "\\r"); | ||
| return "SockJsFrame content='" + result + "'"; | ||
| } | ||
|
|
||
| if (contentLength > maxLen) { | ||
| sb.append("...(truncated)"); | ||
| } | ||
|
|
||
| return "SockJsFrame content='" + sb + "'"; | ||
|
||
| } | ||
|
|
||
| public static SockJsFrame openFrame() { | ||
| return OPEN_FRAME; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.