ChannelBuffers -> ByteBufs / Add MessageBuf & ChannelBuf
- Add MessageBuf which replaces java.util.Queue - Add ChannelBuf which is common type of ByteBuf and ChannelBuf - ChannelBuffers was renamed to ByteBufs - Add MessageBufs - All these changes are going to replace ChannelBufferHolder.
This commit is contained in:
parent
5164d91255
commit
a849d11877
@ -34,6 +34,11 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
|||||||
private int markedReaderIndex;
|
private int markedReaderIndex;
|
||||||
private int markedWriterIndex;
|
private int markedWriterIndex;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPooled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int readerIndex() {
|
public int readerIndex() {
|
||||||
return readerIndex;
|
return readerIndex;
|
||||||
@ -370,7 +375,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
|||||||
public ByteBuf readBytes(int length) {
|
public ByteBuf readBytes(int length) {
|
||||||
checkReadableBytes(length);
|
checkReadableBytes(length);
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
ByteBuf buf = factory().getBuffer(order(), length);
|
ByteBuf buf = factory().getBuffer(order(), length);
|
||||||
buf.writeBytes(this, readerIndex, length);
|
buf.writeBytes(this, readerIndex, length);
|
||||||
@ -624,17 +629,17 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
|||||||
nioBuffer.flip();
|
nioBuffer.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ChannelBuffers.decodeString(nioBuffer, charset);
|
return ByteBufs.decodeString(nioBuffer, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int indexOf(int fromIndex, int toIndex, byte value) {
|
public int indexOf(int fromIndex, int toIndex, byte value) {
|
||||||
return ChannelBuffers.indexOf(this, fromIndex, toIndex, value);
|
return ByteBufs.indexOf(this, fromIndex, toIndex, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
|
public int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
|
||||||
return ChannelBuffers.indexOf(this, fromIndex, toIndex, indexFinder);
|
return ByteBufs.indexOf(this, fromIndex, toIndex, indexFinder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -680,7 +685,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ChannelBuffers.hashCode(this);
|
return ByteBufs.hashCode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -688,12 +693,12 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
|||||||
if (!(o instanceof ByteBuf)) {
|
if (!(o instanceof ByteBuf)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ChannelBuffers.equals(this, (ByteBuf) o);
|
return ByteBufs.equals(this, (ByteBuf) o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(ByteBuf that) {
|
public int compareTo(ByteBuf that) {
|
||||||
return ChannelBuffers.compare(this, that);
|
return ByteBufs.compare(this, that);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,8 +19,8 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A big-endian Java heap buffer. It is recommended to use {@link ChannelBuffers#buffer(int)}
|
* A big-endian Java heap buffer. It is recommended to use {@link ByteBufs#buffer(int)}
|
||||||
* and {@link ChannelBuffers#wrappedBuffer(byte[])} instead of calling the
|
* and {@link ByteBufs#wrappedBuffer(byte[])} instead of calling the
|
||||||
* constructor explicitly.
|
* constructor explicitly.
|
||||||
*/
|
*/
|
||||||
public class BigEndianHeapByteBuf extends HeapByteBuf {
|
public class BigEndianHeapByteBuf extends HeapByteBuf {
|
||||||
|
@ -33,7 +33,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
|||||||
* <h3>Creation of a buffer</h3>
|
* <h3>Creation of a buffer</h3>
|
||||||
*
|
*
|
||||||
* It is recommended to create a new buffer using the helper methods in
|
* It is recommended to create a new buffer using the helper methods in
|
||||||
* {@link ChannelBuffers} rather than calling an individual implementation's
|
* {@link ByteBufs} rather than calling an individual implementation's
|
||||||
* constructor.
|
* constructor.
|
||||||
*
|
*
|
||||||
* <h3>Random Access Indexing</h3>
|
* <h3>Random Access Indexing</h3>
|
||||||
@ -228,7 +228,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
|||||||
* {@link ByteBufOutputStream}.
|
* {@link ByteBufOutputStream}.
|
||||||
* @apiviz.landmark
|
* @apiviz.landmark
|
||||||
*/
|
*/
|
||||||
public interface ByteBuf extends Comparable<ByteBuf> {
|
public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the factory which creates a {@link ByteBuf} whose
|
* Returns the factory which creates a {@link ByteBuf} whose
|
||||||
@ -292,7 +292,7 @@ public interface ByteBuf extends Comparable<ByteBuf> {
|
|||||||
* <pre>
|
* <pre>
|
||||||
* // Create a buffer whose readerIndex, writerIndex and capacity are
|
* // Create a buffer whose readerIndex, writerIndex and capacity are
|
||||||
* // 0, 0 and 8 respectively.
|
* // 0, 0 and 8 respectively.
|
||||||
* {@link ByteBuf} buf = {@link ChannelBuffers}.buffer(8);
|
* {@link ByteBuf} buf = {@link ByteBufs}.buffer(8);
|
||||||
*
|
*
|
||||||
* // IndexOutOfBoundsException is thrown because the specified
|
* // IndexOutOfBoundsException is thrown because the specified
|
||||||
* // readerIndex (2) cannot be greater than the current writerIndex (0).
|
* // readerIndex (2) cannot be greater than the current writerIndex (0).
|
||||||
@ -305,7 +305,7 @@ public interface ByteBuf extends Comparable<ByteBuf> {
|
|||||||
* <pre>
|
* <pre>
|
||||||
* // Create a buffer whose readerIndex, writerIndex and capacity are
|
* // Create a buffer whose readerIndex, writerIndex and capacity are
|
||||||
* // 0, 8 and 8 respectively.
|
* // 0, 8 and 8 respectively.
|
||||||
* {@link ByteBuf} buf = {@link ChannelBuffers}.wrappedBuffer(new byte[8]);
|
* {@link ByteBuf} buf = {@link ByteBufs}.wrappedBuffer(new byte[8]);
|
||||||
*
|
*
|
||||||
* // readerIndex becomes 8.
|
* // readerIndex becomes 8.
|
||||||
* buf.readLong();
|
* buf.readLong();
|
||||||
|
@ -37,7 +37,7 @@ import java.util.List;
|
|||||||
* This classes is intended to be used with Java 5 static import statement:
|
* This classes is intended to be used with Java 5 static import statement:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* import static io.netty.buffer.{@link ChannelBuffers}.*;
|
* import static io.netty.buffer.{@link ByteBufs}.*;
|
||||||
*
|
*
|
||||||
* {@link ByteBuf} heapBuffer = buffer(128);
|
* {@link ByteBuf} heapBuffer = buffer(128);
|
||||||
* {@link ByteBuf} directBuffer = directBuffer(256);
|
* {@link ByteBuf} directBuffer = directBuffer(256);
|
||||||
@ -84,7 +84,7 @@ import java.util.List;
|
|||||||
* @apiviz.landmark
|
* @apiviz.landmark
|
||||||
* @apiviz.has io.netty.buffer.ChannelBuffer oneway - - creates
|
* @apiviz.has io.netty.buffer.ChannelBuffer oneway - - creates
|
||||||
*/
|
*/
|
||||||
public final class ChannelBuffers {
|
public final class ByteBufs {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Big endian byte order.
|
* Big endian byte order.
|
||||||
@ -803,7 +803,7 @@ public final class ChannelBuffers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ByteBuf copiedBuffer(ByteOrder endianness, CharBuffer buffer, Charset charset) {
|
private static ByteBuf copiedBuffer(ByteOrder endianness, CharBuffer buffer, Charset charset) {
|
||||||
ByteBuffer dst = ChannelBuffers.encodeString(buffer, charset);
|
ByteBuffer dst = ByteBufs.encodeString(buffer, charset);
|
||||||
ByteBuf result = wrappedBuffer(endianness, dst.array());
|
ByteBuf result = wrappedBuffer(endianness, dst.array());
|
||||||
result.writerIndex(dst.remaining());
|
result.writerIndex(dst.remaining());
|
||||||
return result;
|
return result;
|
||||||
@ -1321,7 +1321,7 @@ public final class ChannelBuffers {
|
|||||||
return dst.flip().toString();
|
return dst.flip().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChannelBuffers() {
|
private ByteBufs() {
|
||||||
// Unused
|
// Unused
|
||||||
}
|
}
|
||||||
}
|
}
|
20
buffer/src/main/java/io/netty/buffer/ChannelBuf.java
Normal file
20
buffer/src/main/java/io/netty/buffer/ChannelBuf.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public interface ChannelBuf {
|
||||||
|
boolean isPooled();
|
||||||
|
}
|
@ -31,7 +31,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A virtual buffer which shows multiple buffers as a single merged buffer. It
|
* A virtual buffer which shows multiple buffers as a single merged buffer. It
|
||||||
* is recommended to use {@link ChannelBuffers#wrappedBuffer(ByteBuf...)}
|
* is recommended to use {@link ByteBufs#wrappedBuffer(ByteBuf...)}
|
||||||
* instead of calling the constructor explicitly.
|
* instead of calling the constructor explicitly.
|
||||||
*/
|
*/
|
||||||
public class CompositeByteBuf extends AbstractByteBuf {
|
public class CompositeByteBuf extends AbstractByteBuf {
|
||||||
@ -581,20 +581,20 @@ public class CompositeByteBuf extends AbstractByteBuf {
|
|||||||
public ByteBuf slice(int index, int length) {
|
public ByteBuf slice(int index, int length) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
} else if (index < 0 || index > capacity() - length) {
|
} else if (index < 0 || index > capacity() - length) {
|
||||||
throw new IndexOutOfBoundsException("Invalid index: " + index
|
throw new IndexOutOfBoundsException("Invalid index: " + index
|
||||||
+ " - Bytes needed: " + (index + length) + ", maximum is "
|
+ " - Bytes needed: " + (index + length) + ", maximum is "
|
||||||
+ capacity());
|
+ capacity());
|
||||||
} else if (length == 0) {
|
} else if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ByteBuf> components = decompose(index, length);
|
List<ByteBuf> components = decompose(index, length);
|
||||||
switch (components.size()) {
|
switch (components.size()) {
|
||||||
case 0:
|
case 0:
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
case 1:
|
case 1:
|
||||||
return components.get(0);
|
return components.get(0);
|
||||||
default:
|
default:
|
||||||
@ -710,7 +710,7 @@ public class CompositeByteBuf extends AbstractByteBuf {
|
|||||||
// Add a new buffer so that the capacity of this composite buffer does
|
// Add a new buffer so that the capacity of this composite buffer does
|
||||||
// not decrease due to the discarded components.
|
// not decrease due to the discarded components.
|
||||||
// XXX Might create too many components if discarded by small amount.
|
// XXX Might create too many components if discarded by small amount.
|
||||||
final ByteBuf padding = ChannelBuffers.buffer(order(), localReaderIndex);
|
final ByteBuf padding = ByteBufs.buffer(order(), localReaderIndex);
|
||||||
padding.writerIndex(localReaderIndex);
|
padding.writerIndex(localReaderIndex);
|
||||||
list.add(padding);
|
list.add(padding);
|
||||||
|
|
||||||
|
67
buffer/src/main/java/io/netty/buffer/DefaultMessageBuf.java
Normal file
67
buffer/src/main/java/io/netty/buffer/DefaultMessageBuf.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.ArrayDeque;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class DefaultMessageBuf<T> extends ArrayDeque<T> implements MessageBuf<T> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1229808623624907552L;
|
||||||
|
|
||||||
|
public DefaultMessageBuf() { }
|
||||||
|
|
||||||
|
public DefaultMessageBuf(Collection<? extends T> c) {
|
||||||
|
super(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultMessageBuf(int initialCapacity) {
|
||||||
|
super(initialCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPooled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drainTo(Collection<? super T> c) {
|
||||||
|
int cnt = 0;
|
||||||
|
for (;;) {
|
||||||
|
T o = poll();
|
||||||
|
if (o == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c.add(o);
|
||||||
|
cnt ++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drainTo(Collection<? super T> c, int maxElements) {
|
||||||
|
int cnt = 0;
|
||||||
|
while (cnt < maxElements) {
|
||||||
|
T o = poll();
|
||||||
|
if (o == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c.add(o);
|
||||||
|
cnt ++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
}
|
@ -111,10 +111,10 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
|
|||||||
throw new IllegalArgumentException("capacity: " + capacity);
|
throw new IllegalArgumentException("capacity: " + capacity);
|
||||||
}
|
}
|
||||||
if (capacity == 0) {
|
if (capacity == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (capacity >= preallocatedBufCapacity) {
|
if (capacity >= preallocatedBufCapacity) {
|
||||||
return ChannelBuffers.directBuffer(order, capacity);
|
return ByteBufs.directBuffer(order, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf slice;
|
ByteBuf slice;
|
||||||
@ -136,7 +136,7 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
|
|||||||
throw new IndexOutOfBoundsException("offset: " + offset);
|
throw new IndexOutOfBoundsException("offset: " + offset);
|
||||||
}
|
}
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (offset + length > array.length) {
|
if (offset + length > array.length) {
|
||||||
throw new IndexOutOfBoundsException("length: " + length);
|
throw new IndexOutOfBoundsException("length: " + length);
|
||||||
@ -150,7 +150,7 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
|
|||||||
@Override
|
@Override
|
||||||
public ByteBuf getBuffer(ByteBuffer nioBuffer) {
|
public ByteBuf getBuffer(ByteBuffer nioBuffer) {
|
||||||
if (!nioBuffer.isReadOnly() && nioBuffer.isDirect()) {
|
if (!nioBuffer.isReadOnly() && nioBuffer.isDirect()) {
|
||||||
return ChannelBuffers.wrappedBuffer(nioBuffer);
|
return ByteBufs.wrappedBuffer(nioBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
|
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
|
||||||
@ -164,14 +164,14 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
|
|||||||
ByteBuf slice;
|
ByteBuf slice;
|
||||||
synchronized (bigEndianLock) {
|
synchronized (bigEndianLock) {
|
||||||
if (preallocatedBEBuf == null) {
|
if (preallocatedBEBuf == null) {
|
||||||
preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
preallocatedBEBuf = ByteBufs.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
||||||
slice = preallocatedBEBuf.slice(0, capacity);
|
slice = preallocatedBEBuf.slice(0, capacity);
|
||||||
preallocatedBEBufPos = capacity;
|
preallocatedBEBufPos = capacity;
|
||||||
} else if (preallocatedBEBuf.capacity() - preallocatedBEBufPos >= capacity) {
|
} else if (preallocatedBEBuf.capacity() - preallocatedBEBufPos >= capacity) {
|
||||||
slice = preallocatedBEBuf.slice(preallocatedBEBufPos, capacity);
|
slice = preallocatedBEBuf.slice(preallocatedBEBufPos, capacity);
|
||||||
preallocatedBEBufPos += capacity;
|
preallocatedBEBufPos += capacity;
|
||||||
} else {
|
} else {
|
||||||
preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
preallocatedBEBuf = ByteBufs.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
||||||
slice = preallocatedBEBuf.slice(0, capacity);
|
slice = preallocatedBEBuf.slice(0, capacity);
|
||||||
preallocatedBEBufPos = capacity;
|
preallocatedBEBufPos = capacity;
|
||||||
}
|
}
|
||||||
@ -183,14 +183,14 @@ public class DirectByteBufFactory extends AbstractByteBufFactory {
|
|||||||
ByteBuf slice;
|
ByteBuf slice;
|
||||||
synchronized (littleEndianLock) {
|
synchronized (littleEndianLock) {
|
||||||
if (preallocatedLEBuf == null) {
|
if (preallocatedLEBuf == null) {
|
||||||
preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
preallocatedLEBuf = ByteBufs.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
||||||
slice = preallocatedLEBuf.slice(0, capacity);
|
slice = preallocatedLEBuf.slice(0, capacity);
|
||||||
preallocatedLEBufPos = capacity;
|
preallocatedLEBufPos = capacity;
|
||||||
} else if (preallocatedLEBuf.capacity() - preallocatedLEBufPos >= capacity) {
|
} else if (preallocatedLEBuf.capacity() - preallocatedLEBufPos >= capacity) {
|
||||||
slice = preallocatedLEBuf.slice(preallocatedLEBufPos, capacity);
|
slice = preallocatedLEBuf.slice(preallocatedLEBufPos, capacity);
|
||||||
preallocatedLEBufPos += capacity;
|
preallocatedLEBufPos += capacity;
|
||||||
} else {
|
} else {
|
||||||
preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
preallocatedLEBuf = ByteBufs.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
||||||
slice = preallocatedLEBuf.slice(0, capacity);
|
slice = preallocatedLEBuf.slice(0, capacity);
|
||||||
preallocatedLEBufPos = capacity;
|
preallocatedLEBufPos = capacity;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import java.nio.channels.ScatteringByteChannel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A dynamic capacity buffer which increases its capacity as needed. It is
|
* A dynamic capacity buffer which increases its capacity as needed. It is
|
||||||
* recommended to use {@link ChannelBuffers#dynamicBuffer(int)} instead of
|
* recommended to use {@link ByteBufs#dynamicBuffer(int)} instead of
|
||||||
* calling the constructor explicitly.
|
* calling the constructor explicitly.
|
||||||
*/
|
*/
|
||||||
public class DynamicByteBuf extends AbstractByteBuf {
|
public class DynamicByteBuf extends AbstractByteBuf {
|
||||||
@ -310,12 +310,12 @@ public class DynamicByteBuf extends AbstractByteBuf {
|
|||||||
public ByteBuf slice(int index, int length) {
|
public ByteBuf slice(int index, int length) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
return new TruncatedByteBuf(this, length);
|
return new TruncatedByteBuf(this, length);
|
||||||
} else {
|
} else {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
return new SlicedByteBuf(this, index, length);
|
return new SlicedByteBuf(this, index, length);
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ public abstract class HeapByteBuf extends AbstractByteBuf {
|
|||||||
public ByteBuf slice(int index, int length) {
|
public ByteBuf slice(int index, int length) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (length == array.length) {
|
if (length == array.length) {
|
||||||
ByteBuf slice = duplicate();
|
ByteBuf slice = duplicate();
|
||||||
@ -183,7 +183,7 @@ public abstract class HeapByteBuf extends AbstractByteBuf {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
return new SlicedByteBuf(this, index, length);
|
return new SlicedByteBuf(this, index, length);
|
||||||
}
|
}
|
||||||
|
@ -66,18 +66,18 @@ public class HeapByteBufFactory extends AbstractByteBufFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf getBuffer(ByteOrder order, int capacity) {
|
public ByteBuf getBuffer(ByteOrder order, int capacity) {
|
||||||
return ChannelBuffers.buffer(order, capacity);
|
return ByteBufs.buffer(order, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf getBuffer(ByteOrder order, byte[] array, int offset, int length) {
|
public ByteBuf getBuffer(ByteOrder order, byte[] array, int offset, int length) {
|
||||||
return ChannelBuffers.wrappedBuffer(order, array, offset, length);
|
return ByteBufs.wrappedBuffer(order, array, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf getBuffer(ByteBuffer nioBuffer) {
|
public ByteBuf getBuffer(ByteBuffer nioBuffer) {
|
||||||
if (nioBuffer.hasArray()) {
|
if (nioBuffer.hasArray()) {
|
||||||
return ChannelBuffers.wrappedBuffer(nioBuffer);
|
return ByteBufs.wrappedBuffer(nioBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
|
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
|
||||||
|
@ -19,8 +19,8 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A little-endian Java heap buffer. It is recommended to use {@link ChannelBuffers#buffer(ByteOrder, int)}
|
* A little-endian Java heap buffer. It is recommended to use {@link ByteBufs#buffer(ByteOrder, int)}
|
||||||
* and {@link ChannelBuffers#wrappedBuffer(ByteOrder, byte[])} instead of
|
* and {@link ByteBufs#wrappedBuffer(ByteOrder, byte[])} instead of
|
||||||
* calling the constructor explicitly.
|
* calling the constructor explicitly.
|
||||||
*/
|
*/
|
||||||
public class LittleEndianHeapByteBuf extends HeapByteBuf {
|
public class LittleEndianHeapByteBuf extends HeapByteBuf {
|
||||||
|
24
buffer/src/main/java/io/netty/buffer/MessageBuf.java
Normal file
24
buffer/src/main/java/io/netty/buffer/MessageBuf.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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.Collection;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
public interface MessageBuf<T> extends ChannelBuf, Queue<T> {
|
||||||
|
int drainTo(Collection<? super T> c);
|
||||||
|
int drainTo(Collection<? super T> c, int maxElements);
|
||||||
|
}
|
36
buffer/src/main/java/io/netty/buffer/MessageBufs.java
Normal file
36
buffer/src/main/java/io/netty/buffer/MessageBufs.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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> messageBuffer() {
|
||||||
|
return new DefaultMessageBuf<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> MessageBuf<T> messageBuffer(int initialCapacity) {
|
||||||
|
return new DefaultMessageBuf<T>(initialCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> MessageBuf<T> messageBuffer(Queue<T> queue) {
|
||||||
|
return new QueueBackedMessageBuf<T>(queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private MessageBufs() { }
|
||||||
|
}
|
@ -25,8 +25,8 @@ import java.nio.channels.GatheringByteChannel;
|
|||||||
import java.nio.channels.ScatteringByteChannel;
|
import java.nio.channels.ScatteringByteChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A NIO {@link ByteBuffer} based buffer. It is recommended to use {@link ChannelBuffers#directBuffer(int)}
|
* A NIO {@link ByteBuffer} based buffer. It is recommended to use {@link ByteBufs#directBuffer(int)}
|
||||||
* and {@link ChannelBuffers#wrappedBuffer(ByteBuffer)} instead of calling the
|
* and {@link ByteBufs#wrappedBuffer(ByteBuffer)} instead of calling the
|
||||||
* constructor explicitly.
|
* constructor explicitly.
|
||||||
*/
|
*/
|
||||||
public class NioBufferBackedByteBuf extends AbstractByteBuf {
|
public class NioBufferBackedByteBuf extends AbstractByteBuf {
|
||||||
@ -299,7 +299,7 @@ public class NioBufferBackedByteBuf extends AbstractByteBuf {
|
|||||||
return slice;
|
return slice;
|
||||||
} else {
|
} else {
|
||||||
if (index >= 0 && length == 0) {
|
if (index >= 0 && length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
return new NioBufferBackedByteBuf(
|
return new NioBufferBackedByteBuf(
|
||||||
((ByteBuffer) tmpBuf.clear().position(
|
((ByteBuffer) tmpBuf.clear().position(
|
||||||
|
160
buffer/src/main/java/io/netty/buffer/QueueBackedMessageBuf.java
Normal file
160
buffer/src/main/java/io/netty/buffer/QueueBackedMessageBuf.java
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* 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.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
public class QueueBackedMessageBuf<T> implements MessageBuf<T> {
|
||||||
|
|
||||||
|
private final Queue<T> queue;
|
||||||
|
|
||||||
|
public QueueBackedMessageBuf(Queue<T> queue) {
|
||||||
|
if (queue == null) {
|
||||||
|
throw new NullPointerException("queue");
|
||||||
|
}
|
||||||
|
this.queue = queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPooled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(T e) {
|
||||||
|
return queue.add(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean offer(T e) {
|
||||||
|
return queue.offer(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T remove() {
|
||||||
|
return queue.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T poll() {
|
||||||
|
return queue.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T element() {
|
||||||
|
return queue.element();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T peek() {
|
||||||
|
return queue.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return queue.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return queue.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Object o) {
|
||||||
|
return queue.contains(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return queue.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] toArray() {
|
||||||
|
return queue.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> E[] toArray(E[] a) {
|
||||||
|
return queue.toArray(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object o) {
|
||||||
|
return queue.remove(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsAll(Collection<?> c) {
|
||||||
|
return queue.containsAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAll(Collection<? extends T> c) {
|
||||||
|
return queue.addAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(Collection<?> c) {
|
||||||
|
return queue.removeAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(Collection<?> c) {
|
||||||
|
return queue.retainAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
queue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drainTo(Collection<? super T> c) {
|
||||||
|
int cnt = 0;
|
||||||
|
for (;;) {
|
||||||
|
T o = poll();
|
||||||
|
if (o == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c.add(o);
|
||||||
|
cnt ++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drainTo(Collection<? super T> c, int maxElements) {
|
||||||
|
int cnt = 0;
|
||||||
|
while (cnt < maxElements) {
|
||||||
|
T o = poll();
|
||||||
|
if (o == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c.add(o);
|
||||||
|
cnt ++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return queue.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,7 @@ import java.nio.channels.ScatteringByteChannel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A derived buffer which forbids any write requests to its parent. It is
|
* A derived buffer which forbids any write requests to its parent. It is
|
||||||
* recommended to use {@link ChannelBuffers#unmodifiableBuffer(ByteBuf)}
|
* recommended to use {@link ByteBufs#unmodifiableBuffer(ByteBuf)}
|
||||||
* instead of calling the constructor explicitly.
|
* instead of calling the constructor explicitly.
|
||||||
*/
|
*/
|
||||||
public class ReadOnlyByteBuf extends AbstractByteBuf implements WrappedByteBuf {
|
public class ReadOnlyByteBuf extends AbstractByteBuf implements WrappedByteBuf {
|
||||||
|
@ -140,7 +140,7 @@ public class SlicedByteBuf extends AbstractByteBuf implements WrappedByteBuf {
|
|||||||
public ByteBuf slice(int index, int length) {
|
public ByteBuf slice(int index, int length) {
|
||||||
checkIndex(index, length);
|
checkIndex(index, length);
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
return new SlicedByteBuf(buffer, index + adjustment, length);
|
return new SlicedByteBuf(buffer, index + adjustment, length);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class TruncatedByteBuf extends AbstractByteBuf implements WrappedByteBuf
|
|||||||
public ByteBuf slice(int index, int length) {
|
public ByteBuf slice(int index, int length) {
|
||||||
checkIndex(index, length);
|
checkIndex(index, length);
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
return buffer.slice(index, length);
|
return buffer.slice(index, length);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
* of the resulting string and let {@link java.lang.StringBuffer} expand itself
|
* of the resulting string and let {@link java.lang.StringBuffer} expand itself
|
||||||
* on demand. Netty allows you to do the same via a <em>dynamic</em> buffer
|
* on demand. Netty allows you to do the same via a <em>dynamic</em> buffer
|
||||||
* which is created by the
|
* which is created by the
|
||||||
* {@link io.netty.buffer.ChannelBuffers#dynamicBuffer()} method.
|
* {@link io.netty.buffer.ByteBufs#dynamicBuffer()} method.
|
||||||
* <pre>
|
* <pre>
|
||||||
* // A new dynamic buffer is created. Internally, the actual buffer is created
|
* // A new dynamic buffer is created. Internally, the actual buffer is created
|
||||||
* // lazily to avoid potentially wasted memory space.
|
* // lazily to avoid potentially wasted memory space.
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -47,30 +47,30 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffers = new ArrayList<ByteBuf>();
|
buffers = new ArrayList<ByteBuf>();
|
||||||
for (int i = 0; i < length; i += 10) {
|
for (int i = 0; i < length; i += 10) {
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[1]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[1]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[2]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[2]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[3]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[3]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[4]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[4]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[5]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[5]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[6]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[6]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[7]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[7]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[8]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[8]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[9]));
|
buffers.add(ByteBufs.wrappedBuffer(order, new byte[9]));
|
||||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
buffers.add(ByteBufs.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = ChannelBuffers.wrappedBuffer(buffers.toArray(new ByteBuf[buffers.size()]));
|
buffer = ByteBufs.wrappedBuffer(buffers.toArray(new ByteBuf[buffers.size()]));
|
||||||
buffer.writerIndex(length);
|
buffer.writerIndex(length);
|
||||||
buffer = ChannelBuffers.wrappedBuffer(buffer);
|
buffer = ByteBufs.wrappedBuffer(buffer);
|
||||||
assertEquals(length, buffer.capacity());
|
assertEquals(length, buffer.capacity());
|
||||||
assertEquals(length, buffer.readableBytes());
|
assertEquals(length, buffer.readableBytes());
|
||||||
assertFalse(buffer.writable());
|
assertFalse(buffer.writable());
|
||||||
@ -113,20 +113,20 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
a.writerIndex(a.writerIndex() + 1);
|
a.writerIndex(a.writerIndex() + 1);
|
||||||
b.writerIndex(b.writerIndex() + 1);
|
b.writerIndex(b.writerIndex() + 1);
|
||||||
assertEquals(a.writerIndex(), b.writerIndex());
|
assertEquals(a.writerIndex(), b.writerIndex());
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
// now discard
|
// now discard
|
||||||
a.discardReadBytes();
|
a.discardReadBytes();
|
||||||
b.discardReadBytes();
|
b.discardReadBytes();
|
||||||
assertEquals(a.readerIndex(), b.readerIndex());
|
assertEquals(a.readerIndex(), b.readerIndex());
|
||||||
assertEquals(a.writerIndex(), b.writerIndex());
|
assertEquals(a.writerIndex(), b.writerIndex());
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
a.resetReaderIndex();
|
a.resetReaderIndex();
|
||||||
b.resetReaderIndex();
|
b.resetReaderIndex();
|
||||||
assertEquals(a.readerIndex(), b.readerIndex());
|
assertEquals(a.readerIndex(), b.readerIndex());
|
||||||
a.resetWriterIndex();
|
a.resetWriterIndex();
|
||||||
b.resetWriterIndex();
|
b.resetWriterIndex();
|
||||||
assertEquals(a.writerIndex(), b.writerIndex());
|
assertEquals(a.writerIndex(), b.writerIndex());
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -154,57 +154,57 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
a = wrappedBuffer(order, new byte[] { 1 });
|
a = wrappedBuffer(order, new byte[] { 1 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }),
|
||||||
wrappedBuffer(order, new byte[] { 2 }));
|
wrappedBuffer(order, new byte[] { 2 }));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, same firstIndex, short length.
|
// Same content, same firstIndex, short length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }),
|
||||||
wrappedBuffer(order, new byte[] { 2 }),
|
wrappedBuffer(order, new byte[] { 2 }),
|
||||||
wrappedBuffer(order, new byte[] { 3 }));
|
wrappedBuffer(order, new byte[] { 3 }));
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, different firstIndex, short length.
|
// Same content, different firstIndex, short length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 1, 2),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 1, 2),
|
||||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1));
|
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1));
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, same firstIndex, short length.
|
// Different content, same firstIndex, short length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2 }),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2 }),
|
||||||
wrappedBuffer(order, new byte[] { 4 }));
|
wrappedBuffer(order, new byte[] { 4 }));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, different firstIndex, short length.
|
// Different content, different firstIndex, short length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 1, 2),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 1, 2),
|
||||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1));
|
wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, same firstIndex, long length.
|
// Same content, same firstIndex, long length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3 }),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3 }),
|
||||||
wrappedBuffer(order, new byte[] { 4, 5, 6 }),
|
wrappedBuffer(order, new byte[] { 4, 5, 6 }),
|
||||||
wrappedBuffer(order, new byte[] { 7, 8, 9, 10 }));
|
wrappedBuffer(order, new byte[] { 7, 8, 9, 10 }));
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, different firstIndex, long length.
|
// Same content, different firstIndex, long length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 5),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 5),
|
||||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5));
|
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5));
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, same firstIndex, long length.
|
// Different content, same firstIndex, long length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 6 }),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 6 }),
|
||||||
wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 }));
|
wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 }));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, different firstIndex, long length.
|
// Different content, different firstIndex, long length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 5),
|
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 5),
|
||||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5));
|
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testWrappedBuffer() {
|
public void testWrappedBuffer() {
|
||||||
@ -259,7 +259,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
b.writerIndex(b.writerIndex() - 1);
|
b.writerIndex(b.writerIndex() - 1);
|
||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 2 }));
|
wrappedBuffer(order, new byte[] { 2 }));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, same firstIndex, short length.
|
// Same content, same firstIndex, short length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||||
@ -269,7 +269,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 2 }));
|
wrappedBuffer(order, new byte[] { 2 }));
|
||||||
b.writeBytes(wrappedBuffer(order, new byte[] { 3 }));
|
b.writeBytes(wrappedBuffer(order, new byte[] { 3 }));
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, different firstIndex, short length.
|
// Same content, different firstIndex, short length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||||
@ -278,7 +278,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
b.writerIndex(b.writerIndex() - 1);
|
b.writerIndex(b.writerIndex() - 1);
|
||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1));
|
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4 }, 3, 1));
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, same firstIndex, short length.
|
// Different content, same firstIndex, short length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||||
@ -287,7 +287,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
b.writerIndex(b.writerIndex() - 1);
|
b.writerIndex(b.writerIndex() - 1);
|
||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 4 }));
|
wrappedBuffer(order, new byte[] { 4 }));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, different firstIndex, short length.
|
// Different content, different firstIndex, short length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3 });
|
||||||
@ -296,7 +296,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
b.writerIndex(b.writerIndex() - 1);
|
b.writerIndex(b.writerIndex() - 1);
|
||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1));
|
wrappedBuffer(order, new byte[] { 0, 1, 2, 4, 5 }, 3, 1));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, same firstIndex, long length.
|
// Same content, same firstIndex, long length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
@ -307,7 +307,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
wrappedBuffer(order, new byte[] { 4, 5, 6 }));
|
wrappedBuffer(order, new byte[] { 4, 5, 6 }));
|
||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 7, 8, 9, 10 }));
|
wrappedBuffer(order, new byte[] { 7, 8, 9, 10 }));
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, different firstIndex, long length.
|
// Same content, different firstIndex, long length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
@ -316,7 +316,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
b.writerIndex(b.writerIndex() - 5);
|
b.writerIndex(b.writerIndex() - 5);
|
||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5));
|
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5));
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, same firstIndex, long length.
|
// Different content, same firstIndex, long length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
@ -325,7 +325,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
b.writerIndex(b.writerIndex() - 5);
|
b.writerIndex(b.writerIndex() - 5);
|
||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 }));
|
wrappedBuffer(order, new byte[] { 7, 8, 5, 9, 10 }));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, different firstIndex, long length.
|
// Different content, different firstIndex, long length.
|
||||||
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(order, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
@ -334,6 +334,6 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
b.writerIndex(b.writerIndex() - 5);
|
b.writerIndex(b.writerIndex() - 5);
|
||||||
b.writeBytes(
|
b.writeBytes(
|
||||||
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5));
|
wrappedBuffer(order, new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5));
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,6 @@ package io.netty.buffer;
|
|||||||
*/
|
*/
|
||||||
public class BigEndianCompositeChannelBufferTest extends AbstractCompositeChannelBufferTest {
|
public class BigEndianCompositeChannelBufferTest extends AbstractCompositeChannelBufferTest {
|
||||||
public BigEndianCompositeChannelBufferTest() {
|
public BigEndianCompositeChannelBufferTest() {
|
||||||
super(ChannelBuffers.BIG_ENDIAN);
|
super(ByteBufs.BIG_ENDIAN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class BigEndianDirectChannelBufferTest extends AbstractChannelBufferTest
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffer = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, length);
|
buffer = ByteBufs.directBuffer(ByteOrder.BIG_ENDIAN, length);
|
||||||
assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
|
assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
|
@ -28,7 +28,7 @@ public class BigEndianHeapChannelBufferTest extends AbstractChannelBufferTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffer = ChannelBuffers.buffer(length);
|
buffer = ByteBufs.buffer(length);
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class ChannelBufferIndexFinderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForward() {
|
public void testForward() {
|
||||||
ByteBuf buf = ChannelBuffers.copiedBuffer(
|
ByteBuf buf = ByteBufs.copiedBuffer(
|
||||||
"abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx",
|
"abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx",
|
||||||
CharsetUtil.ISO_8859_1);
|
CharsetUtil.ISO_8859_1);
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public class ChannelBufferIndexFinderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBackward() {
|
public void testBackward() {
|
||||||
ByteBuf buf = ChannelBuffers.copiedBuffer(
|
ByteBuf buf = ByteBufs.copiedBuffer(
|
||||||
"abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx",
|
"abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx",
|
||||||
CharsetUtil.ISO_8859_1);
|
CharsetUtil.ISO_8859_1);
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class ChannelBufferStreamTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAll() throws Exception {
|
public void testAll() throws Exception {
|
||||||
ByteBuf buf = ChannelBuffers.dynamicBuffer();
|
ByteBuf buf = ByteBufs.dynamicBuffer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new ByteBufOutputStream(null);
|
new ByteBufOutputStream(null);
|
||||||
@ -171,7 +171,7 @@ public class ChannelBufferStreamTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyReadLine() throws Exception {
|
public void testEmptyReadLine() throws Exception {
|
||||||
ByteBuf buf = ChannelBuffers.buffer(0);
|
ByteBuf buf = ByteBufs.buffer(0);
|
||||||
ByteBufInputStream in = new ByteBufInputStream(buf);
|
ByteBufInputStream in = new ByteBufInputStream(buf);
|
||||||
|
|
||||||
String s = in.readLine();
|
String s = in.readLine();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -67,7 +67,7 @@ public class ChannelBuffersTest {
|
|||||||
for (Entry<byte[], Integer> e: map.entrySet()) {
|
for (Entry<byte[], Integer> e: map.entrySet()) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
e.getValue().intValue(),
|
e.getValue().intValue(),
|
||||||
ChannelBuffers.hashCode(wrappedBuffer(e.getKey())));
|
ByteBufs.hashCode(wrappedBuffer(e.getKey())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,47 +78,47 @@ public class ChannelBuffersTest {
|
|||||||
// Different length.
|
// Different length.
|
||||||
a = wrappedBuffer(new byte[] { 1 });
|
a = wrappedBuffer(new byte[] { 1 });
|
||||||
b = wrappedBuffer(new byte[] { 1, 2 });
|
b = wrappedBuffer(new byte[] { 1, 2 });
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, same firstIndex, short length.
|
// Same content, same firstIndex, short length.
|
||||||
a = wrappedBuffer(new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(new byte[] { 1, 2, 3 });
|
||||||
b = wrappedBuffer(new byte[] { 1, 2, 3 });
|
b = wrappedBuffer(new byte[] { 1, 2, 3 });
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, different firstIndex, short length.
|
// Same content, different firstIndex, short length.
|
||||||
a = wrappedBuffer(new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(new byte[] { 1, 2, 3 });
|
||||||
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 3);
|
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 3);
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, same firstIndex, short length.
|
// Different content, same firstIndex, short length.
|
||||||
a = wrappedBuffer(new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(new byte[] { 1, 2, 3 });
|
||||||
b = wrappedBuffer(new byte[] { 1, 2, 4 });
|
b = wrappedBuffer(new byte[] { 1, 2, 4 });
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, different firstIndex, short length.
|
// Different content, different firstIndex, short length.
|
||||||
a = wrappedBuffer(new byte[] { 1, 2, 3 });
|
a = wrappedBuffer(new byte[] { 1, 2, 3 });
|
||||||
b = wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 3);
|
b = wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 3);
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, same firstIndex, long length.
|
// Same content, same firstIndex, long length.
|
||||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Same content, different firstIndex, long length.
|
// Same content, different firstIndex, long length.
|
||||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10);
|
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10);
|
||||||
assertTrue(ChannelBuffers.equals(a, b));
|
assertTrue(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, same firstIndex, long length.
|
// Different content, same firstIndex, long length.
|
||||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 6, 7, 8, 5, 9, 10 });
|
b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 6, 7, 8, 5, 9, 10 });
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
|
|
||||||
// Different content, different firstIndex, long length.
|
// Different content, different firstIndex, long length.
|
||||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10);
|
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10);
|
||||||
assertFalse(ChannelBuffers.equals(a, b));
|
assertFalse(ByteBufs.equals(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -197,14 +197,14 @@ public class ChannelBuffersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompare2() {
|
public void testCompare2() {
|
||||||
assertTrue(ChannelBuffers.compare(
|
assertTrue(ByteBufs.compare(
|
||||||
ChannelBuffers.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}),
|
ByteBufs.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}),
|
||||||
ChannelBuffers.wrappedBuffer(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}))
|
ByteBufs.wrappedBuffer(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}))
|
||||||
> 0);
|
> 0);
|
||||||
|
|
||||||
assertTrue(ChannelBuffers.compare(
|
assertTrue(ByteBufs.compare(
|
||||||
ChannelBuffers.wrappedBuffer(new byte[]{(byte) 0xFF}),
|
ByteBufs.wrappedBuffer(new byte[]{(byte) 0xFF}),
|
||||||
ChannelBuffers.wrappedBuffer(new byte[]{(byte) 0x00}))
|
ByteBufs.wrappedBuffer(new byte[]{(byte) 0x00}))
|
||||||
> 0);
|
> 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,7 +427,7 @@ public class ChannelBuffersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapSingleInt() {
|
public void testWrapSingleInt() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyInt(42);
|
ByteBuf buffer = ByteBufs.copyInt(42);
|
||||||
assertEquals(4, buffer.capacity());
|
assertEquals(4, buffer.capacity());
|
||||||
assertEquals(42, buffer.readInt());
|
assertEquals(42, buffer.readInt());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
@ -435,19 +435,19 @@ public class ChannelBuffersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapInt() {
|
public void testWrapInt() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyInt(1, 4);
|
ByteBuf buffer = ByteBufs.copyInt(1, 4);
|
||||||
assertEquals(8, buffer.capacity());
|
assertEquals(8, buffer.capacity());
|
||||||
assertEquals(1, buffer.readInt());
|
assertEquals(1, buffer.readInt());
|
||||||
assertEquals(4, buffer.readInt());
|
assertEquals(4, buffer.readInt());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
|
|
||||||
assertEquals(0, ChannelBuffers.copyInt(null).capacity());
|
assertEquals(0, ByteBufs.copyInt(null).capacity());
|
||||||
assertEquals(0, ChannelBuffers.copyInt(new int[0]).capacity());
|
assertEquals(0, ByteBufs.copyInt(new int[0]).capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapSingleShort() {
|
public void testWrapSingleShort() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyShort(42);
|
ByteBuf buffer = ByteBufs.copyShort(42);
|
||||||
assertEquals(2, buffer.capacity());
|
assertEquals(2, buffer.capacity());
|
||||||
assertEquals(42, buffer.readShort());
|
assertEquals(42, buffer.readShort());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
@ -455,31 +455,31 @@ public class ChannelBuffersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapShortFromShortArray() {
|
public void testWrapShortFromShortArray() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyShort(new short[] { 1, 4 });
|
ByteBuf buffer = ByteBufs.copyShort(new short[] { 1, 4 });
|
||||||
assertEquals(4, buffer.capacity());
|
assertEquals(4, buffer.capacity());
|
||||||
assertEquals(1, buffer.readShort());
|
assertEquals(1, buffer.readShort());
|
||||||
assertEquals(4, buffer.readShort());
|
assertEquals(4, buffer.readShort());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
|
|
||||||
assertEquals(0, ChannelBuffers.copyShort((short[]) null).capacity());
|
assertEquals(0, ByteBufs.copyShort((short[]) null).capacity());
|
||||||
assertEquals(0, ChannelBuffers.copyShort(new short[0]).capacity());
|
assertEquals(0, ByteBufs.copyShort(new short[0]).capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapShortFromIntArray() {
|
public void testWrapShortFromIntArray() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyShort(1, 4);
|
ByteBuf buffer = ByteBufs.copyShort(1, 4);
|
||||||
assertEquals(4, buffer.capacity());
|
assertEquals(4, buffer.capacity());
|
||||||
assertEquals(1, buffer.readShort());
|
assertEquals(1, buffer.readShort());
|
||||||
assertEquals(4, buffer.readShort());
|
assertEquals(4, buffer.readShort());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
|
|
||||||
assertEquals(0, ChannelBuffers.copyShort((int[]) null).capacity());
|
assertEquals(0, ByteBufs.copyShort((int[]) null).capacity());
|
||||||
assertEquals(0, ChannelBuffers.copyShort(new int[0]).capacity());
|
assertEquals(0, ByteBufs.copyShort(new int[0]).capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapSingleMedium() {
|
public void testWrapSingleMedium() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyMedium(42);
|
ByteBuf buffer = ByteBufs.copyMedium(42);
|
||||||
assertEquals(3, buffer.capacity());
|
assertEquals(3, buffer.capacity());
|
||||||
assertEquals(42, buffer.readMedium());
|
assertEquals(42, buffer.readMedium());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
@ -487,19 +487,19 @@ public class ChannelBuffersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapMedium() {
|
public void testWrapMedium() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyMedium(1, 4);
|
ByteBuf buffer = ByteBufs.copyMedium(1, 4);
|
||||||
assertEquals(6, buffer.capacity());
|
assertEquals(6, buffer.capacity());
|
||||||
assertEquals(1, buffer.readMedium());
|
assertEquals(1, buffer.readMedium());
|
||||||
assertEquals(4, buffer.readMedium());
|
assertEquals(4, buffer.readMedium());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
|
|
||||||
assertEquals(0, ChannelBuffers.copyMedium(null).capacity());
|
assertEquals(0, ByteBufs.copyMedium(null).capacity());
|
||||||
assertEquals(0, ChannelBuffers.copyMedium(new int[0]).capacity());
|
assertEquals(0, ByteBufs.copyMedium(new int[0]).capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapSingleLong() {
|
public void testWrapSingleLong() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyLong(42);
|
ByteBuf buffer = ByteBufs.copyLong(42);
|
||||||
assertEquals(8, buffer.capacity());
|
assertEquals(8, buffer.capacity());
|
||||||
assertEquals(42, buffer.readLong());
|
assertEquals(42, buffer.readLong());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
@ -507,19 +507,19 @@ public class ChannelBuffersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapLong() {
|
public void testWrapLong() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyLong(1, 4);
|
ByteBuf buffer = ByteBufs.copyLong(1, 4);
|
||||||
assertEquals(16, buffer.capacity());
|
assertEquals(16, buffer.capacity());
|
||||||
assertEquals(1, buffer.readLong());
|
assertEquals(1, buffer.readLong());
|
||||||
assertEquals(4, buffer.readLong());
|
assertEquals(4, buffer.readLong());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
|
|
||||||
assertEquals(0, ChannelBuffers.copyLong(null).capacity());
|
assertEquals(0, ByteBufs.copyLong(null).capacity());
|
||||||
assertEquals(0, ChannelBuffers.copyLong(new long[0]).capacity());
|
assertEquals(0, ByteBufs.copyLong(new long[0]).capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapSingleFloat() {
|
public void testWrapSingleFloat() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyFloat(42);
|
ByteBuf buffer = ByteBufs.copyFloat(42);
|
||||||
assertEquals(4, buffer.capacity());
|
assertEquals(4, buffer.capacity());
|
||||||
assertEquals(42, buffer.readFloat(), 0.01);
|
assertEquals(42, buffer.readFloat(), 0.01);
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
@ -527,19 +527,19 @@ public class ChannelBuffersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapFloat() {
|
public void testWrapFloat() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyFloat(1, 4);
|
ByteBuf buffer = ByteBufs.copyFloat(1, 4);
|
||||||
assertEquals(8, buffer.capacity());
|
assertEquals(8, buffer.capacity());
|
||||||
assertEquals(1, buffer.readFloat(), 0.01);
|
assertEquals(1, buffer.readFloat(), 0.01);
|
||||||
assertEquals(4, buffer.readFloat(), 0.01);
|
assertEquals(4, buffer.readFloat(), 0.01);
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
|
|
||||||
assertEquals(0, ChannelBuffers.copyFloat(null).capacity());
|
assertEquals(0, ByteBufs.copyFloat(null).capacity());
|
||||||
assertEquals(0, ChannelBuffers.copyFloat(new float[0]).capacity());
|
assertEquals(0, ByteBufs.copyFloat(new float[0]).capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapSingleDouble() {
|
public void testWrapSingleDouble() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyDouble(42);
|
ByteBuf buffer = ByteBufs.copyDouble(42);
|
||||||
assertEquals(8, buffer.capacity());
|
assertEquals(8, buffer.capacity());
|
||||||
assertEquals(42, buffer.readDouble(), 0.01);
|
assertEquals(42, buffer.readDouble(), 0.01);
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
@ -547,26 +547,26 @@ public class ChannelBuffersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapDouble() {
|
public void testWrapDouble() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyDouble(1, 4);
|
ByteBuf buffer = ByteBufs.copyDouble(1, 4);
|
||||||
assertEquals(16, buffer.capacity());
|
assertEquals(16, buffer.capacity());
|
||||||
assertEquals(1, buffer.readDouble(), 0.01);
|
assertEquals(1, buffer.readDouble(), 0.01);
|
||||||
assertEquals(4, buffer.readDouble(), 0.01);
|
assertEquals(4, buffer.readDouble(), 0.01);
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
|
|
||||||
assertEquals(0, ChannelBuffers.copyDouble(null).capacity());
|
assertEquals(0, ByteBufs.copyDouble(null).capacity());
|
||||||
assertEquals(0, ChannelBuffers.copyDouble(new double[0]).capacity());
|
assertEquals(0, ByteBufs.copyDouble(new double[0]).capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapBoolean() {
|
public void testWrapBoolean() {
|
||||||
ByteBuf buffer = ChannelBuffers.copyBoolean(true, false);
|
ByteBuf buffer = ByteBufs.copyBoolean(true, false);
|
||||||
assertEquals(2, buffer.capacity());
|
assertEquals(2, buffer.capacity());
|
||||||
assertEquals(true, buffer.readBoolean());
|
assertEquals(true, buffer.readBoolean());
|
||||||
assertEquals(false, buffer.readBoolean());
|
assertEquals(false, buffer.readBoolean());
|
||||||
assertFalse(buffer.readable());
|
assertFalse(buffer.readable());
|
||||||
|
|
||||||
assertEquals(0, ChannelBuffers.copyBoolean(null).capacity());
|
assertEquals(0, ByteBufs.copyBoolean(null).capacity());
|
||||||
assertEquals(0, ChannelBuffers.copyBoolean(new boolean[0]).capacity());
|
assertEquals(0, ByteBufs.copyBoolean(new boolean[0]).capacity());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class DuplicateChannelBufferTest extends AbstractChannelBufferTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffer = new DuplicatedByteBuf(ChannelBuffers.buffer(length));
|
buffer = new DuplicatedByteBuf(ByteBufs.buffer(length));
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class DynamicChannelBufferTest extends AbstractChannelBufferTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffer = ChannelBuffers.dynamicBuffer(length);
|
buffer = ByteBufs.dynamicBuffer(length);
|
||||||
|
|
||||||
assertEquals(0, buffer.readerIndex());
|
assertEquals(0, buffer.readerIndex());
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
|
@ -21,6 +21,6 @@ package io.netty.buffer;
|
|||||||
*/
|
*/
|
||||||
public class LittleEndianCompositeChannelBufferTest extends AbstractCompositeChannelBufferTest {
|
public class LittleEndianCompositeChannelBufferTest extends AbstractCompositeChannelBufferTest {
|
||||||
public LittleEndianCompositeChannelBufferTest() {
|
public LittleEndianCompositeChannelBufferTest() {
|
||||||
super(ChannelBuffers.LITTLE_ENDIAN);
|
super(ByteBufs.LITTLE_ENDIAN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class LittleEndianDirectChannelBufferTest extends AbstractChannelBufferTe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffer = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
|
buffer = ByteBufs.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
|
||||||
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
|
@ -30,7 +30,7 @@ public class LittleEndianHeapChannelBufferTest extends AbstractChannelBufferTest
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffer = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, length);
|
buffer = ByteBufs.buffer(ByteOrder.LITTLE_ENDIAN, length);
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static org.easymock.EasyMock.*;
|
import static org.easymock.EasyMock.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@ -40,24 +40,24 @@ public class ReadOnlyChannelBufferTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmodifiableBuffer() {
|
public void testUnmodifiableBuffer() {
|
||||||
assertTrue(ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1)) instanceof ReadOnlyByteBuf);
|
assertTrue(ByteBufs.unmodifiableBuffer(ByteBufs.buffer(1)) instanceof ReadOnlyByteBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnwrap() {
|
public void testUnwrap() {
|
||||||
ByteBuf buf = ChannelBuffers.buffer(1);
|
ByteBuf buf = ByteBufs.buffer(1);
|
||||||
assertSame(buf, ((WrappedByteBuf) ChannelBuffers.unmodifiableBuffer(buf)).unwrap());
|
assertSame(buf, ((WrappedByteBuf) ByteBufs.unmodifiableBuffer(buf)).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveSameByteOrder() {
|
public void shouldHaveSameByteOrder() {
|
||||||
ByteBuf buf = ChannelBuffers.buffer(ChannelBuffers.LITTLE_ENDIAN, 1);
|
ByteBuf buf = ByteBufs.buffer(ByteBufs.LITTLE_ENDIAN, 1);
|
||||||
assertSame(ChannelBuffers.LITTLE_ENDIAN, ChannelBuffers.unmodifiableBuffer(buf).order());
|
assertSame(ByteBufs.LITTLE_ENDIAN, ByteBufs.unmodifiableBuffer(buf).order());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnReadOnlyDerivedBuffer() {
|
public void shouldReturnReadOnlyDerivedBuffer() {
|
||||||
ByteBuf buf = ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1));
|
ByteBuf buf = ByteBufs.unmodifiableBuffer(ByteBufs.buffer(1));
|
||||||
assertTrue(buf.duplicate() instanceof ReadOnlyByteBuf);
|
assertTrue(buf.duplicate() instanceof ReadOnlyByteBuf);
|
||||||
assertTrue(buf.slice() instanceof ReadOnlyByteBuf);
|
assertTrue(buf.slice() instanceof ReadOnlyByteBuf);
|
||||||
assertTrue(buf.slice(0, 1) instanceof ReadOnlyByteBuf);
|
assertTrue(buf.slice(0, 1) instanceof ReadOnlyByteBuf);
|
||||||
@ -66,7 +66,7 @@ public class ReadOnlyChannelBufferTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnWritableCopy() {
|
public void shouldReturnWritableCopy() {
|
||||||
ByteBuf buf = ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1));
|
ByteBuf buf = ByteBufs.unmodifiableBuffer(ByteBufs.buffer(1));
|
||||||
assertFalse(buf.copy() instanceof ReadOnlyByteBuf);
|
assertFalse(buf.copy() instanceof ReadOnlyByteBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class SlicedChannelBufferTest extends AbstractChannelBufferTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffer = ChannelBuffers.wrappedBuffer(
|
buffer = ByteBufs.wrappedBuffer(
|
||||||
new byte[length * 2], random.nextInt(length - 1) + 1, length);
|
new byte[length * 2], random.nextInt(length - 1) + 1, length);
|
||||||
assertEquals(length, buffer.writerIndex());
|
assertEquals(length, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
|
@ -28,7 +28,7 @@ public class TruncatedChannelBufferTest extends AbstractChannelBufferTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length) {
|
||||||
buffer = ChannelBuffers.wrappedBuffer(
|
buffer = ByteBufs.wrappedBuffer(
|
||||||
new byte[length * 2], 0, length);
|
new byte[length * 2], 0, length);
|
||||||
assertEquals(length, buffer.writerIndex());
|
assertEquals(length, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -97,7 +97,7 @@ public class DefaultHttpChunkTrailer implements HttpChunkTrailer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf getContent() {
|
public ByteBuf getContent() {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -30,7 +30,7 @@ public class DefaultHttpMessage implements HttpMessage {
|
|||||||
|
|
||||||
private final HttpHeaders headers = new HttpHeaders();
|
private final HttpHeaders headers = new HttpHeaders();
|
||||||
private HttpVersion version;
|
private HttpVersion version;
|
||||||
private ByteBuf content = ChannelBuffers.EMPTY_BUFFER;
|
private ByteBuf content = ByteBufs.EMPTY_BUFFER;
|
||||||
private boolean chunked;
|
private boolean chunked;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +73,7 @@ public class DefaultHttpMessage implements HttpMessage {
|
|||||||
public void setChunked(boolean chunked) {
|
public void setChunked(boolean chunked) {
|
||||||
this.chunked = chunked;
|
this.chunked = chunked;
|
||||||
if (chunked) {
|
if (chunked) {
|
||||||
setContent(ChannelBuffers.EMPTY_BUFFER);
|
setContent(ByteBufs.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class DefaultHttpMessage implements HttpMessage {
|
|||||||
@Override
|
@Override
|
||||||
public void setContent(ByteBuf content) {
|
public void setContent(ByteBuf content) {
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
content = ChannelBuffers.EMPTY_BUFFER;
|
content = ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (content.readable() && isChunked()) {
|
if (content.readable() && isChunked()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -41,7 +41,7 @@ public interface HttpChunk {
|
|||||||
HttpChunkTrailer LAST_CHUNK = new HttpChunkTrailer() {
|
HttpChunkTrailer LAST_CHUNK = new HttpChunkTrailer() {
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf getContent() {
|
public ByteBuf getContent() {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -113,7 +113,7 @@ public interface HttpChunk {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the content of this chunk. If this is the 'end of content'
|
* Returns the content of this chunk. If this is the 'end of content'
|
||||||
* marker, {@link ChannelBuffers#EMPTY_BUFFER} will be returned.
|
* marker, {@link ByteBufs#EMPTY_BUFFER} will be returned.
|
||||||
*/
|
*/
|
||||||
ByteBuf getContent();
|
ByteBuf getContent();
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.http;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaders.*;
|
import static io.netty.handler.codec.http.HttpHeaders.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
@ -48,7 +48,7 @@ import java.util.Map.Entry;
|
|||||||
*/
|
*/
|
||||||
public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMessage> {
|
public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMessage> {
|
||||||
|
|
||||||
private static final ByteBuf CONTINUE = ChannelBuffers.copiedBuffer(
|
private static final ByteBuf CONTINUE = ByteBufs.copiedBuffer(
|
||||||
"HTTP/1.1 100 Continue\r\n\r\n", CharsetUtil.US_ASCII);
|
"HTTP/1.1 100 Continue\r\n\r\n", CharsetUtil.US_ASCII);
|
||||||
|
|
||||||
private final int maxContentLength;
|
private final int maxContentLength;
|
||||||
@ -101,7 +101,7 @@ public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMes
|
|||||||
m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
|
m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||||
}
|
}
|
||||||
m.setChunked(false);
|
m.setChunked(false);
|
||||||
m.setContent(ChannelBuffers.dynamicBuffer());
|
m.setContent(ByteBufs.dynamicBuffer());
|
||||||
this.currentMessage = m;
|
this.currentMessage = m;
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
@ -84,7 +84,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
|||||||
if (!m.isChunked()) {
|
if (!m.isChunked()) {
|
||||||
ByteBuf content = m.getContent();
|
ByteBuf content = m.getContent();
|
||||||
// Decode the content
|
// Decode the content
|
||||||
ByteBuf newContent = ChannelBuffers.dynamicBuffer();
|
ByteBuf newContent = ByteBufs.dynamicBuffer();
|
||||||
decode(content, newContent);
|
decode(content, newContent);
|
||||||
finishDecode(newContent);
|
finishDecode(newContent);
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
|||||||
// Decode the chunk if necessary.
|
// Decode the chunk if necessary.
|
||||||
if (decoder != null) {
|
if (decoder != null) {
|
||||||
if (!c.isLast()) {
|
if (!c.isLast()) {
|
||||||
ByteBuf newContent = ChannelBuffers.dynamicBuffer();
|
ByteBuf newContent = ByteBufs.dynamicBuffer();
|
||||||
decode(content, newContent);
|
decode(content, newContent);
|
||||||
if (newContent.readable()) {
|
if (newContent.readable()) {
|
||||||
c.setContent(newContent);
|
c.setContent(newContent);
|
||||||
@ -112,7 +112,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ByteBuf lastProduct = ChannelBuffers.dynamicBuffer();
|
ByteBuf lastProduct = ByteBufs.dynamicBuffer();
|
||||||
finishDecode(lastProduct);
|
finishDecode(lastProduct);
|
||||||
|
|
||||||
// Generate an additional chunk if the decoder produced
|
// Generate an additional chunk if the decoder produced
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import io.netty.handler.codec.MessageToMessageCodec;
|
import io.netty.handler.codec.MessageToMessageCodec;
|
||||||
@ -117,7 +117,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
|||||||
if (!m.isChunked()) {
|
if (!m.isChunked()) {
|
||||||
ByteBuf content = m.getContent();
|
ByteBuf content = m.getContent();
|
||||||
// Encode the content.
|
// Encode the content.
|
||||||
ByteBuf newContent = ChannelBuffers.dynamicBuffer();
|
ByteBuf newContent = ByteBufs.dynamicBuffer();
|
||||||
encode(content, newContent);
|
encode(content, newContent);
|
||||||
finishEncode(newContent);
|
finishEncode(newContent);
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
|||||||
// Encode the chunk if necessary.
|
// Encode the chunk if necessary.
|
||||||
if (encoder != null) {
|
if (encoder != null) {
|
||||||
if (!c.isLast()) {
|
if (!c.isLast()) {
|
||||||
ByteBuf newContent = ChannelBuffers.dynamicBuffer();
|
ByteBuf newContent = ByteBufs.dynamicBuffer();
|
||||||
encode(content, newContent);
|
encode(content, newContent);
|
||||||
if (content.readable()) {
|
if (content.readable()) {
|
||||||
c.setContent(newContent);
|
c.setContent(newContent);
|
||||||
@ -144,7 +144,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ByteBuf lastProduct = ChannelBuffers.dynamicBuffer();
|
ByteBuf lastProduct = ByteBufs.dynamicBuffer();
|
||||||
finishEncode(lastProduct);
|
finishEncode(lastProduct);
|
||||||
|
|
||||||
// Generate an additional chunk if the decoder produced
|
// Generate an additional chunk if the decoder produced
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -83,13 +83,13 @@ public interface HttpMessage {
|
|||||||
/**
|
/**
|
||||||
* Returns the content of this message. If there is no content or
|
* Returns the content of this message. If there is no content or
|
||||||
* {@link #isChunked()} returns {@code true}, an
|
* {@link #isChunked()} returns {@code true}, an
|
||||||
* {@link ChannelBuffers#EMPTY_BUFFER} is returned.
|
* {@link ByteBufs#EMPTY_BUFFER} is returned.
|
||||||
*/
|
*/
|
||||||
ByteBuf getContent();
|
ByteBuf getContent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the content of this message. If {@code null} is specified,
|
* Sets the content of this message. If {@code null} is specified,
|
||||||
* the content of this message will be set to {@link ChannelBuffers#EMPTY_BUFFER}.
|
* the content of this message will be set to {@link ByteBufs#EMPTY_BUFFER}.
|
||||||
*/
|
*/
|
||||||
void setContent(ByteBuf content);
|
void setContent(ByteBuf content);
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public interface HttpMessage {
|
|||||||
* consecutively, contain the actual content.
|
* consecutively, contain the actual content.
|
||||||
* <p>
|
* <p>
|
||||||
* If this method is called with {@code true}, the content of this message
|
* If this method is called with {@code true}, the content of this message
|
||||||
* becomes {@link ChannelBuffers#EMPTY_BUFFER}.
|
* becomes {@link ByteBufs#EMPTY_BUFFER}.
|
||||||
* <p>
|
* <p>
|
||||||
* Even if this method is called with {@code false}, {@link #isChunked()}
|
* Even if this method is called with {@code false}, {@link #isChunked()}
|
||||||
* will keep returning {@code true} if the {@code "Transfer-Encoding"} of
|
* will keep returning {@code true} if the {@code "Transfer-Encoding"} of
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.handler.codec.ReplayingDecoder;
|
import io.netty.handler.codec.ReplayingDecoder;
|
||||||
@ -204,7 +204,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
|||||||
} else {
|
} else {
|
||||||
long contentLength = HttpHeaders.getContentLength(message, -1);
|
long contentLength = HttpHeaders.getContentLength(message, -1);
|
||||||
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
|
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
|
||||||
content = ChannelBuffers.EMPTY_BUFFER;
|
content = ByteBufs.EMPTY_BUFFER;
|
||||||
return reset();
|
return reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static io.netty.handler.codec.http.HttpConstants.*;
|
import static io.netty.handler.codec.http.HttpConstants.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web Socket frame containing binary data
|
* Web Socket frame containing binary data
|
||||||
@ -27,7 +27,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
|
|||||||
* Creates a new empty binary frame.
|
* Creates a new empty binary frame.
|
||||||
*/
|
*/
|
||||||
public BinaryWebSocketFrame() {
|
public BinaryWebSocketFrame() {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +28,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
|||||||
* Creates a new empty close frame.
|
* Creates a new empty close frame.
|
||||||
*/
|
*/
|
||||||
public CloseWebSocketFrame() {
|
public CloseWebSocketFrame() {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +78,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
|||||||
reasonBytes = reasonText.getBytes(CharsetUtil.UTF_8);
|
reasonBytes = reasonText.getBytes(CharsetUtil.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf binaryData = ChannelBuffers.buffer(2 + reasonBytes.length);
|
ByteBuf binaryData = ByteBufs.buffer(2 + reasonBytes.length);
|
||||||
binaryData.writeShort(statusCode);
|
binaryData.writeShort(statusCode);
|
||||||
if (reasonBytes.length > 0) {
|
if (reasonBytes.length > 0) {
|
||||||
binaryData.writeBytes(reasonBytes);
|
binaryData.writeBytes(reasonBytes);
|
||||||
@ -102,7 +102,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
|||||||
setFinalFragment(finalFragment);
|
setFinalFragment(finalFragment);
|
||||||
setRsv(rsv);
|
setRsv(rsv);
|
||||||
if (binaryData == null) {
|
if (binaryData == null) {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
} else {
|
} else {
|
||||||
setBinaryData(binaryData);
|
setBinaryData(binaryData);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +31,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
|||||||
* Creates a new empty continuation frame.
|
* Creates a new empty continuation frame.
|
||||||
*/
|
*/
|
||||||
public ContinuationWebSocketFrame() {
|
public ContinuationWebSocketFrame() {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,9 +115,9 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
|||||||
*/
|
*/
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
if (text == null || text.isEmpty()) {
|
if (text == null || text.isEmpty()) {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
} else {
|
} else {
|
||||||
setBinaryData(ChannelBuffers.copiedBuffer(text, CharsetUtil.UTF_8));
|
setBinaryData(ByteBufs.copiedBuffer(text, CharsetUtil.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web Socket frame containing binary data
|
* Web Socket frame containing binary data
|
||||||
@ -28,7 +28,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
|
|||||||
*/
|
*/
|
||||||
public PingWebSocketFrame() {
|
public PingWebSocketFrame() {
|
||||||
setFinalFragment(true);
|
setFinalFragment(true);
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web Socket frame containing binary data
|
* Web Socket frame containing binary data
|
||||||
@ -27,7 +27,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
|
|||||||
* Creates a new empty pong frame.
|
* Creates a new empty pong frame.
|
||||||
*/
|
*/
|
||||||
public PongWebSocketFrame() {
|
public PongWebSocketFrame() {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +28,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
|||||||
* Creates a new empty text frame.
|
* Creates a new empty text frame.
|
||||||
*/
|
*/
|
||||||
public TextWebSocketFrame() {
|
public TextWebSocketFrame() {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,9 +39,9 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
|||||||
*/
|
*/
|
||||||
public TextWebSocketFrame(String text) {
|
public TextWebSocketFrame(String text) {
|
||||||
if (text == null || text.isEmpty()) {
|
if (text == null || text.isEmpty()) {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
} else {
|
} else {
|
||||||
setBinaryData(ChannelBuffers.copiedBuffer(text, CharsetUtil.UTF_8));
|
setBinaryData(ByteBufs.copiedBuffer(text, CharsetUtil.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,9 +69,9 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
|||||||
setFinalFragment(finalFragment);
|
setFinalFragment(finalFragment);
|
||||||
setRsv(rsv);
|
setRsv(rsv);
|
||||||
if (text == null || text.isEmpty()) {
|
if (text == null || text.isEmpty()) {
|
||||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
setBinaryData(ByteBufs.EMPTY_BUFFER);
|
||||||
} else {
|
} else {
|
||||||
setBinaryData(ChannelBuffers.copiedBuffer(text, CharsetUtil.UTF_8));
|
setBinaryData(ByteBufs.copiedBuffer(text, CharsetUtil.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
|||||||
if (text == null) {
|
if (text == null) {
|
||||||
throw new NullPointerException("text");
|
throw new NullPointerException("text");
|
||||||
}
|
}
|
||||||
setBinaryData(ChannelBuffers.copiedBuffer(text, CharsetUtil.UTF_8));
|
setBinaryData(ByteBufs.copiedBuffer(text, CharsetUtil.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.CorruptedFrameException;
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
@ -257,7 +257,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
|
|||||||
// Returning null means we will get called back
|
// Returning null means we will get called back
|
||||||
payloadBuffer = in.readBytes(rbytes);
|
payloadBuffer = in.readBytes(rbytes);
|
||||||
if (framePayload == null) {
|
if (framePayload == null) {
|
||||||
framePayload = ChannelBuffers.buffer(toFrameLength(framePayloadLength));
|
framePayload = ByteBufs.buffer(toFrameLength(framePayloadLength));
|
||||||
}
|
}
|
||||||
framePayload.writeBytes(payloadBuffer);
|
framePayload.writeBytes(payloadBuffer);
|
||||||
framePayloadBytesRead += rbytes;
|
framePayloadBytesRead += rbytes;
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
@ -106,7 +106,7 @@ public class WebSocket08FrameEncoder extends MessageToByteEncoder<WebSocketFrame
|
|||||||
WebSocketFrame frame = msg;
|
WebSocketFrame frame = msg;
|
||||||
ByteBuf data = frame.getBinaryData();
|
ByteBuf data = frame.getBinaryData();
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
data = ChannelBuffers.EMPTY_BUFFER;
|
data = ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte opcode;
|
byte opcode;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||||
@ -164,7 +164,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request.setContent(ChannelBuffers.copiedBuffer(key3));
|
request.setContent(ByteBufs.copiedBuffer(key3));
|
||||||
|
|
||||||
ChannelFuture future = channel.write(request);
|
ChannelFuture future = channel.write(request);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
|||||||
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
|
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
@ -154,11 +154,11 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
|||||||
int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length());
|
int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length());
|
||||||
int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
|
int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
|
||||||
long c = req.getContent().readLong();
|
long c = req.getContent().readLong();
|
||||||
ByteBuf input = ChannelBuffers.buffer(16);
|
ByteBuf input = ByteBufs.buffer(16);
|
||||||
input.writeInt(a);
|
input.writeInt(a);
|
||||||
input.writeInt(b);
|
input.writeInt(b);
|
||||||
input.writeLong(c);
|
input.writeLong(c);
|
||||||
ByteBuf output = ChannelBuffers.wrappedBuffer(WebSocketUtil.md5(input.array()));
|
ByteBuf output = ByteBufs.wrappedBuffer(WebSocketUtil.md5(input.array()));
|
||||||
res.setContent(output);
|
res.setContent(output);
|
||||||
} else {
|
} else {
|
||||||
// Old Hixie 75 handshake method with no challenge:
|
// Old Hixie 75 handshake method with no challenge:
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.handler.codec.base64.Base64;
|
import io.netty.handler.codec.base64.Base64;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ final class WebSocketUtil {
|
|||||||
* @return encoded string
|
* @return encoded string
|
||||||
*/
|
*/
|
||||||
static String base64(byte[] bytes) {
|
static String base64(byte[] bytes) {
|
||||||
ByteBuf hashed = ChannelBuffers.wrappedBuffer(bytes);
|
ByteBuf hashed = ByteBufs.wrappedBuffer(bytes);
|
||||||
return Base64.encode(hashed).toString(CharsetUtil.UTF_8);
|
return Base64.encode(hashed).toString(CharsetUtil.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.spdy;
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +27,7 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame {
|
|||||||
private int streamID;
|
private int streamID;
|
||||||
private boolean last;
|
private boolean last;
|
||||||
private boolean compressed;
|
private boolean compressed;
|
||||||
private ByteBuf data = ChannelBuffers.EMPTY_BUFFER;
|
private ByteBuf data = ByteBufs.EMPTY_BUFFER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
@ -80,7 +80,7 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void setData(ByteBuf data) {
|
public void setData(ByteBuf data) {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
data = ChannelBuffers.EMPTY_BUFFER;
|
data = ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (data.readableBytes() > SpdyCodecUtil.SPDY_MAX_LENGTH) {
|
if (data.readableBytes() > SpdyCodecUtil.SPDY_MAX_LENGTH) {
|
||||||
throw new IllegalArgumentException("data payload cannot exceed "
|
throw new IllegalArgumentException("data payload cannot exceed "
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.spdy;
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A SPDY Protocol Data Frame
|
* A SPDY Protocol Data Frame
|
||||||
@ -58,13 +58,13 @@ public interface SpdyDataFrame {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data payload of this frame. If there is no data payload
|
* Returns the data payload of this frame. If there is no data payload
|
||||||
* {@link ChannelBuffers#EMPTY_BUFFER} is returned.
|
* {@link ByteBufs#EMPTY_BUFFER} is returned.
|
||||||
*/
|
*/
|
||||||
ByteBuf getData();
|
ByteBuf getData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the data payload of this frame. If {@code null} is specified,
|
* Sets the data payload of this frame. If {@code null} is specified,
|
||||||
* the data payload will be set to {@link ChannelBuffers#EMPTY_BUFFER}.
|
* the data payload will be set to {@link ByteBufs#EMPTY_BUFFER}.
|
||||||
* The data payload cannot exceed 16777215 bytes.
|
* The data payload cannot exceed 16777215 bytes.
|
||||||
*/
|
*/
|
||||||
void setData(ByteBuf data);
|
void setData(ByteBuf data);
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.spdy;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
@ -554,7 +554,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
|||||||
// Initialize header block decoding fields
|
// Initialize header block decoding fields
|
||||||
headerSize = 0;
|
headerSize = 0;
|
||||||
numHeaders = -1;
|
numHeaders = -1;
|
||||||
decompressed = ChannelBuffers.dynamicBuffer(8192);
|
decompressed = ByteBufs.dynamicBuffer(8192);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accumulate decompressed data
|
// Accumulate decompressed data
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.spdy;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -305,13 +305,13 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
|||||||
Set<String> names = headerFrame.getHeaderNames();
|
Set<String> names = headerFrame.getHeaderNames();
|
||||||
int numHeaders = names.size();
|
int numHeaders = names.size();
|
||||||
if (numHeaders == 0) {
|
if (numHeaders == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
if (numHeaders > SPDY_MAX_NV_LENGTH) {
|
if (numHeaders > SPDY_MAX_NV_LENGTH) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"header block contains too many headers");
|
"header block contains too many headers");
|
||||||
}
|
}
|
||||||
ByteBuf headerBlock = ChannelBuffers.dynamicBuffer(
|
ByteBuf headerBlock = ByteBufs.dynamicBuffer(
|
||||||
ByteOrder.BIG_ENDIAN, 256);
|
ByteOrder.BIG_ENDIAN, 256);
|
||||||
writeLengthField(version, headerBlock, numHeaders);
|
writeLengthField(version, headerBlock, numHeaders);
|
||||||
for (String name: names) {
|
for (String name: names) {
|
||||||
@ -341,9 +341,9 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
|||||||
private synchronized ByteBuf compressHeaderBlock(
|
private synchronized ByteBuf compressHeaderBlock(
|
||||||
ByteBuf uncompressed) throws Exception {
|
ByteBuf uncompressed) throws Exception {
|
||||||
if (uncompressed.readableBytes() == 0) {
|
if (uncompressed.readableBytes() == 0) {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
ByteBuf compressed = ChannelBuffers.dynamicBuffer();
|
ByteBuf compressed = ByteBufs.dynamicBuffer();
|
||||||
synchronized (headerBlockCompressor) {
|
synchronized (headerBlockCompressor) {
|
||||||
if (!finished) {
|
if (!finished) {
|
||||||
headerBlockCompressor.setInput(uncompressed);
|
headerBlockCompressor.setInput(uncompressed);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.spdy;
|
package io.netty.handler.codec.spdy;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
@ -206,8 +206,8 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<Object, HttpMessage
|
|||||||
|
|
||||||
ByteBuf spdyDataFrameData = spdyDataFrame.getData();
|
ByteBuf spdyDataFrameData = spdyDataFrame.getData();
|
||||||
int spdyDataFrameDataLen = spdyDataFrameData.readableBytes();
|
int spdyDataFrameDataLen = spdyDataFrameData.readableBytes();
|
||||||
if (content == ChannelBuffers.EMPTY_BUFFER) {
|
if (content == ByteBufs.EMPTY_BUFFER) {
|
||||||
content = ChannelBuffers.dynamicBuffer(spdyDataFrameDataLen);
|
content = ByteBufs.dynamicBuffer(spdyDataFrameDataLen);
|
||||||
content.writeBytes(spdyDataFrameData, spdyDataFrameData.readerIndex(), spdyDataFrameDataLen);
|
content.writeBytes(spdyDataFrameData, spdyDataFrameData.readerIndex(), spdyDataFrameDataLen);
|
||||||
httpMessage.setContent(content);
|
httpMessage.setContent(content);
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import io.netty.handler.codec.CodecException;
|
import io.netty.handler.codec.CodecException;
|
||||||
import io.netty.handler.codec.PrematureChannelClosureException;
|
import io.netty.handler.codec.PrematureChannelClosureException;
|
||||||
@ -39,7 +39,7 @@ public class HttpClientCodecTest {
|
|||||||
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
|
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
|
||||||
|
|
||||||
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
||||||
ch.writeInbound(ChannelBuffers.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1));
|
ch.writeInbound(ByteBufs.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1));
|
||||||
ch.finish();
|
ch.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public class HttpClientCodecTest {
|
|||||||
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
|
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
|
||||||
|
|
||||||
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
||||||
ch.writeInbound(ChannelBuffers.copiedBuffer(CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1));
|
ch.writeInbound(ByteBufs.copiedBuffer(CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1));
|
||||||
ch.finish();
|
ch.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ public class HttpClientCodecTest {
|
|||||||
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
|
EmbeddedByteChannel ch = new EmbeddedByteChannel(codec);
|
||||||
|
|
||||||
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
ch.writeOutbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
||||||
ch.writeInbound(ChannelBuffers.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1));
|
ch.writeInbound(ByteBufs.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ch.finish();
|
ch.finish();
|
||||||
|
@ -19,7 +19,7 @@ import static io.netty.handler.codec.http.HttpHeaders.Values.*;
|
|||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import static org.easymock.EasyMock.*;
|
import static org.easymock.EasyMock.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.DefaultChannelFuture;
|
import io.netty.channel.DefaultChannelFuture;
|
||||||
import io.netty.channel.DefaultChannelPipeline;
|
import io.netty.channel.DefaultChannelPipeline;
|
||||||
@ -71,7 +71,7 @@ public class WebSocketServerHandshaker00Test {
|
|||||||
req.setHeader(Names.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00");
|
req.setHeader(Names.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00");
|
||||||
req.setHeader(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
|
req.setHeader(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
|
||||||
|
|
||||||
ByteBuf buffer = ChannelBuffers.copiedBuffer("^n:ds[4U", Charset.defaultCharset());
|
ByteBuf buffer = ByteBufs.copiedBuffer("^n:ds[4U", Charset.defaultCharset());
|
||||||
req.setContent(buffer);
|
req.setContent(buffer);
|
||||||
|
|
||||||
WebSocketServerHandshaker00 handsaker = new WebSocketServerHandshaker00("ws://example.com/chat", "chat", Integer.MAX_VALUE);
|
WebSocketServerHandshaker00 handsaker = new WebSocketServerHandshaker00("ws://example.com/chat", "chat", Integer.MAX_VALUE);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec;
|
package io.netty.handler.codec;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of commonly used delimiters for {@link DelimiterBasedFrameDecoder}.
|
* A set of commonly used delimiters for {@link DelimiterBasedFrameDecoder}.
|
||||||
@ -29,7 +29,7 @@ public final class Delimiters {
|
|||||||
*/
|
*/
|
||||||
public static ByteBuf[] nulDelimiter() {
|
public static ByteBuf[] nulDelimiter() {
|
||||||
return new ByteBuf[] {
|
return new ByteBuf[] {
|
||||||
ChannelBuffers.wrappedBuffer(new byte[] { 0 }) };
|
ByteBufs.wrappedBuffer(new byte[] { 0 }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,8 +38,8 @@ public final class Delimiters {
|
|||||||
*/
|
*/
|
||||||
public static ByteBuf[] lineDelimiter() {
|
public static ByteBuf[] lineDelimiter() {
|
||||||
return new ByteBuf[] {
|
return new ByteBuf[] {
|
||||||
ChannelBuffers.wrappedBuffer(new byte[] { '\r', '\n' }),
|
ByteBufs.wrappedBuffer(new byte[] { '\r', '\n' }),
|
||||||
ChannelBuffers.wrappedBuffer(new byte[] { '\n' }),
|
ByteBufs.wrappedBuffer(new byte[] { '\n' }),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec;
|
package io.netty.handler.codec;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
import io.netty.channel.ChannelBufferHolder;
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
import io.netty.channel.ChannelBufferHolders;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -71,7 +71,7 @@ public class FixedLengthFrameDecoder extends ByteToMessageDecoder<Object> {
|
|||||||
public ChannelBufferHolder<Byte> newInboundBuffer(
|
public ChannelBufferHolder<Byte> newInboundBuffer(
|
||||||
ChannelHandlerContext ctx) throws Exception {
|
ChannelHandlerContext ctx) throws Exception {
|
||||||
if (allocateFullBuffer) {
|
if (allocateFullBuffer) {
|
||||||
return ChannelBufferHolders.byteBuffer(ChannelBuffers.dynamicBuffer(frameLength));
|
return ChannelBufferHolders.byteBuffer(ByteBufs.dynamicBuffer(frameLength));
|
||||||
} else {
|
} else {
|
||||||
return super.newInboundBuffer(ctx);
|
return super.newInboundBuffer(ctx);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package io.netty.handler.codec;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufFactory;
|
import io.netty.buffer.ByteBufFactory;
|
||||||
import io.netty.buffer.ByteBufIndexFinder;
|
import io.netty.buffer.ByteBufIndexFinder;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.util.Signal;
|
import io.netty.util.Signal;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -37,7 +37,7 @@ class ReplayingDecoderBuffer implements ByteBuf {
|
|||||||
private final ByteBuf buffer;
|
private final ByteBuf buffer;
|
||||||
private boolean terminated;
|
private boolean terminated;
|
||||||
|
|
||||||
public static ReplayingDecoderBuffer EMPTY_BUFFER = new ReplayingDecoderBuffer(ChannelBuffers.EMPTY_BUFFER);
|
public static ReplayingDecoderBuffer EMPTY_BUFFER = new ReplayingDecoderBuffer(ByteBufs.EMPTY_BUFFER);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
EMPTY_BUFFER.terminate();
|
EMPTY_BUFFER.terminate();
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.bytes;
|
package io.netty.handler.codec.bytes;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
import io.netty.channel.ChannelBufferHolder;
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
import io.netty.channel.ChannelBufferHolders;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -67,6 +67,6 @@ public class ByteArrayEncoder extends MessageToMessageEncoder<byte[], ByteBuf> {
|
|||||||
if (msg.length == 0) {
|
if (msg.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ChannelBuffers.wrappedBuffer(msg);
|
return ByteBufs.wrappedBuffer(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.compression;
|
package io.netty.handler.codec.compression;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -383,9 +383,9 @@ public class ZlibEncoder extends ByteToByteEncoder {
|
|||||||
future.setFailure(ZlibUtil.exception(z, "compression failure", resultCode));
|
future.setFailure(ZlibUtil.exception(z, "compression failure", resultCode));
|
||||||
return future;
|
return future;
|
||||||
} else if (z.next_out_index != 0) {
|
} else if (z.next_out_index != 0) {
|
||||||
footer = ChannelBuffers.wrappedBuffer(out, 0, z.next_out_index);
|
footer = ByteBufs.wrappedBuffer(out, 0, z.next_out_index);
|
||||||
} else {
|
} else {
|
||||||
footer = ChannelBuffers.EMPTY_BUFFER;
|
footer = ByteBufs.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
z.deflateEnd();
|
z.deflateEnd();
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.marshalling;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufFactory;
|
import io.netty.buffer.ByteBufFactory;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class ChannelBufferByteOutput implements ByteOutput {
|
|||||||
* Calls {@link #ChannelBufferByteOutput(ByteBuf)} with a dynamic {@link ByteBuf}
|
* Calls {@link #ChannelBufferByteOutput(ByteBuf)} with a dynamic {@link ByteBuf}
|
||||||
*/
|
*/
|
||||||
public ChannelBufferByteOutput(ByteBufFactory factory, int estimatedLength) {
|
public ChannelBufferByteOutput(ByteBufFactory factory, int estimatedLength) {
|
||||||
this(ChannelBuffers.dynamicBuffer(estimatedLength, factory));
|
this(ByteBufs.dynamicBuffer(estimatedLength, factory));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.protobuf;
|
package io.netty.handler.codec.protobuf;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.serialization;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufOutputStream;
|
import io.netty.buffer.ByteBufOutputStream;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -81,7 +81,7 @@ public class ObjectEncoderOutputStream extends OutputStream implements
|
|||||||
@Override
|
@Override
|
||||||
public void writeObject(Object obj) throws IOException {
|
public void writeObject(Object obj) throws IOException {
|
||||||
ByteBufOutputStream bout = new ByteBufOutputStream(
|
ByteBufOutputStream bout = new ByteBufOutputStream(
|
||||||
ChannelBuffers.dynamicBuffer(estimatedLength));
|
ByteBufs.dynamicBuffer(estimatedLength));
|
||||||
ObjectOutputStream oout = new CompactObjectOutputStream(bout);
|
ObjectOutputStream oout = new CompactObjectOutputStream(bout);
|
||||||
oout.writeObject(obj);
|
oout.writeObject(obj);
|
||||||
oout.flush();
|
oout.flush();
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.string;
|
package io.netty.handler.codec.string;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
@ -79,6 +79,6 @@ public class StringEncoder extends MessageToMessageEncoder<String, ByteBuf> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf encode(ChannelHandlerContext ctx, String msg) throws Exception {
|
public ByteBuf encode(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||||
return ChannelBuffers.copiedBuffer(msg, charset);
|
return ByteBufs.copiedBuffer(msg, charset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package io.netty.handler.codec;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufIndexFinder;
|
import io.netty.buffer.ByteBufIndexFinder;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import io.netty.util.VoidEnum;
|
import io.netty.util.VoidEnum;
|
||||||
@ -32,17 +32,17 @@ public class ReplayingDecoderTest {
|
|||||||
EmbeddedByteChannel ch = new EmbeddedByteChannel(new LineDecoder());
|
EmbeddedByteChannel ch = new EmbeddedByteChannel(new LineDecoder());
|
||||||
|
|
||||||
// Ordinary input
|
// Ordinary input
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 'A' }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A' }));
|
||||||
assertNull(ch.readInbound());
|
assertNull(ch.readInbound());
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 'B' }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'B' }));
|
||||||
assertNull(ch.readInbound());
|
assertNull(ch.readInbound());
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 'C' }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'C' }));
|
||||||
assertNull(ch.readInbound());
|
assertNull(ch.readInbound());
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { '\n' }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { '\n' }));
|
||||||
assertEquals(ChannelBuffers.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound());
|
assertEquals(ByteBufs.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound());
|
||||||
|
|
||||||
// Truncated input
|
// Truncated input
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 'A' }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A' }));
|
||||||
assertNull(ch.readInbound());
|
assertNull(ch.readInbound());
|
||||||
ch.close();
|
ch.close();
|
||||||
assertNull(ch.readInbound());
|
assertNull(ch.readInbound());
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.bytes;
|
package io.netty.handler.codec.bytes;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static org.hamcrest.core.Is.*;
|
import static org.hamcrest.core.Is.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.channel.embedded.EmbeddedMessageChannel;
|
import io.netty.channel.embedded.EmbeddedMessageChannel;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.bytes;
|
package io.netty.handler.codec.bytes;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static org.hamcrest.core.Is.*;
|
import static org.hamcrest.core.Is.*;
|
||||||
import static org.hamcrest.core.IsNull.*;
|
import static org.hamcrest.core.IsNull.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.frame;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import io.netty.handler.codec.DecoderException;
|
import io.netty.handler.codec.DecoderException;
|
||||||
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
|
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
|
||||||
@ -36,15 +36,15 @@ public class DelimiterBasedFrameDecoderTest {
|
|||||||
new DelimiterBasedFrameDecoder(1, true, false, Delimiters.nulDelimiter()));
|
new DelimiterBasedFrameDecoder(1, true, false, Delimiters.nulDelimiter()));
|
||||||
|
|
||||||
for (int i = 0; i < 2; i ++) {
|
for (int i = 0; i < 2; i ++) {
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 1, 2 }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 1, 2 }));
|
||||||
try {
|
try {
|
||||||
assertTrue(ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 0 })));
|
assertTrue(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0 })));
|
||||||
Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
|
Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
|
||||||
} catch (TooLongFrameException e) {
|
} catch (TooLongFrameException e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 'A', 0 }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 'A', 0 }));
|
||||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||||
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
||||||
}
|
}
|
||||||
@ -57,13 +57,13 @@ public class DelimiterBasedFrameDecoderTest {
|
|||||||
|
|
||||||
for (int i = 0; i < 2; i ++) {
|
for (int i = 0; i < 2; i ++) {
|
||||||
try {
|
try {
|
||||||
assertTrue(ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 1, 2 })));
|
assertTrue(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 1, 2 })));
|
||||||
Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
|
Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
|
||||||
} catch (TooLongFrameException e) {
|
} catch (TooLongFrameException e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 0, 'A', 0 }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 'A', 0 }));
|
||||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||||
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.frame;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import io.netty.handler.codec.DecoderException;
|
import io.netty.handler.codec.DecoderException;
|
||||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||||
@ -34,15 +34,15 @@ public class LengthFieldBasedFrameDecoderTest {
|
|||||||
new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4, false));
|
new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4, false));
|
||||||
|
|
||||||
for (int i = 0; i < 2; i ++) {
|
for (int i = 0; i < 2; i ++) {
|
||||||
assertFalse(ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0, 0, 2 })));
|
assertFalse(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0, 0, 2 })));
|
||||||
try {
|
try {
|
||||||
assertTrue(ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0 })));
|
assertTrue(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0 })));
|
||||||
Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
|
Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
|
||||||
} catch (TooLongFrameException e) {
|
} catch (TooLongFrameException e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0, 0, 1, 'A' }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0, 0, 1, 'A' }));
|
||||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||||
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
||||||
}
|
}
|
||||||
@ -55,13 +55,13 @@ public class LengthFieldBasedFrameDecoderTest {
|
|||||||
|
|
||||||
for (int i = 0; i < 2; i ++) {
|
for (int i = 0; i < 2; i ++) {
|
||||||
try {
|
try {
|
||||||
assertTrue(ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0, 0, 2 })));
|
assertTrue(ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0, 0, 2 })));
|
||||||
Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
|
Assert.fail(DecoderException.class.getSimpleName() + " must be raised.");
|
||||||
} catch (TooLongFrameException e) {
|
} catch (TooLongFrameException e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
ch.writeInbound(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, 'A' }));
|
ch.writeInbound(ByteBufs.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, 'A' }));
|
||||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||||
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.marshalling;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import io.netty.handler.codec.CodecException;
|
import io.netty.handler.codec.CodecException;
|
||||||
@ -64,7 +64,7 @@ public abstract class AbstractCompatibleMarshallingDecoderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ByteBuf input(byte[] input) {
|
protected ByteBuf input(byte[] input) {
|
||||||
return ChannelBuffers.wrappedBuffer(input);
|
return ByteBufs.wrappedBuffer(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -16,16 +16,16 @@
|
|||||||
package io.netty.handler.codec.marshalling;
|
package io.netty.handler.codec.marshalling;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
|
|
||||||
public class RiverMarshallingDecoderTest extends RiverCompatibleMarshallingDecoderTest {
|
public class RiverMarshallingDecoderTest extends RiverCompatibleMarshallingDecoderTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf input(byte[] input) {
|
protected ByteBuf input(byte[] input) {
|
||||||
ByteBuf length = ChannelBuffers.buffer(4);
|
ByteBuf length = ByteBufs.buffer(4);
|
||||||
length.writeInt(input.length);
|
length.writeInt(input.length);
|
||||||
return ChannelBuffers.wrappedBuffer(length, ChannelBuffers.wrappedBuffer(input));
|
return ByteBufs.wrappedBuffer(length, ByteBufs.wrappedBuffer(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,16 +16,16 @@
|
|||||||
package io.netty.handler.codec.marshalling;
|
package io.netty.handler.codec.marshalling;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
|
|
||||||
public class SerialMarshallingDecoderTest extends SerialCompatibleMarshallingDecoderTest {
|
public class SerialMarshallingDecoderTest extends SerialCompatibleMarshallingDecoderTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf input(byte[] input) {
|
protected ByteBuf input(byte[] input) {
|
||||||
ByteBuf length = ChannelBuffers.buffer(4);
|
ByteBuf length = ByteBufs.buffer(4);
|
||||||
length.writeInt(input.length);
|
length.writeInt(input.length);
|
||||||
return ChannelBuffers.wrappedBuffer(length, ChannelBuffers.wrappedBuffer(input));
|
return ByteBufs.wrappedBuffer(length, ByteBufs.wrappedBuffer(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.protobuf;
|
package io.netty.handler.codec.protobuf;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static org.hamcrest.core.Is.*;
|
import static org.hamcrest.core.Is.*;
|
||||||
import static org.hamcrest.core.IsNull.*;
|
import static org.hamcrest.core.IsNull.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.protobuf;
|
package io.netty.handler.codec.protobuf;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import static org.hamcrest.core.Is.*;
|
import static org.hamcrest.core.Is.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.example.echo;
|
package io.netty.example.echo;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundByteHandlerAdapter;
|
import io.netty.channel.ChannelInboundByteHandlerAdapter;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public class EchoClientHandler extends ChannelInboundByteHandlerAdapter {
|
|||||||
if (firstMessageSize <= 0) {
|
if (firstMessageSize <= 0) {
|
||||||
throw new IllegalArgumentException("firstMessageSize: " + firstMessageSize);
|
throw new IllegalArgumentException("firstMessageSize: " + firstMessageSize);
|
||||||
}
|
}
|
||||||
firstMessage = ChannelBuffers.buffer(firstMessageSize);
|
firstMessage = ByteBufs.buffer(firstMessageSize);
|
||||||
for (int i = 0; i < firstMessage.capacity(); i ++) {
|
for (int i = 0; i < firstMessage.capacity(); i ++) {
|
||||||
firstMessage.writeByte((byte) i);
|
firstMessage.writeByte((byte) i);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
|||||||
import static io.netty.handler.codec.http.HttpMethod.*;
|
import static io.netty.handler.codec.http.HttpMethod.*;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -215,7 +215,7 @@ public class HttpStaticFileServerHandler extends ChannelInboundMessageHandlerAda
|
|||||||
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
|
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
|
||||||
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
|
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
|
||||||
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
|
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
|
||||||
response.setContent(ChannelBuffers.copiedBuffer(
|
response.setContent(ByteBufs.copiedBuffer(
|
||||||
"Failure: " + status.toString() + "\r\n",
|
"Failure: " + status.toString() + "\r\n",
|
||||||
CharsetUtil.UTF_8));
|
CharsetUtil.UTF_8));
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
|||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
import io.netty.channel.ChannelBufferHolder;
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
import io.netty.channel.ChannelBufferHolders;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
@ -131,7 +131,7 @@ public class HttpSnoopServerHandler extends ChannelInboundMessageHandlerAdapter<
|
|||||||
|
|
||||||
// Build the response object.
|
// Build the response object.
|
||||||
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
|
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
|
||||||
response.setContent(ChannelBuffers.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));
|
response.setContent(ByteBufs.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));
|
||||||
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
|
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
|
||||||
|
|
||||||
if (keepAlive) {
|
if (keepAlive) {
|
||||||
|
@ -19,7 +19,7 @@ import static io.netty.handler.codec.http.HttpHeaders.*;
|
|||||||
import static io.netty.handler.codec.http.HttpMethod.*;
|
import static io.netty.handler.codec.http.HttpMethod.*;
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -108,7 +108,7 @@ public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<O
|
|||||||
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
|
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
|
||||||
// Generate an error page if response status code is not OK (200).
|
// Generate an error page if response status code is not OK (200).
|
||||||
if (res.getStatus().getCode() != 200) {
|
if (res.getStatus().getCode() != 200) {
|
||||||
res.setContent(ChannelBuffers.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
|
res.setContent(ByteBufs.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
|
||||||
setContentLength(res, res.getContent().readableBytes());
|
setContentLength(res, res.getContent().readableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
package io.netty.example.http.websocketx.client;
|
package io.netty.example.http.websocketx.client;
|
||||||
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
@ -108,7 +108,7 @@ public class WebSocketClient {
|
|||||||
|
|
||||||
// Ping
|
// Ping
|
||||||
System.out.println("WebSocket Client sending ping");
|
System.out.println("WebSocket Client sending ping");
|
||||||
ch.write(new PingWebSocketFrame(ChannelBuffers.copiedBuffer(new byte[]{1, 2, 3, 4, 5, 6})));
|
ch.write(new PingWebSocketFrame(ByteBufs.copiedBuffer(new byte[]{1, 2, 3, 4, 5, 6})));
|
||||||
|
|
||||||
// Close
|
// Close
|
||||||
System.out.println("WebSocket Client sending close");
|
System.out.println("WebSocket Client sending close");
|
||||||
|
@ -21,7 +21,7 @@ import static io.netty.handler.codec.http.HttpMethod.*;
|
|||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -121,7 +121,7 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
|
|||||||
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
|
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
|
||||||
// Generate an error page if response status code is not OK (200).
|
// Generate an error page if response status code is not OK (200).
|
||||||
if (res.getStatus().getCode() != 200) {
|
if (res.getStatus().getCode() != 200) {
|
||||||
res.setContent(ChannelBuffers.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
|
res.setContent(ByteBufs.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
|
||||||
setContentLength(res, res.getContent().readableBytes());
|
setContentLength(res, res.getContent().readableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.example.http.websocketx.server;
|
package io.netty.example.http.websocketx.server;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +27,7 @@ public final class WebSocketServerIndexPage {
|
|||||||
private static final String NEWLINE = "\r\n";
|
private static final String NEWLINE = "\r\n";
|
||||||
|
|
||||||
public static ByteBuf getContent(String webSocketLocation) {
|
public static ByteBuf getContent(String webSocketLocation) {
|
||||||
return ChannelBuffers.copiedBuffer(
|
return ByteBufs.copiedBuffer(
|
||||||
"<html><head><title>Web Socket Test</title></head>" + NEWLINE +
|
"<html><head><title>Web Socket Test</title></head>" + NEWLINE +
|
||||||
"<body>" + NEWLINE +
|
"<body>" + NEWLINE +
|
||||||
"<script type=\"text/javascript\">" + NEWLINE +
|
"<script type=\"text/javascript\">" + NEWLINE +
|
||||||
|
@ -21,7 +21,7 @@ import static io.netty.handler.codec.http.HttpMethod.*;
|
|||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -122,7 +122,7 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
|
|||||||
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
|
private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
|
||||||
// Generate an error page if response status code is not OK (200).
|
// Generate an error page if response status code is not OK (200).
|
||||||
if (res.getStatus().getCode() != 200) {
|
if (res.getStatus().getCode() != 200) {
|
||||||
res.setContent(ChannelBuffers.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
|
res.setContent(ByteBufs.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
|
||||||
setContentLength(res, res.getContent().readableBytes());
|
setContentLength(res, res.getContent().readableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.example.qotm;
|
package io.netty.example.qotm;
|
||||||
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.socket.DatagramPacket;
|
import io.netty.channel.socket.DatagramPacket;
|
||||||
@ -53,7 +53,7 @@ public class QuoteOfTheMomentClient {
|
|||||||
|
|
||||||
// Broadcast the QOTM request to port 8080.
|
// Broadcast the QOTM request to port 8080.
|
||||||
ch.write(new DatagramPacket(
|
ch.write(new DatagramPacket(
|
||||||
ChannelBuffers.copiedBuffer("QOTM?", CharsetUtil.UTF_8),
|
ByteBufs.copiedBuffer("QOTM?", CharsetUtil.UTF_8),
|
||||||
new InetSocketAddress("255.255.255.255", port)));
|
new InetSocketAddress("255.255.255.255", port)));
|
||||||
|
|
||||||
// QuoteOfTheMomentClientHandler will close the DatagramChannel when a
|
// QuoteOfTheMomentClientHandler will close the DatagramChannel when a
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.example.qotm;
|
package io.netty.example.qotm;
|
||||||
|
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
import io.netty.channel.socket.DatagramPacket;
|
import io.netty.channel.socket.DatagramPacket;
|
||||||
@ -49,7 +49,7 @@ public class QuoteOfTheMomentServerHandler extends ChannelInboundMessageHandlerA
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
if (msg.data().toString(CharsetUtil.UTF_8).equals("QOTM?")) {
|
if (msg.data().toString(CharsetUtil.UTF_8).equals("QOTM?")) {
|
||||||
ctx.write(new DatagramPacket(
|
ctx.write(new DatagramPacket(
|
||||||
ChannelBuffers.copiedBuffer("QOTM: " + nextQuote(), CharsetUtil.UTF_8),
|
ByteBufs.copiedBuffer("QOTM: " + nextQuote(), CharsetUtil.UTF_8),
|
||||||
msg.remoteAddress()));
|
msg.remoteAddress()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.stream;
|
package io.netty.handler.stream;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.stream;
|
package io.netty.handler.stream;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.stream;
|
package io.netty.handler.stream;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.stream;
|
package io.netty.handler.stream;
|
||||||
|
|
||||||
import static io.netty.buffer.ChannelBuffers.*;
|
import static io.netty.buffer.ByteBufs.*;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PushbackInputStream;
|
import java.io.PushbackInputStream;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.stream;
|
package io.netty.handler.stream;
|
||||||
|
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
import io.netty.channel.ChannelBufferHolder;
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
import io.netty.channel.ChannelBufferHolders;
|
||||||
@ -197,7 +197,7 @@ public class ChunkedWriteHandler
|
|||||||
chunk = chunks.nextChunk();
|
chunk = chunks.nextChunk();
|
||||||
endOfInput = chunks.isEndOfInput();
|
endOfInput = chunks.isEndOfInput();
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
chunk = ChannelBuffers.EMPTY_BUFFER;
|
chunk = ByteBufs.EMPTY_BUFFER;
|
||||||
// No need to suspend when reached at the end.
|
// No need to suspend when reached at the end.
|
||||||
suspend = !endOfInput;
|
suspend = !endOfInput;
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.stream;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.ChannelBufferHolder;
|
import io.netty.channel.ChannelBufferHolder;
|
||||||
import io.netty.channel.ChannelBufferHolders;
|
import io.netty.channel.ChannelBufferHolders;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
@ -103,11 +103,11 @@ public class ChunkedWriteHandlerTest {
|
|||||||
// http://stackoverflow.com/questions/10409241/why-is-close-channelfuturelistener-not-notified/10426305#comment14126161_10426305
|
// http://stackoverflow.com/questions/10409241/why-is-close-channelfuturelistener-not-notified/10426305#comment14126161_10426305
|
||||||
@Test
|
@Test
|
||||||
public void testListenerNotifiedWhenIsEnd() {
|
public void testListenerNotifiedWhenIsEnd() {
|
||||||
ByteBuf buffer = ChannelBuffers.copiedBuffer("Test", CharsetUtil.ISO_8859_1);
|
ByteBuf buffer = ByteBufs.copiedBuffer("Test", CharsetUtil.ISO_8859_1);
|
||||||
|
|
||||||
ChunkedInput input = new ChunkedInput() {
|
ChunkedInput input = new ChunkedInput() {
|
||||||
private boolean done;
|
private boolean done;
|
||||||
private final ByteBuf buffer = ChannelBuffers.copiedBuffer("Test", CharsetUtil.ISO_8859_1);
|
private final ByteBuf buffer = ByteBufs.copiedBuffer("Test", CharsetUtil.ISO_8859_1);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object nextChunk() throws Exception {
|
public Object nextChunk() throws Exception {
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.testsuite.transport.socket;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
@ -68,7 +68,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
|
|||||||
|
|
||||||
cc.joinGroup(groupAddress, NetworkConstants.LOOPBACK_IF).sync();
|
cc.joinGroup(groupAddress, NetworkConstants.LOOPBACK_IF).sync();
|
||||||
|
|
||||||
sc.write(new DatagramPacket(ChannelBuffers.copyInt(1), groupAddress)).sync();
|
sc.write(new DatagramPacket(ByteBufs.copyInt(1), groupAddress)).sync();
|
||||||
assertTrue(mhandler.await());
|
assertTrue(mhandler.await());
|
||||||
|
|
||||||
// leave the group
|
// leave the group
|
||||||
@ -78,7 +78,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
// we should not receive a message anymore as we left the group before
|
// we should not receive a message anymore as we left the group before
|
||||||
sc.write(new DatagramPacket(ChannelBuffers.copyInt(1), groupAddress)).sync();
|
sc.write(new DatagramPacket(ByteBufs.copyInt(1), groupAddress)).sync();
|
||||||
mhandler.await();
|
mhandler.await();
|
||||||
|
|
||||||
sc.close().awaitUninterruptibly();
|
sc.close().awaitUninterruptibly();
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.testsuite.transport.socket;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ChannelBuffers;
|
import io.netty.buffer.ByteBufs;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
@ -61,7 +61,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
|||||||
Channel sc = sb.bind().sync().channel();
|
Channel sc = sb.bind().sync().channel();
|
||||||
Channel cc = cb.bind().sync().channel();
|
Channel cc = cb.bind().sync().channel();
|
||||||
|
|
||||||
cc.write(new DatagramPacket(ChannelBuffers.copyInt(1), addr)).sync();
|
cc.write(new DatagramPacket(ByteBufs.copyInt(1), addr)).sync();
|
||||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||||
|
|
||||||
sc.close().sync();
|
sc.close().sync();
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user