Fixed issue: NETTY-24 (Move ChannelBuffer.EMPTY_BUFFER to ChannelBuffers.)
This commit is contained in:
parent
ff8f148990
commit
9dd9b00851
@ -265,7 +265,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
|||||||
public ChannelBuffer readBytes(int length) {
|
public ChannelBuffer readBytes(int length) {
|
||||||
checkReadableBytes(length);
|
checkReadableBytes(length);
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return ChannelBuffers.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
ChannelBuffer buf = ChannelBuffers.buffer(length);
|
ChannelBuffer buf = ChannelBuffers.buffer(length);
|
||||||
buf.writeBytes(this, readerIndex, length);
|
buf.writeBytes(this, readerIndex, length);
|
||||||
|
@ -231,11 +231,6 @@ import java.util.NoSuchElementException;
|
|||||||
*/
|
*/
|
||||||
public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
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.
|
* Returns the number of bytes (octets) this buffer can contain.
|
||||||
*/
|
*/
|
||||||
|
@ -101,6 +101,11 @@ public class ChannelBuffers {
|
|||||||
*/
|
*/
|
||||||
public static final ByteOrder LITTLE_ENDIAN = ByteOrder.LITTLE_ENDIAN;
|
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][];
|
private static final char[][] HEXDUMP_TABLE = new char[65536][];
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -125,7 +130,7 @@ public class ChannelBuffers {
|
|||||||
*/
|
*/
|
||||||
public static ChannelBuffer buffer(ByteOrder endianness, int capacity) {
|
public static ChannelBuffer buffer(ByteOrder endianness, int capacity) {
|
||||||
if (capacity == 0) {
|
if (capacity == 0) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (endianness == BIG_ENDIAN) {
|
if (endianness == BIG_ENDIAN) {
|
||||||
return new BigEndianHeapChannelBuffer(capacity);
|
return new BigEndianHeapChannelBuffer(capacity);
|
||||||
@ -152,7 +157,7 @@ public class ChannelBuffers {
|
|||||||
*/
|
*/
|
||||||
public static ChannelBuffer directBuffer(ByteOrder endianness, int capacity) {
|
public static ChannelBuffer directBuffer(ByteOrder endianness, int capacity) {
|
||||||
if (capacity == 0) {
|
if (capacity == 0) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
ChannelBuffer buffer = new ByteBufferBackedChannelBuffer(
|
ChannelBuffer buffer = new ByteBufferBackedChannelBuffer(
|
||||||
ByteBuffer.allocateDirect(capacity).order(endianness));
|
ByteBuffer.allocateDirect(capacity).order(endianness));
|
||||||
@ -205,7 +210,7 @@ public class ChannelBuffers {
|
|||||||
*/
|
*/
|
||||||
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array) {
|
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array) {
|
||||||
if (array.length == 0) {
|
if (array.length == 0) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (endianness == BIG_ENDIAN) {
|
if (endianness == BIG_ENDIAN) {
|
||||||
return new BigEndianHeapChannelBuffer(array);
|
return new BigEndianHeapChannelBuffer(array);
|
||||||
@ -232,7 +237,7 @@ public class ChannelBuffers {
|
|||||||
*/
|
*/
|
||||||
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
|
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (offset == 0) {
|
if (offset == 0) {
|
||||||
if (length == array.length) {
|
if (length == array.length) {
|
||||||
@ -252,7 +257,7 @@ public class ChannelBuffers {
|
|||||||
*/
|
*/
|
||||||
public static ChannelBuffer wrappedBuffer(ByteBuffer buffer) {
|
public static ChannelBuffer wrappedBuffer(ByteBuffer buffer) {
|
||||||
if (!buffer.hasRemaining()) {
|
if (!buffer.hasRemaining()) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (!buffer.isReadOnly() && buffer.hasArray()) {
|
if (!buffer.isReadOnly() && buffer.hasArray()) {
|
||||||
return wrappedBuffer(buffer.array(), buffer.arrayOffset(),buffer.remaining());
|
return wrappedBuffer(buffer.array(), buffer.arrayOffset(),buffer.remaining());
|
||||||
@ -270,7 +275,7 @@ public class ChannelBuffers {
|
|||||||
if (buffer.readable()) {
|
if (buffer.readable()) {
|
||||||
return buffer.slice();
|
return buffer.slice();
|
||||||
} else {
|
} else {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +298,7 @@ public class ChannelBuffers {
|
|||||||
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[]... arrays) {
|
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[]... arrays) {
|
||||||
switch (arrays.length) {
|
switch (arrays.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
case 1:
|
case 1:
|
||||||
return wrappedBuffer(endianness, arrays[0]);
|
return wrappedBuffer(endianness, arrays[0]);
|
||||||
}
|
}
|
||||||
@ -316,7 +321,7 @@ public class ChannelBuffers {
|
|||||||
public static ChannelBuffer wrappedBuffer(ChannelBuffer... buffers) {
|
public static ChannelBuffer wrappedBuffer(ChannelBuffer... buffers) {
|
||||||
switch (buffers.length) {
|
switch (buffers.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
case 1:
|
case 1:
|
||||||
return wrappedBuffer(buffers[0]);
|
return wrappedBuffer(buffers[0]);
|
||||||
default:
|
default:
|
||||||
@ -336,7 +341,7 @@ public class ChannelBuffers {
|
|||||||
public static ChannelBuffer wrappedBuffer(ByteBuffer... buffers) {
|
public static ChannelBuffer wrappedBuffer(ByteBuffer... buffers) {
|
||||||
switch (buffers.length) {
|
switch (buffers.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
case 1:
|
case 1:
|
||||||
return wrappedBuffer(buffers[0]);
|
return wrappedBuffer(buffers[0]);
|
||||||
}
|
}
|
||||||
@ -364,7 +369,7 @@ public class ChannelBuffers {
|
|||||||
*/
|
*/
|
||||||
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array) {
|
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array) {
|
||||||
if (array.length == 0) {
|
if (array.length == 0) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (endianness == BIG_ENDIAN) {
|
if (endianness == BIG_ENDIAN) {
|
||||||
return new BigEndianHeapChannelBuffer(array.clone());
|
return new BigEndianHeapChannelBuffer(array.clone());
|
||||||
@ -393,7 +398,7 @@ public class ChannelBuffers {
|
|||||||
*/
|
*/
|
||||||
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
|
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
byte[] copy = new byte[length];
|
byte[] copy = new byte[length];
|
||||||
System.arraycopy(array, offset, copy, 0, length);
|
System.arraycopy(array, offset, copy, 0, length);
|
||||||
@ -409,7 +414,7 @@ public class ChannelBuffers {
|
|||||||
public static ChannelBuffer copiedBuffer(ByteBuffer buffer) {
|
public static ChannelBuffer copiedBuffer(ByteBuffer buffer) {
|
||||||
int length = buffer.remaining();
|
int length = buffer.remaining();
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
byte[] copy = new byte[length];
|
byte[] copy = new byte[length];
|
||||||
int position = buffer.position();
|
int position = buffer.position();
|
||||||
@ -450,7 +455,7 @@ public class ChannelBuffers {
|
|||||||
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[]... arrays) {
|
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[]... arrays) {
|
||||||
switch (arrays.length) {
|
switch (arrays.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
case 1:
|
case 1:
|
||||||
return copiedBuffer(endianness, arrays[0]);
|
return copiedBuffer(endianness, arrays[0]);
|
||||||
}
|
}
|
||||||
@ -488,7 +493,7 @@ public class ChannelBuffers {
|
|||||||
public static ChannelBuffer copiedBuffer(ChannelBuffer... buffers) {
|
public static ChannelBuffer copiedBuffer(ChannelBuffer... buffers) {
|
||||||
switch (buffers.length) {
|
switch (buffers.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
case 1:
|
case 1:
|
||||||
return copiedBuffer(buffers[0]);
|
return copiedBuffer(buffers[0]);
|
||||||
}
|
}
|
||||||
@ -513,7 +518,7 @@ public class ChannelBuffers {
|
|||||||
public static ChannelBuffer copiedBuffer(ByteBuffer... buffers) {
|
public static ChannelBuffer copiedBuffer(ByteBuffer... buffers) {
|
||||||
switch (buffers.length) {
|
switch (buffers.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
case 1:
|
case 1:
|
||||||
return copiedBuffer(buffers[0]);
|
return copiedBuffer(buffers[0]);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
|||||||
|
|
||||||
private final int initialCapacity;
|
private final int initialCapacity;
|
||||||
private final ByteOrder endianness;
|
private final ByteOrder endianness;
|
||||||
private ChannelBuffer buffer = ChannelBuffer.EMPTY_BUFFER;
|
private ChannelBuffer buffer = ChannelBuffers.EMPTY_BUFFER;
|
||||||
|
|
||||||
public DynamicChannelBuffer(int estimatedLength) {
|
public DynamicChannelBuffer(int estimatedLength) {
|
||||||
this(ByteOrder.BIG_ENDIAN, estimatedLength);
|
this(ByteOrder.BIG_ENDIAN, estimatedLength);
|
||||||
@ -216,7 +216,7 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
|||||||
DynamicChannelBuffer copiedBuffer = new DynamicChannelBuffer(endianness, Math.max(length, 64));
|
DynamicChannelBuffer copiedBuffer = new DynamicChannelBuffer(endianness, Math.max(length, 64));
|
||||||
copiedBuffer.buffer = buffer.copy();
|
copiedBuffer.buffer = buffer.copy();
|
||||||
if (copiedBuffer.buffer.capacity() == 0) {
|
if (copiedBuffer.buffer.capacity() == 0) {
|
||||||
copiedBuffer.buffer = ChannelBuffer.EMPTY_BUFFER;
|
copiedBuffer.buffer = ChannelBuffers.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
return copiedBuffer;
|
return copiedBuffer;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class EchoHandler extends SimpleChannelHandler {
|
|||||||
* Creates a server-side handler.
|
* Creates a server-side handler.
|
||||||
*/
|
*/
|
||||||
public EchoHandler() {
|
public EchoHandler() {
|
||||||
firstMessage = ChannelBuffer.EMPTY_BUFFER;
|
firstMessage = ChannelBuffers.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package org.jboss.netty.handler.codec.frame;
|
package org.jboss.netty.handler.codec.frame;
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffers;
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
|
|||||||
return frame;
|
return frame;
|
||||||
} else if (delimIndex == 0) {
|
} else if (delimIndex == 0) {
|
||||||
buffer.skipBytes(delim.capacity());
|
buffer.skipBytes(delim.capacity());
|
||||||
return ChannelBuffer.EMPTY_BUFFER;
|
return ChannelBuffers.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
|
|||||||
public void channelDisconnected(ChannelHandlerContext ctx,
|
public void channelDisconnected(ChannelHandlerContext ctx,
|
||||||
ChannelStateEvent e) throws Exception {
|
ChannelStateEvent e) throws Exception {
|
||||||
super.channelDisconnected(ctx, e);
|
super.channelDisconnected(ctx, e);
|
||||||
unwrap(ctx, e.getChannel(), ChannelBuffer.EMPTY_BUFFER, 0, 0);
|
unwrap(ctx, e.getChannel(), ChannelBuffers.EMPTY_BUFFER, 0, 0);
|
||||||
engine.closeOutbound();
|
engine.closeOutbound();
|
||||||
if (!sentCloseNotify.get() && handshaken) {
|
if (!sentCloseNotify.get() && handshaken) {
|
||||||
try {
|
try {
|
||||||
@ -524,7 +524,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
|
|||||||
|
|
||||||
private void closeOutboundAndChannel(
|
private void closeOutboundAndChannel(
|
||||||
final ChannelHandlerContext context, final ChannelStateEvent e) throws SSLException {
|
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 (!engine.isInboundDone()) {
|
||||||
if (sentCloseNotify.compareAndSet(false, true)) {
|
if (sentCloseNotify.compareAndSet(false, true)) {
|
||||||
engine.closeOutbound();
|
engine.closeOutbound();
|
||||||
|
Loading…
Reference in New Issue
Block a user