Merge MessageBufs and ByteBufs into Unpooled

- e.g. Unpooled.messageBuffer()
- It will make much more sense once we introduce pooling:
  - i.e. Pooled.buffer()
This commit is contained in:
Trustin Lee 2012-06-11 17:02:00 +09:00
parent 71ad0125d6
commit 876847fd20
117 changed files with 404 additions and 431 deletions

View File

@ -375,7 +375,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
public ByteBuf readBytes(int length) { public ByteBuf readBytes(int length) {
checkReadableBytes(length); checkReadableBytes(length);
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
ByteBuf buf = factory().getBuffer(order(), length); ByteBuf buf = factory().getBuffer(order(), length);
buf.writeBytes(this, readerIndex, length); buf.writeBytes(this, readerIndex, length);
@ -629,17 +629,17 @@ public abstract class AbstractByteBuf implements ByteBuf {
nioBuffer.flip(); nioBuffer.flip();
} }
return ByteBufs.decodeString(nioBuffer, charset); return Unpooled.decodeString(nioBuffer, charset);
} }
@Override @Override
public int indexOf(int fromIndex, int toIndex, byte value) { public int indexOf(int fromIndex, int toIndex, byte value) {
return ByteBufs.indexOf(this, fromIndex, toIndex, value); return Unpooled.indexOf(this, fromIndex, toIndex, value);
} }
@Override @Override
public int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) { public int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
return ByteBufs.indexOf(this, fromIndex, toIndex, indexFinder); return Unpooled.indexOf(this, fromIndex, toIndex, indexFinder);
} }
@Override @Override
@ -685,7 +685,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
@Override @Override
public int hashCode() { public int hashCode() {
return ByteBufs.hashCode(this); return Unpooled.hashCode(this);
} }
@Override @Override
@ -693,12 +693,12 @@ public abstract class AbstractByteBuf implements ByteBuf {
if (!(o instanceof ByteBuf)) { if (!(o instanceof ByteBuf)) {
return false; return false;
} }
return ByteBufs.equals(this, (ByteBuf) o); return Unpooled.equals(this, (ByteBuf) o);
} }
@Override @Override
public int compareTo(ByteBuf that) { public int compareTo(ByteBuf that) {
return ByteBufs.compare(this, that); return Unpooled.compare(this, that);
} }
@Override @Override

View File

@ -19,8 +19,8 @@ import java.nio.ByteOrder;
/** /**
* A big-endian Java heap buffer. It is recommended to use {@link ByteBufs#buffer(int)} * A big-endian Java heap buffer. It is recommended to use {@link Unpooled#buffer(int)}
* and {@link ByteBufs#wrappedBuffer(byte[])} instead of calling the * and {@link Unpooled#wrappedBuffer(byte[])} instead of calling the
* constructor explicitly. * constructor explicitly.
*/ */
public class BigEndianHeapByteBuf extends HeapByteBuf { public class BigEndianHeapByteBuf extends HeapByteBuf {

View File

@ -33,7 +33,7 @@ import java.nio.charset.UnsupportedCharsetException;
* <h3>Creation of a buffer</h3> * <h3>Creation of a buffer</h3>
* *
* It is recommended to create a new buffer using the helper methods in * It is recommended to create a new buffer using the helper methods in
* {@link ByteBufs} rather than calling an individual implementation's * {@link Unpooled} rather than calling an individual implementation's
* constructor. * constructor.
* *
* <h3>Random Access Indexing</h3> * <h3>Random Access Indexing</h3>
@ -292,7 +292,7 @@ public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
* <pre> * <pre>
* // Create a buffer whose readerIndex, writerIndex and capacity are * // Create a buffer whose readerIndex, writerIndex and capacity are
* // 0, 0 and 8 respectively. * // 0, 0 and 8 respectively.
* {@link ByteBuf} buf = {@link ByteBufs}.buffer(8); * {@link ByteBuf} buf = {@link Unpooled}.buffer(8);
* *
* // IndexOutOfBoundsException is thrown because the specified * // IndexOutOfBoundsException is thrown because the specified
* // readerIndex (2) cannot be greater than the current writerIndex (0). * // readerIndex (2) cannot be greater than the current writerIndex (0).
@ -305,7 +305,7 @@ public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
* <pre> * <pre>
* // Create a buffer whose readerIndex, writerIndex and capacity are * // Create a buffer whose readerIndex, writerIndex and capacity are
* // 0, 8 and 8 respectively. * // 0, 8 and 8 respectively.
* {@link ByteBuf} buf = {@link ByteBufs}.wrappedBuffer(new byte[8]); * {@link ByteBuf} buf = {@link Unpooled}.wrappedBuffer(new byte[8]);
* *
* // readerIndex becomes 8. * // readerIndex becomes 8.
* buf.readLong(); * buf.readLong();

View File

@ -31,7 +31,7 @@ import java.util.List;
/** /**
* A virtual buffer which shows multiple buffers as a single merged buffer. It * A virtual buffer which shows multiple buffers as a single merged buffer. It
* is recommended to use {@link ByteBufs#wrappedBuffer(ByteBuf...)} * is recommended to use {@link Unpooled#wrappedBuffer(ByteBuf...)}
* instead of calling the constructor explicitly. * instead of calling the constructor explicitly.
*/ */
public class CompositeByteBuf extends AbstractByteBuf { public class CompositeByteBuf extends AbstractByteBuf {
@ -581,20 +581,20 @@ public class CompositeByteBuf extends AbstractByteBuf {
public ByteBuf slice(int index, int length) { public ByteBuf slice(int index, int length) {
if (index == 0) { if (index == 0) {
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
} else if (index < 0 || index > capacity() - length) { } else if (index < 0 || index > capacity() - length) {
throw new IndexOutOfBoundsException("Invalid index: " + index throw new IndexOutOfBoundsException("Invalid index: " + index
+ " - Bytes needed: " + (index + length) + ", maximum is " + " - Bytes needed: " + (index + length) + ", maximum is "
+ capacity()); + capacity());
} else if (length == 0) { } else if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
List<ByteBuf> components = decompose(index, length); List<ByteBuf> components = decompose(index, length);
switch (components.size()) { switch (components.size()) {
case 0: case 0:
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
case 1: case 1:
return components.get(0); return components.get(0);
default: default:
@ -710,7 +710,7 @@ public class CompositeByteBuf extends AbstractByteBuf {
// Add a new buffer so that the capacity of this composite buffer does // Add a new buffer so that the capacity of this composite buffer does
// not decrease due to the discarded components. // not decrease due to the discarded components.
// XXX Might create too many components if discarded by small amount. // XXX Might create too many components if discarded by small amount.
final ByteBuf padding = ByteBufs.buffer(order(), localReaderIndex); final ByteBuf padding = Unpooled.buffer(order(), localReaderIndex);
padding.writerIndex(localReaderIndex); padding.writerIndex(localReaderIndex);
list.add(padding); list.add(padding);

View File

@ -111,10 +111,10 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
throw new IllegalArgumentException("capacity: " + capacity); throw new IllegalArgumentException("capacity: " + capacity);
} }
if (capacity == 0) { if (capacity == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
if (capacity >= preallocatedBufCapacity) { if (capacity >= preallocatedBufCapacity) {
return ByteBufs.directBuffer(order, capacity); return Unpooled.directBuffer(order, capacity);
} }
ByteBuf slice; ByteBuf slice;
@ -136,7 +136,7 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
throw new IndexOutOfBoundsException("offset: " + offset); throw new IndexOutOfBoundsException("offset: " + offset);
} }
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
if (offset + length > array.length) { if (offset + length > array.length) {
throw new IndexOutOfBoundsException("length: " + length); throw new IndexOutOfBoundsException("length: " + length);
@ -150,7 +150,7 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
@Override @Override
public ByteBuf getBuffer(ByteBuffer nioBuffer) { public ByteBuf getBuffer(ByteBuffer nioBuffer) {
if (!nioBuffer.isReadOnly() && nioBuffer.isDirect()) { if (!nioBuffer.isReadOnly() && nioBuffer.isDirect()) {
return ByteBufs.wrappedBuffer(nioBuffer); return Unpooled.wrappedBuffer(nioBuffer);
} }
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining()); ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
@ -164,14 +164,14 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
ByteBuf slice; ByteBuf slice;
synchronized (bigEndianLock) { synchronized (bigEndianLock) {
if (preallocatedBEBuf == null) { if (preallocatedBEBuf == null) {
preallocatedBEBuf = ByteBufs.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity); preallocatedBEBuf = Unpooled.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
slice = preallocatedBEBuf.slice(0, capacity); slice = preallocatedBEBuf.slice(0, capacity);
preallocatedBEBufPos = capacity; preallocatedBEBufPos = capacity;
} else if (preallocatedBEBuf.capacity() - preallocatedBEBufPos >= capacity) { } else if (preallocatedBEBuf.capacity() - preallocatedBEBufPos >= capacity) {
slice = preallocatedBEBuf.slice(preallocatedBEBufPos, capacity); slice = preallocatedBEBuf.slice(preallocatedBEBufPos, capacity);
preallocatedBEBufPos += capacity; preallocatedBEBufPos += capacity;
} else { } else {
preallocatedBEBuf = ByteBufs.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity); preallocatedBEBuf = Unpooled.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
slice = preallocatedBEBuf.slice(0, capacity); slice = preallocatedBEBuf.slice(0, capacity);
preallocatedBEBufPos = capacity; preallocatedBEBufPos = capacity;
} }
@ -183,14 +183,14 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
ByteBuf slice; ByteBuf slice;
synchronized (littleEndianLock) { synchronized (littleEndianLock) {
if (preallocatedLEBuf == null) { if (preallocatedLEBuf == null) {
preallocatedLEBuf = ByteBufs.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity); preallocatedLEBuf = Unpooled.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
slice = preallocatedLEBuf.slice(0, capacity); slice = preallocatedLEBuf.slice(0, capacity);
preallocatedLEBufPos = capacity; preallocatedLEBufPos = capacity;
} else if (preallocatedLEBuf.capacity() - preallocatedLEBufPos >= capacity) { } else if (preallocatedLEBuf.capacity() - preallocatedLEBufPos >= capacity) {
slice = preallocatedLEBuf.slice(preallocatedLEBufPos, capacity); slice = preallocatedLEBuf.slice(preallocatedLEBufPos, capacity);
preallocatedLEBufPos += capacity; preallocatedLEBufPos += capacity;
} else { } else {
preallocatedLEBuf = ByteBufs.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity); preallocatedLEBuf = Unpooled.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
slice = preallocatedLEBuf.slice(0, capacity); slice = preallocatedLEBuf.slice(0, capacity);
preallocatedLEBufPos = capacity; preallocatedLEBufPos = capacity;
} }

View File

@ -26,7 +26,7 @@ import java.nio.channels.ScatteringByteChannel;
/** /**
* A dynamic capacity buffer which increases its capacity as needed. It is * A dynamic capacity buffer which increases its capacity as needed. It is
* recommended to use {@link ByteBufs#dynamicBuffer(int)} instead of * recommended to use {@link Unpooled#dynamicBuffer(int)} instead of
* calling the constructor explicitly. * calling the constructor explicitly.
*/ */
public class DynamicByteBuf extends AbstractByteBuf { public class DynamicByteBuf extends AbstractByteBuf {
@ -310,12 +310,12 @@ public class DynamicByteBuf extends AbstractByteBuf {
public ByteBuf slice(int index, int length) { public ByteBuf slice(int index, int length) {
if (index == 0) { if (index == 0) {
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
return new TruncatedByteBuf(this, length); return new TruncatedByteBuf(this, length);
} else { } else {
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
return new SlicedByteBuf(this, index, length); return new SlicedByteBuf(this, index, length);
} }

View File

@ -172,7 +172,7 @@ public abstract class HeapByteBuf extends AbstractByteBuf {
public ByteBuf slice(int index, int length) { public ByteBuf slice(int index, int length) {
if (index == 0) { if (index == 0) {
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
if (length == array.length) { if (length == array.length) {
ByteBuf slice = duplicate(); ByteBuf slice = duplicate();
@ -183,7 +183,7 @@ public abstract class HeapByteBuf extends AbstractByteBuf {
} }
} else { } else {
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
return new SlicedByteBuf(this, index, length); return new SlicedByteBuf(this, index, length);
} }

View File

@ -66,18 +66,18 @@ public class HeapByteBufFactory extends AbstractByteBufFactory {
@Override @Override
public ByteBuf getBuffer(ByteOrder order, int capacity) { public ByteBuf getBuffer(ByteOrder order, int capacity) {
return ByteBufs.buffer(order, capacity); return Unpooled.buffer(order, capacity);
} }
@Override @Override
public ByteBuf getBuffer(ByteOrder order, byte[] array, int offset, int length) { public ByteBuf getBuffer(ByteOrder order, byte[] array, int offset, int length) {
return ByteBufs.wrappedBuffer(order, array, offset, length); return Unpooled.wrappedBuffer(order, array, offset, length);
} }
@Override @Override
public ByteBuf getBuffer(ByteBuffer nioBuffer) { public ByteBuf getBuffer(ByteBuffer nioBuffer) {
if (nioBuffer.hasArray()) { if (nioBuffer.hasArray()) {
return ByteBufs.wrappedBuffer(nioBuffer); return Unpooled.wrappedBuffer(nioBuffer);
} }
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining()); ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());

View File

@ -19,8 +19,8 @@ import java.nio.ByteOrder;
/** /**
* A little-endian Java heap buffer. It is recommended to use {@link ByteBufs#buffer(ByteOrder, int)} * A little-endian Java heap buffer. It is recommended to use {@link Unpooled#buffer(ByteOrder, int)}
* and {@link ByteBufs#wrappedBuffer(ByteOrder, byte[])} instead of * and {@link Unpooled#wrappedBuffer(ByteOrder, byte[])} instead of
* calling the constructor explicitly. * calling the constructor explicitly.
*/ */
public class LittleEndianHeapByteBuf extends HeapByteBuf { public class LittleEndianHeapByteBuf extends HeapByteBuf {

View File

@ -1,35 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.buffer;
import java.util.Queue;
public final class MessageBufs {
public static <T> MessageBuf<T> buffer() {
return new DefaultMessageBuf<T>();
}
public static <T> MessageBuf<T> buffer(int initialCapacity) {
return new DefaultMessageBuf<T>(initialCapacity);
}
public static <T> MessageBuf<T> wrappedBuffer(Queue<T> queue) {
return new QueueBackedMessageBuf<T>(queue);
}
private MessageBufs() { }
}

View File

@ -25,8 +25,8 @@ import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel; import java.nio.channels.ScatteringByteChannel;
/** /**
* A NIO {@link ByteBuffer} based buffer. It is recommended to use {@link ByteBufs#directBuffer(int)} * A NIO {@link ByteBuffer} based buffer. It is recommended to use {@link Unpooled#directBuffer(int)}
* and {@link ByteBufs#wrappedBuffer(ByteBuffer)} instead of calling the * and {@link Unpooled#wrappedBuffer(ByteBuffer)} instead of calling the
* constructor explicitly. * constructor explicitly.
*/ */
public class NioBufferBackedByteBuf extends AbstractByteBuf { public class NioBufferBackedByteBuf extends AbstractByteBuf {
@ -299,7 +299,7 @@ public class NioBufferBackedByteBuf extends AbstractByteBuf {
return slice; return slice;
} else { } else {
if (index >= 0 && length == 0) { if (index >= 0 && length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
return new NioBufferBackedByteBuf( return new NioBufferBackedByteBuf(
((ByteBuffer) tmpBuf.clear().position( ((ByteBuffer) tmpBuf.clear().position(

View File

@ -26,7 +26,7 @@ import java.nio.channels.ScatteringByteChannel;
/** /**
* A derived buffer which forbids any write requests to its parent. It is * A derived buffer which forbids any write requests to its parent. It is
* recommended to use {@link ByteBufs#unmodifiableBuffer(ByteBuf)} * recommended to use {@link Unpooled#unmodifiableBuffer(ByteBuf)}
* instead of calling the constructor explicitly. * instead of calling the constructor explicitly.
*/ */
public class ReadOnlyByteBuf extends AbstractByteBuf implements WrappedByteBuf { public class ReadOnlyByteBuf extends AbstractByteBuf implements WrappedByteBuf {

View File

@ -140,7 +140,7 @@ public class SlicedByteBuf extends AbstractByteBuf implements WrappedByteBuf {
public ByteBuf slice(int index, int length) { public ByteBuf slice(int index, int length) {
checkIndex(index, length); checkIndex(index, length);
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
return new SlicedByteBuf(buffer, index + adjustment, length); return new SlicedByteBuf(buffer, index + adjustment, length);
} }

View File

@ -133,7 +133,7 @@ public class TruncatedByteBuf extends AbstractByteBuf implements WrappedByteBuf
public ByteBuf slice(int index, int length) { public ByteBuf slice(int index, int length) {
checkIndex(index, length); checkIndex(index, length);
if (length == 0) { if (length == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
return buffer.slice(index, length); return buffer.slice(index, length);
} }

View File

@ -27,17 +27,18 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult; import java.nio.charset.CoderResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Queue;
/** /**
* Creates a new {@link ByteBuf} by allocating new space or by wrapping * Creates a new {@link ByteBuf} or a new {@link MessageBuf} by allocating new space or by wrapping
* or copying existing byte arrays, byte buffers and a string. * or copying existing byte arrays, byte buffers and a string.
* *
* <h3>Use static import</h3> * <h3>Use static import</h3>
* This classes is intended to be used with Java 5 static import statement: * This classes is intended to be used with Java 5 static import statement:
* *
* <pre> * <pre>
* import static io.netty.buffer.{@link ByteBufs}.*; * import static io.netty.buffer.{@link Unpooled}.*;
* *
* {@link ByteBuf} heapBuffer = buffer(128); * {@link ByteBuf} heapBuffer = buffer(128);
* {@link ByteBuf} directBuffer = directBuffer(256); * {@link ByteBuf} directBuffer = directBuffer(256);
@ -84,7 +85,7 @@ import java.util.List;
* @apiviz.landmark * @apiviz.landmark
* @apiviz.has io.netty.buffer.ChannelBuffer oneway - - creates * @apiviz.has io.netty.buffer.ChannelBuffer oneway - - creates
*/ */
public final class ByteBufs { public final class Unpooled {
/** /**
* Big endian byte order. * Big endian byte order.
@ -111,6 +112,18 @@ public final class ByteBufs {
} }
} }
public static <T> MessageBuf<T> messageBuffer() {
return new DefaultMessageBuf<T>();
}
public static <T> MessageBuf<T> messageBuffer(int initialCapacity) {
return new DefaultMessageBuf<T>(initialCapacity);
}
public static <T> MessageBuf<T> wrappedBuffer(Queue<T> queue) {
return new QueueBackedMessageBuf<T>(queue);
}
/** /**
* Creates a new big-endian Java heap buffer with the specified * Creates a new big-endian Java heap buffer with the specified
* {@code capacity}. The new buffer's {@code readerIndex} and * {@code capacity}. The new buffer's {@code readerIndex} and
@ -803,7 +816,7 @@ public final class ByteBufs {
} }
private static ByteBuf copiedBuffer(ByteOrder endianness, CharBuffer buffer, Charset charset) { private static ByteBuf copiedBuffer(ByteOrder endianness, CharBuffer buffer, Charset charset) {
ByteBuffer dst = ByteBufs.encodeString(buffer, charset); ByteBuffer dst = Unpooled.encodeString(buffer, charset);
ByteBuf result = wrappedBuffer(endianness, dst.array()); ByteBuf result = wrappedBuffer(endianness, dst.array());
result.writerIndex(dst.remaining()); result.writerIndex(dst.remaining());
return result; return result;
@ -1321,7 +1334,7 @@ public final class ByteBufs {
return dst.flip().toString(); return dst.flip().toString();
} }
private ByteBufs() { private Unpooled() {
// Unused // Unused
} }
} }

View File

@ -98,7 +98,7 @@
* of the resulting string and let {@link java.lang.StringBuffer} expand itself * of the resulting string and let {@link java.lang.StringBuffer} expand itself
* on demand. Netty allows you to do the same via a <em>dynamic</em> buffer * on demand. Netty allows you to do the same via a <em>dynamic</em> buffer
* which is created by the * which is created by the
* {@link io.netty.buffer.ByteBufs#dynamicBuffer()} method. * {@link io.netty.buffer.Unpooled#dynamicBuffer()} method.
* <pre> * <pre>
* // A new dynamic buffer is created. Internally, the actual buffer is created * // A new dynamic buffer is created. Internally, the actual buffer is created
* // lazily to avoid potentially wasted memory space. * // lazily to avoid potentially wasted memory space.

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -47,30 +47,30 @@ public abstract class AbstractCompositeChannelBufferTest extends
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffers = new ArrayList<ByteBuf>(); buffers = new ArrayList<ByteBuf>();
for (int i = 0; i < length; i += 10) { for (int i = 0; i < length; i += 10) {
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[1])); buffers.add(Unpooled.wrappedBuffer(order, new byte[1]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[2])); buffers.add(Unpooled.wrappedBuffer(order, new byte[2]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[3])); buffers.add(Unpooled.wrappedBuffer(order, new byte[3]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[4])); buffers.add(Unpooled.wrappedBuffer(order, new byte[4]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[5])); buffers.add(Unpooled.wrappedBuffer(order, new byte[5]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[6])); buffers.add(Unpooled.wrappedBuffer(order, new byte[6]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[7])); buffers.add(Unpooled.wrappedBuffer(order, new byte[7]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[8])); buffers.add(Unpooled.wrappedBuffer(order, new byte[8]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
buffers.add(ByteBufs.wrappedBuffer(order, new byte[9])); buffers.add(Unpooled.wrappedBuffer(order, new byte[9]));
buffers.add(ByteBufs.EMPTY_BUFFER); buffers.add(Unpooled.EMPTY_BUFFER);
} }
buffer = ByteBufs.wrappedBuffer(buffers.toArray(new ByteBuf[buffers.size()])); buffer = Unpooled.wrappedBuffer(buffers.toArray(new ByteBuf[buffers.size()]));
buffer.writerIndex(length); buffer.writerIndex(length);
buffer = ByteBufs.wrappedBuffer(buffer); buffer = Unpooled.wrappedBuffer(buffer);
assertEquals(length, buffer.capacity()); assertEquals(length, buffer.capacity());
assertEquals(length, buffer.readableBytes()); assertEquals(length, buffer.readableBytes());
assertFalse(buffer.writable()); assertFalse(buffer.writable());
@ -113,20 +113,20 @@ public abstract class AbstractCompositeChannelBufferTest extends
a.writerIndex(a.writerIndex() + 1); a.writerIndex(a.writerIndex() + 1);
b.writerIndex(b.writerIndex() + 1); b.writerIndex(b.writerIndex() + 1);
assertEquals(a.writerIndex(), b.writerIndex()); assertEquals(a.writerIndex(), b.writerIndex());
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// now discard // now discard
a.discardReadBytes(); a.discardReadBytes();
b.discardReadBytes(); b.discardReadBytes();
assertEquals(a.readerIndex(), b.readerIndex()); assertEquals(a.readerIndex(), b.readerIndex());
assertEquals(a.writerIndex(), b.writerIndex()); assertEquals(a.writerIndex(), b.writerIndex());
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
a.resetReaderIndex(); a.resetReaderIndex();
b.resetReaderIndex(); b.resetReaderIndex();
assertEquals(a.readerIndex(), b.readerIndex()); assertEquals(a.readerIndex(), b.readerIndex());
a.resetWriterIndex(); a.resetWriterIndex();
b.resetWriterIndex(); b.resetWriterIndex();
assertEquals(a.writerIndex(), b.writerIndex()); assertEquals(a.writerIndex(), b.writerIndex());
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
} }
@Test @Test
@ -154,57 +154,57 @@ public abstract class AbstractCompositeChannelBufferTest extends
a = wrappedBuffer(order, new byte[] { 1 }); a = wrappedBuffer(order, new byte[] { 1 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }),
wrappedBuffer(order, new byte[] { 2 })); wrappedBuffer(order, new byte[] { 2 }));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Same content, same firstIndex, short length. // Same content, same firstIndex, short length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }),
wrappedBuffer(order, new byte[] { 2 }), wrappedBuffer(order, new byte[] { 2 }),
wrappedBuffer(order, new byte[] { 3 })); wrappedBuffer(order, new byte[] { 3 }));
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Same content, different firstIndex, short length. // Same content, different firstIndex, short length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 1, 2), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 1, 2),
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1)); wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1));
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Different content, same firstIndex, short length. // Different content, same firstIndex, short length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2 }), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2 }),
wrappedBuffer(order, new byte[] { 4 })); wrappedBuffer(order, new byte[] { 4 }));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Different content, different firstIndex, short length. // Different content, different firstIndex, short length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 1, 2), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 1, 2),
wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1)); wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Same content, same firstIndex, long length. // Same content, same firstIndex, long length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3 }), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3 }),
wrappedBuffer(order, new byte[] { 4, 5, 6 }), wrappedBuffer(order, new byte[] { 4, 5, 6 }),
wrappedBuffer(order, new byte[] { 7, 8, 9, 10 })); wrappedBuffer(order, new byte[] { 7, 8, 9, 10 }));
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Same content, different firstIndex, long length. // Same content, different firstIndex, long length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 5), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 5),
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5)); wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5));
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Different content, same firstIndex, long length. // Different content, same firstIndex, long length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 6 }), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 6 }),
wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 })); wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 }));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Different content, different firstIndex, long length. // Different content, different firstIndex, long length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 5), b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 5),
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5)); wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
} }
@Test @Test
public void testWrappedBuffer() { public void testWrappedBuffer() {
@ -259,7 +259,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
b.writerIndex(b.writerIndex() - 1); b.writerIndex(b.writerIndex() - 1);
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 2 })); wrappedBuffer(order, new byte[] { 2 }));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Same content, same firstIndex, short length. // Same content, same firstIndex, short length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
@ -269,7 +269,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 2 })); wrappedBuffer(order, new byte[] { 2 }));
b.writeBytes(wrappedBuffer(order, new byte[] { 3 })); b.writeBytes(wrappedBuffer(order, new byte[] { 3 }));
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Same content, different firstIndex, short length. // Same content, different firstIndex, short length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
@ -278,7 +278,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
b.writerIndex(b.writerIndex() - 1); b.writerIndex(b.writerIndex() - 1);
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1)); wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1));
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Different content, same firstIndex, short length. // Different content, same firstIndex, short length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
@ -287,7 +287,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
b.writerIndex(b.writerIndex() - 1); b.writerIndex(b.writerIndex() - 1);
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 4 })); wrappedBuffer(order, new byte[] { 4 }));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Different content, different firstIndex, short length. // Different content, different firstIndex, short length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
@ -296,7 +296,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
b.writerIndex(b.writerIndex() - 1); b.writerIndex(b.writerIndex() - 1);
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1)); wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Same content, same firstIndex, long length. // Same content, same firstIndex, long length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
@ -307,7 +307,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
wrappedBuffer(order, new byte[] { 4, 5, 6 })); wrappedBuffer(order, new byte[] { 4, 5, 6 }));
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 7, 8, 9, 10 })); wrappedBuffer(order, new byte[] { 7, 8, 9, 10 }));
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Same content, different firstIndex, long length. // Same content, different firstIndex, long length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
@ -316,7 +316,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
b.writerIndex(b.writerIndex() - 5); b.writerIndex(b.writerIndex() - 5);
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5)); wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5));
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Different content, same firstIndex, long length. // Different content, same firstIndex, long length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
@ -325,7 +325,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
b.writerIndex(b.writerIndex() - 5); b.writerIndex(b.writerIndex() - 5);
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 })); wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 }));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Different content, different firstIndex, long length. // Different content, different firstIndex, long length.
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
@ -334,6 +334,6 @@ public abstract class AbstractCompositeChannelBufferTest extends
b.writerIndex(b.writerIndex() - 5); b.writerIndex(b.writerIndex() - 5);
b.writeBytes( b.writeBytes(
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5)); wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5));
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
} }
} }

View File

@ -21,6 +21,6 @@ package io.netty.buffer;
*/ */
public class BigEndianCompositeChannelBufferTest extends AbstractCompositeChannelBufferTest { public class BigEndianCompositeChannelBufferTest extends AbstractCompositeChannelBufferTest {
public BigEndianCompositeChannelBufferTest() { public BigEndianCompositeChannelBufferTest() {
super(ByteBufs.BIG_ENDIAN); super(Unpooled.BIG_ENDIAN);
} }
} }

View File

@ -28,7 +28,7 @@ public class BigEndianDirectChannelBufferTest extends AbstractChannelBufferTest
@Override @Override
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffer = ByteBufs.directBuffer(ByteOrder.BIG_ENDIAN, length); buffer = Unpooled.directBuffer(ByteOrder.BIG_ENDIAN, length);
assertSame(ByteOrder.BIG_ENDIAN, buffer.order()); assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
assertEquals(0, buffer.writerIndex()); assertEquals(0, buffer.writerIndex());
return buffer; return buffer;

View File

@ -28,7 +28,7 @@ public class BigEndianHeapChannelBufferTest extends AbstractChannelBufferTest {
@Override @Override
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffer = ByteBufs.buffer(length); buffer = Unpooled.buffer(length);
assertEquals(0, buffer.writerIndex()); assertEquals(0, buffer.writerIndex());
return buffer; return buffer;
} }

View File

@ -28,7 +28,7 @@ public class ChannelBufferIndexFinderTest {
@Test @Test
public void testForward() { public void testForward() {
ByteBuf buf = ByteBufs.copiedBuffer( ByteBuf buf = Unpooled.copiedBuffer(
"abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx", "abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx",
CharsetUtil.ISO_8859_1); CharsetUtil.ISO_8859_1);
@ -47,7 +47,7 @@ public class ChannelBufferIndexFinderTest {
@Test @Test
public void testBackward() { public void testBackward() {
ByteBuf buf = ByteBufs.copiedBuffer( ByteBuf buf = Unpooled.copiedBuffer(
"abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx", "abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx",
CharsetUtil.ISO_8859_1); CharsetUtil.ISO_8859_1);

View File

@ -29,7 +29,7 @@ public class ChannelBufferStreamTest {
@Test @Test
public void testAll() throws Exception { public void testAll() throws Exception {
ByteBuf buf = ByteBufs.dynamicBuffer(); ByteBuf buf = Unpooled.dynamicBuffer();
try { try {
new ByteBufOutputStream(null); new ByteBufOutputStream(null);
@ -171,7 +171,7 @@ public class ChannelBufferStreamTest {
@Test @Test
public void testEmptyReadLine() throws Exception { public void testEmptyReadLine() throws Exception {
ByteBuf buf = ByteBufs.buffer(0); ByteBuf buf = Unpooled.buffer(0);
ByteBufInputStream in = new ByteBufInputStream(buf); ByteBufInputStream in = new ByteBufInputStream(buf);
String s = in.readLine(); String s = in.readLine();

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.InputStream; import java.io.InputStream;
@ -67,7 +67,7 @@ public class ChannelBuffersTest {
for (Entry<byte[], Integer> e: map.entrySet()) { for (Entry<byte[], Integer> e: map.entrySet()) {
assertEquals( assertEquals(
e.getValue().intValue(), e.getValue().intValue(),
ByteBufs.hashCode(wrappedBuffer(e.getKey()))); Unpooled.hashCode(wrappedBuffer(e.getKey())));
} }
} }
@ -78,47 +78,47 @@ public class ChannelBuffersTest {
// Different length. // Different length.
a = wrappedBuffer(new byte[] { 1 }); a = wrappedBuffer(new byte[] { 1 });
b = wrappedBuffer(new byte[] { 1, 2 }); b = wrappedBuffer(new byte[] { 1, 2 });
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Same content, same firstIndex, short length. // Same content, same firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }); a = wrappedBuffer(new byte[] { 1, 2, 3 });
b = wrappedBuffer(new byte[] { 1, 2, 3 }); b = wrappedBuffer(new byte[] { 1, 2, 3 });
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Same content, different firstIndex, short length. // Same content, different firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }); a = wrappedBuffer(new byte[] { 1, 2, 3 });
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 3); b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 3);
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Different content, same firstIndex, short length. // Different content, same firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }); a = wrappedBuffer(new byte[] { 1, 2, 3 });
b = wrappedBuffer(new byte[] { 1, 2, 4 }); b = wrappedBuffer(new byte[] { 1, 2, 4 });
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Different content, different firstIndex, short length. // Different content, different firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }); a = wrappedBuffer(new byte[] { 1, 2, 3 });
b = wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 3); b = wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 3);
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Same content, same firstIndex, long length. // Same content, same firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Same content, different firstIndex, long length. // Same content, different firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10); b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10);
assertTrue(ByteBufs.equals(a, b)); assertTrue(Unpooled.equals(a, b));
// Different content, same firstIndex, long length. // Different content, same firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 6, 7, 8, 5, 9, 10 }); b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 6, 7, 8, 5, 9, 10 });
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
// Different content, different firstIndex, long length. // Different content, different firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10); b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10);
assertFalse(ByteBufs.equals(a, b)); assertFalse(Unpooled.equals(a, b));
} }
@Test @Test
@ -197,14 +197,14 @@ public class ChannelBuffersTest {
@Test @Test
public void testCompare2() { public void testCompare2() {
assertTrue(ByteBufs.compare( assertTrue(Unpooled.compare(
ByteBufs.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}), Unpooled.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}),
ByteBufs.wrappedBuffer(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00})) Unpooled.wrappedBuffer(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}))
> 0); > 0);
assertTrue(ByteBufs.compare( assertTrue(Unpooled.compare(
ByteBufs.wrappedBuffer(new byte[]{(byte) 0xFF}), Unpooled.wrappedBuffer(new byte[]{(byte) 0xFF}),
ByteBufs.wrappedBuffer(new byte[]{(byte) 0x00})) Unpooled.wrappedBuffer(new byte[]{(byte) 0x00}))
> 0); > 0);
} }
@ -427,7 +427,7 @@ public class ChannelBuffersTest {
@Test @Test
public void testWrapSingleInt() { public void testWrapSingleInt() {
ByteBuf buffer = ByteBufs.copyInt(42); ByteBuf buffer = Unpooled.copyInt(42);
assertEquals(4, buffer.capacity()); assertEquals(4, buffer.capacity());
assertEquals(42, buffer.readInt()); assertEquals(42, buffer.readInt());
assertFalse(buffer.readable()); assertFalse(buffer.readable());
@ -435,19 +435,19 @@ public class ChannelBuffersTest {
@Test @Test
public void testWrapInt() { public void testWrapInt() {
ByteBuf buffer = ByteBufs.copyInt(1, 4); ByteBuf buffer = Unpooled.copyInt(1, 4);
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.readable());
assertEquals(0, ByteBufs.copyInt(null).capacity()); assertEquals(0, Unpooled.copyInt(null).capacity());
assertEquals(0, ByteBufs.copyInt(new int[0]).capacity()); assertEquals(0, Unpooled.copyInt(new int[0]).capacity());
} }
@Test @Test
public void testWrapSingleShort() { public void testWrapSingleShort() {
ByteBuf buffer = ByteBufs.copyShort(42); ByteBuf buffer = Unpooled.copyShort(42);
assertEquals(2, buffer.capacity()); assertEquals(2, buffer.capacity());
assertEquals(42, buffer.readShort()); assertEquals(42, buffer.readShort());
assertFalse(buffer.readable()); assertFalse(buffer.readable());
@ -455,31 +455,31 @@ public class ChannelBuffersTest {
@Test @Test
public void testWrapShortFromShortArray() { public void testWrapShortFromShortArray() {
ByteBuf buffer = ByteBufs.copyShort(new short[] { 1, 4 }); ByteBuf buffer = Unpooled.copyShort(new short[] { 1, 4 });
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.readable());
assertEquals(0, ByteBufs.copyShort((short[]) null).capacity()); assertEquals(0, Unpooled.copyShort((short[]) null).capacity());
assertEquals(0, ByteBufs.copyShort(new short[0]).capacity()); assertEquals(0, Unpooled.copyShort(new short[0]).capacity());
} }
@Test @Test
public void testWrapShortFromIntArray() { public void testWrapShortFromIntArray() {
ByteBuf buffer = ByteBufs.copyShort(1, 4); ByteBuf buffer = Unpooled.copyShort(1, 4);
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.readable());
assertEquals(0, ByteBufs.copyShort((int[]) null).capacity()); assertEquals(0, Unpooled.copyShort((int[]) null).capacity());
assertEquals(0, ByteBufs.copyShort(new int[0]).capacity()); assertEquals(0, Unpooled.copyShort(new int[0]).capacity());
} }
@Test @Test
public void testWrapSingleMedium() { public void testWrapSingleMedium() {
ByteBuf buffer = ByteBufs.copyMedium(42); ByteBuf buffer = Unpooled.copyMedium(42);
assertEquals(3, buffer.capacity()); assertEquals(3, buffer.capacity());
assertEquals(42, buffer.readMedium()); assertEquals(42, buffer.readMedium());
assertFalse(buffer.readable()); assertFalse(buffer.readable());
@ -487,19 +487,19 @@ public class ChannelBuffersTest {
@Test @Test
public void testWrapMedium() { public void testWrapMedium() {
ByteBuf buffer = ByteBufs.copyMedium(1, 4); ByteBuf buffer = Unpooled.copyMedium(1, 4);
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.readable());
assertEquals(0, ByteBufs.copyMedium(null).capacity()); assertEquals(0, Unpooled.copyMedium(null).capacity());
assertEquals(0, ByteBufs.copyMedium(new int[0]).capacity()); assertEquals(0, Unpooled.copyMedium(new int[0]).capacity());
} }
@Test @Test
public void testWrapSingleLong() { public void testWrapSingleLong() {
ByteBuf buffer = ByteBufs.copyLong(42); ByteBuf buffer = Unpooled.copyLong(42);
assertEquals(8, buffer.capacity()); assertEquals(8, buffer.capacity());
assertEquals(42, buffer.readLong()); assertEquals(42, buffer.readLong());
assertFalse(buffer.readable()); assertFalse(buffer.readable());
@ -507,19 +507,19 @@ public class ChannelBuffersTest {
@Test @Test
public void testWrapLong() { public void testWrapLong() {
ByteBuf buffer = ByteBufs.copyLong(1, 4); ByteBuf buffer = Unpooled.copyLong(1, 4);
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.readable());
assertEquals(0, ByteBufs.copyLong(null).capacity()); assertEquals(0, Unpooled.copyLong(null).capacity());
assertEquals(0, ByteBufs.copyLong(new long[0]).capacity()); assertEquals(0, Unpooled.copyLong(new long[0]).capacity());
} }
@Test @Test
public void testWrapSingleFloat() { public void testWrapSingleFloat() {
ByteBuf buffer = ByteBufs.copyFloat(42); ByteBuf buffer = Unpooled.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.readable());
@ -527,19 +527,19 @@ public class ChannelBuffersTest {
@Test @Test
public void testWrapFloat() { public void testWrapFloat() {
ByteBuf buffer = ByteBufs.copyFloat(1, 4); ByteBuf buffer = Unpooled.copyFloat(1, 4);
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.readable());
assertEquals(0, ByteBufs.copyFloat(null).capacity()); assertEquals(0, Unpooled.copyFloat(null).capacity());
assertEquals(0, ByteBufs.copyFloat(new float[0]).capacity()); assertEquals(0, Unpooled.copyFloat(new float[0]).capacity());
} }
@Test @Test
public void testWrapSingleDouble() { public void testWrapSingleDouble() {
ByteBuf buffer = ByteBufs.copyDouble(42); ByteBuf buffer = Unpooled.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.readable());
@ -547,26 +547,26 @@ public class ChannelBuffersTest {
@Test @Test
public void testWrapDouble() { public void testWrapDouble() {
ByteBuf buffer = ByteBufs.copyDouble(1, 4); ByteBuf buffer = Unpooled.copyDouble(1, 4);
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.readable());
assertEquals(0, ByteBufs.copyDouble(null).capacity()); assertEquals(0, Unpooled.copyDouble(null).capacity());
assertEquals(0, ByteBufs.copyDouble(new double[0]).capacity()); assertEquals(0, Unpooled.copyDouble(new double[0]).capacity());
} }
@Test @Test
public void testWrapBoolean() { public void testWrapBoolean() {
ByteBuf buffer = ByteBufs.copyBoolean(true, false); ByteBuf buffer = Unpooled.copyBoolean(true, false);
assertEquals(2, buffer.capacity()); assertEquals(2, buffer.capacity());
assertEquals(true, buffer.readBoolean()); assertEquals(true, buffer.readBoolean());
assertEquals(false, buffer.readBoolean()); assertEquals(false, buffer.readBoolean());
assertFalse(buffer.readable()); assertFalse(buffer.readable());
assertEquals(0, ByteBufs.copyBoolean(null).capacity()); assertEquals(0, Unpooled.copyBoolean(null).capacity());
assertEquals(0, ByteBufs.copyBoolean(new boolean[0]).capacity()); assertEquals(0, Unpooled.copyBoolean(new boolean[0]).capacity());
} }
} }

View File

@ -28,7 +28,7 @@ public class DuplicateChannelBufferTest extends AbstractChannelBufferTest {
@Override @Override
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffer = new DuplicatedByteBuf(ByteBufs.buffer(length)); buffer = new DuplicatedByteBuf(Unpooled.buffer(length));
assertEquals(0, buffer.writerIndex()); assertEquals(0, buffer.writerIndex());
return buffer; return buffer;
} }

View File

@ -30,7 +30,7 @@ public class DynamicChannelBufferTest extends AbstractChannelBufferTest {
@Override @Override
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffer = ByteBufs.dynamicBuffer(length); buffer = Unpooled.dynamicBuffer(length);
assertEquals(0, buffer.readerIndex()); assertEquals(0, buffer.readerIndex());
assertEquals(0, buffer.writerIndex()); assertEquals(0, buffer.writerIndex());

View File

@ -21,6 +21,6 @@ package io.netty.buffer;
*/ */
public class LittleEndianCompositeChannelBufferTest extends AbstractCompositeChannelBufferTest { public class LittleEndianCompositeChannelBufferTest extends AbstractCompositeChannelBufferTest {
public LittleEndianCompositeChannelBufferTest() { public LittleEndianCompositeChannelBufferTest() {
super(ByteBufs.LITTLE_ENDIAN); super(Unpooled.LITTLE_ENDIAN);
} }
} }

View File

@ -28,7 +28,7 @@ public class LittleEndianDirectChannelBufferTest extends AbstractChannelBufferTe
@Override @Override
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffer = ByteBufs.directBuffer(ByteOrder.LITTLE_ENDIAN, length); buffer = Unpooled.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order()); assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
assertEquals(0, buffer.writerIndex()); assertEquals(0, buffer.writerIndex());
return buffer; return buffer;

View File

@ -30,7 +30,7 @@ public class LittleEndianHeapChannelBufferTest extends AbstractChannelBufferTest
@Override @Override
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffer = ByteBufs.buffer(ByteOrder.LITTLE_ENDIAN, length); buffer = Unpooled.buffer(ByteOrder.LITTLE_ENDIAN, length);
assertEquals(0, buffer.writerIndex()); assertEquals(0, buffer.writerIndex());
return buffer; return buffer;
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static org.easymock.EasyMock.*; import static org.easymock.EasyMock.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -40,24 +40,24 @@ public class ReadOnlyChannelBufferTest {
@Test @Test
public void testUnmodifiableBuffer() { public void testUnmodifiableBuffer() {
assertTrue(ByteBufs.unmodifiableBuffer(ByteBufs.buffer(1)) instanceof ReadOnlyByteBuf); assertTrue(Unpooled.unmodifiableBuffer(Unpooled.buffer(1)) instanceof ReadOnlyByteBuf);
} }
@Test @Test
public void testUnwrap() { public void testUnwrap() {
ByteBuf buf = ByteBufs.buffer(1); ByteBuf buf = Unpooled.buffer(1);
assertSame(buf, ((WrappedByteBuf) ByteBufs.unmodifiableBuffer(buf)).unwrap()); assertSame(buf, ((WrappedByteBuf) Unpooled.unmodifiableBuffer(buf)).unwrap());
} }
@Test @Test
public void shouldHaveSameByteOrder() { public void shouldHaveSameByteOrder() {
ByteBuf buf = ByteBufs.buffer(ByteBufs.LITTLE_ENDIAN, 1); ByteBuf buf = Unpooled.buffer(Unpooled.LITTLE_ENDIAN, 1);
assertSame(ByteBufs.LITTLE_ENDIAN, ByteBufs.unmodifiableBuffer(buf).order()); assertSame(Unpooled.LITTLE_ENDIAN, Unpooled.unmodifiableBuffer(buf).order());
} }
@Test @Test
public void shouldReturnReadOnlyDerivedBuffer() { public void shouldReturnReadOnlyDerivedBuffer() {
ByteBuf buf = ByteBufs.unmodifiableBuffer(ByteBufs.buffer(1)); ByteBuf buf = Unpooled.unmodifiableBuffer(Unpooled.buffer(1));
assertTrue(buf.duplicate() instanceof ReadOnlyByteBuf); assertTrue(buf.duplicate() instanceof ReadOnlyByteBuf);
assertTrue(buf.slice() instanceof ReadOnlyByteBuf); assertTrue(buf.slice() instanceof ReadOnlyByteBuf);
assertTrue(buf.slice(0, 1) instanceof ReadOnlyByteBuf); assertTrue(buf.slice(0, 1) instanceof ReadOnlyByteBuf);
@ -66,7 +66,7 @@ public class ReadOnlyChannelBufferTest {
@Test @Test
public void shouldReturnWritableCopy() { public void shouldReturnWritableCopy() {
ByteBuf buf = ByteBufs.unmodifiableBuffer(ByteBufs.buffer(1)); ByteBuf buf = Unpooled.unmodifiableBuffer(Unpooled.buffer(1));
assertFalse(buf.copy() instanceof ReadOnlyByteBuf); assertFalse(buf.copy() instanceof ReadOnlyByteBuf);
} }

View File

@ -31,7 +31,7 @@ public class SlicedChannelBufferTest extends AbstractChannelBufferTest {
@Override @Override
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffer = ByteBufs.wrappedBuffer( buffer = Unpooled.wrappedBuffer(
new byte[length * 2], random.nextInt(length - 1) + 1, length); new byte[length * 2], random.nextInt(length - 1) + 1, length);
assertEquals(length, buffer.writerIndex()); assertEquals(length, buffer.writerIndex());
return buffer; return buffer;

View File

@ -28,7 +28,7 @@ public class TruncatedChannelBufferTest extends AbstractChannelBufferTest {
@Override @Override
protected ByteBuf newBuffer(int length) { protected ByteBuf newBuffer(int length) {
buffer = ByteBufs.wrappedBuffer( buffer = Unpooled.wrappedBuffer(
new byte[length * 2], 0, length); new byte[length * 2], 0, length);
assertEquals(length, buffer.writerIndex()); assertEquals(length, buffer.writerIndex());
return buffer; return buffer;

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -97,7 +97,7 @@ public class DefaultHttpChunkTrailer implements HttpChunkTrailer {
@Override @Override
public ByteBuf getContent() { public ByteBuf getContent() {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
@Override @Override

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import java.util.List; import java.util.List;
@ -30,7 +30,7 @@ public class DefaultHttpMessage implements HttpMessage {
private final HttpHeaders headers = new HttpHeaders(); private final HttpHeaders headers = new HttpHeaders();
private HttpVersion version; private HttpVersion version;
private ByteBuf content = ByteBufs.EMPTY_BUFFER; private ByteBuf content = Unpooled.EMPTY_BUFFER;
private boolean chunked; private boolean chunked;
/** /**
@ -73,7 +73,7 @@ public class DefaultHttpMessage implements HttpMessage {
public void setChunked(boolean chunked) { public void setChunked(boolean chunked) {
this.chunked = chunked; this.chunked = chunked;
if (chunked) { if (chunked) {
setContent(ByteBufs.EMPTY_BUFFER); setContent(Unpooled.EMPTY_BUFFER);
} }
} }
@ -85,7 +85,7 @@ public class DefaultHttpMessage implements HttpMessage {
@Override @Override
public void setContent(ByteBuf content) { public void setContent(ByteBuf content) {
if (content == null) { if (content == null) {
content = ByteBufs.EMPTY_BUFFER; content = Unpooled.EMPTY_BUFFER;
} }
if (content.readable() && isChunked()) { if (content.readable() && isChunked()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import java.util.Collections; import java.util.Collections;
@ -41,7 +41,7 @@ public interface HttpChunk {
HttpChunkTrailer LAST_CHUNK = new HttpChunkTrailer() { HttpChunkTrailer LAST_CHUNK = new HttpChunkTrailer() {
@Override @Override
public ByteBuf getContent() { public ByteBuf getContent() {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
@Override @Override
@ -113,7 +113,7 @@ public interface HttpChunk {
/** /**
* Returns the content of this chunk. If this is the 'end of content' * Returns the content of this chunk. If this is the 'end of content'
* marker, {@link ByteBufs#EMPTY_BUFFER} will be returned. * marker, {@link Unpooled#EMPTY_BUFFER} will be returned.
*/ */
ByteBuf getContent(); ByteBuf getContent();

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.http;
import static io.netty.handler.codec.http.HttpHeaders.*; import static io.netty.handler.codec.http.HttpHeaders.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
@ -48,7 +48,7 @@ import java.util.Map.Entry;
*/ */
public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMessage> { public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMessage> {
private static final ByteBuf CONTINUE = ByteBufs.copiedBuffer( private static final ByteBuf CONTINUE = Unpooled.copiedBuffer(
"HTTP/1.1 100 Continue\r\n\r\n", CharsetUtil.US_ASCII); "HTTP/1.1 100 Continue\r\n\r\n", CharsetUtil.US_ASCII);
private final int maxContentLength; private final int maxContentLength;
@ -101,7 +101,7 @@ public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMes
m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING); m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
} }
m.setChunked(false); m.setChunked(false);
m.setContent(ByteBufs.dynamicBuffer()); m.setContent(Unpooled.dynamicBuffer());
this.currentMessage = m; this.currentMessage = m;
return null; return null;
} else { } else {

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.MessageToMessageDecoder; import io.netty.handler.codec.MessageToMessageDecoder;
@ -84,7 +84,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
if (!m.isChunked()) { if (!m.isChunked()) {
ByteBuf content = m.getContent(); ByteBuf content = m.getContent();
// Decode the content // Decode the content
ByteBuf newContent = ByteBufs.dynamicBuffer(); ByteBuf newContent = Unpooled.dynamicBuffer();
decode(content, newContent); decode(content, newContent);
finishDecode(newContent); finishDecode(newContent);
@ -104,7 +104,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
// Decode the chunk if necessary. // Decode the chunk if necessary.
if (decoder != null) { if (decoder != null) {
if (!c.isLast()) { if (!c.isLast()) {
ByteBuf newContent = ByteBufs.dynamicBuffer(); ByteBuf newContent = Unpooled.dynamicBuffer();
decode(content, newContent); decode(content, newContent);
if (newContent.readable()) { if (newContent.readable()) {
c.setContent(newContent); c.setContent(newContent);
@ -112,7 +112,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
return null; return null;
} }
} else { } else {
ByteBuf lastProduct = ByteBufs.dynamicBuffer(); ByteBuf lastProduct = Unpooled.dynamicBuffer();
finishDecode(lastProduct); finishDecode(lastProduct);
// Generate an additional chunk if the decoder produced // Generate an additional chunk if the decoder produced

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.MessageToMessageCodec; import io.netty.handler.codec.MessageToMessageCodec;
@ -117,7 +117,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
if (!m.isChunked()) { if (!m.isChunked()) {
ByteBuf content = m.getContent(); ByteBuf content = m.getContent();
// Encode the content. // Encode the content.
ByteBuf newContent = ByteBufs.dynamicBuffer(); ByteBuf newContent = Unpooled.dynamicBuffer();
encode(content, newContent); encode(content, newContent);
finishEncode(newContent); finishEncode(newContent);
@ -136,7 +136,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
// Encode the chunk if necessary. // Encode the chunk if necessary.
if (encoder != null) { if (encoder != null) {
if (!c.isLast()) { if (!c.isLast()) {
ByteBuf newContent = ByteBufs.dynamicBuffer(); ByteBuf newContent = Unpooled.dynamicBuffer();
encode(content, newContent); encode(content, newContent);
if (content.readable()) { if (content.readable()) {
c.setContent(newContent); c.setContent(newContent);
@ -144,7 +144,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
return null; return null;
} }
} else { } else {
ByteBuf lastProduct = ByteBufs.dynamicBuffer(); ByteBuf lastProduct = Unpooled.dynamicBuffer();
finishEncode(lastProduct); finishEncode(lastProduct);
// Generate an additional chunk if the decoder produced // Generate an additional chunk if the decoder produced

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@ -83,13 +83,13 @@ public interface HttpMessage {
/** /**
* Returns the content of this message. If there is no content or * Returns the content of this message. If there is no content or
* {@link #isChunked()} returns {@code true}, an * {@link #isChunked()} returns {@code true}, an
* {@link ByteBufs#EMPTY_BUFFER} is returned. * {@link Unpooled#EMPTY_BUFFER} is returned.
*/ */
ByteBuf getContent(); ByteBuf getContent();
/** /**
* Sets the content of this message. If {@code null} is specified, * Sets the content of this message. If {@code null} is specified,
* the content of this message will be set to {@link ByteBufs#EMPTY_BUFFER}. * the content of this message will be set to {@link Unpooled#EMPTY_BUFFER}.
*/ */
void setContent(ByteBuf content); void setContent(ByteBuf content);
@ -156,7 +156,7 @@ public interface HttpMessage {
* consecutively, contain the actual content. * consecutively, contain the actual content.
* <p> * <p>
* If this method is called with {@code true}, the content of this message * If this method is called with {@code true}, the content of this message
* becomes {@link ByteBufs#EMPTY_BUFFER}. * becomes {@link Unpooled#EMPTY_BUFFER}.
* <p> * <p>
* Even if this method is called with {@code false}, {@link #isChunked()} * Even if this method is called with {@code false}, {@link #isChunked()}
* will keep returning {@code true} if the {@code "Transfer-Encoding"} of * will keep returning {@code true} if the {@code "Transfer-Encoding"} of

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.ReplayingDecoder; import io.netty.handler.codec.ReplayingDecoder;
@ -204,7 +204,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
} else { } else {
long contentLength = HttpHeaders.getContentLength(message, -1); long contentLength = HttpHeaders.getContentLength(message, -1);
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) { if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
content = ByteBufs.EMPTY_BUFFER; content = Unpooled.EMPTY_BUFFER;
return reset(); return reset();
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static io.netty.handler.codec.http.HttpConstants.*; import static io.netty.handler.codec.http.HttpConstants.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
/** /**
* Web Socket frame containing binary data * Web Socket frame containing binary data
@ -27,7 +27,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
* Creates a new empty binary frame. * Creates a new empty binary frame.
*/ */
public BinaryWebSocketFrame() { public BinaryWebSocketFrame() {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} }
/** /**

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
/** /**
@ -28,7 +28,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
* Creates a new empty close frame. * Creates a new empty close frame.
*/ */
public CloseWebSocketFrame() { public CloseWebSocketFrame() {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} }
/** /**
@ -78,7 +78,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
reasonBytes = reasonText.getBytes(CharsetUtil.UTF_8); reasonBytes = reasonText.getBytes(CharsetUtil.UTF_8);
} }
ByteBuf binaryData = ByteBufs.buffer(2 + reasonBytes.length); ByteBuf binaryData = Unpooled.buffer(2 + reasonBytes.length);
binaryData.writeShort(statusCode); binaryData.writeShort(statusCode);
if (reasonBytes.length > 0) { if (reasonBytes.length > 0) {
binaryData.writeBytes(reasonBytes); binaryData.writeBytes(reasonBytes);
@ -102,7 +102,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
setFinalFragment(finalFragment); setFinalFragment(finalFragment);
setRsv(rsv); setRsv(rsv);
if (binaryData == null) { if (binaryData == null) {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} else { } else {
setBinaryData(binaryData); setBinaryData(binaryData);
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
/** /**
@ -31,7 +31,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
* Creates a new empty continuation frame. * Creates a new empty continuation frame.
*/ */
public ContinuationWebSocketFrame() { public ContinuationWebSocketFrame() {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} }
/** /**
@ -115,9 +115,9 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
*/ */
public void setText(String text) { public void setText(String text) {
if (text == null || text.isEmpty()) { if (text == null || text.isEmpty()) {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} else { } else {
setBinaryData(ByteBufs.copiedBuffer(text, CharsetUtil.UTF_8)); setBinaryData(Unpooled.copiedBuffer(text, CharsetUtil.UTF_8));
} }
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
/** /**
* Web Socket frame containing binary data * Web Socket frame containing binary data
@ -28,7 +28,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
*/ */
public PingWebSocketFrame() { public PingWebSocketFrame() {
setFinalFragment(true); setFinalFragment(true);
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} }
/** /**

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
/** /**
* Web Socket frame containing binary data * Web Socket frame containing binary data
@ -27,7 +27,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
* Creates a new empty pong frame. * Creates a new empty pong frame.
*/ */
public PongWebSocketFrame() { public PongWebSocketFrame() {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} }
/** /**

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
/** /**
@ -28,7 +28,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
* Creates a new empty text frame. * Creates a new empty text frame.
*/ */
public TextWebSocketFrame() { public TextWebSocketFrame() {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} }
/** /**
@ -39,9 +39,9 @@ public class TextWebSocketFrame extends WebSocketFrame {
*/ */
public TextWebSocketFrame(String text) { public TextWebSocketFrame(String text) {
if (text == null || text.isEmpty()) { if (text == null || text.isEmpty()) {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} else { } else {
setBinaryData(ByteBufs.copiedBuffer(text, CharsetUtil.UTF_8)); setBinaryData(Unpooled.copiedBuffer(text, CharsetUtil.UTF_8));
} }
} }
@ -69,9 +69,9 @@ public class TextWebSocketFrame extends WebSocketFrame {
setFinalFragment(finalFragment); setFinalFragment(finalFragment);
setRsv(rsv); setRsv(rsv);
if (text == null || text.isEmpty()) { if (text == null || text.isEmpty()) {
setBinaryData(ByteBufs.EMPTY_BUFFER); setBinaryData(Unpooled.EMPTY_BUFFER);
} else { } else {
setBinaryData(ByteBufs.copiedBuffer(text, CharsetUtil.UTF_8)); setBinaryData(Unpooled.copiedBuffer(text, CharsetUtil.UTF_8));
} }
} }
@ -111,7 +111,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
if (text == null) { if (text == null) {
throw new NullPointerException("text"); throw new NullPointerException("text");
} }
setBinaryData(ByteBufs.copiedBuffer(text, CharsetUtil.UTF_8)); setBinaryData(Unpooled.copiedBuffer(text, CharsetUtil.UTF_8));
} }
@Override @Override

View File

@ -54,7 +54,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.CorruptedFrameException; import io.netty.handler.codec.CorruptedFrameException;
@ -257,7 +257,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
// Returning null means we will get called back // Returning null means we will get called back
payloadBuffer = in.readBytes(rbytes); payloadBuffer = in.readBytes(rbytes);
if (framePayload == null) { if (framePayload == null) {
framePayload = ByteBufs.buffer(toFrameLength(framePayloadLength)); framePayload = Unpooled.buffer(toFrameLength(framePayloadLength));
} }
framePayload.writeBytes(payloadBuffer); framePayload.writeBytes(payloadBuffer);
framePayloadBytesRead += rbytes; framePayloadBytesRead += rbytes;

View File

@ -54,7 +54,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.TooLongFrameException; import io.netty.handler.codec.TooLongFrameException;
@ -106,7 +106,7 @@ public class WebSocket08FrameEncoder extends MessageToByteEncoder<WebSocketFrame
WebSocketFrame frame = msg; WebSocketFrame frame = msg;
ByteBuf data = frame.getBinaryData(); ByteBuf data = frame.getBinaryData();
if (data == null) { if (data == null) {
data = ByteBufs.EMPTY_BUFFER; data = Unpooled.EMPTY_BUFFER;
} }
byte opcode; byte opcode;

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.DefaultHttpRequest;
@ -164,7 +164,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
} }
} }
request.setContent(ByteBufs.copiedBuffer(key3)); request.setContent(Unpooled.copiedBuffer(key3));
ChannelFuture future = channel.write(request); ChannelFuture future = channel.write(request);

View File

@ -19,7 +19,7 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.Values.*; import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*; import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
@ -154,11 +154,11 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length()); int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length());
int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length()); int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
long c = req.getContent().readLong(); long c = req.getContent().readLong();
ByteBuf input = ByteBufs.buffer(16); ByteBuf input = Unpooled.buffer(16);
input.writeInt(a); input.writeInt(a);
input.writeInt(b); input.writeInt(b);
input.writeLong(c); input.writeLong(c);
ByteBuf output = ByteBufs.wrappedBuffer(WebSocketUtil.md5(input.array())); ByteBuf output = Unpooled.wrappedBuffer(WebSocketUtil.md5(input.array()));
res.setContent(output); res.setContent(output);
} else { } else {
// Old Hixie 75 handshake method with no challenge: // Old Hixie 75 handshake method with no challenge:

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.handler.codec.base64.Base64; import io.netty.handler.codec.base64.Base64;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
@ -68,7 +68,7 @@ final class WebSocketUtil {
* @return encoded string * @return encoded string
*/ */
static String base64(byte[] bytes) { static String base64(byte[] bytes) {
ByteBuf hashed = ByteBufs.wrappedBuffer(bytes); ByteBuf hashed = Unpooled.wrappedBuffer(bytes);
return Base64.encode(hashed).toString(CharsetUtil.UTF_8); return Base64.encode(hashed).toString(CharsetUtil.UTF_8);
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
/** /**
@ -27,7 +27,7 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame {
private int streamID; private int streamID;
private boolean last; private boolean last;
private boolean compressed; private boolean compressed;
private ByteBuf data = ByteBufs.EMPTY_BUFFER; private ByteBuf data = Unpooled.EMPTY_BUFFER;
/** /**
* Creates a new instance. * Creates a new instance.
@ -80,7 +80,7 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame {
@Override @Override
public void setData(ByteBuf data) { public void setData(ByteBuf data) {
if (data == null) { if (data == null) {
data = ByteBufs.EMPTY_BUFFER; data = Unpooled.EMPTY_BUFFER;
} }
if (data.readableBytes() > SpdyCodecUtil.SPDY_MAX_LENGTH) { if (data.readableBytes() > SpdyCodecUtil.SPDY_MAX_LENGTH) {
throw new IllegalArgumentException("data payload cannot exceed " throw new IllegalArgumentException("data payload cannot exceed "

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
/** /**
* A SPDY Protocol Data Frame * A SPDY Protocol Data Frame
@ -58,13 +58,13 @@ public interface SpdyDataFrame {
/** /**
* Returns the data payload of this frame. If there is no data payload * Returns the data payload of this frame. If there is no data payload
* {@link ByteBufs#EMPTY_BUFFER} is returned. * {@link Unpooled#EMPTY_BUFFER} is returned.
*/ */
ByteBuf getData(); ByteBuf getData();
/** /**
* Sets the data payload of this frame. If {@code null} is specified, * Sets the data payload of this frame. If {@code null} is specified,
* the data payload will be set to {@link ByteBufs#EMPTY_BUFFER}. * the data payload will be set to {@link Unpooled#EMPTY_BUFFER}.
* The data payload cannot exceed 16777215 bytes. * The data payload cannot exceed 16777215 bytes.
*/ */
void setData(ByteBuf data); void setData(ByteBuf data);

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.spdy;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
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.TooLongFrameException; import io.netty.handler.codec.TooLongFrameException;
@ -554,7 +554,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
// Initialize header block decoding fields // Initialize header block decoding fields
headerSize = 0; headerSize = 0;
numHeaders = -1; numHeaders = -1;
decompressed = ByteBufs.dynamicBuffer(8192); decompressed = Unpooled.dynamicBuffer(8192);
} }
// Accumulate decompressed data // Accumulate decompressed data

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.spdy;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -305,13 +305,13 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
Set<String> names = headerFrame.getHeaderNames(); Set<String> names = headerFrame.getHeaderNames();
int numHeaders = names.size(); int numHeaders = names.size();
if (numHeaders == 0) { if (numHeaders == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
if (numHeaders > SPDY_MAX_NV_LENGTH) { if (numHeaders > SPDY_MAX_NV_LENGTH) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"header block contains too many headers"); "header block contains too many headers");
} }
ByteBuf headerBlock = ByteBufs.dynamicBuffer( ByteBuf headerBlock = Unpooled.dynamicBuffer(
ByteOrder.BIG_ENDIAN, 256); ByteOrder.BIG_ENDIAN, 256);
writeLengthField(version, headerBlock, numHeaders); writeLengthField(version, headerBlock, numHeaders);
for (String name: names) { for (String name: names) {
@ -341,9 +341,9 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
private synchronized ByteBuf compressHeaderBlock( private synchronized ByteBuf compressHeaderBlock(
ByteBuf uncompressed) throws Exception { ByteBuf uncompressed) throws Exception {
if (uncompressed.readableBytes() == 0) { if (uncompressed.readableBytes() == 0) {
return ByteBufs.EMPTY_BUFFER; return Unpooled.EMPTY_BUFFER;
} }
ByteBuf compressed = ByteBufs.dynamicBuffer(); ByteBuf compressed = Unpooled.dynamicBuffer();
synchronized (headerBlockCompressor) { synchronized (headerBlockCompressor) {
if (!finished) { if (!finished) {
headerBlockCompressor.setInput(uncompressed); headerBlockCompressor.setInput(uncompressed);

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder; import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.TooLongFrameException; import io.netty.handler.codec.TooLongFrameException;
@ -206,8 +206,8 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<Object, HttpMessage
ByteBuf spdyDataFrameData = spdyDataFrame.getData(); ByteBuf spdyDataFrameData = spdyDataFrame.getData();
int spdyDataFrameDataLen = spdyDataFrameData.readableBytes(); int spdyDataFrameDataLen = spdyDataFrameData.readableBytes();
if (content == ByteBufs.EMPTY_BUFFER) { if (content == Unpooled.EMPTY_BUFFER) {
content = ByteBufs.dynamicBuffer(spdyDataFrameDataLen); content = Unpooled.dynamicBuffer(spdyDataFrameDataLen);
content.writeBytes(spdyDataFrameData, spdyDataFrameData.readerIndex(), spdyDataFrameDataLen); content.writeBytes(spdyDataFrameData, spdyDataFrameData.readerIndex(), spdyDataFrameDataLen);
httpMessage.setContent(content); httpMessage.setContent(content);
} else { } else {

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.buffer.MessageBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerAdapter;
@ -88,12 +88,12 @@ public class SpdySessionHandler
@Override @Override
public MessageBuf<Object> newInboundBuffer(ChannelHandlerContext ctx) throws Exception { public MessageBuf<Object> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
return MessageBufs.buffer(); return Unpooled.messageBuffer();
} }
@Override @Override
public MessageBuf<Object> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception { public MessageBuf<Object> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
return MessageBufs.buffer(); return Unpooled.messageBuffer();
} }
@Override @Override

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.CodecException; import io.netty.handler.codec.CodecException;
import io.netty.handler.codec.PrematureChannelClosureException; import io.netty.handler.codec.PrematureChannelClosureException;
@ -39,7 +39,7 @@ public class HttpClientCodecTest {
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec); EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")); ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
ch.writeInbound(ByteBufs.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1)); ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1));
ch.finish(); ch.finish();
} }
@ -49,7 +49,7 @@ public class HttpClientCodecTest {
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec); EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")); ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
ch.writeInbound(ByteBufs.copiedBuffer(CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1)); ch.writeInbound(Unpooled.copiedBuffer(CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1));
ch.finish(); ch.finish();
} }
@ -76,7 +76,7 @@ public class HttpClientCodecTest {
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec); EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")); ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
ch.writeInbound(ByteBufs.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1)); ch.writeInbound(Unpooled.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1));
try { try {
ch.finish(); ch.finish();

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http.websocketx;
import static io.netty.handler.codec.http.HttpHeaders.Values.*; import static io.netty.handler.codec.http.HttpHeaders.Values.*;
import static io.netty.handler.codec.http.HttpVersion.*; import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpChunkAggregator; import io.netty.handler.codec.http.HttpChunkAggregator;
@ -50,7 +50,7 @@ public class WebSocketServerHandshaker00Test {
req.setHeader(Names.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00"); req.setHeader(Names.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00");
req.setHeader(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat"); req.setHeader(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
ByteBuf buffer = ByteBufs.copiedBuffer("^n:ds[4U", CharsetUtil.US_ASCII); ByteBuf buffer = Unpooled.copiedBuffer("^n:ds[4U", CharsetUtil.US_ASCII);
req.setContent(buffer); req.setContent(buffer);
new WebSocketServerHandshaker00( new WebSocketServerHandshaker00(

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundByteHandler; import io.netty.channel.ChannelInboundByteHandler;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
@ -35,7 +35,7 @@ public abstract class ByteToMessageDecoder<O>
@Override @Override
public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
return ByteBufs.dynamicBuffer(); return Unpooled.dynamicBuffer();
} }
@Override @Override

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
/** /**
* A set of commonly used delimiters for {@link DelimiterBasedFrameDecoder}. * A set of commonly used delimiters for {@link DelimiterBasedFrameDecoder}.
@ -29,7 +29,7 @@ public final class Delimiters {
*/ */
public static ByteBuf[] nulDelimiter() { public static ByteBuf[] nulDelimiter() {
return new ByteBuf[] { return new ByteBuf[] {
ByteBufs.wrappedBuffer(new byte[] { 0 }) }; Unpooled.wrappedBuffer(new byte[] { 0 }) };
} }
/** /**
@ -38,8 +38,8 @@ public final class Delimiters {
*/ */
public static ByteBuf[] lineDelimiter() { public static ByteBuf[] lineDelimiter() {
return new ByteBuf[] { return new ByteBuf[] {
ByteBufs.wrappedBuffer(new byte[] { '\r', '\n' }), Unpooled.wrappedBuffer(new byte[] { '\r', '\n' }),
ByteBufs.wrappedBuffer(new byte[] { '\n' }), Unpooled.wrappedBuffer(new byte[] { '\n' }),
}; };
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
/** /**
@ -68,7 +68,7 @@ public class FixedLengthFrameDecoder extends ByteToMessageDecoder<Object> {
@Override @Override
public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
if (allocateFullBuffer) { if (allocateFullBuffer) {
return ByteBufs.dynamicBuffer(frameLength); return Unpooled.dynamicBuffer(frameLength);
} else { } else {
return super.newInboundBuffer(ctx); return super.newInboundBuffer(ctx);
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.buffer.MessageBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInboundMessageHandler; import io.netty.channel.ChannelInboundMessageHandler;
@ -28,7 +28,7 @@ public abstract class MessageToMessageDecoder<I, O>
@Override @Override
public MessageBuf<I> newInboundBuffer(ChannelHandlerContext ctx) throws Exception { public MessageBuf<I> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
return MessageBufs.buffer(); return Unpooled.messageBuffer();
} }
@Override @Override

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -281,7 +281,7 @@ public abstract class ReplayingDecoder<O, S extends Enum<S>> extends ByteToMessa
static final Signal REPLAY = new Signal(ReplayingDecoder.class.getName() + ".REPLAY"); static final Signal REPLAY = new Signal(ReplayingDecoder.class.getName() + ".REPLAY");
private final ByteBuf cumulation = ByteBufs.dynamicBuffer(); private final ByteBuf cumulation = Unpooled.dynamicBuffer();
private final ReplayingDecoderBuffer replayable = new ReplayingDecoderBuffer(cumulation); private final ReplayingDecoderBuffer replayable = new ReplayingDecoderBuffer(cumulation);
private S state; private S state;
private int checkpoint = -1; private int checkpoint = -1;

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufFactory; import io.netty.buffer.ByteBufFactory;
import io.netty.buffer.ByteBufIndexFinder; import io.netty.buffer.ByteBufIndexFinder;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.util.Signal; import io.netty.util.Signal;
import java.io.IOException; import java.io.IOException;
@ -37,7 +37,7 @@ class ReplayingDecoderBuffer implements ByteBuf {
private final ByteBuf buffer; private final ByteBuf buffer;
private boolean terminated; private boolean terminated;
public static ReplayingDecoderBuffer EMPTY_BUFFER = new ReplayingDecoderBuffer(ByteBufs.EMPTY_BUFFER); public static ReplayingDecoderBuffer EMPTY_BUFFER = new ReplayingDecoderBuffer(Unpooled.EMPTY_BUFFER);
static { static {
EMPTY_BUFFER.terminate(); EMPTY_BUFFER.terminate();

View File

@ -16,9 +16,8 @@
package io.netty.handler.codec.bytes; package io.netty.handler.codec.bytes;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.buffer.MessageBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
@ -54,7 +53,7 @@ public class ByteArrayEncoder extends MessageToMessageEncoder<byte[], ByteBuf> {
@Override @Override
public MessageBuf<byte[]> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception { public MessageBuf<byte[]> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
return MessageBufs.buffer(); return Unpooled.messageBuffer();
} }
@Override @Override
@ -67,6 +66,6 @@ public class ByteArrayEncoder extends MessageToMessageEncoder<byte[], ByteBuf> {
if (msg.length == 0) { if (msg.length == 0) {
return null; return null;
} }
return ByteBufs.wrappedBuffer(msg); return Unpooled.wrappedBuffer(msg);
} }
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.compression; package io.netty.handler.codec.compression;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -383,9 +383,9 @@ public class ZlibEncoder extends ByteToByteEncoder {
future.setFailure(ZlibUtil.exception(z, "compression failure", resultCode)); future.setFailure(ZlibUtil.exception(z, "compression failure", resultCode));
return future; return future;
} else if (z.next_out_index != 0) { } else if (z.next_out_index != 0) {
footer = ByteBufs.wrappedBuffer(out, 0, z.next_out_index); footer = Unpooled.wrappedBuffer(out, 0, z.next_out_index);
} else { } else {
footer = ByteBufs.EMPTY_BUFFER; footer = Unpooled.EMPTY_BUFFER;
} }
} finally { } finally {
z.deflateEnd(); z.deflateEnd();

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.marshalling;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufFactory; import io.netty.buffer.ByteBufFactory;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import java.io.IOException; import java.io.IOException;
@ -44,7 +44,7 @@ class ChannelBufferByteOutput implements ByteOutput {
* Calls {@link #ChannelBufferByteOutput(ByteBuf)} with a dynamic {@link ByteBuf} * Calls {@link #ChannelBufferByteOutput(ByteBuf)} with a dynamic {@link ByteBuf}
*/ */
public ChannelBufferByteOutput(ByteBufFactory factory, int estimatedLength) { public ChannelBufferByteOutput(ByteBufFactory factory, int estimatedLength) {
this(ByteBufs.dynamicBuffer(estimatedLength, factory)); this(Unpooled.dynamicBuffer(estimatedLength, factory));
} }
@Override @Override

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.protobuf; package io.netty.handler.codec.protobuf;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.serialization;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -81,7 +81,7 @@ public class ObjectEncoderOutputStream extends OutputStream implements
@Override @Override
public void writeObject(Object obj) throws IOException { public void writeObject(Object obj) throws IOException {
ByteBufOutputStream bout = new ByteBufOutputStream( ByteBufOutputStream bout = new ByteBufOutputStream(
ByteBufs.dynamicBuffer(estimatedLength)); Unpooled.dynamicBuffer(estimatedLength));
ObjectOutputStream oout = new CompactObjectOutputStream(bout); ObjectOutputStream oout = new CompactObjectOutputStream(bout);
oout.writeObject(obj); oout.writeObject(obj);
oout.flush(); oout.flush();

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.string; package io.netty.handler.codec.string;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
@ -79,6 +79,6 @@ public class StringEncoder extends MessageToMessageEncoder<String, ByteBuf> {
@Override @Override
public ByteBuf encode(ChannelHandlerContext ctx, String msg) throws Exception { public ByteBuf encode(ChannelHandlerContext ctx, String msg) throws Exception {
return ByteBufs.copiedBuffer(msg, charset); return Unpooled.copiedBuffer(msg, charset);
} }
} }

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufIndexFinder; import io.netty.buffer.ByteBufIndexFinder;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.util.VoidEnum; import io.netty.util.VoidEnum;
@ -32,17 +32,17 @@ public class ReplayingDecoderTest {
EmbeddedByteChannel ch = new EmbeddedByteChannel(new LineDecoder()); EmbeddedByteChannel ch = new EmbeddedByteChannel(new LineDecoder());
// Ordinary input // Ordinary input
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A' })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
assertNull(ch.readInbound()); assertNull(ch.readInbound());
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'B' })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'B' }));
assertNull(ch.readInbound()); assertNull(ch.readInbound());
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'C' })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'C' }));
assertNull(ch.readInbound()); assertNull(ch.readInbound());
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { '\n' })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { '\n' }));
assertEquals(ByteBufs.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound()); assertEquals(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound());
// Truncated input // Truncated input
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A' })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
assertNull(ch.readInbound()); assertNull(ch.readInbound());
ch.close(); ch.close();
assertNull(ch.readInbound()); assertNull(ch.readInbound());

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.bytes; package io.netty.handler.codec.bytes;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static org.hamcrest.core.Is.*; import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.channel.embedded.EmbeddedMessageChannel; import io.netty.channel.embedded.EmbeddedMessageChannel;

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.bytes; package io.netty.handler.codec.bytes;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static org.hamcrest.core.Is.*; import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*; import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.frame;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.DelimiterBasedFrameDecoder; import io.netty.handler.codec.DelimiterBasedFrameDecoder;
@ -36,15 +36,15 @@ public class DelimiterBasedFrameDecoderTest {
new DelimiterBasedFrameDecoder(1, true, false, Delimiters.nulDelimiter())); new DelimiterBasedFrameDecoder(1, true, false, Delimiters.nulDelimiter()));
for (int i = 0; i < 2; i ++) { for (int i = 0; i < 2; i ++) {
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 1, 2 })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 }));
try { try {
assertTrue(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0 }))); assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0 })));
Assert.fail(DecoderException.class.getSimpleName() + " must be raised."); Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
} catch (TooLongFrameException e) { } catch (TooLongFrameException e) {
// Expected // Expected
} }
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A', 0 })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 }));
ByteBuf buf = (ByteBuf) ch.readInbound(); ByteBuf buf = (ByteBuf) ch.readInbound();
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
} }
@ -57,13 +57,13 @@ public class DelimiterBasedFrameDecoderTest {
for (int i = 0; i < 2; i ++) { for (int i = 0; i < 2; i ++) {
try { try {
assertTrue(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 1, 2 }))); assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 })));
Assert.fail(DecoderException.class.getSimpleName() + " must be raised."); Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
} catch (TooLongFrameException e) { } catch (TooLongFrameException e) {
// Expected // Expected
} }
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 'A', 0 })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 'A', 0 }));
ByteBuf buf = (ByteBuf) ch.readInbound(); ByteBuf buf = (ByteBuf) ch.readInbound();
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
} }

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.frame;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
@ -34,15 +34,15 @@ public class LengthFieldBasedFrameDecoderTest {
new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4, false)); new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4, false));
for (int i = 0; i < 2; i ++) { for (int i = 0; i < 2; i ++) {
assertFalse(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0, 0, 2 }))); assertFalse(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 2 })));
try { try {
assertTrue(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0 }))); assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0 })));
Assert.fail(DecoderException.class.getSimpleName() + " must be raised."); Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
} catch (TooLongFrameException e) { } catch (TooLongFrameException e) {
// Expected // Expected
} }
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0, 0, 1, 'A' })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 1, 'A' }));
ByteBuf buf = (ByteBuf) ch.readInbound(); ByteBuf buf = (ByteBuf) ch.readInbound();
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
} }
@ -55,13 +55,13 @@ public class LengthFieldBasedFrameDecoderTest {
for (int i = 0; i < 2; i ++) { for (int i = 0; i < 2; i ++) {
try { try {
assertTrue(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0, 0, 2 }))); assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 2 })));
Assert.fail(DecoderException.class.getSimpleName() + " must be raised."); Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
} catch (TooLongFrameException e) { } catch (TooLongFrameException e) {
// Expected // Expected
} }
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, 'A' })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, 'A' }));
ByteBuf buf = (ByteBuf) ch.readInbound(); ByteBuf buf = (ByteBuf) ch.readInbound();
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
} }

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.marshalling;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.CodecException; import io.netty.handler.codec.CodecException;
@ -64,7 +64,7 @@ public abstract class AbstractCompatibleMarshallingDecoderTest {
} }
protected ByteBuf input(byte[] input) { protected ByteBuf input(byte[] input) {
return ByteBufs.wrappedBuffer(input); return Unpooled.wrappedBuffer(input);
} }
@Test @Test

View File

@ -16,16 +16,16 @@
package io.netty.handler.codec.marshalling; package io.netty.handler.codec.marshalling;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
public class RiverMarshallingDecoderTest extends RiverCompatibleMarshallingDecoderTest { public class RiverMarshallingDecoderTest extends RiverCompatibleMarshallingDecoderTest {
@Override @Override
protected ByteBuf input(byte[] input) { protected ByteBuf input(byte[] input) {
ByteBuf length = ByteBufs.buffer(4); ByteBuf length = Unpooled.buffer(4);
length.writeInt(input.length); length.writeInt(input.length);
return ByteBufs.wrappedBuffer(length, ByteBufs.wrappedBuffer(input)); return Unpooled.wrappedBuffer(length, Unpooled.wrappedBuffer(input));
} }
@Override @Override

View File

@ -16,16 +16,16 @@
package io.netty.handler.codec.marshalling; package io.netty.handler.codec.marshalling;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
public class SerialMarshallingDecoderTest extends SerialCompatibleMarshallingDecoderTest { public class SerialMarshallingDecoderTest extends SerialCompatibleMarshallingDecoderTest {
@Override @Override
protected ByteBuf input(byte[] input) { protected ByteBuf input(byte[] input) {
ByteBuf length = ByteBufs.buffer(4); ByteBuf length = Unpooled.buffer(4);
length.writeInt(input.length); length.writeInt(input.length);
return ByteBufs.wrappedBuffer(length, ByteBufs.wrappedBuffer(input)); return Unpooled.wrappedBuffer(length, Unpooled.wrappedBuffer(input));
} }
@Override @Override

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.protobuf; package io.netty.handler.codec.protobuf;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static org.hamcrest.core.Is.*; import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*; import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.protobuf; package io.netty.handler.codec.protobuf;
import static io.netty.buffer.ByteBufs.*; import static io.netty.buffer.Unpooled.*;
import static org.hamcrest.core.Is.*; import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.channel.embedded.EmbeddedByteChannel; import io.netty.channel.embedded.EmbeddedByteChannel;

View File

@ -16,7 +16,7 @@
package io.netty.example.echo; package io.netty.example.echo;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundByteHandlerAdapter; import io.netty.channel.ChannelInboundByteHandlerAdapter;
@ -42,7 +42,7 @@ public class EchoClientHandler extends ChannelInboundByteHandlerAdapter {
if (firstMessageSize <= 0) { if (firstMessageSize <= 0) {
throw new IllegalArgumentException("firstMessageSize: " + firstMessageSize); throw new IllegalArgumentException("firstMessageSize: " + firstMessageSize);
} }
firstMessage = ByteBufs.buffer(firstMessageSize); firstMessage = Unpooled.buffer(firstMessageSize);
for (int i = 0; i < firstMessage.capacity(); i ++) { for (int i = 0; i < firstMessage.capacity(); i ++) {
firstMessage.writeByte((byte) i); firstMessage.writeByte((byte) i);
} }

View File

@ -20,7 +20,7 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpMethod.*; import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*; import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -215,7 +215,7 @@ public class HttpStaticFileServerHandler extends ChannelInboundMessageHandlerAda
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) { private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status); HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8"); response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.setContent(ByteBufs.copiedBuffer( response.setContent(Unpooled.copiedBuffer(
"Failure: " + status.toString() + "\r\n", "Failure: " + status.toString() + "\r\n",
CharsetUtil.UTF_8)); CharsetUtil.UTF_8));

View File

@ -20,7 +20,7 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*; import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -123,7 +123,7 @@ public class HttpSnoopServerHandler extends ChannelInboundMessageHandlerAdapter<
// Build the response object. // Build the response object.
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
response.setContent(ByteBufs.copiedBuffer(buf.toString(), CharsetUtil.UTF_8)); response.setContent(Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8"); response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
if (keepAlive) { if (keepAlive) {

View File

@ -19,7 +19,7 @@ import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpMethod.*; import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*; import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -108,7 +108,7 @@ public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<O
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) { private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
// Generate an error page if response status code is not OK (200). // Generate an error page if response status code is not OK (200).
if (res.getStatus().getCode() != 200) { if (res.getStatus().getCode() != 200) {
res.setContent(ByteBufs.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8)); res.setContent(Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
setContentLength(res, res.getContent().readableBytes()); setContentLength(res, res.getContent().readableBytes());
} }

View File

@ -37,7 +37,7 @@
package io.netty.example.http.websocketx.client; package io.netty.example.http.websocketx.client;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
@ -108,7 +108,7 @@ public class WebSocketClient {
// Ping // Ping
System.out.println("WebSocket Client sending ping"); System.out.println("WebSocket Client sending ping");
ch.write(new PingWebSocketFrame(ByteBufs.copiedBuffer(new byte[]{1, 2, 3, 4, 5, 6}))); ch.write(new PingWebSocketFrame(Unpooled.copiedBuffer(new byte[]{1, 2, 3, 4, 5, 6})));
// Close // Close
System.out.println("WebSocket Client sending close"); System.out.println("WebSocket Client sending close");

View File

@ -21,7 +21,7 @@ import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*; import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -121,7 +121,7 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) { private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
// Generate an error page if response status code is not OK (200). // Generate an error page if response status code is not OK (200).
if (res.getStatus().getCode() != 200) { if (res.getStatus().getCode() != 200) {
res.setContent(ByteBufs.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8)); res.setContent(Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
setContentLength(res, res.getContent().readableBytes()); setContentLength(res, res.getContent().readableBytes());
} }

View File

@ -16,7 +16,7 @@
package io.netty.example.http.websocketx.server; package io.netty.example.http.websocketx.server;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
/** /**
@ -27,7 +27,7 @@ public final class WebSocketServerIndexPage {
private static final String NEWLINE = "\r\n"; private static final String NEWLINE = "\r\n";
public static ByteBuf getContent(String webSocketLocation) { public static ByteBuf getContent(String webSocketLocation) {
return ByteBufs.copiedBuffer( return Unpooled.copiedBuffer(
"<html><head><title>Web Socket Test</title></head>" + NEWLINE + "<html><head><title>Web Socket Test</title></head>" + NEWLINE +
"<body>" + NEWLINE + "<body>" + NEWLINE +
"<script type=\"text/javascript\">" + NEWLINE + "<script type=\"text/javascript\">" + NEWLINE +

View File

@ -21,7 +21,7 @@ import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*; import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -122,7 +122,7 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) { private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
// Generate an error page if response status code is not OK (200). // Generate an error page if response status code is not OK (200).
if (res.getStatus().getCode() != 200) { if (res.getStatus().getCode() != 200) {
res.setContent(ByteBufs.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8)); res.setContent(Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
setContentLength(res, res.getContent().readableBytes()); setContentLength(res, res.getContent().readableBytes());
} }

View File

@ -16,7 +16,7 @@
package io.netty.example.qotm; package io.netty.example.qotm;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
@ -53,7 +53,7 @@ public class QuoteOfTheMomentClient {
// Broadcast the QOTM request to port 8080. // Broadcast the QOTM request to port 8080.
ch.write(new DatagramPacket( ch.write(new DatagramPacket(
ByteBufs.copiedBuffer("QOTM?", CharsetUtil.UTF_8), Unpooled.copiedBuffer("QOTM?", CharsetUtil.UTF_8),
new InetSocketAddress("255.255.255.255", port))); new InetSocketAddress("255.255.255.255", port)));
// QuoteOfTheMomentClientHandler will close the DatagramChannel when a // QuoteOfTheMomentClientHandler will close the DatagramChannel when a

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.qotm; package io.netty.example.qotm;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
@ -49,7 +49,7 @@ public class QuoteOfTheMomentServerHandler extends ChannelInboundMessageHandlerA
throws Exception { throws Exception {
if (msg.data().toString(CharsetUtil.UTF_8).equals("QOTM?")) { if (msg.data().toString(CharsetUtil.UTF_8).equals("QOTM?")) {
ctx.write(new DatagramPacket( ctx.write(new DatagramPacket(
ByteBufs.copiedBuffer("QOTM: " + nextQuote(), CharsetUtil.UTF_8), Unpooled.copiedBuffer("QOTM: " + nextQuote(), CharsetUtil.UTF_8),
msg.remoteAddress())); msg.remoteAddress()));
} }
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.logging; package io.netty.handler.logging;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundByteHandler; import io.netty.channel.ChannelInboundByteHandler;
@ -110,12 +110,12 @@ public class ByteLoggingHandler
} }
@Override @Override
public ByteBuf newOutboundBuffer(ChannelHandlerContext ctx) throws Exception { public ByteBuf newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
return ByteBufs.dynamicBuffer(); return Unpooled.dynamicBuffer();
} }
@Override @Override
public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
return ByteBufs.dynamicBuffer(); return Unpooled.dynamicBuffer();
} }
@Override @Override

View File

@ -16,7 +16,7 @@
package io.netty.handler.logging; package io.netty.handler.logging;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.buffer.MessageBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandler; import io.netty.channel.ChannelInboundMessageHandler;
@ -53,12 +53,12 @@ public class MessageLoggingHandler
} }
@Override @Override
public MessageBuf<Object> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception { public MessageBuf<Object> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
return MessageBufs.buffer(); return Unpooled.messageBuffer();
} }
@Override @Override
public MessageBuf<Object> newInboundBuffer(ChannelHandlerContext ctx) throws Exception { public MessageBuf<Object> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
return MessageBufs.buffer(); return Unpooled.messageBuffer();
} }
@Override @Override

View File

@ -17,7 +17,7 @@ package io.netty.handler.queue;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.buffer.MessageBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.BlockingOperationException; import io.netty.channel.BlockingOperationException;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -99,7 +99,7 @@ public class BlockingReadHandler<E> extends ChannelInboundMessageHandlerAdapter<
public MessageBuf<Object> newInboundBuffer( public MessageBuf<Object> newInboundBuffer(
ChannelHandlerContext ctx) throws Exception { ChannelHandlerContext ctx) throws Exception {
this.ctx = ctx; this.ctx = ctx;
return MessageBufs.wrappedBuffer(queue); return Unpooled.wrappedBuffer(queue);
} }
/** /**

View File

@ -16,7 +16,7 @@
package io.netty.handler.ssl; package io.netty.handler.ssl;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
@ -304,12 +304,12 @@ public class SslHandler
@Override @Override
public ByteBuf newOutboundBuffer(ChannelHandlerContext ctx) throws Exception { public ByteBuf newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
return ByteBufs.dynamicBuffer(); return Unpooled.dynamicBuffer();
} }
@Override @Override
public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
return ByteBufs.dynamicBuffer(); return Unpooled.dynamicBuffer();
} }
@Override @Override

View File

@ -16,7 +16,7 @@
package io.netty.handler.stream; package io.netty.handler.stream;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.buffer.MessageBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@ -72,7 +72,7 @@ public class ChunkedWriteHandler
InternalLoggerFactory.getInstance(ChunkedWriteHandler.class); InternalLoggerFactory.getInstance(ChunkedWriteHandler.class);
private final MessageBuf<Object> queue = MessageBufs.buffer(); private final MessageBuf<Object> queue = Unpooled.messageBuffer();
private final int maxPendingWrites; private final int maxPendingWrites;
private volatile ChannelHandlerContext ctx; private volatile ChannelHandlerContext ctx;
private final AtomicInteger pendingWrites = new AtomicInteger(); private final AtomicInteger pendingWrites = new AtomicInteger();

View File

@ -17,7 +17,7 @@ package io.netty.handler.stream;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
@ -101,11 +101,11 @@ public class ChunkedWriteHandlerTest {
// http://stackoverflow.com/questions/10409241/why-is-close-channelfuturelistener-not-notified/10426305#comment14126161_10426305 // http://stackoverflow.com/questions/10409241/why-is-close-channelfuturelistener-not-notified/10426305#comment14126161_10426305
@Test @Test
public void testListenerNotifiedWhenIsEnd() { public void testListenerNotifiedWhenIsEnd() {
ByteBuf buffer = ByteBufs.copiedBuffer("Test", CharsetUtil.ISO_8859_1); ByteBuf buffer = Unpooled.copiedBuffer("Test", CharsetUtil.ISO_8859_1);
ChunkedByteInput input = new ChunkedByteInput() { ChunkedByteInput input = new ChunkedByteInput() {
private boolean done; private boolean done;
private final ByteBuf buffer = ByteBufs.copiedBuffer("Test", CharsetUtil.ISO_8859_1); private final ByteBuf buffer = Unpooled.copiedBuffer("Test", CharsetUtil.ISO_8859_1);
@Override @Override
public boolean isEndOfInput() throws Exception { public boolean isEndOfInput() throws Exception {

View File

@ -17,7 +17,7 @@ package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandlerAdapter;
@ -68,7 +68,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
cc.joinGroup(groupAddress, NetworkConstants.LOOPBACK_IF).sync(); cc.joinGroup(groupAddress, NetworkConstants.LOOPBACK_IF).sync();
sc.write(new DatagramPacket(ByteBufs.copyInt(1), groupAddress)).sync(); sc.write(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
assertTrue(mhandler.await()); assertTrue(mhandler.await());
// leave the group // leave the group
@ -78,7 +78,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
Thread.sleep(1000); Thread.sleep(1000);
// we should not receive a message anymore as we left the group before // we should not receive a message anymore as we left the group before
sc.write(new DatagramPacket(ByteBufs.copyInt(1), groupAddress)).sync(); sc.write(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
mhandler.await(); mhandler.await();
sc.close().awaitUninterruptibly(); sc.close().awaitUninterruptibly();

View File

@ -17,7 +17,7 @@ package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufs; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandlerAdapter;
@ -61,7 +61,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
Channel sc = sb.bind().sync().channel(); Channel sc = sb.bind().sync().channel();
Channel cc = cb.bind().sync().channel(); Channel cc = cb.bind().sync().channel();
cc.write(new DatagramPacket(ByteBufs.copyInt(1), addr)).sync(); cc.write(new DatagramPacket(Unpooled.copyInt(1), addr)).sync();
assertTrue(latch.await(10, TimeUnit.SECONDS)); assertTrue(latch.await(10, TimeUnit.SECONDS));
sc.close().sync(); sc.close().sync();

Some files were not shown because too many files have changed in this diff Show More