【问题标题】:How to convert a netty ByteBuf to a String and vice versa如何将 netty ByteBuf 转换为字符串,反之亦然
【发布时间】:2017-03-10 09:49:08
【问题描述】:

有没有办法将 netty ByteBuf 转换为 String,反之亦然?

public String toString(ByteBuf b){

 //return b enconded to a String
}

public Bytebuf ToByteBuff(String s){

  //return s decoded to Bytebuf
}

【问题讨论】:

    标签: java encoding netty decoding


    【解决方案1】:

    您可以使用ByteBuf.toString(Charset) 转换为字符串。

    您可以使用String.getBytes(Charset) 和Unpooled.wrappedBuffer(byte[]) 转换为ByteBuf。

    【讨论】:

    • 这非常有用,尽管它很简单,哈哈。非常感谢!
    【解决方案2】:

    您可以使用Unpooled.copiedBuffer(String, Charset) 从字符串创建ByteBuf。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多