本文整理汇总了Java中io.netty.buffer.ByteBuf.writeBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.writeBytes方法的具体用法?Java ByteBuf.writeBytes怎么用?Java ByteBuf.writeBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.writeBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(entityID);
buf.writeByte(type);
if (type == 0)
buf.writeInt(intValue);
else if (type == 1)
buf.writeFloat(floatValue);
else if (type == 2)
buf.writeByte(byteValue);
else if (type == 3) {
byte[] stringValueArray = stringValue.getBytes(StandardCharsets.UTF_8);
buf.writeByte(stringValueArray.length);
buf.writeBytes(stringValueArray);
}
byte[] stringNameArray = name.getBytes(StandardCharsets.UTF_8);
buf.writeBytes(stringNameArray);
}
示例2: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void encode(ByteBuf out, Object message) throws IOException {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
closer.register(byteArrayOutputStream);
KryoSerialize kryoSerialization = new KryoSerialize(pool);
kryoSerialization.serialize(byteArrayOutputStream, message);
byte[] body = byteArrayOutputStream.toByteArray();
int dataLength = body.length;
out.writeInt(dataLength);
out.writeBytes(body);
} finally {
closer.close();
}
}
示例3: mirrorUnknown
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private ByteBuf mirrorUnknown ( final ByteBuf data, final byte typeId, final InformationStructure informationStructure, final byte size, final ASDUHeader header, final Cause newCause )
{
logger.debug ( "Mirror unknown message -> {}", newCause );
final ByteBuf reply = Unpooled.buffer ();
EncodeHelper.encodeHeader ( typeId, informationStructure, this.options, (int)size, header.clone ( newCause ), reply );
reply.writeBytes ( data ); // copy data
return reply;
}
示例4: channelActive
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
*@description 客户端成功连接到服务器之后向服务器发送数据
*@time 创建时间:2017年7月26日下午7:51:31
*@param ctx
*@throws Exception
*@author dzn
*/
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ByteBuf message = null;
for(int i = 0; i < 100; i ++){
message = Unpooled.buffer(req.length);
message.writeBytes(req);
ctx.channel().writeAndFlush(message);
}
}
示例5: write
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void write(byte[] bytes) {
if(bytes!=null && bytes.length>0 && isActive())
{
ByteBuf buf=PooledByteBufAllocator.DEFAULT.buffer();
buf.writeBytes(bytes);
write(buf);
}
}
示例6: writeInet
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static void writeInet(InetSocketAddress inet, ByteBuf cb)
{
byte[] address = inet.getAddress().getAddress();
cb.writeByte(address.length);
cb.writeBytes(address);
cb.writeInt(inet.getPort());
}
示例7: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
* 编码
*
* @param out
*/
public void encode(ByteBuf out) {
byte[] head = encodeHead();
byte[] body = encodeBody();
out.writeShort((short) (head.length + body.length + 2)); // 消息的总长度
out.writeBytes(head); // 协议头
out.writeShort((short) body.length); // 消息体长度
out.writeBytes(body); // 消息体
}
示例8: writeBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void writeBytes(ByteBuffer bytes, ByteBuf dest) {
if (bytes == null) {
writeInt(-1, dest);
} else {
writeInt(bytes.remaining(), dest);
dest.writeBytes(bytes.duplicate());
}
}
示例9: metadata
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected ByteBuf metadata(ByteBufAllocator alloc) {
byte[] pathBytes = fileId.pathBytes();
int metaSize = 2 * FastdfsConstants.FDFS_PROTO_PKG_LEN_SIZE + pathBytes.length;
ByteBuf buf = alloc.buffer(metaSize);
buf.writeLong(pathBytes.length);
buf.writeLong(size());
buf.writeBytes(pathBytes);
return buf;
}
示例10: shouldDeserializeTheMapCorrectly
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Test
public void shouldDeserializeTheMapCorrectly() throws Exception {
ByteBuf buf = new PooledByteBufAllocator(true).buffer();
buf.writeBytes(new ObjectMapper().writeValueAsBytes(map));
assertThat(mapCodec.getMapValueDecoder().decode(buf, new State(false)))
.isInstanceOf(Map.class)
.isEqualTo(map);
}
示例11: serialize
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
if (partResult != null) {
byte[] data = partResult.getClass().getName().getBytes();
buf.writeInt(data.length);
buf.writeBytes(data);
partResult.serialize(buf);
}
}
示例12: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static void encode(ByteBuf buf, String s) {
byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
buf.writeInt(bytes.length);
buf.writeBytes(bytes);
}
示例13: main
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static void main(String[] args) {
ByteBuf heapBuf = Unpooled.buffer(10);
heapBuf.writeBytes("helloworld".getBytes());
heapBuffer(heapBuf);
}
示例14: writeUUID
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static void writeUUID(UUID uuid, ByteBuf cb)
{
cb.writeBytes(UUIDGen.decompose(uuid));
}
示例15: writeInetAddr
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void writeInetAddr(InetAddress address, ByteBuf dest) {
byte[] addr = address.getAddress();
dest.writeByte(addr.length);
dest.writeBytes(addr);
}