List of usage examples for io.netty.buffer ByteBuf writeBytes
public abstract ByteBuf writeBytes(ByteBuffer src);
From source file:buildcraft.core.network.serializers.SerializerBitSet.java
License:Minecraft Mod Public
@Override public void write(ByteBuf data, Object o, SerializationContext context) { if (o == null) { data.writeBoolean(false);/*w w w. jav a2s .co m*/ } else { data.writeBoolean(true); BitSet set = (BitSet) o; byte[] bytes = BitSetUtils.toByteArray(set); data.writeInt(bytes.length); data.writeBytes(bytes); } }
From source file:buildcraft.core.utils.Utils.java
License:Minecraft Mod Public
public static void writeUTF(ByteBuf data, String str) { try {//from w w w .ja v a 2 s.c o m byte[] b = str.getBytes("UTF-8"); data.writeInt(b.length); data.writeBytes(b); } catch (UnsupportedEncodingException e) { e.printStackTrace(); data.writeInt(0); } }
From source file:buildcraft.core.utils.Utils.java
License:Minecraft Mod Public
public static void writeNBT(ByteBuf data, NBTTagCompound nbt) { try {/*from w w w. j av a 2 s . c o m*/ byte[] compressed = CompressedStreamTools.compress(nbt); data.writeInt(compressed.length); data.writeBytes(compressed); } catch (IOException e) { e.printStackTrace(); } }
From source file:buildcraft.transport.network.PacketFluidUpdate.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { super.writeData(data); byte[] dBytes = toByteArray(delta); // System.out.printf("write %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta); data.writeBytes(dBytes); for (ForgeDirection dir : ForgeDirection.values()) { FluidStack liquid = renderCache[dir.ordinal()]; if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_ID_BIT)) { if (liquid != null) { data.writeShort(liquid.fluidID); data.writeInt(colorRenderCache[dir.ordinal()]); } else { data.writeShort(0);/* www. j ava2 s . c o m*/ data.writeInt(0xFFFFFF); } } if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_AMOUNT_BIT)) { if (liquid != null) { data.writeInt(liquid.amount); } else { data.writeInt(0); } } } }
From source file:buildcraftAdditions.tileEntities.TileItemSorter.java
License:GNU General Public License
@Override public void writeToByteBuff(ByteBuf buf) { buf.writeByte(rotation.ordinal()); buf.writeBytes(colors); }
From source file:cat.tbq.hospital.nio.echoExample.EchoServerHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { ByteBuf byteBuf = (ByteBuf) msg;//from w w w . ja v a 2 s . c o m int size = byteBuf.readableBytes(); for (int i = 0; i < size; i++) { System.out.println("===" + (char) byteBuf.getByte(i)); ; } ByteBuf firstMessage = Unpooled.buffer(20); firstMessage.writeBytes("hello how are you".getBytes()); ctx.writeAndFlush(firstMessage); }
From source file:cc.blynk.integration.model.websocket.AppWebSocketClient.java
License:Apache License
private static WebSocketFrame produceWebSocketFrame(MessageBase msg) { byte[] data = msg.getBytes(); ByteBuf bb = ByteBufAllocator.DEFAULT.buffer(3 + data.length); bb.writeByte(msg.command);//from ww w . j av a 2s .c o m bb.writeShort(msg.id); bb.writeBytes(data); return new BinaryWebSocketFrame(bb); }
From source file:cc.blynk.integration.model.websocket.WebSocketClient.java
License:Apache License
private static WebSocketFrame produceWebSocketFrame(MessageBase msg) { ByteBuf bb = PooledByteBufAllocator.DEFAULT.heapBuffer(5 + msg.length); bb.writeByte(msg.command);/*ww w. j a v a 2s . c o m*/ bb.writeShort(msg.id); bb.writeShort(msg.length); byte[] data = msg.getBytes(); if (data != null) { bb.writeBytes(data); } return new BinaryWebSocketFrame(bb); }
From source file:cf.dropsonde.metron.EnvelopeEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext context, Envelope envelope, ByteBuf byteBuf) throws Exception { byteBuf.writeBytes(Envelope.ADAPTER.encode(envelope)); }
From source file:chapter01.EchoClientHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { String sendMessage = "Hello netty"; ByteBuf messageBuffer = Unpooled.buffer(); messageBuffer.writeBytes(sendMessage.getBytes()); StringBuilder builder = new StringBuilder(); builder.append(" ? ["); builder.append(sendMessage);//from w w w. j a v a 2 s. c om builder.append("]"); //System.out.println(builder.toString()); log.info(String.valueOf(builder)); ctx.writeAndFlush(messageBuffer); }