View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2011 Intalio, Inc.
3    * ======================================================================
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the Eclipse Public License v1.0
6    * and Apache License v2.0 which accompanies this distribution.
7    *
8    *   The Eclipse Public License is available at
9    *   http://www.eclipse.org/legal/epl-v10.html
10   *
11   *   The Apache License v2.0 is available at
12   *   http://www.opensource.org/licenses/apache2.0.php
13   *
14   * You may elect to redistribute this code under either of these licenses.
15   *******************************************************************************/
16  package org.eclipse.jetty.websocket;
17  
18  import java.util.Random;
19  
20  
21  public class RandomMaskGen implements MaskGen
22  {
23      private final Random _random;
24  
25      public RandomMaskGen()
26      {
27          this(new Random());
28      }
29  
30      public RandomMaskGen(Random random)
31      {
32          _random=random;
33      }
34  
35      public void genMask(byte[] mask)
36      {
37          // The assumption is that this code is always called
38          // with an external lock held to prevent concurrent access
39          // Otherwise we need to synchronize on the _random.
40          _random.nextBytes(mask);
41      }
42  }