@Override public DataBuffer ensureCapacity(int capacity) { this.byteBuf.ensureWritable(capacity); return this; }
@Override public void ensureWritableBytes(int writableBytes) { buffer.ensureWritable(writableBytes); }
@Override public ByteBuf ensureWritable(int writableBytes) { buf.ensureWritable(writableBytes); return this; }
@Override public ByteBuf ensureWritable(int minWritableBytes) { buf.ensureWritable(minWritableBytes); return this; }
@Override public int ensureWritable(int minWritableBytes, boolean force) { return buf.ensureWritable(minWritableBytes, force); }
@Override public int ensureWritable(int minWritableBytes, boolean force) { return buf.ensureWritable(minWritableBytes, force); }
@Override public ByteBuf ensureWritable(int writableBytes) { buf.ensureWritable(writableBytes); return this; }
@Override public ByteBuf ensureWritable(int minWritableBytes) { buf.ensureWritable(minWritableBytes); return this; }
@Override public int ensureWritable(int minWritableBytes, boolean force) { return buf.ensureWritable(minWritableBytes, force); }
@Override public int ensureWritable(int minWritableBytes, boolean force) { return buf.ensureWritable(minWritableBytes, force); }
@Override public DataBuffer ensureCapacity(int capacity) { this.byteBuf.ensureWritable(capacity); return this; }
private void ensureWritable(int pos, int len) { int ni = pos + len; int cap = buffer.capacity(); int over = ni - cap; if (over > 0) { buffer.writerIndex(cap); buffer.ensureWritable(over); } //We have to make sure that the writerindex is always positioned on the last bit of data set in the buffer if (ni > buffer.writerIndex()) { buffer.writerIndex(ni); } }
@Override protected void encode( ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { int bodyLen = msg.readableBytes(); int headerLen = computeRawVarint32Size(bodyLen); out.ensureWritable(headerLen + bodyLen); writeRawVarint32(out, bodyLen); out.writeBytes(msg, msg.readerIndex(), bodyLen); }
@Override public ChannelFuture sendPing(ChannelHandlerContext ctx) { final ByteBuf newBuff = ctx.alloc().buffer(); newBuff.ensureWritable(SSE_PING.length()); newBuff.writeCharSequence(SSE_PING, Charsets.UTF_8); return ctx.channel().writeAndFlush(newBuff); }
@Override public ChannelFuture sendPushMessage(ChannelHandlerContext ctx, ByteBuf mesg) { final ByteBuf newBuff = ctx.alloc().buffer(); newBuff.ensureWritable(SSE_PREAMBLE.length()); newBuff.writeCharSequence(SSE_PREAMBLE, Charsets.UTF_8); newBuff.ensureWritable(mesg.writableBytes()); newBuff.writeBytes(mesg); newBuff.ensureWritable(SSE_TERMINATION.length()); newBuff.writeCharSequence(SSE_TERMINATION, Charsets.UTF_8); mesg.release(); return ctx.channel().writeAndFlush(newBuff); }
@Override protected void encode( ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { int bodyLen = msg.readableBytes(); int headerLen = computeRawVarint32Size(bodyLen); out.ensureWritable(headerLen + bodyLen); writeRawVarint32(out, bodyLen); out.writeBytes(msg, msg.readerIndex(), bodyLen); }
private static boolean attemptCopyToCumulation(ByteBuf cumulation, ByteBuf next, int wrapDataSize) { final int inReadableBytes = next.readableBytes(); final int cumulationCapacity = cumulation.capacity(); if (wrapDataSize - cumulation.readableBytes() >= inReadableBytes && // Avoid using the same buffer if next's data would make cumulation exceed the wrapDataSize. // Only copy if there is enough space available and the capacity is large enough, and attempt to // resize if the capacity is small. (cumulation.isWritable(inReadableBytes) && cumulationCapacity >= wrapDataSize || cumulationCapacity < wrapDataSize && ensureWritableSuccess(cumulation.ensureWritable(inReadableBytes, false)))) { cumulation.writeBytes(next); next.release(); return true; } return false; }
static void encoderHeader(CharSequence name, CharSequence value, ByteBuf buf) { final int nameLen = name.length(); final int valueLen = value.length(); final int entryLen = nameLen + valueLen + 4; buf.ensureWritable(entryLen); int offset = buf.writerIndex(); writeAscii(buf, offset, name); offset += nameLen; ByteBufUtil.setShortBE(buf, offset, COLON_AND_SPACE_SHORT); offset += 2; writeAscii(buf, offset, value); offset += valueLen; ByteBufUtil.setShortBE(buf, offset, CRLF_SHORT); offset += 2; buf.writerIndex(offset); }
@Override public ChannelFuture sendPushMessage(ChannelHandlerContext ctx, ByteBuf mesg) { final ByteBuf newBuff = ctx.alloc().buffer(); newBuff.ensureWritable(SSE_PREAMBLE.length()); newBuff.writeCharSequence(SSE_PREAMBLE, Charsets.UTF_8); newBuff.ensureWritable(mesg.writableBytes()); newBuff.writeBytes(mesg); newBuff.ensureWritable(SSE_TERMINATION.length()); newBuff.writeCharSequence(SSE_TERMINATION, Charsets.UTF_8); mesg.release(); return ctx.channel().writeAndFlush(newBuff); }
@Override public ChannelFuture sendPing(ChannelHandlerContext ctx) { final ByteBuf newBuff = ctx.alloc().buffer(); newBuff.ensureWritable(SSE_PING.length()); newBuff.writeCharSequence(SSE_PING, Charsets.UTF_8); return ctx.channel().writeAndFlush(newBuff); }