Implement the ByteBuf methods that should have been overridden

Motivation:

Some ByteBuf implementations do not override all necessary methods,
which can lead to potentially sub-optimal behavior.

Also, SlicedByteBuf does not perform the range check correctly due to
missing overrides.

Modifications:

- Add missing overrides
- Use unwrap() instead of direct member access in derived buffers for
  consistency
- Merge unwrap0() into unwrap() using covariant return type
- Deprecate AbstractDerivedByteBuf and its subtypes, because they were
  not meant to be public

Result:

Correctness
This commit is contained in:
Trustin Lee 2016-04-13 20:34:39 +09:00
parent 6fc05772d0
commit bb3bf5dc2f
9 changed files with 252 additions and 155 deletions

View File

@ -21,7 +21,10 @@ import java.nio.ByteBuffer;
/**
* Abstract base class for {@link ByteBuf} implementations that wrap another
* {@link ByteBuf}.
*
* @deprecated Do not use.
*/
@Deprecated
public abstract class AbstractDerivedByteBuf extends AbstractByteBuf {
protected AbstractDerivedByteBuf(int maxCapacity) {

View File

@ -20,61 +20,63 @@ package io.netty.buffer;
* is of type {@link AbstractByteBuf}.
*/
final class DuplicatedAbstractByteBuf extends DuplicatedByteBuf {
public DuplicatedAbstractByteBuf(AbstractByteBuf buffer) {
DuplicatedAbstractByteBuf(AbstractByteBuf buffer) {
super(buffer);
}
@Override
public AbstractByteBuf unwrap() {
return (AbstractByteBuf) super.unwrap();
}
@Override
protected byte _getByte(int index) {
return unwrap0()._getByte(index);
return unwrap()._getByte(index);
}
@Override
protected short _getShort(int index) {
return unwrap0()._getShort(index);
return unwrap()._getShort(index);
}
@Override
protected int _getUnsignedMedium(int index) {
return unwrap0()._getUnsignedMedium(index);
return unwrap()._getUnsignedMedium(index);
}
@Override
protected int _getInt(int index) {
return unwrap0()._getInt(index);
return unwrap()._getInt(index);
}
@Override
protected long _getLong(int index) {
return unwrap0()._getLong(index);
return unwrap()._getLong(index);
}
@Override
protected void _setByte(int index, int value) {
unwrap0()._setByte(index, value);
unwrap()._setByte(index, value);
}
@Override
protected void _setShort(int index, int value) {
unwrap0()._setShort(index, value);
unwrap()._setShort(index, value);
}
@Override
protected void _setMedium(int index, int value) {
unwrap0()._setMedium(index, value);
unwrap()._setMedium(index, value);
}
@Override
protected void _setInt(int index, int value) {
unwrap0()._setInt(index, value);
unwrap()._setInt(index, value);
}
@Override
protected void _setLong(int index, long value) {
unwrap0()._setLong(index, value);
unwrap()._setLong(index, value);
}
private AbstractByteBuf unwrap0() {
return (AbstractByteBuf) unwrap();
}
}

View File

@ -23,12 +23,14 @@ import java.nio.ByteOrder;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
/**
* A derived buffer which simply forwards all data access requests to its
* parent. It is recommended to use {@link ByteBuf#duplicate()} instead
* of calling the constructor explicitly.
*
* @deprecated Do not use.
*/
@Deprecated
public class DuplicatedByteBuf extends AbstractDerivedByteBuf {
private final ByteBuf buffer;
@ -54,254 +56,250 @@ public class DuplicatedByteBuf extends AbstractDerivedByteBuf {
@Override
public ByteBufAllocator alloc() {
return buffer.alloc();
return unwrap().alloc();
}
@Override
@Deprecated
public ByteOrder order() {
return buffer.order();
return unwrap().order();
}
@Override
public boolean isDirect() {
return buffer.isDirect();
return unwrap().isDirect();
}
@Override
public int capacity() {
return buffer.capacity();
return unwrap().capacity();
}
@Override
public ByteBuf capacity(int newCapacity) {
buffer.capacity(newCapacity);
unwrap().capacity(newCapacity);
return this;
}
@Override
public boolean hasArray() {
return buffer.hasArray();
return unwrap().hasArray();
}
@Override
public byte[] array() {
return buffer.array();
return unwrap().array();
}
@Override
public int arrayOffset() {
return buffer.arrayOffset();
return unwrap().arrayOffset();
}
@Override
public boolean hasMemoryAddress() {
return buffer.hasMemoryAddress();
return unwrap().hasMemoryAddress();
}
@Override
public long memoryAddress() {
return buffer.memoryAddress();
return unwrap().memoryAddress();
}
@Override
public byte getByte(int index) {
return buffer.getByte(index);
return unwrap().getByte(index);
}
@Override
protected byte _getByte(int index) {
return buffer.getByte(index);
return unwrap().getByte(index);
}
@Override
public short getShort(int index) {
return buffer.getShort(index);
return unwrap().getShort(index);
}
@Override
protected short _getShort(int index) {
return buffer.getShort(index);
return unwrap().getShort(index);
}
@Override
public int getUnsignedMedium(int index) {
return buffer.getUnsignedMedium(index);
return unwrap().getUnsignedMedium(index);
}
@Override
protected int _getUnsignedMedium(int index) {
return buffer.getUnsignedMedium(index);
return unwrap().getUnsignedMedium(index);
}
@Override
public int getInt(int index) {
return buffer.getInt(index);
return unwrap().getInt(index);
}
@Override
protected int _getInt(int index) {
return buffer.getInt(index);
return unwrap().getInt(index);
}
@Override
public long getLong(int index) {
return buffer.getLong(index);
return unwrap().getLong(index);
}
@Override
protected long _getLong(int index) {
return buffer.getLong(index);
return unwrap().getLong(index);
}
@Override
public ByteBuf copy(int index, int length) {
return buffer.copy(index, length);
return unwrap().copy(index, length);
}
@Override
public ByteBuf slice(int index, int length) {
return buffer.slice(index, length);
return unwrap().slice(index, length);
}
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
buffer.getBytes(index, dst, dstIndex, length);
unwrap().getBytes(index, dst, dstIndex, length);
return this;
}
@Override
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
buffer.getBytes(index, dst, dstIndex, length);
unwrap().getBytes(index, dst, dstIndex, length);
return this;
}
@Override
public ByteBuf getBytes(int index, ByteBuffer dst) {
buffer.getBytes(index, dst);
unwrap().getBytes(index, dst);
return this;
}
@Override
public ByteBuf setByte(int index, int value) {
buffer.setByte(index, value);
unwrap().setByte(index, value);
return this;
}
@Override
protected void _setByte(int index, int value) {
buffer.setByte(index, value);
unwrap().setByte(index, value);
}
@Override
public ByteBuf setShort(int index, int value) {
buffer.setShort(index, value);
unwrap().setShort(index, value);
return this;
}
@Override
protected void _setShort(int index, int value) {
buffer.setShort(index, value);
unwrap().setShort(index, value);
}
@Override
public ByteBuf setMedium(int index, int value) {
buffer.setMedium(index, value);
unwrap().setMedium(index, value);
return this;
}
@Override
protected void _setMedium(int index, int value) {
buffer.setMedium(index, value);
unwrap().setMedium(index, value);
}
@Override
public ByteBuf setInt(int index, int value) {
buffer.setInt(index, value);
unwrap().setInt(index, value);
return this;
}
@Override
protected void _setInt(int index, int value) {
buffer.setInt(index, value);
unwrap().setInt(index, value);
}
@Override
public ByteBuf setLong(int index, long value) {
buffer.setLong(index, value);
unwrap().setLong(index, value);
return this;
}
@Override
protected void _setLong(int index, long value) {
buffer.setLong(index, value);
unwrap().setLong(index, value);
}
@Override
public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
buffer.setBytes(index, src, srcIndex, length);
unwrap().setBytes(index, src, srcIndex, length);
return this;
}
@Override
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
buffer.setBytes(index, src, srcIndex, length);
unwrap().setBytes(index, src, srcIndex, length);
return this;
}
@Override
public ByteBuf setBytes(int index, ByteBuffer src) {
buffer.setBytes(index, src);
unwrap().setBytes(index, src);
return this;
}
@Override
public ByteBuf getBytes(int index, OutputStream out, int length)
throws IOException {
buffer.getBytes(index, out, length);
unwrap().getBytes(index, out, length);
return this;
}
@Override
public int getBytes(int index, GatheringByteChannel out, int length)
throws IOException {
return buffer.getBytes(index, out, length);
return unwrap().getBytes(index, out, length);
}
@Override
public int setBytes(int index, InputStream in, int length)
throws IOException {
return buffer.setBytes(index, in, length);
return unwrap().setBytes(index, in, length);
}
@Override
public int setBytes(int index, ScatteringByteChannel in, int length)
throws IOException {
return buffer.setBytes(index, in, length);
return unwrap().setBytes(index, in, length);
}
@Override
public int nioBufferCount() {
return buffer.nioBufferCount();
return unwrap().nioBufferCount();
}
@Override
public ByteBuffer[] nioBuffers(int index, int length) {
return buffer.nioBuffers(index, length);
}
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
return nioBuffer(index, length);
return unwrap().nioBuffers(index, length);
}
@Override
public int forEachByte(int index, int length, ByteBufProcessor processor) {
return buffer.forEachByte(index, length, processor);
return unwrap().forEachByte(index, length, processor);
}
@Override
public int forEachByteDesc(int index, int length, ByteBufProcessor processor) {
return buffer.forEachByteDesc(index, length, processor);
return unwrap().forEachByteDesc(index, length, processor);
}
}

View File

@ -1,7 +1,9 @@
/*
* Copyright 2015 The Netty Project
*
* The Netty Project licenses this file tothe License at:
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -92,6 +94,7 @@ final class PooledUnsafeHeapByteBuf extends PooledHeapByteBuf {
}
@Override
@Deprecated
protected SwappedByteBuf newSwappedByteBuf() {
if (PlatformDependent.isUnaligned()) {
// Only use if unaligned access is supported otherwise there is no gain.

View File

@ -28,7 +28,10 @@ import java.nio.channels.ScatteringByteChannel;
* A derived buffer which forbids any write requests to its parent. It is
* recommended to use {@link Unpooled#unmodifiableBuffer(ByteBuf)}
* instead of calling the constructor explicitly.
*
* @deprecated Do not use.
*/
@Deprecated
public class ReadOnlyByteBuf extends AbstractDerivedByteBuf {
private final ByteBuf buffer;
@ -61,17 +64,18 @@ public class ReadOnlyByteBuf extends AbstractDerivedByteBuf {
@Override
public ByteBufAllocator alloc() {
return buffer.alloc();
return unwrap().alloc();
}
@Override
@Deprecated
public ByteOrder order() {
return buffer.order();
return unwrap().order();
}
@Override
public boolean isDirect() {
return buffer.isDirect();
return unwrap().isDirect();
}
@Override
@ -182,31 +186,31 @@ public class ReadOnlyByteBuf extends AbstractDerivedByteBuf {
@Override
public int getBytes(int index, GatheringByteChannel out, int length)
throws IOException {
return buffer.getBytes(index, out, length);
return unwrap().getBytes(index, out, length);
}
@Override
public ByteBuf getBytes(int index, OutputStream out, int length)
throws IOException {
buffer.getBytes(index, out, length);
unwrap().getBytes(index, out, length);
return this;
}
@Override
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
buffer.getBytes(index, dst, dstIndex, length);
unwrap().getBytes(index, dst, dstIndex, length);
return this;
}
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
buffer.getBytes(index, dst, dstIndex, length);
unwrap().getBytes(index, dst, dstIndex, length);
return this;
}
@Override
public ByteBuf getBytes(int index, ByteBuffer dst) {
buffer.getBytes(index, dst);
unwrap().getBytes(index, dst);
return this;
}
@ -217,97 +221,92 @@ public class ReadOnlyByteBuf extends AbstractDerivedByteBuf {
@Override
public ByteBuf copy(int index, int length) {
return buffer.copy(index, length);
return unwrap().copy(index, length);
}
@Override
public ByteBuf slice(int index, int length) {
return Unpooled.unmodifiableBuffer(buffer.slice(index, length));
return Unpooled.unmodifiableBuffer(unwrap().slice(index, length));
}
@Override
public byte getByte(int index) {
return _getByte(index);
return unwrap().getByte(index);
}
@Override
protected byte _getByte(int index) {
return buffer.getByte(index);
return unwrap().getByte(index);
}
@Override
public short getShort(int index) {
return _getShort(index);
return unwrap().getShort(index);
}
@Override
protected short _getShort(int index) {
return buffer.getShort(index);
return unwrap().getShort(index);
}
@Override
public int getUnsignedMedium(int index) {
return _getUnsignedMedium(index);
return unwrap().getUnsignedMedium(index);
}
@Override
protected int _getUnsignedMedium(int index) {
return buffer.getUnsignedMedium(index);
return unwrap().getUnsignedMedium(index);
}
@Override
public int getInt(int index) {
return _getInt(index);
return unwrap().getInt(index);
}
@Override
protected int _getInt(int index) {
return buffer.getInt(index);
return unwrap().getInt(index);
}
@Override
public long getLong(int index) {
return _getLong(index);
return unwrap().getLong(index);
}
@Override
protected long _getLong(int index) {
return buffer.getLong(index);
return unwrap().getLong(index);
}
@Override
public int nioBufferCount() {
return buffer.nioBufferCount();
return unwrap().nioBufferCount();
}
@Override
public ByteBuffer nioBuffer(int index, int length) {
return buffer.nioBuffer(index, length).asReadOnlyBuffer();
return unwrap().nioBuffer(index, length).asReadOnlyBuffer();
}
@Override
public ByteBuffer[] nioBuffers(int index, int length) {
return buffer.nioBuffers(index, length);
}
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
return nioBuffer(index, length);
return unwrap().nioBuffers(index, length);
}
@Override
public int forEachByte(int index, int length, ByteBufProcessor processor) {
return buffer.forEachByte(index, length, processor);
return unwrap().forEachByte(index, length, processor);
}
@Override
public int forEachByteDesc(int index, int length, ByteBufProcessor processor) {
return buffer.forEachByteDesc(index, length, processor);
return unwrap().forEachByteDesc(index, length, processor);
}
@Override
public int capacity() {
return buffer.capacity();
return unwrap().capacity();
}
@Override

View File

@ -80,7 +80,9 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
@Override
protected int _getUnsignedMedium(int index) {
return (getByte(index) & 0xff) << 16 | (getByte(index + 1) & 0xff) << 8 | getByte(index + 2) & 0xff;
return (getByte(index) & 0xff) << 16 |
(getByte(index + 1) & 0xff) << 8 |
getByte(index + 2) & 0xff;
}
@Override
@ -151,26 +153,51 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
return this;
}
@Override
public ByteBuf setByte(int index, int value) {
throw new ReadOnlyBufferException();
}
@Override
protected void _setByte(int index, int value) {
throw new ReadOnlyBufferException();
}
@Override
public ByteBuf setShort(int index, int value) {
throw new ReadOnlyBufferException();
}
@Override
protected void _setShort(int index, int value) {
throw new ReadOnlyBufferException();
}
@Override
public ByteBuf setMedium(int index, int value) {
throw new ReadOnlyBufferException();
}
@Override
protected void _setMedium(int index, int value) {
throw new ReadOnlyBufferException();
}
@Override
public ByteBuf setInt(int index, int value) {
throw new ReadOnlyBufferException();
}
@Override
protected void _setInt(int index, int value) {
throw new ReadOnlyBufferException();
}
@Override
public ByteBuf setLong(int index, long value) {
throw new ReadOnlyBufferException();
}
@Override
protected void _setLong(int index, long value) {
throw new ReadOnlyBufferException();

View File

@ -25,57 +25,59 @@ final class SlicedAbstractByteBuf extends SlicedByteBuf {
super(buffer, index, length);
}
@Override
public AbstractByteBuf unwrap() {
return (AbstractByteBuf) super.unwrap();
}
@Override
protected byte _getByte(int index) {
return unwrap0()._getByte(idx(index));
return unwrap()._getByte(idx(index));
}
@Override
protected short _getShort(int index) {
return unwrap0()._getShort(idx(index));
return unwrap()._getShort(idx(index));
}
@Override
protected int _getUnsignedMedium(int index) {
return unwrap0()._getUnsignedMedium(idx(index));
return unwrap()._getUnsignedMedium(idx(index));
}
@Override
protected int _getInt(int index) {
return unwrap0()._getInt(idx(index));
return unwrap()._getInt(idx(index));
}
@Override
protected long _getLong(int index) {
return unwrap0()._getLong(idx(index));
return unwrap()._getLong(idx(index));
}
@Override
protected void _setByte(int index, int value) {
unwrap0()._setByte(idx(index), value);
unwrap()._setByte(idx(index), value);
}
@Override
protected void _setShort(int index, int value) {
unwrap0()._setShort(idx(index), value);
unwrap()._setShort(idx(index), value);
}
@Override
protected void _setMedium(int index, int value) {
unwrap0()._setMedium(idx(index), value);
unwrap()._setMedium(idx(index), value);
}
@Override
protected void _setInt(int index, int value) {
unwrap0()._setInt(idx(index), value);
unwrap()._setInt(idx(index), value);
}
@Override
protected void _setLong(int index, long value) {
unwrap0()._setLong(idx(index), value);
unwrap()._setLong(idx(index), value);
}
private AbstractByteBuf unwrap0() {
return (AbstractByteBuf) unwrap();
}
}

View File

@ -23,13 +23,15 @@ import java.nio.ByteOrder;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
/**
* A derived buffer which exposes its parent's sub-region only. It is
* recommended to use {@link ByteBuf#slice()} and
* {@link ByteBuf#slice(int, int)} instead of calling the constructor
* explicitly.
*
* @deprecated Do not use.
*/
@Deprecated
public class SlicedByteBuf extends AbstractDerivedByteBuf {
private final ByteBuf buffer;
@ -64,17 +66,18 @@ public class SlicedByteBuf extends AbstractDerivedByteBuf {
@Override
public ByteBufAllocator alloc() {
return buffer.alloc();
return unwrap().alloc();
}
@Override
@Deprecated
public ByteOrder order() {
return buffer.order();
return unwrap().order();
}
@Override
public boolean isDirect() {
return buffer.isDirect();
return unwrap().isDirect();
}
@Override
@ -89,57 +92,87 @@ public class SlicedByteBuf extends AbstractDerivedByteBuf {
@Override
public boolean hasArray() {
return buffer.hasArray();
return unwrap().hasArray();
}
@Override
public byte[] array() {
return buffer.array();
return unwrap().array();
}
@Override
public int arrayOffset() {
return idx(buffer.arrayOffset());
return idx(unwrap().arrayOffset());
}
@Override
public boolean hasMemoryAddress() {
return buffer.hasMemoryAddress();
return unwrap().hasMemoryAddress();
}
@Override
public long memoryAddress() {
return buffer.memoryAddress() + adjustment;
return unwrap().memoryAddress() + adjustment;
}
@Override
public byte getByte(int index) {
checkIndex0(index, 1);
return unwrap().getByte(idx(index));
}
@Override
protected byte _getByte(int index) {
return buffer.getByte(idx(index));
return unwrap().getByte(idx(index));
}
@Override
public short getShort(int index) {
checkIndex0(index, 2);
return unwrap().getShort(idx(index));
}
@Override
protected short _getShort(int index) {
return buffer.getShort(idx(index));
return unwrap().getShort(idx(index));
}
@Override
public int getUnsignedMedium(int index) {
checkIndex0(index, 3);
return unwrap().getUnsignedMedium(idx(index));
}
@Override
protected int _getUnsignedMedium(int index) {
return buffer.getUnsignedMedium(idx(index));
return unwrap().getUnsignedMedium(idx(index));
}
@Override
public int getInt(int index) {
checkIndex0(index, 4);
return unwrap().getInt(idx(index));
}
@Override
protected int _getInt(int index) {
return buffer.getInt(idx(index));
return unwrap().getInt(idx(index));
}
@Override
public long getLong(int index) {
checkIndex0(index, 8);
return unwrap().getLong(idx(index));
}
@Override
protected long _getLong(int index) {
return buffer.getLong(idx(index));
return unwrap().getLong(idx(index));
}
@Override
public ByteBuf duplicate() {
ByteBuf duplicate = buffer.slice(adjustment, length);
final ByteBuf duplicate = unwrap().slice(adjustment, length);
duplicate.setIndex(readerIndex(), writerIndex());
return duplicate;
}
@ -147,133 +180,163 @@ public class SlicedByteBuf extends AbstractDerivedByteBuf {
@Override
public ByteBuf copy(int index, int length) {
checkIndex0(index, length);
return buffer.copy(idx(index), length);
return unwrap().copy(idx(index), length);
}
@Override
public ByteBuf slice(int index, int length) {
checkIndex0(index, length);
return buffer.slice(idx(index), length);
return unwrap().slice(idx(index), length);
}
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
checkIndex0(index, length);
buffer.getBytes(idx(index), dst, dstIndex, length);
unwrap().getBytes(idx(index), dst, dstIndex, length);
return this;
}
@Override
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
checkIndex0(index, length);
buffer.getBytes(idx(index), dst, dstIndex, length);
unwrap().getBytes(idx(index), dst, dstIndex, length);
return this;
}
@Override
public ByteBuf getBytes(int index, ByteBuffer dst) {
checkIndex0(index, dst.remaining());
buffer.getBytes(idx(index), dst);
unwrap().getBytes(idx(index), dst);
return this;
}
@Override
public ByteBuf setByte(int index, int value) {
checkIndex0(index, 1);
unwrap().setByte(idx(index), value);
return this;
}
@Override
protected void _setByte(int index, int value) {
buffer.setByte(idx(index), value);
unwrap().setByte(idx(index), value);
}
@Override
public ByteBuf setShort(int index, int value) {
checkIndex0(index, 2);
unwrap().setShort(idx(index), value);
return this;
}
@Override
protected void _setShort(int index, int value) {
buffer.setShort(idx(index), value);
unwrap().setShort(idx(index), value);
}
@Override
public ByteBuf setMedium(int index, int value) {
checkIndex0(index, 3);
unwrap().setMedium(idx(index), value);
return this;
}
@Override
protected void _setMedium(int index, int value) {
buffer.setMedium(idx(index), value);
unwrap().setMedium(idx(index), value);
}
@Override
public ByteBuf setInt(int index, int value) {
checkIndex0(index, 4);
unwrap().setInt(idx(index), value);
return this;
}
@Override
protected void _setInt(int index, int value) {
buffer.setInt(idx(index), value);
unwrap().setInt(idx(index), value);
}
@Override
public ByteBuf setLong(int index, long value) {
checkIndex0(index, 8);
unwrap().setLong(idx(index), value);
return this;
}
@Override
protected void _setLong(int index, long value) {
buffer.setLong(idx(index), value);
unwrap().setLong(idx(index), value);
}
@Override
public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
checkIndex0(index, length);
buffer.setBytes(idx(index), src, srcIndex, length);
unwrap().setBytes(idx(index), src, srcIndex, length);
return this;
}
@Override
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
checkIndex0(index, length);
buffer.setBytes(idx(index), src, srcIndex, length);
unwrap().setBytes(idx(index), src, srcIndex, length);
return this;
}
@Override
public ByteBuf setBytes(int index, ByteBuffer src) {
checkIndex0(index, src.remaining());
buffer.setBytes(idx(index), src);
unwrap().setBytes(idx(index), src);
return this;
}
@Override
public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException {
checkIndex0(index, length);
buffer.getBytes(idx(index), out, length);
unwrap().getBytes(idx(index), out, length);
return this;
}
@Override
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
checkIndex0(index, length);
return buffer.getBytes(idx(index), out, length);
return unwrap().getBytes(idx(index), out, length);
}
@Override
public int setBytes(int index, InputStream in, int length) throws IOException {
checkIndex0(index, length);
return buffer.setBytes(idx(index), in, length);
return unwrap().setBytes(idx(index), in, length);
}
@Override
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
checkIndex0(index, length);
return buffer.setBytes(idx(index), in, length);
return unwrap().setBytes(idx(index), in, length);
}
@Override
public int nioBufferCount() {
return buffer.nioBufferCount();
return unwrap().nioBufferCount();
}
@Override
public ByteBuffer nioBuffer(int index, int length) {
checkIndex0(index, length);
return buffer.nioBuffer(idx(index), length);
return unwrap().nioBuffer(idx(index), length);
}
@Override
public ByteBuffer[] nioBuffers(int index, int length) {
checkIndex0(index, length);
return buffer.nioBuffers(idx(index), length);
}
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
return nioBuffer(index, length);
return unwrap().nioBuffers(idx(index), length);
}
@Override
public int forEachByte(int index, int length, ByteBufProcessor processor) {
checkIndex0(index, length);
int ret = buffer.forEachByte(idx(index), length, processor);
int ret = unwrap().forEachByte(idx(index), length, processor);
if (ret >= adjustment) {
return ret - adjustment;
} else {
@ -284,7 +347,7 @@ public class SlicedByteBuf extends AbstractDerivedByteBuf {
@Override
public int forEachByteDesc(int index, int length, ByteBufProcessor processor) {
checkIndex0(index, length);
int ret = buffer.forEachByteDesc(idx(index), length, processor);
int ret = unwrap().forEachByteDesc(idx(index), length, processor);
if (ret >= adjustment) {
return ret - adjustment;
} else {

View File

@ -15,7 +15,6 @@
*/
package io.netty.buffer;
import io.netty.util.internal.PlatformDependent;
final class UnpooledUnsafeHeapByteBuf extends UnpooledHeapByteBuf {
@ -146,6 +145,7 @@ final class UnpooledUnsafeHeapByteBuf extends UnpooledHeapByteBuf {
}
@Override
@Deprecated
protected SwappedByteBuf newSwappedByteBuf() {
if (PlatformDependent.isUnaligned()) {
// Only use if unaligned access is supported otherwise there is no gain.