@Override public int getInt(int index) { checkIndex(index, 4); return _getInt(index); }
@Override public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length) { ensureWritable(length); setBytes(writerIndex, src, srcIndex, length); writerIndex += length; return this; }
private static long addr(AbstractByteBuf wrapped, int index) { // We need to call wrapped.memoryAddress() everytime and NOT cache it as it may change if the buffer expand. // See: // - https://github.com/netty/netty/issues/2587 // - https://github.com/netty/netty/issues/2580 return wrapped.memoryAddress() + index; }
@Override public ByteBuf readerIndex(int readerIndex) { if (checkBounds) { checkIndexBounds(readerIndex, writerIndex, capacity()); } this.readerIndex = readerIndex; return this; }
@Override public ByteBuf setShortLE(int index, int value) { checkIndex(index, 2); _setShortLE(index, value); return this; }
@Override public int ensureWritable(int minWritableBytes, boolean force) { ensureAccessible(); checkPositiveOrZero(minWritableBytes, "minWritableBytes"); if (minWritableBytes <= writableBytes()) { return 0; } final int maxCapacity = maxCapacity(); final int writerIndex = writerIndex(); if (minWritableBytes > maxCapacity - writerIndex) { if (!force || capacity() == maxCapacity) { return 1; } capacity(maxCapacity); return 3; } // Normalize the current capacity to the power of 2. int newCapacity = alloc().calculateNewCapacity(writerIndex + minWritableBytes, maxCapacity); // Adjust to the new capacity. capacity(newCapacity); return 2; }
@Override public int bytesBefore(int length, byte value) { checkReadableBytes(length); return bytesBefore(readerIndex(), length, value); }
@Override public int bytesBefore(byte value) { return bytesBefore(readerIndex(), readableBytes(), value); }
@Override public ByteBuf order(ByteOrder endianness) { if (endianness == order()) { return this; } if (endianness == null) { throw new NullPointerException("endianness"); } return newSwappedByteBuf(); }
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); }
private UnsafeDirectLittleEndian(AbstractByteBuf buf, boolean fake, AtomicLong bufferCount, AtomicLong bufferSize) { super(buf); if (!NATIVE_ORDER || buf.order() != ByteOrder.BIG_ENDIAN) { throw new IllegalStateException("Drill only runs on LittleEndian systems."); } this.bufferCount = bufferCount; this.bufferSize = bufferSize; // initCap is used if we're tracking memory release. If we're in non-debug mode, we'll skip this. this.initCap = ASSERT_ENABLED ? buf.capacity() : -1; this.wrapped = buf; this.memoryAddress = buf.memoryAddress(); }
@Override public ByteBuf setIndex(int readerIndex, int writerIndex) { if (checkBounds) { checkIndexBounds(readerIndex, writerIndex, capacity()); } setIndex0(readerIndex, writerIndex); return this; }
@Override public int getIntLE(int index) { checkIndex(index, 4); return _getIntLE(index); }
@Override public byte getByte(int index) { checkIndex(index); return _getByte(index); }
@Override public long getLong(int index) { checkIndex(index, 8); return _getLong(index); }
@Override public ByteBuf setInt(int index, int value) { checkIndex(index, 4); _setInt(index, value); return this; }
@Override public ByteBuf setIntLE(int index, int value) { checkIndex(index, 4); _setIntLE(index, value); return this; }
@Override @Deprecated public final ByteOrder order() { return unwrap().order(); }
@Override public int forEachByte(int index, int length, ByteProcessor processor) { checkIndex(index, length); try { return forEachByteAsc0(index, index + length, processor); } catch (Exception e) { PlatformDependent.throwException(e); return -1; } }
@Override public int forEachByteDesc(int index, int length, ByteProcessor processor) { checkIndex(index, length); try { return forEachByteDesc0(index + length - 1, index, processor); } catch (Exception e) { PlatformDependent.throwException(e); return -1; } }