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

View File

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

View File

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

View File

@ -409,7 +409,7 @@ public class UnpooledTest {
ByteBuf buffer = copyInt(42); ByteBuf buffer = copyInt(42);
assertEquals(4, buffer.capacity()); assertEquals(4, buffer.capacity());
assertEquals(42, buffer.readInt()); assertEquals(42, buffer.readInt());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
} }
@Test @Test
@ -418,7 +418,7 @@ public class UnpooledTest {
assertEquals(8, buffer.capacity()); assertEquals(8, buffer.capacity());
assertEquals(1, buffer.readInt()); assertEquals(1, buffer.readInt());
assertEquals(4, buffer.readInt()); assertEquals(4, buffer.readInt());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyInt(null).capacity()); assertEquals(0, Unpooled.copyInt(null).capacity());
assertEquals(0, Unpooled.copyInt(new int[0]).capacity()); assertEquals(0, Unpooled.copyInt(new int[0]).capacity());
@ -429,7 +429,7 @@ public class UnpooledTest {
ByteBuf buffer = copyShort(42); ByteBuf buffer = copyShort(42);
assertEquals(2, buffer.capacity()); assertEquals(2, buffer.capacity());
assertEquals(42, buffer.readShort()); assertEquals(42, buffer.readShort());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
} }
@Test @Test
@ -438,7 +438,7 @@ public class UnpooledTest {
assertEquals(4, buffer.capacity()); assertEquals(4, buffer.capacity());
assertEquals(1, buffer.readShort()); assertEquals(1, buffer.readShort());
assertEquals(4, buffer.readShort()); assertEquals(4, buffer.readShort());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyShort((short[]) null).capacity()); assertEquals(0, Unpooled.copyShort((short[]) null).capacity());
assertEquals(0, Unpooled.copyShort(new short[0]).capacity()); assertEquals(0, Unpooled.copyShort(new short[0]).capacity());
@ -450,7 +450,7 @@ public class UnpooledTest {
assertEquals(4, buffer.capacity()); assertEquals(4, buffer.capacity());
assertEquals(1, buffer.readShort()); assertEquals(1, buffer.readShort());
assertEquals(4, buffer.readShort()); assertEquals(4, buffer.readShort());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyShort((int[]) null).capacity()); assertEquals(0, Unpooled.copyShort((int[]) null).capacity());
assertEquals(0, Unpooled.copyShort(new int[0]).capacity()); assertEquals(0, Unpooled.copyShort(new int[0]).capacity());
@ -461,7 +461,7 @@ public class UnpooledTest {
ByteBuf buffer = copyMedium(42); ByteBuf buffer = copyMedium(42);
assertEquals(3, buffer.capacity()); assertEquals(3, buffer.capacity());
assertEquals(42, buffer.readMedium()); assertEquals(42, buffer.readMedium());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
} }
@Test @Test
@ -470,7 +470,7 @@ public class UnpooledTest {
assertEquals(6, buffer.capacity()); assertEquals(6, buffer.capacity());
assertEquals(1, buffer.readMedium()); assertEquals(1, buffer.readMedium());
assertEquals(4, buffer.readMedium()); assertEquals(4, buffer.readMedium());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyMedium(null).capacity()); assertEquals(0, Unpooled.copyMedium(null).capacity());
assertEquals(0, Unpooled.copyMedium(new int[0]).capacity()); assertEquals(0, Unpooled.copyMedium(new int[0]).capacity());
@ -481,7 +481,7 @@ public class UnpooledTest {
ByteBuf buffer = copyLong(42); ByteBuf buffer = copyLong(42);
assertEquals(8, buffer.capacity()); assertEquals(8, buffer.capacity());
assertEquals(42, buffer.readLong()); assertEquals(42, buffer.readLong());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
} }
@Test @Test
@ -490,7 +490,7 @@ public class UnpooledTest {
assertEquals(16, buffer.capacity()); assertEquals(16, buffer.capacity());
assertEquals(1, buffer.readLong()); assertEquals(1, buffer.readLong());
assertEquals(4, buffer.readLong()); assertEquals(4, buffer.readLong());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyLong(null).capacity()); assertEquals(0, Unpooled.copyLong(null).capacity());
assertEquals(0, Unpooled.copyLong(new long[0]).capacity()); assertEquals(0, Unpooled.copyLong(new long[0]).capacity());
@ -501,7 +501,7 @@ public class UnpooledTest {
ByteBuf buffer = copyFloat(42); ByteBuf buffer = copyFloat(42);
assertEquals(4, buffer.capacity()); assertEquals(4, buffer.capacity());
assertEquals(42, buffer.readFloat(), 0.01); assertEquals(42, buffer.readFloat(), 0.01);
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
} }
@Test @Test
@ -510,7 +510,7 @@ public class UnpooledTest {
assertEquals(8, buffer.capacity()); assertEquals(8, buffer.capacity());
assertEquals(1, buffer.readFloat(), 0.01); assertEquals(1, buffer.readFloat(), 0.01);
assertEquals(4, 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(null).capacity());
assertEquals(0, Unpooled.copyFloat(new float[0]).capacity()); assertEquals(0, Unpooled.copyFloat(new float[0]).capacity());
@ -521,7 +521,7 @@ public class UnpooledTest {
ByteBuf buffer = copyDouble(42); ByteBuf buffer = copyDouble(42);
assertEquals(8, buffer.capacity()); assertEquals(8, buffer.capacity());
assertEquals(42, buffer.readDouble(), 0.01); assertEquals(42, buffer.readDouble(), 0.01);
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
} }
@Test @Test
@ -530,7 +530,7 @@ public class UnpooledTest {
assertEquals(16, buffer.capacity()); assertEquals(16, buffer.capacity());
assertEquals(1, buffer.readDouble(), 0.01); assertEquals(1, buffer.readDouble(), 0.01);
assertEquals(4, 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(null).capacity());
assertEquals(0, Unpooled.copyDouble(new double[0]).capacity()); assertEquals(0, Unpooled.copyDouble(new double[0]).capacity());
@ -542,7 +542,7 @@ public class UnpooledTest {
assertEquals(2, buffer.capacity()); assertEquals(2, buffer.capacity());
assertTrue(buffer.readBoolean()); assertTrue(buffer.readBoolean());
assertFalse(buffer.readBoolean()); assertFalse(buffer.readBoolean());
assertFalse(buffer.readable()); assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyBoolean(null).capacity()); assertEquals(0, Unpooled.copyBoolean(null).capacity());
assertEquals(0, Unpooled.copyBoolean(new boolean[0]).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 // Generate an additional chunk if the decoder produced
// the last product on closure, // the last product on closure,
if (lastProduct.readable()) { if (lastProduct.isReadable()) {
if (header == null) { if (header == null) {
return new Object[] { new DefaultHttpContent(newContent), new DefaultLastHttpContent(lastProduct)}; return new Object[] { new DefaultHttpContent(newContent), new DefaultLastHttpContent(lastProduct)};
} else { } else {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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