View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 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.common.frames;
20  
21  import org.eclipse.jetty.websocket.api.extensions.Frame;
22  import org.eclipse.jetty.websocket.common.OpCode;
23  import org.eclipse.jetty.websocket.common.WebSocketFrame;
24  
25  /**
26   * A Data Frame
27   */
28  public class DataFrame extends WebSocketFrame
29  {
30      protected DataFrame(byte opcode)
31      {
32          super(opcode);
33      }
34  
35      /**
36       * Construct new DataFrame based on headers of provided frame.
37       * <p>
38       * Useful for when working in extensions and a new frame needs to be created.
39       * @param basedOn the frame this one is based on
40       */
41      public DataFrame(Frame basedOn)
42      {
43          this(basedOn,false);
44      }
45  
46      /**
47       * Construct new DataFrame based on headers of provided frame, overriding for continuations if needed.
48       * <p>
49       * Useful for when working in extensions and a new frame needs to be created.
50       * @param basedOn the frame this one is based on
51       * @param continuation true if this is a continuation frame
52       */
53      public DataFrame(Frame basedOn, boolean continuation)
54      {
55          super(basedOn.getOpCode());
56          copyHeaders(basedOn);
57          if (continuation)
58          {
59              setOpCode(OpCode.CONTINUATION);
60          }
61      }
62  
63      @Override
64      public void assertValid()
65      {
66          /* no extra validation for data frames (yet) here */
67      }
68  
69      @Override
70      public boolean isControlFrame()
71      {
72          return false;
73      }
74  
75      @Override
76      public boolean isDataFrame()
77      {
78          return true;
79      }
80  
81      /**
82       * Set the data frame to continuation mode
83       */
84      public void setIsContinuation()
85      {
86          setOpCode(OpCode.CONTINUATION);
87      }
88  }