1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -37,7 +37,8 @@ public class SockJsFrame {
37
37
38
38
private static final SockJsFrame CLOSE_GO_AWAY_FRAME = closeFrame (3000 , "Go away!" );
39
39
40
- private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME = closeFrame (2010 , "Another connection still open" );
40
+ private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME =
41
+ closeFrame (2010 , "Another connection still open" );
41
42
42
43
43
44
private final SockJsFrameType type ;
@@ -47,10 +48,10 @@ public class SockJsFrame {
47
48
48
49
/**
49
50
* Create a new instance frame with the given frame content.
50
- * @param content the content, must be a non-empty and represent a valid SockJS frame
51
+ * @param content the content ( must be a non-empty and represent a valid SockJS frame)
51
52
*/
52
53
public SockJsFrame (String content ) {
53
- Assert .hasText (content );
54
+ Assert .hasText (content , "Content must not be empty" );
54
55
if ("o" .equals (content )) {
55
56
this .type = SockJsFrameType .OPEN ;
56
57
this .content = content ;
@@ -72,35 +73,10 @@ else if (content.charAt(0) == 'c') {
72
73
this .content = (content .length () > 1 ? content : "c[]" );
73
74
}
74
75
else {
75
- throw new IllegalArgumentException ("Unexpected SockJS frame type in content= \" " + content + "\" " );
76
+ throw new IllegalArgumentException ("Unexpected SockJS frame type in content \" " + content + "\" " );
76
77
}
77
78
}
78
79
79
- public static SockJsFrame openFrame () {
80
- return OPEN_FRAME ;
81
- }
82
-
83
- public static SockJsFrame heartbeatFrame () {
84
- return HEARTBEAT_FRAME ;
85
- }
86
-
87
- public static SockJsFrame messageFrame (SockJsMessageCodec codec , String ... messages ) {
88
- String encoded = codec .encode (messages );
89
- return new SockJsFrame (encoded );
90
- }
91
-
92
- public static SockJsFrame closeFrameGoAway () {
93
- return CLOSE_GO_AWAY_FRAME ;
94
- }
95
-
96
- public static SockJsFrame closeFrameAnotherConnectionOpen () {
97
- return CLOSE_ANOTHER_CONNECTION_OPEN_FRAME ;
98
- }
99
-
100
- public static SockJsFrame closeFrame (int code , String reason ) {
101
- return new SockJsFrame ("c[" + code + ",\" " + reason + "\" ]" );
102
- }
103
-
104
80
105
81
/**
106
82
* Return the SockJS frame type.
@@ -110,7 +86,7 @@ public SockJsFrameType getType() {
110
86
}
111
87
112
88
/**
113
- * Return the SockJS frame content, never {@code null}.
89
+ * Return the SockJS frame content ( never {@code null}) .
114
90
*/
115
91
public String getContent () {
116
92
return this .content ;
@@ -129,7 +105,7 @@ public byte[] getContentBytes() {
129
105
* {@code null}.
130
106
*/
131
107
public String getFrameData () {
132
- if (SockJsFrameType .OPEN == getType () || SockJsFrameType .HEARTBEAT == getType () ) {
108
+ if (getType () == SockJsFrameType .OPEN || getType () == SockJsFrameType .HEARTBEAT ) {
133
109
return null ;
134
110
}
135
111
else {
@@ -146,7 +122,8 @@ public boolean equals(Object other) {
146
122
if (!(other instanceof SockJsFrame )) {
147
123
return false ;
148
124
}
149
- return (this .type .equals (((SockJsFrame ) other ).type ) && this .content .equals (((SockJsFrame ) other ).content ));
125
+ SockJsFrame otherFrame = (SockJsFrame ) other ;
126
+ return (this .type .equals (otherFrame .type ) && this .content .equals (otherFrame .content ));
150
127
}
151
128
152
129
@ Override
@@ -163,4 +140,30 @@ public String toString() {
163
140
return "SockJsFrame content='" + result .replace ("\n " , "\\ n" ).replace ("\r " , "\\ r" ) + "'" ;
164
141
}
165
142
143
+
144
+ public static SockJsFrame openFrame () {
145
+ return OPEN_FRAME ;
146
+ }
147
+
148
+ public static SockJsFrame heartbeatFrame () {
149
+ return HEARTBEAT_FRAME ;
150
+ }
151
+
152
+ public static SockJsFrame messageFrame (SockJsMessageCodec codec , String ... messages ) {
153
+ String encoded = codec .encode (messages );
154
+ return new SockJsFrame (encoded );
155
+ }
156
+
157
+ public static SockJsFrame closeFrameGoAway () {
158
+ return CLOSE_GO_AWAY_FRAME ;
159
+ }
160
+
161
+ public static SockJsFrame closeFrameAnotherConnectionOpen () {
162
+ return CLOSE_ANOTHER_CONNECTION_OPEN_FRAME ;
163
+ }
164
+
165
+ public static SockJsFrame closeFrame (int code , String reason ) {
166
+ return new SockJsFrame ("c[" + code + ",\" " + reason + "\" ]" );
167
+ }
168
+
166
169
}
0 commit comments