Package com.neovisionaries.ws.client
Class WebSocketExtension
- java.lang.Object
-
- com.neovisionaries.ws.client.WebSocketExtension
-
- Direct Known Subclasses:
PerMessageCompressionExtension
public class WebSocketExtension extends java.lang.Object
A class to hold the name and the parameters of a WebSocket extension.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
mName
private java.util.Map<java.lang.String,java.lang.String>
mParameters
static java.lang.String
PERMESSAGE_DEFLATE
The name ofpermessage-deflate
extension that is defined in 7. The "permessage-deflate" Extension in RFC 7692.
-
Constructor Summary
Constructors Constructor Description WebSocketExtension(WebSocketExtension source)
Copy constructor.WebSocketExtension(java.lang.String name)
Constructor with an extension name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsParameter(java.lang.String key)
Check if the parameter identified by the key is contained.private static WebSocketExtension
createInstance(java.lang.String name)
private static java.lang.String
extractValue(java.lang.String[] pair)
java.lang.String
getName()
Get the extension name.java.lang.String
getParameter(java.lang.String key)
Get the value of the specified parameter.java.util.Map<java.lang.String,java.lang.String>
getParameters()
Get the parameters.static WebSocketExtension
parse(java.lang.String string)
Parse a string as aWebSocketExtension
.WebSocketExtension
setParameter(java.lang.String key, java.lang.String value)
Set a value to the specified parameter.java.lang.String
toString()
Stringify this object into the format "{name}[; {key}[={value}]]*".(package private) void
validate()
Validate this instance.
-
-
-
Field Detail
-
PERMESSAGE_DEFLATE
public static final java.lang.String PERMESSAGE_DEFLATE
The name ofpermessage-deflate
extension that is defined in 7. The "permessage-deflate" Extension in RFC 7692.- Since:
- 1.17
- See Also:
- Constant Field Values
-
mName
private final java.lang.String mName
-
mParameters
private final java.util.Map<java.lang.String,java.lang.String> mParameters
-
-
Constructor Detail
-
WebSocketExtension
public WebSocketExtension(java.lang.String name)
Constructor with an extension name.- Parameters:
name
- The extension name.- Throws:
java.lang.IllegalArgumentException
- The given name is not a valid token.
-
WebSocketExtension
public WebSocketExtension(WebSocketExtension source)
Copy constructor.- Parameters:
source
- A source extension. Must not benull
.- Throws:
java.lang.IllegalArgumentException
- The given argument isnull
.- Since:
- 1.6
-
-
Method Detail
-
getName
public java.lang.String getName()
Get the extension name.- Returns:
- The extension name.
-
getParameters
public java.util.Map<java.lang.String,java.lang.String> getParameters()
Get the parameters.- Returns:
- The parameters.
-
containsParameter
public boolean containsParameter(java.lang.String key)
Check if the parameter identified by the key is contained.- Parameters:
key
- The name of the parameter.- Returns:
true
if the parameter is contained.
-
getParameter
public java.lang.String getParameter(java.lang.String key)
Get the value of the specified parameter.- Parameters:
key
- The name of the parameter.- Returns:
- The value of the parameter.
null
may be returned.
-
setParameter
public WebSocketExtension setParameter(java.lang.String key, java.lang.String value)
Set a value to the specified parameter.- Parameters:
key
- The name of the parameter.value
- The value of the parameter. If notnull
, it must be a valid token. Note that RFC 6455 says "When using the quoted-string syntax variant, the value after quoted-string unescaping MUST conform to the 'token' ABNF."- Returns:
this
object.- Throws:
java.lang.IllegalArgumentException
-- The key is not a valid token.
- The value is not
null
and it is not a valid token.
-
toString
public java.lang.String toString()
Stringify this object into the format "{name}[; {key}[={value}]]*".- Overrides:
toString
in classjava.lang.Object
-
validate
void validate() throws WebSocketException
Validate this instance. This method is expected to be overridden.- Throws:
WebSocketException
-
parse
public static WebSocketExtension parse(java.lang.String string)
Parse a string as aWebSocketExtension
. The input string should comply with the format described in 9.1. Negotiating Extensions in RFC 6455.- Parameters:
string
- A string that represents a WebSocket extension.- Returns:
- A new
WebSocketExtension
instance that represents the given string. If the input string does not comply with RFC 6455,null
is returned.
-
extractValue
private static java.lang.String extractValue(java.lang.String[] pair)
-
createInstance
private static WebSocketExtension createInstance(java.lang.String name)
-
-