Netty: ByteBuf 转 Cadena

package tju.SpringBootPostServer.controller;

import java.io.UnsupportedEncodingException;
import java.util.Date;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;

public class TestMe {

	public static void main(String[] args) throws UnsupportedEncodingException {
		ByteBuf byteBuf = Unpooled.copiedBuffer("current time is: "+new Date(),CharsetUtil.UTF_8);
		byte[] bytes = new byte[byteBuf.readableBytes()];
		byteBuf.readBytes(bytes);
		String body = new String(bytes,"UTF-8");
		System.out.println(body);

	}

}

Supongo que te gusta

Origin blog.csdn.net/amadeus_liu2/article/details/115174549
Recomendado
Clasificación