List of usage examples for io.netty.buffer ByteBuf writableBytes
public abstract int writableBytes();
From source file:io.nodyn.netty.pipe.NioDuplexStreamChannel.java
License:Apache License
@Override protected int doReadBytes(ByteBuf byteBuf) throws Exception { return byteBuf.writeBytes(javaChannel(), byteBuf.writableBytes()); }
From source file:me.melchor9000.net.Socket.java
License:Open Source License
/** * Receives some data from the socket into the {@link ByteBuf}. This method * doesn't ensure to write exactly {@code data.remaining()} bytes. Use instead * {@link SocketUtil} methods.//from ww w . ja va 2 s . c om * @param data {@link ByteBuf} where to write the data * @return number of bytes read * @throws Throwable If something bad happens while receiving the data */ public long receive(@NotNull ByteBuf data) throws Throwable { return receive(data, data.writableBytes()); }
From source file:me.melchor9000.net.Socket.java
License:Open Source License
/** * Receives some data from the socket into the {@link ByteBuf}. This method * doesn't ensure to write exactly {@code data.remaining()} bytes. Use instead * {@link SocketUtil} methods. This is an asynchronous operation, so it returns * a {@link Future} about this task.//w w w .j a v a 2 s. c o m * @param data {@link ByteBuf} where to write the data * @return a {@link Future} representing the task */ public @NotNull Future<Long> receiveAsync(@NotNull ByteBuf data) { return receiveAsync(data, data.writableBytes()); }
From source file:me.melchor9000.net.SocketUtil.java
License:Open Source License
/** * Reads from the socket exactly the number of writable bytes * {@link ByteBuf#writableBytes()} of the buffer into the buffer synchronously. * @param socket Socket to read from/* w w w . j a v a 2 s . co m*/ * @param buffer Buffer to write the data * @throws Throwable If the operation fails */ public static void read(@NotNull Socket socket, @NotNull ByteBuf buffer) throws Throwable { read(socket, buffer, buffer.writableBytes()); }
From source file:me.melchor9000.net.SocketUtil.java
License:Open Source License
/** * Reads from the socket exactly the number of writable bytes * {@link ByteBuf#writableBytes()} of the buffer into the buffer asynchronously. * If there's an error, everything that could read is kept inside the buffer. * @param socket Socket to read from/*www . j av a 2 s .c o m*/ * @param buffer Buffer to write the data * @return a {@link Future} */ public static Future<Long> readAsync(@NotNull Socket socket, @NotNull ByteBuf buffer) { return readAsync(socket, buffer, buffer.writableBytes()); }
From source file:me.melchor9000.net.UDPSocket.java
License:Open Source License
public Packet receiveFrom(ByteBuf data) throws Throwable { return receiveFrom(data, data.writableBytes()); }
From source file:me.melchor9000.net.UDPSocket.java
License:Open Source License
public Future<Packet> receiveAsyncFrom(ByteBuf data) { return receiveAsyncFrom(data, data.writableBytes()); }
From source file:nearenough.protocol.RtWire.java
License:Open Source License
/** * Encode the given message for network transmission using the provided ByteBuf allocator. * * @return A {@link ByteBuf} containing this message encoded for transmission. *//*w w w. jav a2 s . com*/ public static ByteBuf toWire(RtMessage msg, ByteBufAllocator allocator) { checkNotNull(msg, "msg"); checkNotNull(allocator, "allocator"); int encodedSize = computeEncodedSize(msg.mapping()); ByteBuf buf = allocator.buffer(encodedSize); checkState(buf.writableBytes() >= 4, "nonsensical output buf size %s", buf.writableBytes()); writeNumTags(msg, buf); writeOffsets(msg, buf); writeTags(msg, buf); writeValues(msg, buf); // Output buffer should have been completely used checkState(buf.writableBytes() == 0, "message was not completely written"); return buf; }
From source file:net.petercashel.nettyCore.common.packetCore.PacketBase.java
License:Apache License
public void sendPacket(ChannelHandlerContext ctx) { ByteBuf b = ctx.alloc().buffer(Packet.packetBufSize + Packet.packetHeaderSize, Packet.packetBufSize + Packet.packetHeaderSize); b.writeInt(PacketRegistry.GetOtherSide()); b.writeInt(packetID);/*w w w . j av a 2s .c om*/ b.writeBytes(packet); if (b.readableBytes() == (Packet.packetBufSize + Packet.packetHeaderSize)) { ctx.writeAndFlush(b); } else if (b.readableBytes() > (Packet.packetBufSize + Packet.packetHeaderSize)) { System.out.println("INVALID PACKET! DISCARDING!"); } else { b.writeZero(b.writableBytes()); if (b.readableBytes() == (Packet.packetBufSize + Packet.packetHeaderSize)) { ctx.writeAndFlush(b); } else if (b.readableBytes() > (Packet.packetBufSize + Packet.packetHeaderSize)) { System.out.println("INVALID PACKET! DISCARDING!"); } } }
From source file:net.petercashel.nettyCore.common.packetCore.PacketBase.java
License:Apache License
public void sendPacket(Channel c) { ByteBuf b = c.alloc().buffer(Packet.packetBufSize + Packet.packetHeaderSize, Packet.packetBufSize + Packet.packetHeaderSize); b.writeInt(PacketRegistry.GetOtherSide()); b.writeInt(packetID);// w ww .j ava 2 s.c om b.writeBytes(packet); if (b.readableBytes() == (Packet.packetBufSize + Packet.packetHeaderSize)) { c.writeAndFlush(b); } else if (b.readableBytes() > (Packet.packetBufSize + Packet.packetHeaderSize)) { System.out.println("INVALID PACKET! DISCARDING!"); } else { b.writeZero(b.writableBytes()); if (b.readableBytes() == (Packet.packetBufSize + Packet.packetHeaderSize)) { c.writeAndFlush(b); } else if (b.readableBytes() > (Packet.packetBufSize + Packet.packetHeaderSize)) { System.out.println("INVALID PACKET! DISCARDING!"); } } }