List of usage examples for io.netty.buffer ByteBuf toString
public abstract String toString(Charset charset);
From source file:org.lanternpowered.server.network.status.LanternFavicon.java
License:MIT License
/** * Encodes the buffered image into the encoded favicon string. * //from w w w . j av a 2 s .c o m * @param image the buffered image * @return the favicon string */ private static String encode(BufferedImage image) throws IOException { checkArgument(image.getWidth() == 64, "favicon must be 64 pixels wide"); checkArgument(image.getHeight() == 64, "favicon must be 64 pixels high"); ByteBuf buf = Unpooled.buffer(); try { ImageIO.write(image, "PNG", new ByteBufOutputStream(buf)); ByteBuf base64 = Base64.encode(buf); try { return FAVICON_PREFIX + base64.toString(StandardCharsets.UTF_8); } finally { base64.release(); } } finally { buf.release(); } }
From source file:org.mbmg.tcp.server.ServerHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { ByteBuf in = (ByteBuf) msg; try {// w ww .java2s. com System.out.println("channelRead"); String receivedContent = in.toString(io.netty.util.CharsetUtil.US_ASCII); new Consumer(receivedContent).start(); // send back message to the datalogger to notify it the bytes were correctly received ctx.writeAndFlush("@888"); } catch (Exception e) { e.printStackTrace(); } finally { in.release(); } }
From source file:org.onosproject.artemis.impl.moas.MoasClientHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws IOException { ByteBuf in = (ByteBuf) msg; String strMsg = in.toString(io.netty.util.CharsetUtil.US_ASCII); ObjectMapper mapper = new ObjectMapper(); ArtemisMessage actObj = mapper.readValue(strMsg, ArtemisMessage.class); packetProcessor.processMoasPacket(actObj, ctx); }
From source file:org.onosproject.artemis.impl.moas.MoasServerHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws IOException { ByteBuf in = (ByteBuf) msg; String strMsg = in.toString(io.netty.util.CharsetUtil.US_ASCII); ObjectMapper mapper = new ObjectMapper(); ArtemisMessage actObj = mapper.readValue(strMsg, ArtemisMessage.class); controller.packetAgent.processMoasPacket(actObj, ctx); }
From source file:org.opendaylight.controller.netconf.netty.EchoClientHandler.java
License:Open Source License
@Override public synchronized void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf bb = (ByteBuf) msg; String string = bb.toString(Charsets.UTF_8); fromServer.append(string);/*from w w w .j a va 2 s . c om*/ LOG.info(">{}", string); bb.release(); }
From source file:org.opendaylight.controller.netconf.netty.EchoServerHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf byteBuf = (ByteBuf) msg; String message = byteBuf.toString(Charsets.UTF_8); LOG.info("writing back '{}'", message); ctx.write(msg);// w ww. jav a 2 s . c o m fromLastNewLine += message; for (String line : splitter.split(fromLastNewLine)) { if ("quit".equals(line)) { LOG.info("closing server ctx"); ctx.flush(); ctx.close(); break; } fromLastNewLine = line; // last line should be preserved } // do not release byteBuf as it is handled back }
From source file:org.opendaylight.controller.netconf.netty.ProxyServerHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { ByteBuf bb = (ByteBuf) msg; LOG.info(">{}", bb.toString(Charsets.UTF_8)); remoteCtx.write(msg);// w w w . j a v a2 s . co m }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.NetconfChunkAggregatorTest.java
License:Open Source License
@Test public void testMultipleChunks() throws Exception { final List<Object> output = Lists.newArrayList(); final ByteBuf input = Unpooled.copiedBuffer(CHUNKED_MESSAGE.getBytes(Charsets.UTF_8)); agr.decode(null, input, output);/*from w ww . j a va2s .com*/ assertEquals(1, output.size()); final ByteBuf chunk = (ByteBuf) output.get(0); assertEquals(EXPECTED_MESSAGE, chunk.toString(Charsets.UTF_8)); }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.NetconfChunkAggregatorTest.java
License:Open Source License
@Test public void testOneChunks() throws Exception { final List<Object> output = Lists.newArrayList(); final ByteBuf input = Unpooled.copiedBuffer(CHUNKED_MESSAGE_ONE.getBytes(Charsets.UTF_8)); agr.decode(null, input, output);/* w ww. j a va 2 s.com*/ assertEquals(1, output.size()); final ByteBuf chunk = (ByteBuf) output.get(0); assertEquals(EXPECTED_MESSAGE, chunk.toString(Charsets.UTF_8)); }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.AsyncSshHandlerWriter.java
License:Open Source License
public static String byteBufToString(final ByteBuf msg) { final String s = msg.toString(Charsets.UTF_8); msg.resetReaderIndex();/*from w w w . j a va2 s. c o m*/ return s; }