@Override public boolean isWritable(int numBytes) { return capacity() - writerIndex >= numBytes; }
@Override public boolean isWritable() { return capacity() > writerIndex; }
@Override public int writableBytes() { return capacity() - writerIndex; }
@Override public boolean isWritable(int numBytes) { return capacity() - writerIndex >= numBytes; }
@Override public int writableBytes() { return capacity() - writerIndex; }
@Override public ByteBuf readerIndex(int readerIndex) { if (checkBounds) { checkIndexBounds(readerIndex, writerIndex, capacity()); } this.readerIndex = readerIndex; return this; }
@Override public ByteBuf writerIndex(int writerIndex) { if (checkBounds) { checkIndexBounds(readerIndex, writerIndex, capacity()); } this.writerIndex = writerIndex; return this; }
final void checkIndex0(int index, int fieldLength) { if (checkBounds) { checkRangeBounds(index, fieldLength, capacity()); } }
@Override public ByteBuf capacity(int newCapacity) { unwrap().capacity(newCapacity); return this; }
@Override public int capacity() { return unwrap().capacity(); }
final void checkIndex0(int index, int fieldLength) { if (checkBounds) { checkRangeBounds(index, fieldLength, capacity()); } }
@Override public ByteBuf capacity(int newCapacity) { unwrap().capacity(newCapacity); return this; }
@Override public ByteBuf writerIndex(int writerIndex) { if (checkBounds) { checkIndexBounds(readerIndex, writerIndex, capacity()); } this.writerIndex = writerIndex; return this; }
@Override public ByteBuf readerIndex(int readerIndex) { if (checkBounds) { checkIndexBounds(readerIndex, writerIndex, capacity()); } this.readerIndex = readerIndex; return this; }
@Override public int capacity() { return unwrap().capacity(); }
@Override public String toString() { if (refCnt() == 0) { return StringUtil.simpleClassName(this) + "(freed)"; } StringBuilder buf = new StringBuilder() .append(StringUtil.simpleClassName(this)) .append("(ridx: ").append(readerIndex) .append(", widx: ").append(writerIndex) .append(", cap: ").append(capacity()); if (maxCapacity != Integer.MAX_VALUE) { buf.append('/').append(maxCapacity); } ByteBuf unwrapped = unwrap(); if (unwrapped != null) { buf.append(", unwrapped: ").append(unwrapped); } buf.append(')'); return buf.toString(); }
@Override public ByteBuf setIndex(int readerIndex, int writerIndex) { if (checkBounds) { checkIndexBounds(readerIndex, writerIndex, capacity()); } setIndex0(readerIndex, writerIndex); return this; }
@Override public ByteBuf setIndex(int readerIndex, int writerIndex) { if (checkBounds) { checkIndexBounds(readerIndex, writerIndex, capacity()); } setIndex0(readerIndex, writerIndex); return this; }
final void ensureWritable0(int minWritableBytes) { ensureAccessible(); if (minWritableBytes <= writableBytes()) { return; } if (checkBounds) { if (minWritableBytes > maxCapacity - writerIndex) { throw new IndexOutOfBoundsException(String.format( "writerIndex(%d) + minWritableBytes(%d) exceeds maxCapacity(%d): %s", writerIndex, minWritableBytes, maxCapacity, this)); } } // Normalize the current capacity to the power of 2. int newCapacity = alloc().calculateNewCapacity(writerIndex + minWritableBytes, maxCapacity); // Adjust to the new capacity. capacity(newCapacity); }
@Override public ByteBuf discardSomeReadBytes() { ensureAccessible(); if (readerIndex == 0) { return this; } if (readerIndex == writerIndex) { adjustMarkers(readerIndex); writerIndex = readerIndex = 0; return this; } if (readerIndex >= capacity() >>> 1) { setBytes(0, this, readerIndex, writerIndex - readerIndex); writerIndex -= readerIndex; adjustMarkers(readerIndex); readerIndex = 0; } return this; }