@@ -65,8 +65,7 @@ public boolean isServerNoContextTakeover()
6565 *
6666 * @param serverNoContextTakeover
6767 */
68- public void setServerNoContextTakeover (boolean serverNoContextTakeover )
69- {
68+ public void setServerNoContextTakeover (boolean serverNoContextTakeover ) {
7069 this .serverNoContextTakeover = serverNoContextTakeover ;
7170 }
7271
@@ -83,8 +82,7 @@ public boolean isClientNoContextTakeover()
8382 *
8483 * @param clientNoContextTakeover
8584 */
86- public void setClientNoContextTakeover (boolean clientNoContextTakeover )
87- {
85+ public void setClientNoContextTakeover (boolean clientNoContextTakeover ) {
8886 this .clientNoContextTakeover = clientNoContextTakeover ;
8987 }
9088
@@ -98,11 +96,11 @@ public void setClientNoContextTakeover(boolean clientNoContextTakeover)
9896 @ Override
9997 public void decodeFrame (Framedata inputFrame ) throws InvalidDataException {
10098 // Only DataFrames can be decompressed.
101- if (!(inputFrame instanceof DataFrame ))
99+ if (!(inputFrame instanceof DataFrame ))
102100 return ;
103101
104102 // RSV1 bit must be set only for the first frame.
105- if (inputFrame .getOpcode () == Opcode .CONTINUOUS && inputFrame .isRSV1 ())
103+ if (inputFrame .getOpcode () == Opcode .CONTINUOUS && inputFrame .isRSV1 ())
106104 throw new InvalidDataException (CloseFrame .POLICY_VALIDATION , "RSV1 bit can only be set for the first frame." );
107105
108106 // Decompressed output buffer.
@@ -118,23 +116,23 @@ We can check the getRemaining() method to see whether the data we supplied has b
118116 And if not, we just reset the inflater and decompress again.
119117 Note that this behavior doesn't occur if the message is "first compressed and then fragmented".
120118 */
121- if (inflater .getRemaining () > 0 ){
119+ if (inflater .getRemaining () > 0 ) {
122120 inflater = new Inflater (true );
123121 decompress (inputFrame .getPayloadData ().array (), output );
124122 }
125123
126- if (inputFrame .isFin ()) {
124+ if (inputFrame .isFin ()) {
127125 decompress (TAIL_BYTES , output );
128126 // If context takeover is disabled, inflater can be reset.
129- if (clientNoContextTakeover )
127+ if (clientNoContextTakeover )
130128 inflater = new Inflater (true );
131129 }
132130 } catch (DataFormatException e ) {
133131 throw new InvalidDataException (CloseFrame .POLICY_VALIDATION , e .getMessage ());
134132 }
135133
136134 // RSV1 bit must be cleared after decoding, so that other extensions don't throw an exception.
137- if (inputFrame .isRSV1 ())
135+ if (inputFrame .isRSV1 ())
138136 ((DataFrame ) inputFrame ).setRSV1 (false );
139137
140138 // Set frames payload to the new decompressed data.
@@ -147,24 +145,24 @@ We can check the getRemaining() method to see whether the data we supplied has b
147145 * @param outputBuffer the output stream
148146 * @throws DataFormatException
149147 */
150- private void decompress (byte [] data , ByteArrayOutputStream outputBuffer ) throws DataFormatException {
148+ private void decompress (byte [] data , ByteArrayOutputStream outputBuffer ) throws DataFormatException {
151149 inflater .setInput (data );
152150 byte [] buffer = new byte [BUFFER_SIZE ];
153151
154152 int bytesInflated ;
155- while ((bytesInflated = inflater .inflate (buffer )) > 0 ){
153+ while ((bytesInflated = inflater .inflate (buffer )) > 0 ) {
156154 outputBuffer .write (buffer , 0 , bytesInflated );
157155 }
158156 }
159157
160158 @ Override
161159 public void encodeFrame (Framedata inputFrame ) {
162160 // Only DataFrames can be decompressed.
163- if (!(inputFrame instanceof DataFrame ))
161+ if (!(inputFrame instanceof DataFrame ))
164162 return ;
165163
166164 // Only the first frame's RSV1 must be set.
167- if (!(inputFrame instanceof ContinuousFrame ))
165+ if (!(inputFrame instanceof ContinuousFrame ))
168166 ((DataFrame ) inputFrame ).setRSV1 (true );
169167
170168 deflater .setInput (inputFrame .getPayloadData ().array ());
@@ -173,7 +171,7 @@ public void encodeFrame(Framedata inputFrame) {
173171 // Temporary buffer to hold compressed output.
174172 byte [] buffer = new byte [1024 ];
175173 int bytesCompressed ;
176- while ((bytesCompressed = deflater .deflate (buffer , 0 , buffer .length , Deflater .SYNC_FLUSH )) > 0 ) {
174+ while ((bytesCompressed = deflater .deflate (buffer , 0 , buffer .length , Deflater .SYNC_FLUSH )) > 0 ) {
177175 output .write (buffer , 0 , bytesCompressed );
178176 }
179177
@@ -186,11 +184,11 @@ public void encodeFrame(Framedata inputFrame) {
186184 To simulate removal, we just pass 4 bytes less to the new payload
187185 if the frame is final and outputBytes ends with 0x00 0x00 0xff 0xff.
188186 */
189- if (inputFrame .isFin ()) {
190- if (endsWithTail (outputBytes ))
187+ if (inputFrame .isFin ()) {
188+ if (endsWithTail (outputBytes ))
191189 outputLength -= TAIL_BYTES .length ;
192190
193- if (serverNoContextTakeover ) {
191+ if (serverNoContextTakeover ) {
194192 deflater .end ();
195193 deflater = new Deflater (Deflater .DEFAULT_COMPRESSION , true );
196194 }
@@ -205,13 +203,13 @@ public void encodeFrame(Framedata inputFrame) {
205203 * @param data the bytes of data
206204 * @return true if the data is OK
207205 */
208- private boolean endsWithTail (byte [] data ){
209- if (data .length < 4 )
206+ private boolean endsWithTail (byte [] data ) {
207+ if (data .length < 4 )
210208 return false ;
211209
212210 int length = data .length ;
213- for (int i = 0 ; i < TAIL_BYTES .length ; i ++){
214- if (TAIL_BYTES [i ] != data [length - TAIL_BYTES .length + i ])
211+ for (int i = 0 ; i < TAIL_BYTES .length ; i ++) {
212+ if (TAIL_BYTES [i ] != data [length - TAIL_BYTES .length + i ])
215213 return false ;
216214 }
217215
@@ -221,15 +219,15 @@ private boolean endsWithTail(byte[] data){
221219 @ Override
222220 public boolean acceptProvidedExtensionAsServer (String inputExtension ) {
223221 String [] requestedExtensions = inputExtension .split ("," );
224- for (String extension : requestedExtensions ) {
222+ for (String extension : requestedExtensions ) {
225223 ExtensionRequestData extensionData = ExtensionRequestData .parseExtensionRequest (extension );
226- if (!EXTENSION_REGISTERED_NAME .equalsIgnoreCase (extensionData .getExtensionName ()))
224+ if (!EXTENSION_REGISTERED_NAME .equalsIgnoreCase (extensionData .getExtensionName ()))
227225 continue ;
228226
229227 // Holds parameters that peer client has sent.
230228 Map <String , String > headers = extensionData .getExtensionParameters ();
231229 requestedParameters .putAll (headers );
232- if (requestedParameters .containsKey (CLIENT_NO_CONTEXT_TAKEOVER ))
230+ if (requestedParameters .containsKey (CLIENT_NO_CONTEXT_TAKEOVER ))
233231 clientNoContextTakeover = true ;
234232
235233 return true ;
@@ -241,9 +239,9 @@ public boolean acceptProvidedExtensionAsServer(String inputExtension) {
241239 @ Override
242240 public boolean acceptProvidedExtensionAsClient (String inputExtension ) {
243241 String [] requestedExtensions = inputExtension .split ("," );
244- for (String extension : requestedExtensions ) {
242+ for (String extension : requestedExtensions ) {
245243 ExtensionRequestData extensionData = ExtensionRequestData .parseExtensionRequest (extension );
246- if (!EXTENSION_REGISTERED_NAME .equalsIgnoreCase (extensionData .getExtensionName ()))
244+ if (!EXTENSION_REGISTERED_NAME .equalsIgnoreCase (extensionData .getExtensionName ()))
247245 continue ;
248246
249247 // Holds parameters that are sent by the server, as a response to our initial extension request.
@@ -281,9 +279,9 @@ public IExtension copyInstance() {
281279 */
282280 @ Override
283281 public void isFrameValid (Framedata inputFrame ) throws InvalidDataException {
284- if ((inputFrame instanceof TextFrame || inputFrame instanceof BinaryFrame ) && !inputFrame .isRSV1 ())
282+ if ((inputFrame instanceof TextFrame || inputFrame instanceof BinaryFrame ) && !inputFrame .isRSV1 ())
285283 throw new InvalidFrameException ("RSV1 bit must be set for DataFrames." );
286- if ((inputFrame instanceof ContinuousFrame ) && (inputFrame .isRSV1 () || inputFrame .isRSV2 () || inputFrame .isRSV3 ()))
284+ if ((inputFrame instanceof ContinuousFrame ) && (inputFrame .isRSV1 () || inputFrame .isRSV2 () || inputFrame .isRSV3 ()))
287285 throw new InvalidFrameException ( "bad rsv RSV1: " + inputFrame .isRSV1 () + " RSV2: " + inputFrame .isRSV2 () + " RSV3: " + inputFrame .isRSV3 () );
288286 super .isFrameValid (inputFrame );
289287 }
0 commit comments