MCPcopy Create free account
hub / github.com/apache/tomcat / generateMask

Method generateMask

java/org/apache/tomcat/websocket/Util.java:130–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

128
129
130 static byte[] generateMask() {
131 // SecureRandom is not thread-safe so need to make sure only one thread
132 // uses it at a time. In theory, the pool could grow to the same size
133 // as the number of request processing threads. In reality, it will be
134 // a lot smaller.
135
136 // Get a SecureRandom from the pool
137 SecureRandom sr = randoms.poll();
138
139 // If one isn't available, generate a new one
140 if (sr == null) {
141 try {
142 sr = SecureRandom.getInstance("SHA1PRNG");
143 } catch (NoSuchAlgorithmException e) {
144 // Fall back to platform default
145 sr = new SecureRandom();
146 }
147 }
148
149 // Generate the mask
150 byte[] result = new byte[4];
151 sr.nextBytes(result);
152
153 // Put the SecureRandom back in the poll
154 randoms.add(sr);
155
156 return result;
157 }
158
159
160 static Class<?> getMessageType(MessageHandler listener) {

Callers 2

generateMaskMethod · 0.95
writeMessagePartMethod · 0.95

Calls 4

getInstanceMethod · 0.65
addMethod · 0.65
pollMethod · 0.45
nextBytesMethod · 0.45

Tested by 1

generateMaskMethod · 0.76