Add ByteBuf.isReadOnly()
Motivation: It is sometimes useful to determins if a buffer is read-only. Modifications: Add ByteBuf.isReadOnly() Result: One more feature
This commit is contained in:
parent
57063b6db0
commit
0b078314b2
@ -69,6 +69,11 @@ public abstract class AbstractByteBuf extends ByteBuf {
|
||||
this.maxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxCapacity() {
|
||||
return maxCapacity;
|
||||
|
@ -70,6 +70,11 @@ public abstract class AbstractDerivedByteBuf extends AbstractByteBuf {
|
||||
return unwrap().release(decrement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return unwrap().isReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer internalNioBuffer(int index, int length) {
|
||||
return nioBuffer(index, length);
|
||||
|
@ -295,6 +295,11 @@ public abstract class ByteBuf implements ReferenceCounted, Comparable<ByteBuf> {
|
||||
*/
|
||||
public abstract boolean isDirect();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if and only if this buffer is read-only.
|
||||
*/
|
||||
public abstract boolean isReadOnly();
|
||||
|
||||
/**
|
||||
* Returns the {@code readerIndex} of this buffer.
|
||||
*/
|
||||
|
@ -95,6 +95,11 @@ public final class EmptyByteBuf extends ByteBuf {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirect() {
|
||||
return true;
|
||||
|
@ -50,6 +50,11 @@ public class ReadOnlyByteBuf extends AbstractDerivedByteBuf {
|
||||
setIndex(buffer.readerIndex(), buffer.writerIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable() {
|
||||
return false;
|
||||
|
@ -315,6 +315,11 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return buffer.isReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirect() {
|
||||
return buffer.isDirect();
|
||||
|
@ -92,6 +92,11 @@ public class SwappedByteBuf extends ByteBuf {
|
||||
return buf.maxCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return buf.isReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirect() {
|
||||
return buf.isDirect();
|
||||
|
@ -93,6 +93,11 @@ class WrappedByteBuf extends ByteBuf {
|
||||
return buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return buf.isReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isDirect() {
|
||||
return buf.isDirect();
|
||||
|
@ -39,7 +39,6 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.CompositeByteBuf;
|
||||
import io.netty.buffer.EmptyByteBuf;
|
||||
import io.netty.buffer.ReadOnlyByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@ -127,7 +126,7 @@ public class Http2FrameRoundtripTest {
|
||||
// Now verify that all of the reference counts are zero.
|
||||
for (ByteBuf buf : needReleasing) {
|
||||
int expectedFinalRefCount = 0;
|
||||
if (buf instanceof ReadOnlyByteBuf || buf instanceof EmptyByteBuf) {
|
||||
if (buf.isReadOnly() || buf instanceof EmptyByteBuf) {
|
||||
// Special case for when we're writing slices of the padding buffer.
|
||||
expectedFinalRefCount = 1;
|
||||
}
|
||||
|
@ -88,6 +88,11 @@ final class ReplayingDecoderByteBuf extends ByteBuf {
|
||||
return buffer.alloc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirect() {
|
||||
return buffer.isDirect();
|
||||
|
Loading…
Reference in New Issue
Block a user