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.ObjectA class to hold the name and the parameters of a WebSocket extension.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringmNameprivate java.util.Map<java.lang.String,java.lang.String>mParametersstatic java.lang.StringPERMESSAGE_DEFLATEThe name ofpermessage-deflateextension 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 booleancontainsParameter(java.lang.String key)Check if the parameter identified by the key is contained.private static WebSocketExtensioncreateInstance(java.lang.String name)private static java.lang.StringextractValue(java.lang.String[] pair)java.lang.StringgetName()Get the extension name.java.lang.StringgetParameter(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 WebSocketExtensionparse(java.lang.String string)Parse a string as aWebSocketExtension.WebSocketExtensionsetParameter(java.lang.String key, java.lang.String value)Set a value to the specified parameter.java.lang.StringtoString()Stringify this object into the format "{name}[; {key}[={value}]]*".(package private) voidvalidate()Validate this instance.
-
-
-
Field Detail
-
PERMESSAGE_DEFLATE
public static final java.lang.String PERMESSAGE_DEFLATE
The name ofpermessage-deflateextension 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:
trueif 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.
nullmay 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:
thisobject.- Throws:
java.lang.IllegalArgumentException-- The key is not a valid token.
- The value is not
nulland it is not a valid token.
-
toString
public java.lang.String toString()
Stringify this object into the format "{name}[; {key}[={value}]]*".- Overrides:
toStringin classjava.lang.Object
-
validate
void validate() throws WebSocketExceptionValidate 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
WebSocketExtensioninstance that represents the given string. If the input string does not comply with RFC 6455,nullis returned.
-
extractValue
private static java.lang.String extractValue(java.lang.String[] pair)
-
createInstance
private static WebSocketExtension createInstance(java.lang.String name)
-
-