List of usage examples for io.netty.buffer ByteBufOutputStream ByteBufOutputStream
public ByteBufOutputStream(ByteBuf buffer)
From source file:ws.wamp.jawampa.transport.netty.WampSerializationHandler.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, WampMessage msg, List<Object> out) throws Exception { ByteBuf msgBuffer = Unpooled.buffer(); ByteBufOutputStream outStream = new ByteBufOutputStream(msgBuffer); ObjectMapper objectMapper = serialization.getObjectMapper(); try {//from w w w .j a v a 2s . c o m JsonNode node = msg.toObjectArray(objectMapper); objectMapper.writeValue(outStream, node); if (logger.isDebugEnabled()) { logger.debug("Serialized Wamp Message: {}", node.toString()); } } catch (Exception e) { msgBuffer.release(); return; } if (serialization.isText()) { TextWebSocketFrame frame = new TextWebSocketFrame(msgBuffer); out.add(frame); } else { BinaryWebSocketFrame frame = new BinaryWebSocketFrame(msgBuffer); out.add(frame); } }
From source file:ws.wamp.jawampa.transport.WampSerializationHandler.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, WampMessage msg, List<Object> out) throws Exception { if (serialization == Serialization.Json) { ByteBuf msgBuffer = Unpooled.buffer(); ByteBufOutputStream outStream = new ByteBufOutputStream(msgBuffer); try {/*from www. j a v a 2s . c o m*/ objectMapper.writeValue(outStream, msg.toObjectArray(objectMapper)); // TODO: Non JSON Mapping } catch (Exception e) { msgBuffer.release(); return; } TextWebSocketFrame frame = new TextWebSocketFrame(msgBuffer); if (logger.isDebugEnabled()) { logger.debug("Serialized Wamp Message: {}", frame.text()); } //System.out.println("Serialized Wamp message: " + frame.text()); out.add(frame); } }