View Javadoc

1   // ========================================================================
2   // Copyright (c) 2010 Mort Bay Consulting Pty. Ltd.
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   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.websocket;
15  
16  import org.eclipse.jetty.io.Buffer;
17  import org.eclipse.jetty.util.Utf8StringBuilder;
18  import org.eclipse.jetty.util.log.Log;
19  
20  final class FrameHandlerD0 implements WebSocketParser.FrameHandler
21  {
22      final WebSocket _websocket;
23      final Utf8StringBuilder _utf8 = new Utf8StringBuilder();
24  
25      FrameHandlerD0(WebSocket websocket)
26      {
27          _websocket=websocket;
28      }
29      
30      public void onFrame(boolean more, byte flags, byte opcode, Buffer buffer)
31      {
32          assert more==false;
33          try
34          {
35              byte[] array=buffer.array();
36              
37              if (opcode==0)
38              {
39                  _websocket.onMessage(opcode,buffer.toString("utf-8"));
40              }
41              else
42              {
43                  _websocket.onMessage(opcode,array,buffer.getIndex(),buffer.length());
44              }
45          }
46          catch(ThreadDeath th)
47          {
48              throw th;
49          }
50          catch(Throwable th)
51          {
52              Log.warn(th);
53          }
54      }
55  }