Package com.trendrr.strest.server.websocket

Source Code of com.trendrr.strest.server.websocket.WebsocketEncoder

/**
*
*/
package com.trendrr.strest.server.websocket;

import java.nio.charset.Charset;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.http.websocket.DefaultWebSocketFrame;
import org.jboss.netty.handler.codec.http.websocket.WebSocketFrame;


/**
* @author Dustin Norlander
* @created Mar 18, 2011
*
*/
public class WebsocketEncoder extends org.jboss.netty.handler.codec.oneone.OneToOneEncoder {

  protected Log log = LogFactory.getLog(WebsocketEncoder.class);

  /* (non-Javadoc)
   * @see org.jboss.netty.handler.codec.oneone.OneToOneEncoder#encode(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.Channel, java.lang.Object)
   */
  @Override
  protected Object encode(ChannelHandlerContext arg0, Channel arg1,
      Object m) throws Exception {
    if (m instanceof ChannelBuffer) {
      ChannelBuffer cbuf = (ChannelBuffer)m;
      WebSocketFrame frame = new DefaultWebSocketFrame(cbuf.toString(Charset.forName("utf8")));
      return frame;
    }
    return m;
  }
}
TOP

Related Classes of com.trendrr.strest.server.websocket.WebsocketEncoder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.