How to convert a netty ByteBuf to a String and vice versa

后端 未结 2 876
失恋的感觉
失恋的感觉 2021-01-17 16:39

Is there a way to convert a netty ByteBuf to a String and vice versa?

public String toString(ByteBuf b){

 //return b enconded to a String
}

public Bytebuf          


        
相关标签:
2条回答
  • 2021-01-17 17:30

    You can use ByteBuf.toString(Charset) to convert to string.

    You can use String.getBytes(Charset) and Unpooled.wrappedBuffer(byte[]) to convert to ByteBuf.

    0 讨论(0)
  • 2021-01-17 17:36

    You can create a ByteBuf from a String with Unpooled.copiedBuffer(String, Charset).

    0 讨论(0)
提交回复
热议问题