Class PerMessageDeflateExtension
java.lang.Object
org.java_websocket.extensions.DefaultExtension
org.java_websocket.extensions.CompressionExtension
org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension
- All Implemented Interfaces:
IExtension
PerMessage Deflate Extension (7. The
"permessage-deflate" Extension in
RFC 7692).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final String
private static final String
private static final int
private boolean
private final int
private final Deflater
private static final String
private final Inflater
private static final String
private static final String
private static final int
private boolean
private static final byte[]
private int
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for the PerMessage Deflate Extension (7. Thepermessage-deflate" Extension) UsesDeflater.DEFAULT_COMPRESSION
as the compression level for theDeflater(int)
PerMessageDeflateExtension
(int compressionLevel) Constructor for the PerMessage Deflate Extension (7. Thepermessage-deflate" Extension) -
Method Summary
Modifier and TypeMethodDescriptionboolean
acceptProvidedExtensionAsClient
(String inputExtension) Check if the received Sec-WebSocket-Extensions header field contains a offer for the specific extension if the endpoint is in the role of a clientboolean
acceptProvidedExtensionAsServer
(String inputExtension) Check if the received Sec-WebSocket-Extensions header field contains a offer for the specific extension if the endpoint is in the role of a serverExtensions must only be by one websocket at all.void
decodeFrame
(Framedata inputFrame) Decode a frame with a extension specific algorithm.private void
decompress
(byte[] data, ByteArrayOutputStream outputBuffer) void
encodeFrame
(Framedata inputFrame) Encode a frame with a extension specific algorithm.private static boolean
endsWithTail
(byte[] data) int
Get the compression level used for the compressor.Return the specific Sec-WebSocket-Extensions header offer for this extension if the endpoint is in the role of a client.Return the specific Sec-WebSocket-Extensions header offer for this extension if the endpoint is in the role of a server.int
Get the size threshold for doing the compressionboolean
Access the "client_no_context_takeover" extension parametervoid
isFrameValid
(Framedata inputFrame) This extension requires the RSV1 bit to be set only for the first frame.boolean
Access the "server_no_context_takeover" extension parametervoid
setClientNoContextTakeover
(boolean clientNoContextTakeover) Setter for the "client_no_context_takeover" extension parametervoid
setServerNoContextTakeover
(boolean serverNoContextTakeover) Setter for the "server_no_context_takeover" extension parametervoid
setThreshold
(int threshold) Set the size when payloads smaller than this will not be compressed.toString()
Return a string which should contain the class name as well as additional information about the current configurations for this extension (DEBUG purposes)Methods inherited from class org.java_websocket.extensions.DefaultExtension
equals, hashCode, reset
-
Field Details
-
EXTENSION_REGISTERED_NAME
- See Also:
-
SERVER_NO_CONTEXT_TAKEOVER
- See Also:
-
CLIENT_NO_CONTEXT_TAKEOVER
- See Also:
-
SERVER_MAX_WINDOW_BITS
- See Also:
-
CLIENT_MAX_WINDOW_BITS
- See Also:
-
serverMaxWindowBits
private static final int serverMaxWindowBits- See Also:
-
clientMaxWindowBits
private static final int clientMaxWindowBits- See Also:
-
TAIL_BYTES
private static final byte[] TAIL_BYTES -
BUFFER_SIZE
private static final int BUFFER_SIZE- See Also:
-
threshold
private int threshold -
serverNoContextTakeover
private boolean serverNoContextTakeover -
clientNoContextTakeover
private boolean clientNoContextTakeover -
requestedParameters
-
compressionLevel
private final int compressionLevel -
inflater
-
deflater
-
-
Constructor Details
-
PerMessageDeflateExtension
public PerMessageDeflateExtension()Constructor for the PerMessage Deflate Extension (7. Thepermessage-deflate" Extension) UsesDeflater.DEFAULT_COMPRESSION
as the compression level for theDeflater(int)
-
PerMessageDeflateExtension
public PerMessageDeflateExtension(int compressionLevel) Constructor for the PerMessage Deflate Extension (7. Thepermessage-deflate" Extension)- Parameters:
compressionLevel
- The compression level passed to theDeflater(int)
-
-
Method Details
-
getCompressionLevel
public int getCompressionLevel()Get the compression level used for the compressor.- Returns:
- the compression level
-
getThreshold
public int getThreshold()Get the size threshold for doing the compression- Returns:
- Size (in bytes) below which messages will not be compressed
- Since:
- 1.5.3
-
setThreshold
public void setThreshold(int threshold) Set the size when payloads smaller than this will not be compressed.- Parameters:
threshold
- the size in bytes- Since:
- 1.5.3
-
isServerNoContextTakeover
public boolean isServerNoContextTakeover()Access the "server_no_context_takeover" extension parameter- Returns:
- serverNoContextTakeover is the server no context parameter active
- See Also:
-
setServerNoContextTakeover
public void setServerNoContextTakeover(boolean serverNoContextTakeover) Setter for the "server_no_context_takeover" extension parameter- Parameters:
serverNoContextTakeover
- set the server no context parameter- See Also:
-
isClientNoContextTakeover
public boolean isClientNoContextTakeover()Access the "client_no_context_takeover" extension parameter- Returns:
- clientNoContextTakeover is the client no context parameter active
- See Also:
-
setClientNoContextTakeover
public void setClientNoContextTakeover(boolean clientNoContextTakeover) Setter for the "client_no_context_takeover" extension parameter- Parameters:
clientNoContextTakeover
- set the client no context parameter- See Also:
-
decodeFrame
Description copied from interface:IExtension
Decode a frame with a extension specific algorithm. The algorithm is subject to be implemented by the specific extension. The resulting frame will be used in the application- Specified by:
decodeFrame
in interfaceIExtension
- Overrides:
decodeFrame
in classDefaultExtension
- Parameters:
inputFrame
- the frame, which has do be decoded to be used in the application- Throws:
InvalidDataException
- Throw InvalidDataException if the received frame is not correctly implemented by the other endpoint or there are other protocol errors/decoding errors
-
decompress
- Parameters:
data
- the bytes of dataoutputBuffer
- the output stream- Throws:
DataFormatException
-
encodeFrame
Description copied from interface:IExtension
Encode a frame with a extension specific algorithm. The algorithm is subject to be implemented by the specific extension. The resulting frame will be send to the other endpoint.- Specified by:
encodeFrame
in interfaceIExtension
- Overrides:
encodeFrame
in classDefaultExtension
- Parameters:
inputFrame
- the frame, which has do be encoded to be used on the other endpoint
-
endsWithTail
private static boolean endsWithTail(byte[] data) - Parameters:
data
- the bytes of data- Returns:
- true if the data is OK
-
acceptProvidedExtensionAsServer
Description copied from interface:IExtension
Check if the received Sec-WebSocket-Extensions header field contains a offer for the specific extension if the endpoint is in the role of a server- Specified by:
acceptProvidedExtensionAsServer
in interfaceIExtension
- Overrides:
acceptProvidedExtensionAsServer
in classDefaultExtension
- Parameters:
inputExtension
- the received Sec-WebSocket-Extensions header field offered by the other endpoint- Returns:
- true, if the offer does fit to this specific extension
-
acceptProvidedExtensionAsClient
Description copied from interface:IExtension
Check if the received Sec-WebSocket-Extensions header field contains a offer for the specific extension if the endpoint is in the role of a client- Specified by:
acceptProvidedExtensionAsClient
in interfaceIExtension
- Overrides:
acceptProvidedExtensionAsClient
in classDefaultExtension
- Parameters:
inputExtension
- the received Sec-WebSocket-Extensions header field offered by the other endpoint- Returns:
- true, if the offer does fit to this specific extension
-
getProvidedExtensionAsClient
Description copied from interface:IExtension
Return the specific Sec-WebSocket-Extensions header offer for this extension if the endpoint is in the role of a client. If the extension returns an empty string (""), the offer will not be included in the handshake.- Specified by:
getProvidedExtensionAsClient
in interfaceIExtension
- Overrides:
getProvidedExtensionAsClient
in classDefaultExtension
- Returns:
- the specific Sec-WebSocket-Extensions header for this extension
-
getProvidedExtensionAsServer
Description copied from interface:IExtension
Return the specific Sec-WebSocket-Extensions header offer for this extension if the endpoint is in the role of a server. If the extension returns an empty string (""), the offer will not be included in the handshake.- Specified by:
getProvidedExtensionAsServer
in interfaceIExtension
- Overrides:
getProvidedExtensionAsServer
in classDefaultExtension
- Returns:
- the specific Sec-WebSocket-Extensions header for this extension
-
copyInstance
Description copied from interface:IExtension
Extensions must only be by one websocket at all. To prevent extensions to be used more than once the Websocket implementation should call this method in order to create a new usable version of a given extension instance.
The copy can be safely used in conjunction with a new websocket connection.- Specified by:
copyInstance
in interfaceIExtension
- Overrides:
copyInstance
in classDefaultExtension
- Returns:
- a copy of the extension
-
isFrameValid
This extension requires the RSV1 bit to be set only for the first frame. If the frame is type is CONTINUOUS, RSV1 bit must be unset.- Specified by:
isFrameValid
in interfaceIExtension
- Overrides:
isFrameValid
in classCompressionExtension
- Parameters:
inputFrame
- the received frame- Throws:
InvalidDataException
- Throw InvalidDataException if the received frame is not correctly implementing the specification for the specific extension
-
toString
Description copied from interface:IExtension
Return a string which should contain the class name as well as additional information about the current configurations for this extension (DEBUG purposes)- Specified by:
toString
in interfaceIExtension
- Overrides:
toString
in classDefaultExtension
- Returns:
- a string containing the class name as well as additional information
-