org.glassfish.grizzly.websockets.frame
Class Frame

java.lang.Object
  extended by org.glassfish.grizzly.websockets.frame.Frame

public abstract class Frame
extends Object

General abstraction, which represents WebSocket frame. Contains a set of static createXXX methods in order to create specific frame.

Author:
Alexey Stashok

Field Summary
protected  Buffer buffer
           
protected  String text
           
protected  int type
           
 
Constructor Summary
protected Frame(int type, Buffer buffer)
          Construct a frame using the given type and binary data.
 
Method Summary
static Frame createCloseFrame()
          Create the close frame, after sending which the WebSocket communication will be closed.
static Frame createFrame(int type, Buffer data)
          Create a custom typed frame, which will contain a binary data.
static Frame createFrame(int type, String text)
          Create a custom typed frame, which will contain a text, which will be encoded using UTF-8 charset.
static Frame createFrame(int type, String text, Charset charset)
          Create a custom typed frame, which will contain a text, which will be encoded using given charset.
static Frame createTextFrame(String text)
          Create the stream-based frame, which will contain UTF-8 string.
 Buffer getAsBinary()
          Get the frame pyload as binary data.
 String getAsText()
          Get the frame pyload as text using UTF-8 charset.
 String getAsText(Charset charset)
          Get the frame pyload as text using given charset.
 int getType()
          Get the frame type.
abstract  boolean isClose()
          Returns true, if this frame is close frame, or false otherwise.
abstract  ParseResult parse(Buffer buffer)
          Parses data from the Grizzly Buffer into this Frame
abstract  Buffer serialize()
          Serializes this frame into a Grizzly Buffer.
 String toString()
          Returns the frame pyload as text using UTF-8 charset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected int type

text

protected String text

buffer

protected Buffer buffer
Constructor Detail

Frame

protected Frame(int type,
                Buffer buffer)
Construct a frame using the given type and binary data.

Parameters:
type - the frame type.
buffer - the binary data.
Method Detail

createTextFrame

public static Frame createTextFrame(String text)
Create the stream-based frame, which will contain UTF-8 string. So far it's the only frame type officially supported for transferring data over WebSockets.

Parameters:
text - the text.
Returns:
the Frame.

createCloseFrame

public static Frame createCloseFrame()
Create the close frame, after sending which the WebSocket communication will be closed.

Returns:
the close frame.

createFrame

public static Frame createFrame(int type,
                                String text)
Create a custom typed frame, which will contain a text, which will be encoded using UTF-8 charset.

Parameters:
type - a frame type.
text - text value.
Returns:
the frame.

createFrame

public static Frame createFrame(int type,
                                String text,
                                Charset charset)
Create a custom typed frame, which will contain a text, which will be encoded using given charset.

Parameters:
type - a frame type.
text - text value.
charset - text charset to use during the frame encoding.
Returns:
the frame.

createFrame

public static Frame createFrame(int type,
                                Buffer data)
Create a custom typed frame, which will contain a binary data.

Parameters:
type - a frame type.
data - binary data
Returns:
the frame.

getType

public int getType()
Get the frame type.

Returns:
the frame type.

getAsText

public String getAsText()
Get the frame pyload as text using UTF-8 charset.

Returns:
the frame pyload as text using UTF-8 charset.

getAsText

public String getAsText(Charset charset)
Get the frame pyload as text using given charset.

Parameters:
charset - Charset to use.
Returns:
the frame pyload as text using given charset.

getAsBinary

public Buffer getAsBinary()
Get the frame pyload as binary data.

Returns:
the frame pyload as binary data.

toString

public String toString()
Returns the frame pyload as text using UTF-8 charset.

Overrides:
toString in class Object
Returns:
the frame pyload as text using UTF-8 charset.

isClose

public abstract boolean isClose()
Returns true, if this frame is close frame, or false otherwise.

Returns:
true, if this frame is close frame, or false otherwise.

serialize

public abstract Buffer serialize()
Serializes this frame into a Grizzly Buffer.

Returns:
Buffer, which contains serialized Frame data.

parse

public abstract ParseResult parse(Buffer buffer)
Parses data from the Grizzly Buffer into this Frame

Returns:
ParseResult, which represents result of parsing operation.


Copyright © 2010 Oracle Corpration. All Rights Reserved.