@@ -45,6 +45,7 @@ public class SockJsFrame {
4545 private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME =
4646 closeFrame (2010 , "Another connection still open" );
4747
48+ private static final String truncatedSuffix = "...(truncated)" ;
4849
4950 private final SockJsFrameType type ;
5051
@@ -130,28 +131,31 @@ public int hashCode() {
130131
131132 @ Override
132133 public String toString () {
133- int maxLen = 80 ;
134+ int maxLength = 80 ;
134135 int contentLength = this .content .length ();
135- int len = Math .min (contentLength , maxLen );
136+ int truncatedContentLength = Math .min (contentLength , maxLength );
136137
137- StringBuilder sb = new StringBuilder ( len + 20 );
138+ int extra = ( contentLength > maxLength ? truncatedSuffix . length () : 0 );
138139
139- for (int i = 0 ; i < len ; i ++) {
140+ StringBuilder sb = new StringBuilder (truncatedContentLength + extra );
141+
142+ for (int i = 0 ; i < truncatedContentLength ; i ++) {
140143 char c = this .content .charAt (i );
141- switch (c ){
144+ switch (c ) {
142145 case '\n' -> sb .append ("\\ n" );
143146 case '\r' -> sb .append ("\\ r" );
144147 default -> sb .append (c );
145148 }
146149 }
147150
148- if (contentLength > maxLen ) {
149- sb .append ("...(truncated)" );
151+ if (contentLength > maxLength ) {
152+ sb .append (truncatedSuffix );
150153 }
151154
152155 return "SockJsFrame content='" + sb + "'" ;
153156 }
154157
158+
155159 public static SockJsFrame openFrame () {
156160 return OPEN_FRAME ;
157161 }
0 commit comments