WebSocketUtil Class — netty Architecture
Architecture documentation for the WebSocketUtil class in WebSocketUtil.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 32ad3c78_b425_e854_d489_6f60f2c146e2["WebSocketUtil"] 72b019c3_1852_f3e6_7d68_6bfb53dfada8["WebSocketUtil.java"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|defined in| 72b019c3_1852_f3e6_7d68_6bfb53dfada8 e1bec297_fc37_52da_bdc7_98f4b5875302["md5()"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|method| e1bec297_fc37_52da_bdc7_98f4b5875302 d70ab269_56a7_76e7_f5eb_9e6df8f76474["sha1()"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|method| d70ab269_56a7_76e7_f5eb_9e6df8f76474 d6482173_01d4_8d44_6ede_0b932430e1b9["digest()"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|method| d6482173_01d4_8d44_6ede_0b932430e1b9 f0e21fa6_33aa_b6ae_72e3_033267665f34["String()"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|method| f0e21fa6_33aa_b6ae_72e3_033267665f34 31205659_72a2_4d6f_c17d_1c3fc2b55d62["randomBytes()"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|method| 31205659_72a2_4d6f_c17d_1c3fc2b55d62 fbf9a1d0_ab6c_836e_a9ba_fb90ac52ecd6["randomNumber()"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|method| fbf9a1d0_ab6c_836e_a9ba_fb90ac52ecd6 7b69c8e7_a3a2_f497_5089_a57425b522d4["byteAtIndex()"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|method| 7b69c8e7_a3a2_f497_5089_a57425b522d4 2c942f1b_13e0_d911_c7ad_6b452be57605["WebSocketUtil()"] 32ad3c78_b425_e854_d489_6f60f2c146e2 -->|method| 2c942f1b_13e0_d911_c7ad_6b452be57605
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketUtil.java lines 28–153
final class WebSocketUtil {
private static final FastThreadLocal<MessageDigest> MD5 = new FastThreadLocal<MessageDigest>() {
@Override
protected MessageDigest initialValue() throws Exception {
try {
//Try to get a MessageDigest that uses MD5
//Suppress a warning about weak hash algorithm
//since it's defined in draft-ietf-hybi-thewebsocketprotocol-00
return MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
//This shouldn't happen! How old is the computer?
throw new InternalError("MD5 not supported on this platform - Outdated?");
}
}
};
private static final FastThreadLocal<MessageDigest> SHA1 = new FastThreadLocal<MessageDigest>() {
@Override
protected MessageDigest initialValue() throws Exception {
try {
//Try to get a MessageDigest that uses SHA1
//Suppress a warning about weak hash algorithm
//since it's defined in draft-ietf-hybi-thewebsocketprotocol-00
return MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
//This shouldn't happen! How old is the computer?
throw new InternalError("SHA-1 not supported on this platform - Outdated?");
}
}
};
/**
* Performs a MD5 hash on the specified data
*
* @param data The data to hash
* @return The hashed data
*/
static byte[] md5(byte[] data) {
// TODO(normanmaurer): Create md5 method that not need MessageDigest.
return digest(MD5, data);
}
/**
* Performs a SHA-1 hash on the specified data
*
* @param data The data to hash
* @return The hashed data
*/
static byte[] sha1(byte[] data) {
// TODO(normanmaurer): Create sha1 method that not need MessageDigest.
return digest(SHA1, data);
}
private static byte[] digest(FastThreadLocal<MessageDigest> digestFastThreadLocal, byte[] data) {
MessageDigest digest = digestFastThreadLocal.get();
digest.reset();
return digest.digest(data);
}
/**
* Performs base64 encoding on the specified data
*
* @param data The data to encode
* @return An encoded string containing the data
*/
static String base64(byte[] data) {
return Base64.getEncoder().encodeToString(data);
}
/**
* Creates an arbitrary number of random bytes
*
* @param size the number of random bytes to create
* @return An array of random bytes
*/
static byte[] randomBytes(int size) {
byte[] bytes = new byte[size];
ThreadLocalRandom.current().nextBytes(bytes);
return bytes;
}
Source
Frequently Asked Questions
What is the WebSocketUtil class?
WebSocketUtil is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketUtil.java.
Where is WebSocketUtil defined?
WebSocketUtil is defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketUtil.java at line 28.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free