Example usage for io.netty.buffer ByteBufInputStream ByteBufInputStream

List of usage examples for io.netty.buffer ByteBufInputStream ByteBufInputStream

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufInputStream ByteBufInputStream.

Prototype

public ByteBufInputStream(ByteBuf buffer) 

Source Link

Document

Creates a new stream which reads data from the specified buffer starting at the current readerIndex and ending at the current writerIndex .

Usage

From source file:ws.wamp.jawampa.transport.WampDeserializationHandler.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out) throws Exception {
    if (readState != ReadState.Reading)
        return;//from   www  . j av  a 2s. c  om
    if (frame instanceof TextWebSocketFrame) {
        // Only want Text when JSON subprotocol
        if (serialization != Serialization.Json)
            throw new IllegalStateException("Received unexpected TextFrame");

        TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
        if (logger.isDebugEnabled()) {
            logger.debug("Deserialized Wamp Message: {}", textFrame.text());
        }
        //System.out.println("Deserialized Wamp message: " + textFrame.text());

        try {
            // If we receive an invalid frame on of the following functions will throw
            // This will lead Netty to closing the connection
            ArrayNode arr = objectMapper.readValue(new ByteBufInputStream(textFrame.content()),
                    ArrayNode.class);

            WampMessage recvdMessage = WampMessage.fromObjectArray(arr);
            out.add(recvdMessage);
        } finally {
        }
    } else if (frame instanceof BinaryWebSocketFrame) {
        // Only want Binary when MessagePack subprotocol
        if (serialization != Serialization.MessagePack)
            throw new IllegalStateException("Received unexpected BinaryFrame");

        // TODO: Support MessagePack
    } else if (frame instanceof PongWebSocketFrame) {
        // System.out.println("WebSocket Client received pong");
    } else if (frame instanceof CloseWebSocketFrame) {
        // System.out.println("WebSocket Client received closing");
        readState = ReadState.Closed;
    }
}