66import org .java_websocket .extensions .CompressionExtension ;
77import org .java_websocket .extensions .ExtensionRequestData ;
88import org .java_websocket .extensions .IExtension ;
9- import org .java_websocket .framing .*;
9+ import org .java_websocket .framing .BinaryFrame ;
10+ import org .java_websocket .framing .CloseFrame ;
11+ import org .java_websocket .framing .ContinuousFrame ;
12+ import org .java_websocket .framing .DataFrame ;
13+ import org .java_websocket .framing .Framedata ;
14+ import org .java_websocket .framing .FramedataImpl1 ;
15+ import org .java_websocket .framing .TextFrame ;
1016
1117import java .io .ByteArrayOutputStream ;
1218import java .nio .ByteBuffer ;
1622import java .util .zip .Deflater ;
1723import java .util .zip .Inflater ;
1824
25+ /**
26+ * PerMessage Deflate Extension (<a href="https://tools.ietf.org/html/rfc7692#section-7">7. The "permessage-deflate" Extension</a> in
27+ * <a href="https://tools.ietf.org/html/rfc7692">RFC 7692</a>).
28+ *
29+ * @see <a href="https://tools.ietf.org/html/rfc7692#section-7">7. The "permessage-deflate" Extension in RFC 7692</a>
30+ */
1931public class PerMessageDeflateExtension extends CompressionExtension {
2032
2133// Name of the extension as registered by IETF https://tools.ietf.org/html/rfc7692#section-9.
@@ -28,7 +40,7 @@ public class PerMessageDeflateExtension extends CompressionExtension{
2840private static final String CLIENT_MAX_WINDOW_BITS = "client_max_window_bits" ;
2941private static final int serverMaxWindowBits = 1 << 15 ;
3042private static final int clientMaxWindowBits = 1 << 15 ;
31- private static final byte [] TAIL_BYTES ={0x00 , 0x00 , (byte )0xFF , (byte )0xFF };
43+ private static final byte [] TAIL_BYTES ={ ( byte ) 0x00 , ( byte ) 0x00 , (byte )0xFF , (byte )0xFF };
3244private static final int BUFFER_SIZE = 1 << 10 ;
3345
3446private boolean serverNoContextTakeover = true ;
@@ -40,6 +52,24 @@ public class PerMessageDeflateExtension extends CompressionExtension{
4052private Inflater inflater = new Inflater (true );
4153private Deflater deflater = new Deflater (Deflater .DEFAULT_COMPRESSION , true );
4254
55+ /**
56+ *
57+ * @return serverNoContextTakeover
58+ */
59+ public boolean isServerNoContextTakeover ()
60+ {
61+ return serverNoContextTakeover ;
62+ }
63+
64+ /**
65+ *
66+ * @return clientNoContextTakeover
67+ */
68+ public boolean isClientNoContextTakeover ()
69+ {
70+ return clientNoContextTakeover ;
71+ }
72+
4373/*
4474 An endpoint uses the following algorithm to decompress a message.
4575 1. Append 4 octets of 0x00 0x00 0xff 0xff to the tail end of the
@@ -93,6 +123,12 @@ We can check the getRemaining() method to see whether the data we supplied has b
93123 ((FramedataImpl1 ) inputFrame ).setPayload (ByteBuffer .wrap (output .toByteArray (), 0 , output .size ()));
94124 }
95125
126+ /**
127+ *
128+ * @param data the bytes of date
129+ * @param outputBuffer the output stream
130+ * @throws DataFormatException
131+ */
96132private void decompress (byte [] data , ByteArrayOutputStream outputBuffer ) throws DataFormatException {
97133inflater .setInput (data );
98134byte [] buffer = new byte [BUFFER_SIZE ];
@@ -146,6 +182,11 @@ public void encodeFrame(Framedata inputFrame){
146182 ((FramedataImpl1 ) inputFrame ).setPayload (ByteBuffer .wrap (outputBytes , 0 , outputLength ));
147183 }
148184
185+ /**
186+ *
187+ * @param data the bytes of data
188+ * @return true if the data is OK
189+ */
149190private boolean endsWithTail (byte [] data ){
150191if (data .length < 4 )
151192return false ;
0 commit comments