Replace .readable() and .writable() to .isReadable() and .isWritable()

This commit is contained in:
Trustin Lee 2013-01-31 23:39:57 +09:00 committed by Norman Maurer
parent 42c65cca3a
commit 2ec932798f
28 changed files with 125 additions and 123 deletions

View File

@ -473,7 +473,7 @@ public abstract class AbstractByteBufTest {
@Test
public void testSetZero() {
buffer.clear();
while (buffer.writable()) {
while (buffer.isWritable()) {
buffer.writeByte((byte) 0xFF);
}
@ -494,26 +494,26 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity(); i ++) {
byte value = (byte) random.nextInt();
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeByte(value);
}
assertEquals(0, buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.writable());
assertFalse(buffer.isWritable());
random.setSeed(seed);
for (int i = 0; i < buffer.capacity(); i ++) {
byte value = (byte) random.nextInt();
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readByte());
}
assertEquals(buffer.capacity(), buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.readable());
assertFalse(buffer.writable());
assertFalse(buffer.isReadable());
assertFalse(buffer.isWritable());
}
@Test
@ -522,26 +522,26 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity(); i ++) {
byte value = (byte) random.nextInt();
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeByte(value);
}
assertEquals(0, buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.writable());
assertFalse(buffer.isWritable());
random.setSeed(seed);
for (int i = 0; i < buffer.capacity(); i ++) {
int value = random.nextInt() & 0xFF;
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readUnsignedByte());
}
assertEquals(buffer.capacity(), buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.readable());
assertFalse(buffer.writable());
assertFalse(buffer.isReadable());
assertFalse(buffer.isWritable());
}
@Test
@ -550,26 +550,26 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity(); i += 2) {
short value = (short) random.nextInt();
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeShort(value);
}
assertEquals(0, buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.writable());
assertFalse(buffer.isWritable());
random.setSeed(seed);
for (int i = 0; i < buffer.capacity(); i += 2) {
short value = (short) random.nextInt();
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readShort());
}
assertEquals(buffer.capacity(), buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.readable());
assertFalse(buffer.writable());
assertFalse(buffer.isReadable());
assertFalse(buffer.isWritable());
}
@Test
@ -578,26 +578,26 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity(); i += 2) {
short value = (short) random.nextInt();
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeShort(value);
}
assertEquals(0, buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.writable());
assertFalse(buffer.isWritable());
random.setSeed(seed);
for (int i = 0; i < buffer.capacity(); i += 2) {
int value = random.nextInt() & 0xFFFF;
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readUnsignedShort());
}
assertEquals(buffer.capacity(), buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.readable());
assertFalse(buffer.writable());
assertFalse(buffer.isReadable());
assertFalse(buffer.isWritable());
}
@Test
@ -606,7 +606,7 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity() / 3 * 3; i += 3) {
int value = random.nextInt();
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeMedium(value);
}
@ -618,7 +618,7 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity() / 3 * 3; i += 3) {
int value = random.nextInt() << 8 >> 8;
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readMedium());
}
@ -634,7 +634,7 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity() / 3 * 3; i += 3) {
int value = random.nextInt() & 0x00FFFFFF;
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeMedium(value);
}
@ -646,7 +646,7 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity() / 3 * 3; i += 3) {
int value = random.nextInt() & 0x00FFFFFF;
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readUnsignedMedium());
}
@ -662,26 +662,26 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity(); i += 4) {
int value = random.nextInt();
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeInt(value);
}
assertEquals(0, buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.writable());
assertFalse(buffer.isWritable());
random.setSeed(seed);
for (int i = 0; i < buffer.capacity(); i += 4) {
int value = random.nextInt();
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readInt());
}
assertEquals(buffer.capacity(), buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.readable());
assertFalse(buffer.writable());
assertFalse(buffer.isReadable());
assertFalse(buffer.isWritable());
}
@Test
@ -690,26 +690,26 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity(); i += 4) {
int value = random.nextInt();
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeInt(value);
}
assertEquals(0, buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.writable());
assertFalse(buffer.isWritable());
random.setSeed(seed);
for (int i = 0; i < buffer.capacity(); i += 4) {
long value = random.nextInt() & 0xFFFFFFFFL;
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readUnsignedInt());
}
assertEquals(buffer.capacity(), buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.readable());
assertFalse(buffer.writable());
assertFalse(buffer.isReadable());
assertFalse(buffer.isWritable());
}
@Test
@ -718,26 +718,26 @@ public abstract class AbstractByteBufTest {
for (int i = 0; i < buffer.capacity(); i += 8) {
long value = random.nextLong();
assertEquals(i, buffer.writerIndex());
assertTrue(buffer.writable());
assertTrue(buffer.isWritable());
buffer.writeLong(value);
}
assertEquals(0, buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.writable());
assertFalse(buffer.isWritable());
random.setSeed(seed);
for (int i = 0; i < buffer.capacity(); i += 8) {
long value = random.nextLong();
assertEquals(i, buffer.readerIndex());
assertTrue(buffer.readable());
assertTrue(buffer.isReadable());
assertEquals(value, buffer.readLong());
}
assertEquals(buffer.capacity(), buffer.readerIndex());
assertEquals(buffer.capacity(), buffer.writerIndex());
assertFalse(buffer.readable());
assertFalse(buffer.writable());
assertFalse(buffer.isReadable());
assertFalse(buffer.isWritable());
}
@Test
@ -1254,7 +1254,7 @@ public abstract class AbstractByteBufTest {
}
buffer.clear();
while (buffer.writable()) {
while (buffer.isWritable()) {
buffer.writeByte((byte) 0xFF);
}

View File

@ -28,6 +28,7 @@ import static org.junit.Assert.*;
/**
* An abstract test class for composite channel buffers
*/
@SuppressWarnings("ZeroLengthArrayAllocation")
public abstract class AbstractCompositeByteBufTest extends
AbstractByteBufTest {
@ -76,7 +77,7 @@ public abstract class AbstractCompositeByteBufTest extends
assertEquals(length, buffer.capacity());
assertEquals(length, buffer.readableBytes());
assertFalse(buffer.writable());
assertFalse(buffer.isWritable());
buffer.writerIndex(0);
return buffer;
}

View File

@ -15,17 +15,18 @@
*/
package io.netty.buffer;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.EOFException;
import java.nio.charset.Charset;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Tests channel buffer streams
*/
@SuppressWarnings("ZeroLengthArrayAllocation")
public class ByteBufStreamTest {
@Test
@ -93,7 +94,7 @@ public class ByteBufStreamTest {
in.mark(Integer.MAX_VALUE);
assertEquals(buf.writerIndex(), in.skip(Long.MAX_VALUE));
assertFalse(buf.readable());
assertFalse(buf.isReadable());
in.reset();
assertEquals(0, buf.readerIndex());

View File

@ -409,7 +409,7 @@ public class UnpooledTest {
ByteBuf buffer = copyInt(42);
assertEquals(4, buffer.capacity());
assertEquals(42, buffer.readInt());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
}
@Test
@ -418,7 +418,7 @@ public class UnpooledTest {
assertEquals(8, buffer.capacity());
assertEquals(1, buffer.readInt());
assertEquals(4, buffer.readInt());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyInt(null).capacity());
assertEquals(0, Unpooled.copyInt(new int[0]).capacity());
@ -429,7 +429,7 @@ public class UnpooledTest {
ByteBuf buffer = copyShort(42);
assertEquals(2, buffer.capacity());
assertEquals(42, buffer.readShort());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
}
@Test
@ -438,7 +438,7 @@ public class UnpooledTest {
assertEquals(4, buffer.capacity());
assertEquals(1, buffer.readShort());
assertEquals(4, buffer.readShort());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyShort((short[]) null).capacity());
assertEquals(0, Unpooled.copyShort(new short[0]).capacity());
@ -450,7 +450,7 @@ public class UnpooledTest {
assertEquals(4, buffer.capacity());
assertEquals(1, buffer.readShort());
assertEquals(4, buffer.readShort());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyShort((int[]) null).capacity());
assertEquals(0, Unpooled.copyShort(new int[0]).capacity());
@ -461,7 +461,7 @@ public class UnpooledTest {
ByteBuf buffer = copyMedium(42);
assertEquals(3, buffer.capacity());
assertEquals(42, buffer.readMedium());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
}
@Test
@ -470,7 +470,7 @@ public class UnpooledTest {
assertEquals(6, buffer.capacity());
assertEquals(1, buffer.readMedium());
assertEquals(4, buffer.readMedium());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyMedium(null).capacity());
assertEquals(0, Unpooled.copyMedium(new int[0]).capacity());
@ -481,7 +481,7 @@ public class UnpooledTest {
ByteBuf buffer = copyLong(42);
assertEquals(8, buffer.capacity());
assertEquals(42, buffer.readLong());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
}
@Test
@ -490,7 +490,7 @@ public class UnpooledTest {
assertEquals(16, buffer.capacity());
assertEquals(1, buffer.readLong());
assertEquals(4, buffer.readLong());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyLong(null).capacity());
assertEquals(0, Unpooled.copyLong(new long[0]).capacity());
@ -501,7 +501,7 @@ public class UnpooledTest {
ByteBuf buffer = copyFloat(42);
assertEquals(4, buffer.capacity());
assertEquals(42, buffer.readFloat(), 0.01);
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
}
@Test
@ -510,7 +510,7 @@ public class UnpooledTest {
assertEquals(8, buffer.capacity());
assertEquals(1, buffer.readFloat(), 0.01);
assertEquals(4, buffer.readFloat(), 0.01);
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyFloat(null).capacity());
assertEquals(0, Unpooled.copyFloat(new float[0]).capacity());
@ -521,7 +521,7 @@ public class UnpooledTest {
ByteBuf buffer = copyDouble(42);
assertEquals(8, buffer.capacity());
assertEquals(42, buffer.readDouble(), 0.01);
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
}
@Test
@ -530,7 +530,7 @@ public class UnpooledTest {
assertEquals(16, buffer.capacity());
assertEquals(1, buffer.readDouble(), 0.01);
assertEquals(4, buffer.readDouble(), 0.01);
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyDouble(null).capacity());
assertEquals(0, Unpooled.copyDouble(new double[0]).capacity());
@ -542,7 +542,7 @@ public class UnpooledTest {
assertEquals(2, buffer.capacity());
assertTrue(buffer.readBoolean());
assertFalse(buffer.readBoolean());
assertFalse(buffer.readable());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyBoolean(null).capacity());
assertEquals(0, Unpooled.copyBoolean(new boolean[0]).capacity());

View File

@ -134,7 +134,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object>
// Generate an additional chunk if the decoder produced
// the last product on closure,
if (lastProduct.readable()) {
if (lastProduct.isReadable()) {
if (header == null) {
return new Object[] { new DefaultHttpContent(newContent), new DefaultLastHttpContent(lastProduct)};
} else {

View File

@ -85,7 +85,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
}
// handle the case of single complete message without content
if (msg instanceof FullHttpMessage && !((FullHttpMessage) msg).data().readable()) {
if (msg instanceof FullHttpMessage && !((FullHttpMessage) msg).data().isReadable()) {
// Remove content encoding
String acceptEncoding = acceptEncodingQueue.poll();
@ -200,7 +200,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
// Generate an additional chunk if the decoder produced
// the last product on closure,
if (lastProduct.readable()) {
if (lastProduct.isReadable()) {
if (header == null) {
return new Object[] { new DefaultHttpContent(newContent), new DefaultLastHttpContent(lastProduct)};
} else {

View File

@ -169,7 +169,7 @@ public class HttpObjectAggregator extends MessageToMessageDecoder<HttpObject> {
}
// Append the content of the chunk
if (chunk.data().readable()) {
if (chunk.data().isReadable()) {
content.addComponent(chunk.data());
content.writerIndex(content.writerIndex() + chunk.data().readableBytes());
} else {

View File

@ -253,7 +253,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
toRead = maxChunkSize;
}
ByteBuf content = buffer.readBytes(toRead);
if (!buffer.readable()) {
if (!buffer.isReadable()) {
reset();
return new DefaultLastHttpContent(content);
}
@ -432,7 +432,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
ByteBuf content = this.content;
LastHttpContent httpContent;
if (content == null || !content.readable()) {
if (content == null || !content.isReadable()) {
httpContent = LastHttpContent.EMPTY_LAST_CONTENT;
} else {
httpContent = new DefaultLastHttpContent(content);

View File

@ -449,7 +449,7 @@ public class HttpPostRequestDecoder {
}
boolean contRead = true;
try {
while (undecodedChunk.readable() && contRead) {
while (undecodedChunk.isReadable() && contRead) {
char read = (char) undecodedChunk.readUnsignedByte();
currentpos++;
switch (currentStatus) {
@ -482,7 +482,7 @@ public class HttpPostRequestDecoder {
firstpos = currentpos;
contRead = true;
} else if (read == HttpConstants.CR) {
if (undecodedChunk.readable()) {
if (undecodedChunk.isReadable()) {
read = (char) undecodedChunk.readUnsignedByte();
currentpos++;
if (read == HttpConstants.LF) {
@ -1188,7 +1188,7 @@ public class HttpPostRequestDecoder {
try {
ByteBuf line = buffer(64);
while (undecodedChunk.readable()) {
while (undecodedChunk.isReadable()) {
byte nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.CR) {
nextByte = undecodedChunk.readByte();
@ -1276,7 +1276,7 @@ public class HttpPostRequestDecoder {
StringBuilder sb = new StringBuilder(64);
int delimiterPos = 0;
int len = delimiter.length();
while (undecodedChunk.readable() && delimiterPos < len) {
while (undecodedChunk.isReadable() && delimiterPos < len) {
byte nextByte = undecodedChunk.readByte();
if (nextByte == delimiter.charAt(delimiterPos)) {
delimiterPos++;
@ -1288,7 +1288,7 @@ public class HttpPostRequestDecoder {
}
}
// Now check if either opening delimiter or closing delimiter
if (undecodedChunk.readable()) {
if (undecodedChunk.isReadable()) {
byte nextByte = undecodedChunk.readByte();
// first check for opening delimiter
if (nextByte == HttpConstants.CR) {
@ -1310,7 +1310,7 @@ public class HttpPostRequestDecoder {
if (nextByte == '-') {
sb.append('-');
// now try to find if CRLF or LF there
if (undecodedChunk.readable()) {
if (undecodedChunk.isReadable()) {
nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.CR) {
nextByte = undecodedChunk.readByte();
@ -1484,7 +1484,7 @@ public class HttpPostRequestDecoder {
int index = 0;
int lastPosition = undecodedChunk.readerIndex();
boolean found = false;
while (undecodedChunk.readable()) {
while (undecodedChunk.isReadable()) {
byte nextByte = undecodedChunk.readByte();
if (newLine) {
// Check the delimiter
@ -1500,7 +1500,7 @@ public class HttpPostRequestDecoder {
index = 0;
// continue until end of line
if (nextByte == HttpConstants.CR) {
if (undecodedChunk.readable()) {
if (undecodedChunk.isReadable()) {
nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.LF) {
newLine = true;
@ -1520,7 +1520,7 @@ public class HttpPostRequestDecoder {
} else {
// continue until end of line
if (nextByte == HttpConstants.CR) {
if (undecodedChunk.readable()) {
if (undecodedChunk.isReadable()) {
nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.LF) {
newLine = true;
@ -1684,7 +1684,7 @@ public class HttpPostRequestDecoder {
int index = 0;
int lastPosition = undecodedChunk.readerIndex();
boolean found = false;
while (undecodedChunk.readable()) {
while (undecodedChunk.isReadable()) {
byte nextByte = undecodedChunk.readByte();
if (newLine) {
// Check the delimiter
@ -1700,7 +1700,7 @@ public class HttpPostRequestDecoder {
index = 0;
// continue until end of line
if (nextByte == HttpConstants.CR) {
if (undecodedChunk.readable()) {
if (undecodedChunk.isReadable()) {
nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.LF) {
newLine = true;
@ -1719,7 +1719,7 @@ public class HttpPostRequestDecoder {
} else {
// continue until end of line
if (nextByte == HttpConstants.CR) {
if (undecodedChunk.readable()) {
if (undecodedChunk.isReadable()) {
nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.LF) {
newLine = true;
@ -1899,12 +1899,12 @@ public class HttpPostRequestDecoder {
* @return True if one empty line was skipped
*/
private boolean skipOneLine() {
if (!undecodedChunk.readable()) {
if (!undecodedChunk.isReadable()) {
return false;
}
byte nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.CR) {
if (!undecodedChunk.readable()) {
if (!undecodedChunk.isReadable()) {
undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
return false;
}

View File

@ -421,7 +421,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
}
// May have UTF-8 message
if (buffer.readable()) {
if (buffer.isReadable()) {
try {
new UTF8Output(buffer);

View File

@ -75,7 +75,7 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
ByteBuf in = ctx.inboundByteBuffer();
ByteBuf out = ctx.nextInboundByteBuffer();
if (!in.readable()) {
if (!in.isReadable()) {
callDecode(ctx, in, out);
}
@ -102,7 +102,7 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
*/
private void callDecode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) {
int oldOutSize = out.readableBytes();
while (in.readable()) {
while (in.isReadable()) {
int oldInSize = in.readableBytes();
try {
decode(ctx, in, out);

View File

@ -52,7 +52,7 @@ public abstract class ByteToByteEncoder extends ChannelOutboundByteHandlerAdapte
ByteBuf out = ctx.nextOutboundByteBuffer();
boolean encoded = false;
while (in.readable()) {
while (in.isReadable()) {
int oldInSize = in.readableBytes();
try {
encode(ctx, in, out);

View File

@ -83,7 +83,7 @@ public abstract class ByteToMessageDecoder
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
ByteBuf in = ctx.inboundByteBuffer();
if (in.readable()) {
if (in.isReadable()) {
callDecode(ctx, in);
}
@ -106,7 +106,7 @@ public abstract class ByteToMessageDecoder
boolean wasNull = false;
boolean decoded = false;
while (in.readable()) {
while (in.isReadable()) {
try {
int oldInputLength = in.readableBytes();
Object o = decode(ctx, in);

View File

@ -326,7 +326,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
if (delimiter == null) {
throw new NullPointerException("delimiter");
}
if (!delimiter.readable()) {
if (!delimiter.isReadable()) {
throw new IllegalArgumentException("empty delimiter");
}
}

View File

@ -248,7 +248,7 @@ import io.netty.util.internal.Signal;
* // Remove the first decoder (me)
* ctx.pipeline().remove(this);
*
* if (buf.readable()) {
* if (buf.isReadable()) {
* // Hand off the remaining data to the second decoder
* return new Object[] { firstMessage, buf.readBytes(<b>super.actualReadableBytes()</b>) };
* } else {
@ -362,7 +362,7 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
replayable.terminate();
ByteBuf in = cumulation;
if (in.readable()) {
if (in.isReadable()) {
callDecode(ctx, in);
}
@ -390,7 +390,7 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
ByteBuf in = cumulation;
boolean decoded = false;
while (in.readable()) {
while (in.isReadable()) {
try {
int oldReaderIndex = checkpoint = in.readerIndex();
Object result = null;

View File

@ -143,6 +143,7 @@ final class ReplayingDecoderBuffer implements ByteBuf {
}
@Override
@Deprecated
public ByteBuf ensureWritableBytes(int writableBytes) {
throw new UnreplayableOperationException();
}
@ -395,6 +396,7 @@ final class ReplayingDecoderBuffer implements ByteBuf {
}
@Override
@Deprecated
public boolean readable() {
return isReadable();
}
@ -739,6 +741,7 @@ final class ReplayingDecoderBuffer implements ByteBuf {
}
@Override
@Deprecated
public boolean writable() {
return false;
}

View File

@ -70,11 +70,11 @@ public class SnappyFramedDecoder extends ByteToByteDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
if (!in.readable()) {
if (!in.isReadable()) {
return;
}
while (in.readable()) {
while (in.isReadable()) {
if (chunkLength == 0) {
if (in.readableBytes() < 3) {
// We need to be at least able to read the chunk type identifier (one byte),

View File

@ -47,7 +47,7 @@ public class SnappyFramedEncoder extends ByteToByteEncoder {
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
if (!in.readable()) {
if (!in.isReadable()) {
return;
}

View File

@ -16,11 +16,10 @@
package io.netty.handler.codec.marshalling;
import io.netty.buffer.ByteBuf;
import org.jboss.marshalling.ByteInput;
import java.io.IOException;
import org.jboss.marshalling.ByteInput;
/**
* {@link ByteInput} implementation which reads its data from a {@link ByteBuf}
*/
@ -44,7 +43,7 @@ class ChannelBufferByteInput implements ByteInput {
@Override
public int read() throws IOException {
if (buffer.readable()) {
if (buffer.isReadable()) {
return buffer.readByte() & 0xff;
}
return -1;

View File

@ -15,13 +15,12 @@
*/
package io.netty.handler.codec.protobuf;
import com.google.protobuf.CodedInputStream;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.CorruptedFrameException;
import com.google.protobuf.CodedInputStream;
/**
* A decoder that splits the received {@link ByteBuf}s dynamically by the
* value of the Google Protocol Buffers
@ -47,7 +46,7 @@ public class ProtobufVarint32FrameDecoder extends ByteToMessageDecoder {
in.markReaderIndex();
final byte[] buf = new byte[5];
for (int i = 0; i < buf.length; i ++) {
if (!in.readable()) {
if (!in.isReadable()) {
in.resetReaderIndex();
return null;
}

View File

@ -15,15 +15,14 @@
*/
package io.netty.handler.codec;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.Signal;
import org.junit.Test;
import static org.junit.Assert.*;
public class ReplayingDecoderBufferTest {
/**
@ -76,7 +75,7 @@ public class ReplayingDecoderBufferTest {
@Test
public void testGetBoolean() {
ByteBuf buf = Unpooled.buffer(10);
while(buf.writable()) {
while(buf.isWritable()) {
buf.writeBoolean(true);
}
ReplayingDecoderBuffer buffer = new ReplayingDecoderBuffer(buf);

View File

@ -15,7 +15,6 @@
*/
package io.netty.handler.stream;
import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.MessageBuf;
import io.netty.buffer.Unpooled;
@ -24,6 +23,7 @@ import io.netty.channel.ChannelFutureListener;
import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.channel.embedded.EmbeddedMessageChannel;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -32,7 +32,7 @@ import java.io.IOException;
import java.nio.channels.Channels;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import static org.junit.Assert.*;
public class ChunkedWriteHandlerTest {
private static final byte[] BYTES = new byte[1024 * 64];
@ -203,7 +203,7 @@ public class ChunkedWriteHandlerTest {
if (buffer == null) {
break;
}
while (buffer.readable()) {
while (buffer.isReadable()) {
assertEquals(BYTES[i++], buffer.readByte());
read++;
if (i == BYTES.length) {

View File

@ -66,13 +66,13 @@ public class SctpMessageCompletionHandler extends ChannelInboundMessageHandlerAd
frag = Unpooled.EMPTY_BUFFER;
}
if (isComplete && !frag.readable()) {
if (isComplete && !frag.isReadable()) {
//data chunk is not fragmented
handleAssembledMessage(ctx, msg);
} else if (!isComplete && frag.readable()) {
} else if (!isComplete && frag.isReadable()) {
//more message to complete
fragments.put(streamIdentifier, Unpooled.wrappedBuffer(frag, byteBuf));
} else if (isComplete && frag.readable()) {
} else if (isComplete && frag.isReadable()) {
//last message to complete
fragments.remove(streamIdentifier);
SctpMessage assembledMsg = new SctpMessage(

View File

@ -198,7 +198,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
}
void forwardBufferContent() {
if (hasOutboundByteBuffer() && outboundByteBuffer().readable()) {
if (hasOutboundByteBuffer() && outboundByteBuffer().isReadable()) {
nextOutboundByteBuffer().writeBytes(outboundByteBuffer());
flush();
}
@ -207,7 +207,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
flush();
}
}
if (hasInboundByteBuffer() && inboundByteBuffer().readable()) {
if (hasInboundByteBuffer() && inboundByteBuffer().isReadable()) {
nextInboundByteBuffer().writeBytes(inboundByteBuffer());
fireInboundBufferUpdated();
}
@ -1833,7 +1833,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
}
private void fill() {
if (!byteBuf.readable()) {
if (!byteBuf.isReadable()) {
return;
}
@ -1851,7 +1851,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
}
private void flush(ByteBuf out) {
while (out.writable()) {
while (out.isWritable()) {
ByteBuf data = exchangeBuf.peek();
if (data == null) {
break;

View File

@ -135,7 +135,7 @@ public abstract class AbstractEmbeddedChannel<O> extends AbstractChannel {
* Return received data from this {@link Channel}
*/
public Object readInbound() {
if (lastInboundByteBuffer.readable()) {
if (lastInboundByteBuffer.isReadable()) {
try {
return lastInboundByteBuffer.readBytes(lastInboundByteBuffer.readableBytes());
} finally {
@ -275,7 +275,7 @@ public abstract class AbstractEmbeddedChannel<O> extends AbstractChannel {
close();
runPendingTasks();
checkException();
return lastInboundByteBuffer().readable() || !lastInboundMessageBuffer().isEmpty() ||
return lastInboundByteBuffer().isReadable() || !lastInboundMessageBuffer().isEmpty() ||
hasReadableOutboundBuffer();
}
@ -291,7 +291,7 @@ public abstract class AbstractEmbeddedChannel<O> extends AbstractChannel {
pipeline().fireInboundBufferUpdated();
runPendingTasks();
checkException();
return lastInboundByteBuffer().readable() || !lastInboundMessageBuffer().isEmpty();
return lastInboundByteBuffer().isReadable() || !lastInboundMessageBuffer().isEmpty();
}
/**

View File

@ -55,7 +55,7 @@ public class EmbeddedByteChannel extends AbstractEmbeddedChannel<ByteBuf> {
@Override
public ByteBuf readOutbound() {
if (!lastOutboundBuffer().readable()) {
if (!lastOutboundBuffer().isReadable()) {
return null;
}
try {
@ -72,7 +72,7 @@ public class EmbeddedByteChannel extends AbstractEmbeddedChannel<ByteBuf> {
@Override
protected boolean hasReadableOutboundBuffer() {
return lastOutboundBuffer().readable();
return lastOutboundBuffer().isReadable();
}
@Override

View File

@ -239,7 +239,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
inDoFlushByteBuffer = true;
try {
if (buf.readable()) {
if (buf.isReadable()) {
for (;;) {
if (buf.isFreed()) {
break;
@ -273,7 +273,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
// JDK performed the write operation immediately and notified the handler.
// We know this because we set asyncWriteInProgress to false in the handler.
if (!buf.readable()) {
if (!buf.isReadable()) {
// There's nothing left in the buffer. No need to retry writing.
break;
}
@ -386,7 +386,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
return;
}
if (buf.readable()) {
if (buf.isReadable()) {
channel.unsafe().flushNow();
}
}

View File

@ -86,7 +86,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
if (read) {
read = false;
pipeline.fireInboundBufferUpdated();
if (!byteBuf.writable()) {
if (!byteBuf.isWritable()) {
throw new IllegalStateException(
"an inbound handler whose buffer is full must consume at " +
"least one byte.");
@ -130,7 +130,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
@Override
protected void doFlushByteBuffer(ByteBuf buf) throws Exception {
if (!buf.readable()) {
if (!buf.isReadable()) {
// Reset reader/writerIndex to 0 if the buffer is empty.
buf.clear();
return;
@ -141,7 +141,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
if (localFlushedAmount > 0) {
break;
}
if (!buf.readable()) {
if (!buf.isReadable()) {
// Reset reader/writerIndex to 0 if the buffer is empty.
buf.clear();
break;