1 /* 2 * Copyright 2010 Red Hat, Inc. 3 * 4 * Red Hat licenses this file to you under the Apache License, version 2.0 5 * (the "License"); you may not use this file except in compliance with the 6 * License. You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package org.jboss.netty.handler.codec.http.websocket; 17 18 import org.jboss.netty.buffer.ChannelBuffer; 19 import org.jboss.netty.buffer.ChannelBuffers; 20 21 /** 22 * A Web Socket frame that represents either text or binary data. 23 * 24 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a> 25 * @author <a href="http://gleamynode.net/">Trustin Lee</a> 26 * @version $Rev: 2342 $, $Date: 2010-07-07 14:07:39 +0900 (Wed, 07 Jul 2010) $ 27 */ 28 public interface WebSocketFrame { 29 30 /** 31 * Closing handshake message (<tt>0xFF, 0x00</tt>) 32 */ 33 WebSocketFrame CLOSING_HANDSHAKE = new DefaultWebSocketFrame(0xFF, ChannelBuffers.EMPTY_BUFFER); 34 35 /** 36 * Returns the type of this frame. 37 * <tt>0x00-0x7F</tt> means a text frame encoded in UTF-8, and 38 * <tt>0x80-0xFF</tt> means a binary frame. Currently, {@code 0} is the 39 * only allowed type according to the specification. 40 */ 41 int getType(); 42 43 /** 44 * Returns {@code true} if and only if the content of this frame is a string 45 * encoded in UTF-8. 46 */ 47 boolean isText(); 48 49 /** 50 * Returns {@code true} if and only if the content of this frame is an 51 * arbitrary binary data. 52 */ 53 boolean isBinary(); 54 55 /** 56 * Returns the content of this frame as-is, with no UTF-8 decoding. 57 */ 58 ChannelBuffer getBinaryData(); 59 60 /** 61 * Converts the content of this frame into a UTF-8 string and returns the 62 * converted string. 63 */ 64 String getTextData(); 65 66 /** 67 * Sets the type and the content of this frame. 68 * 69 * @param type 70 * the type of the frame. {@code 0} is the only allowed type currently. 71 * @param binaryData 72 * the content of the frame. If <tt>(type & 0x80 == 0)</tt>, 73 * it must be encoded in UTF-8. 74 * 75 * @throws IllegalArgumentException 76 * if If <tt>(type & 0x80 == 0)</tt> and the data is not encoded 77 * in UTF-8 78 */ 79 void setData(int type, ChannelBuffer binaryData); 80 81 /** 82 * Returns the string representation of this frame. Please note that this 83 * method is not identical to {@link #getTextData()}. 84 */ 85 String toString(); 86 }