Fixed issue: NETTY-24 (Move ChannelBuffer.EMPTY_BUFFER to ChannelBuffers.)

This commit is contained in:
Trustin Lee 2008-08-21 05:54:59 +00:00
parent ff8f148990
commit 9dd9b00851
7 changed files with 28 additions and 27 deletions

View File

@ -265,7 +265,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
public ChannelBuffer readBytes(int length) {
checkReadableBytes(length);
if (length == 0) {
return ChannelBuffer.EMPTY_BUFFER;
return ChannelBuffers.EMPTY_BUFFER;
}
ChannelBuffer buf = ChannelBuffers.buffer(length);
buf.writeBytes(this, readerIndex, length);

View File

@ -231,11 +231,6 @@ import java.util.NoSuchElementException;
*/
public interface ChannelBuffer extends Comparable<ChannelBuffer> {
/**
* A buffer whose capacity is {@code 0}.
*/
static ChannelBuffer EMPTY_BUFFER = new BigEndianHeapChannelBuffer(0);
/**
* Returns the number of bytes (octets) this buffer can contain.
*/

View File

@ -101,6 +101,11 @@ public class ChannelBuffers {
*/
public static final ByteOrder LITTLE_ENDIAN = ByteOrder.LITTLE_ENDIAN;
/**
* A buffer whose capacity is {@code 0}.
*/
public static ChannelBuffer EMPTY_BUFFER = new BigEndianHeapChannelBuffer(0);
private static final char[][] HEXDUMP_TABLE = new char[65536][];
static {
@ -125,7 +130,7 @@ public class ChannelBuffers {
*/
public static ChannelBuffer buffer(ByteOrder endianness, int capacity) {
if (capacity == 0) {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
if (endianness == BIG_ENDIAN) {
return new BigEndianHeapChannelBuffer(capacity);
@ -152,7 +157,7 @@ public class ChannelBuffers {
*/
public static ChannelBuffer directBuffer(ByteOrder endianness, int capacity) {
if (capacity == 0) {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
ChannelBuffer buffer = new ByteBufferBackedChannelBuffer(
ByteBuffer.allocateDirect(capacity).order(endianness));
@ -205,7 +210,7 @@ public class ChannelBuffers {
*/
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array) {
if (array.length == 0) {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
if (endianness == BIG_ENDIAN) {
return new BigEndianHeapChannelBuffer(array);
@ -232,7 +237,7 @@ public class ChannelBuffers {
*/
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
if (length == 0) {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
if (offset == 0) {
if (length == array.length) {
@ -252,7 +257,7 @@ public class ChannelBuffers {
*/
public static ChannelBuffer wrappedBuffer(ByteBuffer buffer) {
if (!buffer.hasRemaining()) {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
if (!buffer.isReadOnly() && buffer.hasArray()) {
return wrappedBuffer(buffer.array(), buffer.arrayOffset(),buffer.remaining());
@ -270,7 +275,7 @@ public class ChannelBuffers {
if (buffer.readable()) {
return buffer.slice();
} else {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
}
@ -293,7 +298,7 @@ public class ChannelBuffers {
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[]... arrays) {
switch (arrays.length) {
case 0:
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
case 1:
return wrappedBuffer(endianness, arrays[0]);
}
@ -316,7 +321,7 @@ public class ChannelBuffers {
public static ChannelBuffer wrappedBuffer(ChannelBuffer... buffers) {
switch (buffers.length) {
case 0:
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
case 1:
return wrappedBuffer(buffers[0]);
default:
@ -336,7 +341,7 @@ public class ChannelBuffers {
public static ChannelBuffer wrappedBuffer(ByteBuffer... buffers) {
switch (buffers.length) {
case 0:
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
case 1:
return wrappedBuffer(buffers[0]);
}
@ -364,7 +369,7 @@ public class ChannelBuffers {
*/
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array) {
if (array.length == 0) {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
if (endianness == BIG_ENDIAN) {
return new BigEndianHeapChannelBuffer(array.clone());
@ -393,7 +398,7 @@ public class ChannelBuffers {
*/
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
if (length == 0) {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
byte[] copy = new byte[length];
System.arraycopy(array, offset, copy, 0, length);
@ -409,7 +414,7 @@ public class ChannelBuffers {
public static ChannelBuffer copiedBuffer(ByteBuffer buffer) {
int length = buffer.remaining();
if (length == 0) {
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
}
byte[] copy = new byte[length];
int position = buffer.position();
@ -450,7 +455,7 @@ public class ChannelBuffers {
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[]... arrays) {
switch (arrays.length) {
case 0:
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
case 1:
return copiedBuffer(endianness, arrays[0]);
}
@ -488,7 +493,7 @@ public class ChannelBuffers {
public static ChannelBuffer copiedBuffer(ChannelBuffer... buffers) {
switch (buffers.length) {
case 0:
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
case 1:
return copiedBuffer(buffers[0]);
}
@ -513,7 +518,7 @@ public class ChannelBuffers {
public static ChannelBuffer copiedBuffer(ByteBuffer... buffers) {
switch (buffers.length) {
case 0:
return ChannelBuffer.EMPTY_BUFFER;
return EMPTY_BUFFER;
case 1:
return copiedBuffer(buffers[0]);
}

View File

@ -44,7 +44,7 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
private final int initialCapacity;
private final ByteOrder endianness;
private ChannelBuffer buffer = ChannelBuffer.EMPTY_BUFFER;
private ChannelBuffer buffer = ChannelBuffers.EMPTY_BUFFER;
public DynamicChannelBuffer(int estimatedLength) {
this(ByteOrder.BIG_ENDIAN, estimatedLength);
@ -216,7 +216,7 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
DynamicChannelBuffer copiedBuffer = new DynamicChannelBuffer(endianness, Math.max(length, 64));
copiedBuffer.buffer = buffer.copy();
if (copiedBuffer.buffer.capacity() == 0) {
copiedBuffer.buffer = ChannelBuffer.EMPTY_BUFFER;
copiedBuffer.buffer = ChannelBuffers.EMPTY_BUFFER;
}
return copiedBuffer;
}

View File

@ -58,7 +58,7 @@ public class EchoHandler extends SimpleChannelHandler {
* Creates a server-side handler.
*/
public EchoHandler() {
firstMessage = ChannelBuffer.EMPTY_BUFFER;
firstMessage = ChannelBuffers.EMPTY_BUFFER;
}
/**

View File

@ -23,6 +23,7 @@
package org.jboss.netty.handler.codec.frame;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
@ -81,7 +82,7 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
return frame;
} else if (delimIndex == 0) {
buffer.skipBytes(delim.capacity());
return ChannelBuffer.EMPTY_BUFFER;
return ChannelBuffers.EMPTY_BUFFER;
}
}

View File

@ -210,7 +210,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
public void channelDisconnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception {
super.channelDisconnected(ctx, e);
unwrap(ctx, e.getChannel(), ChannelBuffer.EMPTY_BUFFER, 0, 0);
unwrap(ctx, e.getChannel(), ChannelBuffers.EMPTY_BUFFER, 0, 0);
engine.closeOutbound();
if (!sentCloseNotify.get() && handshaken) {
try {
@ -524,7 +524,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
private void closeOutboundAndChannel(
final ChannelHandlerContext context, final ChannelStateEvent e) throws SSLException {
unwrap(context, e.getChannel(), ChannelBuffer.EMPTY_BUFFER, 0, 0);
unwrap(context, e.getChannel(), ChannelBuffers.EMPTY_BUFFER, 0, 0);
if (!engine.isInboundDone()) {
if (sentCloseNotify.compareAndSet(false, true)) {
engine.closeOutbound();