@@ -45,6 +45,7 @@ public class SockJsFrame {
45
45
private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME =
46
46
closeFrame (2010 , "Another connection still open" );
47
47
48
+ private static final String truncatedSuffix = "...(truncated)" ;
48
49
49
50
private final SockJsFrameType type ;
50
51
@@ -130,28 +131,31 @@ public int hashCode() {
130
131
131
132
@ Override
132
133
public String toString () {
133
- int maxLen = 80 ;
134
+ int maxLength = 80 ;
134
135
int contentLength = this .content .length ();
135
- int len = Math .min (contentLength , maxLen );
136
+ int truncatedContentLength = Math .min (contentLength , maxLength );
136
137
137
- StringBuilder sb = new StringBuilder ( len + 20 );
138
+ int extra = ( contentLength > maxLength ? truncatedSuffix . length () : 0 );
138
139
139
- for (int i = 0 ; i < len ; i ++) {
140
+ StringBuilder sb = new StringBuilder (truncatedContentLength + extra );
141
+
142
+ for (int i = 0 ; i < truncatedContentLength ; i ++) {
140
143
char c = this .content .charAt (i );
141
- switch (c ){
144
+ switch (c ) {
142
145
case '\n' -> sb .append ("\\ n" );
143
146
case '\r' -> sb .append ("\\ r" );
144
147
default -> sb .append (c );
145
148
}
146
149
}
147
150
148
- if (contentLength > maxLen ) {
149
- sb .append ("...(truncated)" );
151
+ if (contentLength > maxLength ) {
152
+ sb .append (truncatedSuffix );
150
153
}
151
154
152
155
return "SockJsFrame content='" + sb + "'" ;
153
156
}
154
157
158
+
155
159
public static SockJsFrame openFrame () {
156
160
return OPEN_FRAME ;
157
161
}
0 commit comments