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) {
checkReadableBytes(length);
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
ByteBuf buf = factory().getBuffer(order(), length);
buf.writeBytes(this, readerIndex, length);
@ -629,17 +629,17 @@ public abstract class AbstractByteBuf implements ByteBuf {
nioBuffer.flip();
}
return ByteBufs.decodeString(nioBuffer, charset);
return Unpooled.decodeString(nioBuffer, charset);
}
@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
return ByteBufs.indexOf(this, fromIndex, toIndex, value);
return Unpooled.indexOf(this, fromIndex, toIndex, value);
}
@Override
public int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
return ByteBufs.indexOf(this, fromIndex, toIndex, indexFinder);
return Unpooled.indexOf(this, fromIndex, toIndex, indexFinder);
}
@Override
@ -685,7 +685,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
@Override
public int hashCode() {
return ByteBufs.hashCode(this);
return Unpooled.hashCode(this);
}
@Override
@ -693,12 +693,12 @@ public abstract class AbstractByteBuf implements ByteBuf {
if (!(o instanceof ByteBuf)) {
return false;
}
return ByteBufs.equals(this, (ByteBuf) o);
return Unpooled.equals(this, (ByteBuf) o);
}
@Override
public int compareTo(ByteBuf that) {
return ByteBufs.compare(this, that);
return Unpooled.compare(this, that);
}
@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)}
* and {@link ByteBufs#wrappedBuffer(byte[])} instead of calling the
* A big-endian Java heap buffer. It is recommended to use {@link Unpooled#buffer(int)}
* and {@link Unpooled#wrappedBuffer(byte[])} instead of calling the
* constructor explicitly.
*/
public class BigEndianHeapByteBuf extends HeapByteBuf {

View File

@ -33,7 +33,7 @@ import java.nio.charset.UnsupportedCharsetException;
* <h3>Creation of a buffer</h3>
*
* 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.
*
* <h3>Random Access Indexing</h3>
@ -292,7 +292,7 @@ public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
* <pre>
* // Create a buffer whose readerIndex, writerIndex and capacity are
* // 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
* // readerIndex (2) cannot be greater than the current writerIndex (0).
@ -305,7 +305,7 @@ public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
* <pre>
* // Create a buffer whose readerIndex, writerIndex and capacity are
* // 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.
* 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
* is recommended to use {@link ByteBufs#wrappedBuffer(ByteBuf...)}
* is recommended to use {@link Unpooled#wrappedBuffer(ByteBuf...)}
* instead of calling the constructor explicitly.
*/
public class CompositeByteBuf extends AbstractByteBuf {
@ -581,20 +581,20 @@ public class CompositeByteBuf extends AbstractByteBuf {
public ByteBuf slice(int index, int length) {
if (index == 0) {
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
} else if (index < 0 || index > capacity() - length) {
throw new IndexOutOfBoundsException("Invalid index: " + index
+ " - Bytes needed: " + (index + length) + ", maximum is "
+ capacity());
} else if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
List<ByteBuf> components = decompose(index, length);
switch (components.size()) {
case 0:
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
case 1:
return components.get(0);
default:
@ -710,7 +710,7 @@ public class CompositeByteBuf extends AbstractByteBuf {
// Add a new buffer so that the capacity of this composite buffer does
// not decrease due to the discarded components.
// 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);
list.add(padding);

View File

@ -111,10 +111,10 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
throw new IllegalArgumentException("capacity: " + capacity);
}
if (capacity == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
if (capacity >= preallocatedBufCapacity) {
return ByteBufs.directBuffer(order, capacity);
return Unpooled.directBuffer(order, capacity);
}
ByteBuf slice;
@ -136,7 +136,7 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
throw new IndexOutOfBoundsException("offset: " + offset);
}
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
if (offset + length > array.length) {
throw new IndexOutOfBoundsException("length: " + length);
@ -150,7 +150,7 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
@Override
public ByteBuf getBuffer(ByteBuffer nioBuffer) {
if (!nioBuffer.isReadOnly() && nioBuffer.isDirect()) {
return ByteBufs.wrappedBuffer(nioBuffer);
return Unpooled.wrappedBuffer(nioBuffer);
}
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
@ -164,14 +164,14 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
ByteBuf slice;
synchronized (bigEndianLock) {
if (preallocatedBEBuf == null) {
preallocatedBEBuf = ByteBufs.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
preallocatedBEBuf = Unpooled.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
slice = preallocatedBEBuf.slice(0, capacity);
preallocatedBEBufPos = capacity;
} else if (preallocatedBEBuf.capacity() - preallocatedBEBufPos >= capacity) {
slice = preallocatedBEBuf.slice(preallocatedBEBufPos, capacity);
preallocatedBEBufPos += capacity;
} else {
preallocatedBEBuf = ByteBufs.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
preallocatedBEBuf = Unpooled.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
slice = preallocatedBEBuf.slice(0, capacity);
preallocatedBEBufPos = capacity;
}
@ -183,14 +183,14 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
ByteBuf slice;
synchronized (littleEndianLock) {
if (preallocatedLEBuf == null) {
preallocatedLEBuf = ByteBufs.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
preallocatedLEBuf = Unpooled.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
slice = preallocatedLEBuf.slice(0, capacity);
preallocatedLEBufPos = capacity;
} else if (preallocatedLEBuf.capacity() - preallocatedLEBufPos >= capacity) {
slice = preallocatedLEBuf.slice(preallocatedLEBufPos, capacity);
preallocatedLEBufPos += capacity;
} else {
preallocatedLEBuf = ByteBufs.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
preallocatedLEBuf = Unpooled.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
slice = preallocatedLEBuf.slice(0, 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
* recommended to use {@link ByteBufs#dynamicBuffer(int)} instead of
* recommended to use {@link Unpooled#dynamicBuffer(int)} instead of
* calling the constructor explicitly.
*/
public class DynamicByteBuf extends AbstractByteBuf {
@ -310,12 +310,12 @@ public class DynamicByteBuf extends AbstractByteBuf {
public ByteBuf slice(int index, int length) {
if (index == 0) {
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
return new TruncatedByteBuf(this, length);
} else {
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
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) {
if (index == 0) {
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
if (length == array.length) {
ByteBuf slice = duplicate();
@ -183,7 +183,7 @@ public abstract class HeapByteBuf extends AbstractByteBuf {
}
} else {
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
return new SlicedByteBuf(this, index, length);
}

View File

@ -66,18 +66,18 @@ public class HeapByteBufFactory extends AbstractByteBufFactory {
@Override
public ByteBuf getBuffer(ByteOrder order, int capacity) {
return ByteBufs.buffer(order, capacity);
return Unpooled.buffer(order, capacity);
}
@Override
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
public ByteBuf getBuffer(ByteBuffer nioBuffer) {
if (nioBuffer.hasArray()) {
return ByteBufs.wrappedBuffer(nioBuffer);
return Unpooled.wrappedBuffer(nioBuffer);
}
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)}
* and {@link ByteBufs#wrappedBuffer(ByteOrder, byte[])} instead of
* A little-endian Java heap buffer. It is recommended to use {@link Unpooled#buffer(ByteOrder, int)}
* and {@link Unpooled#wrappedBuffer(ByteOrder, byte[])} instead of
* calling the constructor explicitly.
*/
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;
/**
* A NIO {@link ByteBuffer} based buffer. It is recommended to use {@link ByteBufs#directBuffer(int)}
* and {@link ByteBufs#wrappedBuffer(ByteBuffer)} instead of calling the
* A NIO {@link ByteBuffer} based buffer. It is recommended to use {@link Unpooled#directBuffer(int)}
* and {@link Unpooled#wrappedBuffer(ByteBuffer)} instead of calling the
* constructor explicitly.
*/
public class NioBufferBackedByteBuf extends AbstractByteBuf {
@ -299,7 +299,7 @@ public class NioBufferBackedByteBuf extends AbstractByteBuf {
return slice;
} else {
if (index >= 0 && length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
return new NioBufferBackedByteBuf(
((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
* recommended to use {@link ByteBufs#unmodifiableBuffer(ByteBuf)}
* recommended to use {@link Unpooled#unmodifiableBuffer(ByteBuf)}
* instead of calling the constructor explicitly.
*/
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) {
checkIndex(index, length);
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
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) {
checkIndex(index, length);
if (length == 0) {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
return buffer.slice(index, length);
}

View File

@ -27,17 +27,18 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.util.ArrayList;
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.
*
* <h3>Use static import</h3>
* This classes is intended to be used with Java 5 static import statement:
*
* <pre>
* import static io.netty.buffer.{@link ByteBufs}.*;
* import static io.netty.buffer.{@link Unpooled}.*;
*
* {@link ByteBuf} heapBuffer = buffer(128);
* {@link ByteBuf} directBuffer = directBuffer(256);
@ -84,7 +85,7 @@ import java.util.List;
* @apiviz.landmark
* @apiviz.has io.netty.buffer.ChannelBuffer oneway - - creates
*/
public final class ByteBufs {
public final class Unpooled {
/**
* 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
* {@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) {
ByteBuffer dst = ByteBufs.encodeString(buffer, charset);
ByteBuffer dst = Unpooled.encodeString(buffer, charset);
ByteBuf result = wrappedBuffer(endianness, dst.array());
result.writerIndex(dst.remaining());
return result;
@ -1321,7 +1334,7 @@ public final class ByteBufs {
return dst.flip().toString();
}
private ByteBufs() {
private Unpooled() {
// Unused
}
}

View File

@ -98,7 +98,7 @@
* 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
* which is created by the
* {@link io.netty.buffer.ByteBufs#dynamicBuffer()} method.
* {@link io.netty.buffer.Unpooled#dynamicBuffer()} method.
* <pre>
* // A new dynamic buffer is created. Internally, the actual buffer is created
* // lazily to avoid potentially wasted memory space.

View File

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

View File

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

View File

@ -28,7 +28,7 @@ public class BigEndianDirectChannelBufferTest extends AbstractChannelBufferTest
@Override
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());
assertEquals(0, buffer.writerIndex());
return buffer;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ public class LittleEndianDirectChannelBufferTest extends AbstractChannelBufferTe
@Override
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());
assertEquals(0, buffer.writerIndex());
return buffer;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelPipeline;
import java.util.Collections;
@ -41,7 +41,7 @@ public interface HttpChunk {
HttpChunkTrailer LAST_CHUNK = new HttpChunkTrailer() {
@Override
public ByteBuf getContent() {
return ByteBufs.EMPTY_BUFFER;
return Unpooled.EMPTY_BUFFER;
}
@Override
@ -113,7 +113,7 @@ public interface HttpChunk {
/**
* 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();

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.http;
import static io.netty.handler.codec.http.HttpHeaders.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
@ -48,7 +48,7 @@ import java.util.Map.Entry;
*/
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);
private final int maxContentLength;
@ -101,7 +101,7 @@ public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMes
m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
}
m.setChunked(false);
m.setContent(ByteBufs.dynamicBuffer());
m.setContent(Unpooled.dynamicBuffer());
this.currentMessage = m;
return null;
} else {

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@
*/
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 io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

View File

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

View File

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

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
/**
@ -31,7 +31,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
* Creates a new empty continuation frame.
*/
public ContinuationWebSocketFrame() {
setBinaryData(ByteBufs.EMPTY_BUFFER);
setBinaryData(Unpooled.EMPTY_BUFFER);
}
/**
@ -115,9 +115,9 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
*/
public void setText(String text) {
if (text == null || text.isEmpty()) {
setBinaryData(ByteBufs.EMPTY_BUFFER);
setBinaryData(Unpooled.EMPTY_BUFFER);
} 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;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
/**
* Web Socket frame containing binary data
@ -28,7 +28,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
*/
public PingWebSocketFrame() {
setFinalFragment(true);
setBinaryData(ByteBufs.EMPTY_BUFFER);
setBinaryData(Unpooled.EMPTY_BUFFER);
}
/**

View File

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

View File

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

View File

@ -54,7 +54,7 @@
package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
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
payloadBuffer = in.readBytes(rbytes);
if (framePayload == null) {
framePayload = ByteBufs.buffer(toFrameLength(framePayloadLength));
framePayload = Unpooled.buffer(toFrameLength(framePayloadLength));
}
framePayload.writeBytes(payloadBuffer);
framePayloadBytesRead += rbytes;

View File

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

View File

@ -15,7 +15,7 @@
*/
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.ChannelFuture;
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);

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.HttpVersion.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
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 b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
long c = req.getContent().readLong();
ByteBuf input = ByteBufs.buffer(16);
ByteBuf input = Unpooled.buffer(16);
input.writeInt(a);
input.writeInt(b);
input.writeLong(c);
ByteBuf output = ByteBufs.wrappedBuffer(WebSocketUtil.md5(input.array()));
ByteBuf output = Unpooled.wrappedBuffer(WebSocketUtil.md5(input.array()));
res.setContent(output);
} else {
// Old Hixie 75 handshake method with no challenge:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http;
import static org.junit.Assert.*;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.CodecException;
import io.netty.handler.codec.PrematureChannelClosureException;
@ -39,7 +39,7 @@ public class HttpClientCodecTest {
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
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();
}
@ -49,7 +49,7 @@ public class HttpClientCodecTest {
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
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();
}
@ -76,7 +76,7 @@ public class HttpClientCodecTest {
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
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 {
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.HttpVersion.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.http.DefaultHttpRequest;
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_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);
new WebSocketServerHandshaker00(

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
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");
private final ByteBuf cumulation = ByteBufs.dynamicBuffer();
private final ByteBuf cumulation = Unpooled.dynamicBuffer();
private final ReplayingDecoderBuffer replayable = new ReplayingDecoderBuffer(cumulation);
private S state;
private int checkpoint = -1;

View File

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

View File

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

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.compression;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
@ -383,9 +383,9 @@ public class ZlibEncoder extends ByteToByteEncoder {
future.setFailure(ZlibUtil.exception(z, "compression failure", resultCode));
return future;
} 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 {
footer = ByteBufs.EMPTY_BUFFER;
footer = Unpooled.EMPTY_BUFFER;
}
} finally {
z.deflateEnd();

View File

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

View File

@ -15,7 +15,7 @@
*/
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.channel.ChannelHandler.Sharable;
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.ByteBufOutputStream;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import java.io.DataOutputStream;
import java.io.IOException;
@ -81,7 +81,7 @@ public class ObjectEncoderOutputStream extends OutputStream implements
@Override
public void writeObject(Object obj) throws IOException {
ByteBufOutputStream bout = new ByteBufOutputStream(
ByteBufs.dynamicBuffer(estimatedLength));
Unpooled.dynamicBuffer(estimatedLength));
ObjectOutputStream oout = new CompactObjectOutputStream(bout);
oout.writeObject(obj);
oout.flush();

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.string;
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.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
@ -79,6 +79,6 @@ public class StringEncoder extends MessageToMessageEncoder<String, ByteBuf> {
@Override
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufIndexFinder;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.util.VoidEnum;
@ -32,17 +32,17 @@ public class ReplayingDecoderTest {
EmbeddedByteChannel ch = new EmbeddedByteChannel(new LineDecoder());
// Ordinary input
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A' }));
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
assertNull(ch.readInbound());
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'B' }));
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'B' }));
assertNull(ch.readInbound());
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'C' }));
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'C' }));
assertNull(ch.readInbound());
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { '\n' }));
assertEquals(ByteBufs.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound());
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { '\n' }));
assertEquals(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound());
// Truncated input
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A' }));
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
assertNull(ch.readInbound());
ch.close();
assertNull(ch.readInbound());

View File

@ -15,7 +15,7 @@
*/
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.junit.Assert.*;
import io.netty.channel.embedded.EmbeddedMessageChannel;

View File

@ -15,7 +15,7 @@
*/
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.IsNull.*;
import static org.junit.Assert.*;

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.frame;
import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
@ -36,15 +36,15 @@ public class DelimiterBasedFrameDecoderTest {
new DelimiterBasedFrameDecoder(1, true, false, Delimiters.nulDelimiter()));
for (int i = 0; i < 2; i ++) {
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 1, 2 }));
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 }));
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.");
} catch (TooLongFrameException e) {
// Expected
}
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A', 0 }));
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 }));
ByteBuf buf = (ByteBuf) ch.readInbound();
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
}
@ -57,13 +57,13 @@ public class DelimiterBasedFrameDecoderTest {
for (int i = 0; i < 2; i ++) {
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.");
} catch (TooLongFrameException e) {
// Expected
}
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 'A', 0 }));
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 'A', 0 }));
ByteBuf buf = (ByteBuf) ch.readInbound();
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
@ -34,15 +34,15 @@ public class LengthFieldBasedFrameDecoderTest {
new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4, false));
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 {
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.");
} catch (TooLongFrameException e) {
// 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();
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
}
@ -55,13 +55,13 @@ public class LengthFieldBasedFrameDecoderTest {
for (int i = 0; i < 2; i ++) {
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.");
} catch (TooLongFrameException e) {
// 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();
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.embedded.EmbeddedByteChannel;
import io.netty.handler.codec.CodecException;
@ -64,7 +64,7 @@ public abstract class AbstractCompatibleMarshallingDecoderTest {
}
protected ByteBuf input(byte[] input) {
return ByteBufs.wrappedBuffer(input);
return Unpooled.wrappedBuffer(input);
}
@Test

View File

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

View File

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

View File

@ -15,7 +15,7 @@
*/
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.IsNull.*;
import static org.junit.Assert.*;

View File

@ -15,7 +15,7 @@
*/
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.junit.Assert.*;
import io.netty.channel.embedded.EmbeddedByteChannel;

View File

@ -16,7 +16,7 @@
package io.netty.example.echo;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundByteHandlerAdapter;
@ -42,7 +42,7 @@ public class EchoClientHandler extends ChannelInboundByteHandlerAdapter {
if (firstMessageSize <= 0) {
throw new IllegalArgumentException("firstMessageSize: " + firstMessageSize);
}
firstMessage = ByteBufs.buffer(firstMessageSize);
firstMessage = Unpooled.buffer(firstMessageSize);
for (int i = 0; i < firstMessage.capacity(); 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.HttpResponseStatus.*;
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.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
@ -215,7 +215,7 @@ public class HttpStaticFileServerHandler extends ChannelInboundMessageHandlerAda
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.setContent(ByteBufs.copiedBuffer(
response.setContent(Unpooled.copiedBuffer(
"Failure: " + status.toString() + "\r\n",
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.HttpVersion.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
@ -123,7 +123,7 @@ public class HttpSnoopServerHandler extends ChannelInboundMessageHandlerAdapter<
// Build the response object.
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");
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.HttpResponseStatus.*;
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.ChannelFutureListener;
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) {
// Generate an error page if response status code is not OK (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());
}

View File

@ -37,7 +37,7 @@
package io.netty.example.http.websocketx.client;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
@ -108,7 +108,7 @@ public class WebSocketClient {
// 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
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.HttpVersion.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
@ -121,7 +121,7 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
// Generate an error page if response status code is not OK (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());
}

View File

@ -16,7 +16,7 @@
package io.netty.example.http.websocketx.server;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
/**
@ -27,7 +27,7 @@ public final class WebSocketServerIndexPage {
private static final String NEWLINE = "\r\n";
public static ByteBuf getContent(String webSocketLocation) {
return ByteBufs.copiedBuffer(
return Unpooled.copiedBuffer(
"<html><head><title>Web Socket Test</title></head>" + NEWLINE +
"<body>" + 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.HttpVersion.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
@ -122,7 +122,7 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
// Generate an error page if response status code is not OK (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());
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@ package io.netty.handler.stream;
import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.buffer.MessageBuf;
import io.netty.channel.ChannelFuture;
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
@Test
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() {
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
public boolean isEndOfInput() throws Exception {

View File

@ -17,7 +17,7 @@ package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
@ -68,7 +68,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
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());
// leave the group
@ -78,7 +78,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
Thread.sleep(1000);
// 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();
sc.close().awaitUninterruptibly();

View File

@ -17,7 +17,7 @@ package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufs;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
@ -61,7 +61,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
Channel sc = sb.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));
sc.close().sync();

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