List of usage examples for io.netty.buffer ByteBuf toString
public abstract String toString(Charset charset);
From source file:org.opendaylight.controller.netconf.util.handler.NetconfChunkAggregatorTest.java
License:Open Source License
@Test public void testMultipleChunks() throws Exception { List<Object> output = Lists.newArrayList(); ByteBuf input = Unpooled.copiedBuffer(CHUNKED_MESSAGE.getBytes(Charsets.UTF_8)); agr.decode(null, input, output);/*from w ww . ja v a2 s . com*/ Assert.assertEquals(1, output.size()); ByteBuf chunk = (ByteBuf) output.get(0); Assert.assertEquals(EXPECTED_MESSAGE, chunk.toString(Charsets.UTF_8)); }
From source file:org.opendaylight.controller.netconf.util.handler.NetconfChunkAggregatorTest.java
License:Open Source License
@Test public void testOneChunks() throws Exception { List<Object> output = Lists.newArrayList(); ByteBuf input = Unpooled.copiedBuffer(CHUNKED_MESSAGE_ONE.getBytes(Charsets.UTF_8)); agr.decode(null, input, output);/*from ww w . j a v a 2 s .c o m*/ Assert.assertEquals(1, output.size()); ByteBuf chunk = (ByteBuf) output.get(0); Assert.assertEquals(EXPECTED_MESSAGE, chunk.toString(Charsets.UTF_8)); }
From source file:org.opendaylight.controller.netconf.util.handler.NetconfEOMAggregator.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int index = indexOfSequence(in, NetconfMessageConstants.END_OF_MESSAGE); if (index == -1) { logger.debug("Message is not complete, read again."); if (logger.isTraceEnabled()) { String str = in.toString(Charsets.UTF_8); logger.trace("Message read so far: {}", str); }/* w w w . j a v a 2s .com*/ ctx.read(); } else { ByteBuf msg = in.readBytes(index); in.readBytes(NetconfMessageConstants.END_OF_MESSAGE.length); in.discardReadBytes(); logger.debug("Message is complete."); out.add(msg); } }
From source file:org.opendaylight.controller.netconf.util.handler.NetconfMessageChunkDecoder.java
License:Open Source License
private int readHeader(ByteBuf in) { ByteBuf chunkSize = Unpooled.buffer(NetconfMessageConstants.MIN_HEADER_LENGTH, NetconfMessageConstants.MAX_HEADER_LENGTH); byte b = in.readByte(); if (b != 10)/*from w ww.ja v a 2s .c o m*/ return -1; b = in.readByte(); if (b != 35) return -1; while ((b = in.readByte()) != 10) { chunkSize.writeByte(b); } return Integer.parseInt(chunkSize.toString(Charset.forName("UTF-8"))); }
From source file:org.opendaylight.protocol.bmp.impl.tlv.DescriptionTlvHandler.java
License:Open Source License
@Override public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException { if (buffer == null) { return null; }//from www. ja v a 2 s.c o m return new DescriptionTlvBuilder().setDescription(buffer.toString(Charsets.US_ASCII)).build(); }
From source file:org.opendaylight.protocol.bmp.impl.tlv.NameTlvHandler.java
License:Open Source License
@Override public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException { if (buffer == null) { return null; }//from w ww. j a v a 2 s . c om return new NameTlvBuilder().setName(buffer.toString(Charsets.US_ASCII)).build(); }
From source file:org.opendaylight.protocol.bmp.impl.tlv.StringTlvHandler.java
License:Open Source License
@Override public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException { if (buffer == null) { return null; }/* w w w . j a v a2 s . co m*/ return new StringTlvBuilder().setStringInfo(buffer.toString(Charsets.UTF_8)).build(); }
From source file:org.opendaylight.protocol.bmp.parser.tlv.DescriptionTlvHandler.java
License:Open Source License
@Override public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException { if (buffer == null) { return null; }/*from w w w . j a v a 2 s.c om*/ return new DescriptionTlvBuilder().setDescription(buffer.toString(StandardCharsets.US_ASCII)).build(); }
From source file:org.opendaylight.protocol.bmp.parser.tlv.NameTlvHandler.java
License:Open Source License
@Override public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException { if (buffer == null) { return null; }/* ww w. jav a2s.co m*/ return new NameTlvBuilder().setName(buffer.toString(StandardCharsets.US_ASCII)).build(); }
From source file:org.opendaylight.protocol.bmp.parser.tlv.StringTlvHandler.java
License:Open Source License
@Override public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException { if (buffer == null) { return null; }//w w w . ja v a 2s . c o m return new StringTlvBuilder().setStringInfo(buffer.toString(StandardCharsets.UTF_8)).build(); }