View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.websocket.api.extensions;
20  
21  import java.nio.ByteBuffer;
22  
23  /**
24   * An immutable websocket frame.
25   */
26  public interface Frame
27  {
28      public static enum Type
29      {
30          CONTINUATION((byte)0x00),
31          TEXT((byte)0x01),
32          BINARY((byte)0x02),
33          CLOSE((byte)0x08),
34          PING((byte)0x09),
35          PONG((byte)0x0A);
36  
37          public static Type from(byte op)
38          {
39              for (Type type : values())
40              {
41                  if (type.opcode == op)
42                  {
43                      return type;
44                  }
45              }
46              throw new IllegalArgumentException("OpCode " + op + " is not a valid Frame.Type");
47          }
48  
49          private byte opcode;
50  
51          private Type(byte code)
52          {
53              this.opcode = code;
54          }
55  
56          public byte getOpCode()
57          {
58              return opcode;
59          }
60  
61          public boolean isControl()
62          {
63              return (opcode >= CLOSE.getOpCode());
64          }
65  
66          public boolean isData()
67          {
68              return (opcode == TEXT.getOpCode()) | (opcode == BINARY.getOpCode());
69          }
70  
71          @Override
72          public String toString()
73          {
74              return this.name();
75          }
76      }
77  
78      public byte[] getMask();
79  
80      public byte getOpCode();
81  
82      public ByteBuffer getPayload();
83  
84      public int getPayloadLength();
85  
86      public int getPayloadStart();
87  
88      public Type getType();
89  
90      public boolean hasPayload();
91  
92      public boolean isContinuation();
93  
94      public boolean isFin();
95  
96      /**
97       * Same as {@link #isFin()}
98       * 
99       * @return true if final frame.
100      */
101     public boolean isLast();
102 
103     public boolean isMasked();
104 
105     public boolean isRsv1();
106 
107     public boolean isRsv2();
108 
109     public boolean isRsv3();
110 
111     public int remaining();
112 }