Rename ChannelBuffer to ByteBuf as discussed before
- ChannelBuffer gives a perception that it's a buffer of a channel, but channel's buffer is now a byte buffer or a message buffer. Therefore letting it be as is is going to be confusing.
This commit is contained in:
parent
87f52aa604
commit
5164d91255
@ -27,7 +27,7 @@ import java.nio.charset.Charset;
|
||||
/**
|
||||
* A skeletal implementation of a buffer.
|
||||
*/
|
||||
public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
public abstract class AbstractByteBuf implements ByteBuf {
|
||||
|
||||
private int readerIndex;
|
||||
private int writerIndex;
|
||||
@ -194,12 +194,12 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst) {
|
||||
public void getBytes(int index, ByteBuf dst) {
|
||||
getBytes(index, dst, dst.writableBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int length) {
|
||||
if (length > dst.writableBytes()) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be read: Need "
|
||||
+ length + ", maximum is " + dst.writableBytes());
|
||||
@ -234,12 +234,12 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src) {
|
||||
public void setBytes(int index, ByteBuf src) {
|
||||
setBytes(index, src, src.readableBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int length) {
|
||||
if (length > src.readableBytes()) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to write: Need "
|
||||
+ length + ", maximum is " + src.readableBytes());
|
||||
@ -367,20 +367,20 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer readBytes(int length) {
|
||||
public ByteBuf readBytes(int length) {
|
||||
checkReadableBytes(length);
|
||||
if (length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buf = factory().getBuffer(order(), length);
|
||||
ByteBuf buf = factory().getBuffer(order(), length);
|
||||
buf.writeBytes(this, readerIndex, length);
|
||||
readerIndex += length;
|
||||
return buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer readSlice(int length) {
|
||||
ChannelBuffer slice = slice(readerIndex, length);
|
||||
public ByteBuf readSlice(int length) {
|
||||
ByteBuf slice = slice(readerIndex, length);
|
||||
readerIndex += length;
|
||||
return slice;
|
||||
}
|
||||
@ -398,12 +398,12 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readBytes(ChannelBuffer dst) {
|
||||
public void readBytes(ByteBuf dst) {
|
||||
readBytes(dst, dst.writableBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readBytes(ChannelBuffer dst, int length) {
|
||||
public void readBytes(ByteBuf dst, int length) {
|
||||
if (length > dst.writableBytes()) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be read: Need "
|
||||
+ length + ", maximum is " + dst.writableBytes());
|
||||
@ -413,7 +413,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readBytes(ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void readBytes(ByteBuf dst, int dstIndex, int length) {
|
||||
checkReadableBytes(length);
|
||||
getBytes(readerIndex, dst, dstIndex, length);
|
||||
readerIndex += length;
|
||||
@ -514,12 +514,12 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(ChannelBuffer src) {
|
||||
public void writeBytes(ByteBuf src) {
|
||||
writeBytes(src, src.readableBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(ChannelBuffer src, int length) {
|
||||
public void writeBytes(ByteBuf src, int length) {
|
||||
if (length > src.readableBytes()) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to write - Need "
|
||||
+ length + ", maximum is " + src.readableBytes());
|
||||
@ -529,7 +529,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(ChannelBuffer src, int srcIndex, int length) {
|
||||
public void writeBytes(ByteBuf src, int srcIndex, int length) {
|
||||
setBytes(writerIndex, src, srcIndex, length);
|
||||
writerIndex += length;
|
||||
}
|
||||
@ -590,12 +590,12 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy() {
|
||||
public ByteBuf copy() {
|
||||
return copy(readerIndex, readableBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice() {
|
||||
public ByteBuf slice() {
|
||||
return slice(readerIndex, readableBytes());
|
||||
}
|
||||
|
||||
@ -633,7 +633,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
public int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
|
||||
return ChannelBuffers.indexOf(this, fromIndex, toIndex, indexFinder);
|
||||
}
|
||||
|
||||
@ -643,7 +643,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytesBefore(ChannelBufferIndexFinder indexFinder) {
|
||||
public int bytesBefore(ByteBufIndexFinder indexFinder) {
|
||||
return bytesBefore(readerIndex(), readableBytes(), indexFinder);
|
||||
}
|
||||
|
||||
@ -654,7 +654,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytesBefore(int length, ChannelBufferIndexFinder indexFinder) {
|
||||
public int bytesBefore(int length, ByteBufIndexFinder indexFinder) {
|
||||
checkReadableBytes(length);
|
||||
return bytesBefore(readerIndex(), length, indexFinder);
|
||||
}
|
||||
@ -670,7 +670,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
@Override
|
||||
public int bytesBefore(int index, int length,
|
||||
ChannelBufferIndexFinder indexFinder) {
|
||||
ByteBufIndexFinder indexFinder) {
|
||||
int endIndex = indexOf(index, index + length, indexFinder);
|
||||
if (endIndex < 0) {
|
||||
return -1;
|
||||
@ -685,14 +685,14 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ChannelBuffer)) {
|
||||
if (!(o instanceof ByteBuf)) {
|
||||
return false;
|
||||
}
|
||||
return ChannelBuffers.equals(this, (ChannelBuffer) o);
|
||||
return ChannelBuffers.equals(this, (ByteBuf) o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ChannelBuffer that) {
|
||||
public int compareTo(ByteBuf that) {
|
||||
return ChannelBuffers.compare(this, that);
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ package io.netty.buffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* A skeletal implementation of {@link ChannelBufferFactory}.
|
||||
* A skeletal implementation of {@link ByteBufFactory}.
|
||||
*/
|
||||
public abstract class AbstractChannelBufferFactory implements ChannelBufferFactory {
|
||||
public abstract class AbstractByteBufFactory implements ByteBufFactory {
|
||||
|
||||
private final ByteOrder defaultOrder;
|
||||
|
||||
@ -28,7 +28,7 @@ public abstract class AbstractChannelBufferFactory implements ChannelBufferFacto
|
||||
* Creates a new factory whose default {@link ByteOrder} is
|
||||
* {@link ByteOrder#BIG_ENDIAN}.
|
||||
*/
|
||||
protected AbstractChannelBufferFactory() {
|
||||
protected AbstractByteBufFactory() {
|
||||
this(ByteOrder.BIG_ENDIAN);
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public abstract class AbstractChannelBufferFactory implements ChannelBufferFacto
|
||||
*
|
||||
* @param defaultOrder the default {@link ByteOrder} of this factory
|
||||
*/
|
||||
protected AbstractChannelBufferFactory(ByteOrder defaultOrder) {
|
||||
protected AbstractByteBufFactory(ByteOrder defaultOrder) {
|
||||
if (defaultOrder == null) {
|
||||
throw new NullPointerException("defaultOrder");
|
||||
}
|
||||
@ -45,12 +45,12 @@ public abstract class AbstractChannelBufferFactory implements ChannelBufferFacto
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getBuffer(int capacity) {
|
||||
public ByteBuf getBuffer(int capacity) {
|
||||
return getBuffer(getDefaultOrder(), capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getBuffer(byte[] array, int offset, int length) {
|
||||
public ByteBuf getBuffer(byte[] array, int offset, int length) {
|
||||
return getBuffer(getDefaultOrder(), array, offset, length);
|
||||
}
|
||||
|
@ -23,14 +23,14 @@ import java.nio.ByteOrder;
|
||||
* and {@link ChannelBuffers#wrappedBuffer(byte[])} instead of calling the
|
||||
* constructor explicitly.
|
||||
*/
|
||||
public class BigEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
public class BigEndianHeapByteBuf extends HeapByteBuf {
|
||||
|
||||
/**
|
||||
* Creates a new big-endian heap buffer with a newly allocated byte array.
|
||||
*
|
||||
* @param length the length of the new byte array
|
||||
*/
|
||||
public BigEndianHeapChannelBuffer(int length) {
|
||||
public BigEndianHeapByteBuf(int length) {
|
||||
super(length);
|
||||
}
|
||||
|
||||
@ -39,17 +39,17 @@ public class BigEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
*
|
||||
* @param array the byte array to wrap
|
||||
*/
|
||||
public BigEndianHeapChannelBuffer(byte[] array) {
|
||||
public BigEndianHeapByteBuf(byte[] array) {
|
||||
super(array);
|
||||
}
|
||||
|
||||
private BigEndianHeapChannelBuffer(byte[] array, int readerIndex, int writerIndex) {
|
||||
private BigEndianHeapByteBuf(byte[] array, int readerIndex, int writerIndex) {
|
||||
super(array, readerIndex, writerIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
return HeapChannelBufferFactory.getInstance(ByteOrder.BIG_ENDIAN);
|
||||
public ByteBufFactory factory() {
|
||||
return HeapByteBufFactory.getInstance(ByteOrder.BIG_ENDIAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -123,12 +123,12 @@ public class BigEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
return new BigEndianHeapChannelBuffer(array, readerIndex(), writerIndex());
|
||||
public ByteBuf duplicate() {
|
||||
return new BigEndianHeapByteBuf(array, readerIndex(), writerIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
if (index < 0 || length < 0 || index + length > array.length) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to copy - Need "
|
||||
+ (index + length) + ", maximum is " + array.length);
|
||||
@ -136,6 +136,6 @@ public class BigEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
|
||||
byte[] copiedArray = new byte[length];
|
||||
System.arraycopy(array, index, copiedArray, 0, length);
|
||||
return new BigEndianHeapChannelBuffer(copiedArray);
|
||||
return new BigEndianHeapByteBuf(copiedArray);
|
||||
}
|
||||
}
|
@ -38,14 +38,14 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
*
|
||||
* <h3>Random Access Indexing</h3>
|
||||
*
|
||||
* Just like an ordinary primitive byte array, {@link ChannelBuffer} uses
|
||||
* Just like an ordinary primitive byte array, {@link ByteBuf} uses
|
||||
* <a href="http://en.wikipedia.org/wiki/Zero-based_numbering">zero-based indexing</a>.
|
||||
* It means the index of the first byte is always {@code 0} and the index of the last byte is
|
||||
* always {@link #capacity() capacity - 1}. For example, to iterate all bytes of a buffer, you
|
||||
* can do the following, regardless of its internal implementation:
|
||||
*
|
||||
* <pre>
|
||||
* {@link ChannelBuffer} buffer = ...;
|
||||
* {@link ByteBuf} buffer = ...;
|
||||
* for (int i = 0; i < buffer.capacity(); i ++) {
|
||||
* byte b = buffer.getByte(i);
|
||||
* System.out.println((char) b);
|
||||
@ -54,7 +54,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
*
|
||||
* <h3>Sequential Access Indexing</h3>
|
||||
*
|
||||
* {@link ChannelBuffer} provides two pointer variables to support sequential
|
||||
* {@link ByteBuf} provides two pointer variables to support sequential
|
||||
* read and write operations - {@link #readerIndex() readerIndex} for a read
|
||||
* operation and {@link #writerIndex() writerIndex} for a write operation
|
||||
* respectively. The following diagram shows how a buffer is segmented into
|
||||
@ -75,7 +75,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
* starts with {@code read} or {@code skip} will get or skip the data at the
|
||||
* current {@link #readerIndex() readerIndex} and increase it by the number of
|
||||
* read bytes. If the argument of the read operation is also a
|
||||
* {@link ChannelBuffer} and no destination index is specified, the specified
|
||||
* {@link ByteBuf} and no destination index is specified, the specified
|
||||
* buffer's {@link #readerIndex() readerIndex} is increased together.
|
||||
* <p>
|
||||
* If there's not enough content left, {@link IndexOutOfBoundsException} is
|
||||
@ -84,7 +84,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
*
|
||||
* <pre>
|
||||
* // Iterates the readable bytes of a buffer.
|
||||
* {@link ChannelBuffer} buffer = ...;
|
||||
* {@link ByteBuf} buffer = ...;
|
||||
* while (buffer.readable()) {
|
||||
* System.out.println(buffer.readByte());
|
||||
* }
|
||||
@ -95,7 +95,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
* This segment is a undefined space which needs to be filled. Any operation
|
||||
* whose name ends with {@code write} will write the data at the current
|
||||
* {@link #writerIndex() writerIndex} and increase it by the number of written
|
||||
* bytes. If the argument of the write operation is also a {@link ChannelBuffer},
|
||||
* bytes. If the argument of the write operation is also a {@link ByteBuf},
|
||||
* and no source index is specified, the specified buffer's
|
||||
* {@link #readerIndex() readerIndex} is increased together.
|
||||
* <p>
|
||||
@ -107,7 +107,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
*
|
||||
* <pre>
|
||||
* // Fills the writable bytes of a buffer with random integers.
|
||||
* {@link ChannelBuffer} buffer = ...;
|
||||
* {@link ByteBuf} buffer = ...;
|
||||
* while (buffer.writableBytes() >= 4) {
|
||||
* buffer.writeInt(random.nextInt());
|
||||
* }
|
||||
@ -176,7 +176,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
*
|
||||
* Various {@link #indexOf(int, int, byte)} methods help you locate an index of
|
||||
* a value which meets a certain criteria. Complicated dynamic sequential
|
||||
* search can be done with {@link ChannelBufferIndexFinder} as well as simple
|
||||
* search can be done with {@link ByteBufIndexFinder} as well as simple
|
||||
* static single byte search.
|
||||
* <p>
|
||||
* If you are decoding variable length data such as NUL-terminated string, you
|
||||
@ -206,35 +206,35 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
*
|
||||
* <h4>Byte array</h4>
|
||||
*
|
||||
* If a {@link ChannelBuffer} is backed by a byte array (i.e. {@code byte[]}),
|
||||
* If a {@link ByteBuf} is backed by a byte array (i.e. {@code byte[]}),
|
||||
* you can access it directly via the {@link #array()} method. To determine
|
||||
* if a buffer is backed by a byte array, {@link #hasArray()} should be used.
|
||||
*
|
||||
* <h4>NIO Buffers</h4>
|
||||
*
|
||||
* If a {@link ChannelBuffer} can be converted into an NIO {@link ByteBuffer} which shares its
|
||||
* If a {@link ByteBuf} can be converted into an NIO {@link ByteBuffer} which shares its
|
||||
* content (i.e. view buffer), you can get it via the {@link #nioBuffer()} method. To determine
|
||||
* if a buffer can be converted into an NIO buffer, use {@link #nioBuffer()}.
|
||||
*
|
||||
* <h4>Strings</h4>
|
||||
*
|
||||
* Various {@link #toString(Charset)} methods convert a {@link ChannelBuffer}
|
||||
* Various {@link #toString(Charset)} methods convert a {@link ByteBuf}
|
||||
* into a {@link String}. Please note that {@link #toString()} is not a
|
||||
* conversion method.
|
||||
*
|
||||
* <h4>I/O Streams</h4>
|
||||
*
|
||||
* Please refer to {@link ChannelBufferInputStream} and
|
||||
* {@link ChannelBufferOutputStream}.
|
||||
* Please refer to {@link ByteBufInputStream} and
|
||||
* {@link ByteBufOutputStream}.
|
||||
* @apiviz.landmark
|
||||
*/
|
||||
public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
public interface ByteBuf extends Comparable<ByteBuf> {
|
||||
|
||||
/**
|
||||
* Returns the factory which creates a {@link ChannelBuffer} whose
|
||||
* Returns the factory which creates a {@link ByteBuf} whose
|
||||
* type and default {@link ByteOrder} are same with this buffer.
|
||||
*/
|
||||
ChannelBufferFactory factory();
|
||||
ByteBufFactory factory();
|
||||
|
||||
/**
|
||||
* Returns the number of bytes (octets) this buffer can contain.
|
||||
@ -292,7 +292,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* <pre>
|
||||
* // Create a buffer whose readerIndex, writerIndex and capacity are
|
||||
* // 0, 0 and 8 respectively.
|
||||
* {@link ChannelBuffer} buf = {@link ChannelBuffers}.buffer(8);
|
||||
* {@link ByteBuf} buf = {@link ChannelBuffers}.buffer(8);
|
||||
*
|
||||
* // IndexOutOfBoundsException is thrown because the specified
|
||||
* // readerIndex (2) cannot be greater than the current writerIndex (0).
|
||||
@ -305,7 +305,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* <pre>
|
||||
* // Create a buffer whose readerIndex, writerIndex and capacity are
|
||||
* // 0, 8 and 8 respectively.
|
||||
* {@link ChannelBuffer} buf = {@link ChannelBuffers}.wrappedBuffer(new byte[8]);
|
||||
* {@link ByteBuf} buf = {@link ChannelBuffers}.wrappedBuffer(new byte[8]);
|
||||
*
|
||||
* // readerIndex becomes 8.
|
||||
* buf.readLong();
|
||||
@ -588,10 +588,10 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* Transfers this buffer's data to the specified destination starting at
|
||||
* the specified absolute {@code index} until the destination becomes
|
||||
* non-writable. This method is basically same with
|
||||
* {@link #getBytes(int, ChannelBuffer, int, int)}, except that this
|
||||
* {@link #getBytes(int, ByteBuf, int, int)}, except that this
|
||||
* method increases the {@code writerIndex} of the destination by the
|
||||
* number of the transferred bytes while
|
||||
* {@link #getBytes(int, ChannelBuffer, int, int)} does not.
|
||||
* {@link #getBytes(int, ByteBuf, int, int)} does not.
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* the source buffer (i.e. {@code this}).
|
||||
*
|
||||
@ -600,15 +600,15 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* if {@code index + dst.writableBytes} is greater than
|
||||
* {@code this.capacity}
|
||||
*/
|
||||
void getBytes(int index, ChannelBuffer dst);
|
||||
void getBytes(int index, ByteBuf dst);
|
||||
|
||||
/**
|
||||
* Transfers this buffer's data to the specified destination starting at
|
||||
* the specified absolute {@code index}. This method is basically same
|
||||
* with {@link #getBytes(int, ChannelBuffer, int, int)}, except that this
|
||||
* with {@link #getBytes(int, ByteBuf, int, int)}, except that this
|
||||
* method increases the {@code writerIndex} of the destination by the
|
||||
* number of the transferred bytes while
|
||||
* {@link #getBytes(int, ChannelBuffer, int, int)} does not.
|
||||
* {@link #getBytes(int, ByteBuf, int, int)} does not.
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* the source buffer (i.e. {@code this}).
|
||||
*
|
||||
@ -620,7 +620,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* {@code this.capacity}, or
|
||||
* if {@code length} is greater than {@code dst.writableBytes}
|
||||
*/
|
||||
void getBytes(int index, ChannelBuffer dst, int length);
|
||||
void getBytes(int index, ByteBuf dst, int length);
|
||||
|
||||
/**
|
||||
* Transfers this buffer's data to the specified destination starting at
|
||||
@ -639,7 +639,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* if {@code dstIndex + length} is greater than
|
||||
* {@code dst.capacity}
|
||||
*/
|
||||
void getBytes(int index, ChannelBuffer dst, int dstIndex, int length);
|
||||
void getBytes(int index, ByteBuf dst, int dstIndex, int length);
|
||||
|
||||
/**
|
||||
* Transfers this buffer's data to the specified destination starting at
|
||||
@ -838,10 +838,10 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* Transfers the specified source buffer's data to this buffer starting at
|
||||
* the specified absolute {@code index} until the source buffer becomes
|
||||
* unreadable. This method is basically same with
|
||||
* {@link #setBytes(int, ChannelBuffer, int, int)}, except that this
|
||||
* {@link #setBytes(int, ByteBuf, int, int)}, except that this
|
||||
* method increases the {@code readerIndex} of the source buffer by
|
||||
* the number of the transferred bytes while
|
||||
* {@link #setBytes(int, ChannelBuffer, int, int)} does not.
|
||||
* {@link #setBytes(int, ByteBuf, int, int)} does not.
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* the source buffer (i.e. {@code this}).
|
||||
*
|
||||
@ -850,15 +850,15 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* if {@code index + src.readableBytes} is greater than
|
||||
* {@code this.capacity}
|
||||
*/
|
||||
void setBytes(int index, ChannelBuffer src);
|
||||
void setBytes(int index, ByteBuf src);
|
||||
|
||||
/**
|
||||
* Transfers the specified source buffer's data to this buffer starting at
|
||||
* the specified absolute {@code index}. This method is basically same
|
||||
* with {@link #setBytes(int, ChannelBuffer, int, int)}, except that this
|
||||
* with {@link #setBytes(int, ByteBuf, int, int)}, except that this
|
||||
* method increases the {@code readerIndex} of the source buffer by
|
||||
* the number of the transferred bytes while
|
||||
* {@link #setBytes(int, ChannelBuffer, int, int)} does not.
|
||||
* {@link #setBytes(int, ByteBuf, int, int)} does not.
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* the source buffer (i.e. {@code this}).
|
||||
*
|
||||
@ -870,7 +870,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* {@code this.capacity}, or
|
||||
* if {@code length} is greater than {@code src.readableBytes}
|
||||
*/
|
||||
void setBytes(int index, ChannelBuffer src, int length);
|
||||
void setBytes(int index, ByteBuf src, int length);
|
||||
|
||||
/**
|
||||
* Transfers the specified source buffer's data to this buffer starting at
|
||||
@ -889,7 +889,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* if {@code srcIndex + length} is greater than
|
||||
* {@code src.capacity}
|
||||
*/
|
||||
void setBytes(int index, ChannelBuffer src, int srcIndex, int length);
|
||||
void setBytes(int index, ByteBuf src, int srcIndex, int length);
|
||||
|
||||
/**
|
||||
* Transfers the specified source array's data to this buffer starting at
|
||||
@ -1116,7 +1116,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code length} is greater than {@code this.readableBytes}
|
||||
*/
|
||||
ChannelBuffer readBytes(int length);
|
||||
ByteBuf readBytes(int length);
|
||||
|
||||
/**
|
||||
* Returns a new slice of this buffer's sub-region starting at the current
|
||||
@ -1130,38 +1130,38 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code length} is greater than {@code this.readableBytes}
|
||||
*/
|
||||
ChannelBuffer readSlice(int length);
|
||||
ByteBuf readSlice(int length);
|
||||
|
||||
/**
|
||||
* Transfers this buffer's data to the specified destination starting at
|
||||
* the current {@code readerIndex} until the destination becomes
|
||||
* non-writable, and increases the {@code readerIndex} by the number of the
|
||||
* transferred bytes. This method is basically same with
|
||||
* {@link #readBytes(ChannelBuffer, int, int)}, except that this method
|
||||
* {@link #readBytes(ByteBuf, int, int)}, except that this method
|
||||
* increases the {@code writerIndex} of the destination by the number of
|
||||
* the transferred bytes while {@link #readBytes(ChannelBuffer, int, int)}
|
||||
* the transferred bytes while {@link #readBytes(ByteBuf, int, int)}
|
||||
* does not.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code dst.writableBytes} is greater than
|
||||
* {@code this.readableBytes}
|
||||
*/
|
||||
void readBytes(ChannelBuffer dst);
|
||||
void readBytes(ByteBuf dst);
|
||||
|
||||
/**
|
||||
* Transfers this buffer's data to the specified destination starting at
|
||||
* the current {@code readerIndex} and increases the {@code readerIndex}
|
||||
* by the number of the transferred bytes (= {@code length}). This method
|
||||
* is basically same with {@link #readBytes(ChannelBuffer, int, int)},
|
||||
* is basically same with {@link #readBytes(ByteBuf, int, int)},
|
||||
* except that this method increases the {@code writerIndex} of the
|
||||
* destination by the number of the transferred bytes (= {@code length})
|
||||
* while {@link #readBytes(ChannelBuffer, int, int)} does not.
|
||||
* while {@link #readBytes(ByteBuf, int, int)} does not.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code length} is greater than {@code this.readableBytes} or
|
||||
* if {@code length} is greater than {@code dst.writableBytes}
|
||||
*/
|
||||
void readBytes(ChannelBuffer dst, int length);
|
||||
void readBytes(ByteBuf dst, int length);
|
||||
|
||||
/**
|
||||
* Transfers this buffer's data to the specified destination starting at
|
||||
@ -1177,7 +1177,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* if {@code dstIndex + length} is greater than
|
||||
* {@code dst.capacity}
|
||||
*/
|
||||
void readBytes(ChannelBuffer dst, int dstIndex, int length);
|
||||
void readBytes(ByteBuf dst, int dstIndex, int length);
|
||||
|
||||
/**
|
||||
* Transfers this buffer's data to the specified destination starting at
|
||||
@ -1346,25 +1346,25 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* the current {@code writerIndex} until the source buffer becomes
|
||||
* unreadable, and increases the {@code writerIndex} by the number of
|
||||
* the transferred bytes. This method is basically same with
|
||||
* {@link #writeBytes(ChannelBuffer, int, int)}, except that this method
|
||||
* {@link #writeBytes(ByteBuf, int, int)}, except that this method
|
||||
* increases the {@code readerIndex} of the source buffer by the number of
|
||||
* the transferred bytes while {@link #writeBytes(ChannelBuffer, int, int)}
|
||||
* the transferred bytes while {@link #writeBytes(ByteBuf, int, int)}
|
||||
* does not.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code src.readableBytes} is greater than
|
||||
* {@code this.writableBytes}
|
||||
*/
|
||||
void writeBytes(ChannelBuffer src);
|
||||
void writeBytes(ByteBuf src);
|
||||
|
||||
/**
|
||||
* Transfers the specified source buffer's data to this buffer starting at
|
||||
* the current {@code writerIndex} and increases the {@code writerIndex}
|
||||
* by the number of the transferred bytes (= {@code length}). This method
|
||||
* is basically same with {@link #writeBytes(ChannelBuffer, int, int)},
|
||||
* is basically same with {@link #writeBytes(ByteBuf, int, int)},
|
||||
* except that this method increases the {@code readerIndex} of the source
|
||||
* buffer by the number of the transferred bytes (= {@code length}) while
|
||||
* {@link #writeBytes(ChannelBuffer, int, int)} does not.
|
||||
* {@link #writeBytes(ByteBuf, int, int)} does not.
|
||||
*
|
||||
* @param length the number of bytes to transfer
|
||||
*
|
||||
@ -1372,7 +1372,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* if {@code length} is greater than {@code this.writableBytes} or
|
||||
* if {@code length} is greater then {@code src.readableBytes}
|
||||
*/
|
||||
void writeBytes(ChannelBuffer src, int length);
|
||||
void writeBytes(ByteBuf src, int length);
|
||||
|
||||
/**
|
||||
* Transfers the specified source buffer's data to this buffer starting at
|
||||
@ -1388,7 +1388,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* {@code src.capacity}, or
|
||||
* if {@code length} is greater than {@code this.writableBytes}
|
||||
*/
|
||||
void writeBytes(ChannelBuffer src, int srcIndex, int length);
|
||||
void writeBytes(ByteBuf src, int srcIndex, int length);
|
||||
|
||||
/**
|
||||
* Transfers the specified source array's data to this buffer starting at
|
||||
@ -1504,7 +1504,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* returned {@code true}. {@code -1} if the {@code indexFinder}
|
||||
* did not return {@code true} at all.
|
||||
*/
|
||||
int indexOf(int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder);
|
||||
int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder);
|
||||
|
||||
/**
|
||||
* Locates the first occurrence of the specified {@code value} in this
|
||||
@ -1532,7 +1532,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* {@code true}. {@code -1} if the {@code indexFinder} did not
|
||||
* return {@code true} at all.
|
||||
*/
|
||||
int bytesBefore(ChannelBufferIndexFinder indexFinder);
|
||||
int bytesBefore(ByteBufIndexFinder indexFinder);
|
||||
|
||||
/**
|
||||
* Locates the first occurrence of the specified {@code value} in this
|
||||
@ -1566,7 +1566,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code length} is greater than {@code this.readableBytes}
|
||||
*/
|
||||
int bytesBefore(int length, ChannelBufferIndexFinder indexFinder);
|
||||
int bytesBefore(int length, ByteBufIndexFinder indexFinder);
|
||||
|
||||
/**
|
||||
* Locates the first occurrence of the specified {@code value} in this
|
||||
@ -1600,7 +1600,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code index + length} is greater than {@code this.capacity}
|
||||
*/
|
||||
int bytesBefore(int index, int length, ChannelBufferIndexFinder indexFinder);
|
||||
int bytesBefore(int index, int length, ByteBufIndexFinder indexFinder);
|
||||
|
||||
/**
|
||||
* Returns a copy of this buffer's readable bytes. Modifying the content
|
||||
@ -1609,7 +1609,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* this buffer.
|
||||
*/
|
||||
ChannelBuffer copy();
|
||||
ByteBuf copy();
|
||||
|
||||
/**
|
||||
* Returns a copy of this buffer's sub-region. Modifying the content of
|
||||
@ -1617,7 +1617,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* this buffer.
|
||||
*/
|
||||
ChannelBuffer copy(int index, int length);
|
||||
ByteBuf copy(int index, int length);
|
||||
|
||||
/**
|
||||
* Returns a slice of this buffer's readable bytes. Modifying the content
|
||||
@ -1627,7 +1627,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* this buffer.
|
||||
*/
|
||||
ChannelBuffer slice();
|
||||
ByteBuf slice();
|
||||
|
||||
/**
|
||||
* Returns a slice of this buffer's sub-region. Modifying the content of
|
||||
@ -1636,7 +1636,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* this buffer.
|
||||
*/
|
||||
ChannelBuffer slice(int index, int length);
|
||||
ByteBuf slice(int index, int length);
|
||||
|
||||
/**
|
||||
* Returns a buffer which shares the whole region of this buffer.
|
||||
@ -1646,7 +1646,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* This method does not modify {@code readerIndex} or {@code writerIndex} of
|
||||
* this buffer.
|
||||
*/
|
||||
ChannelBuffer duplicate();
|
||||
ByteBuf duplicate();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if and only if {@link #nioBuffer()} method will not fail.
|
||||
@ -1744,7 +1744,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* Please note that it does not compare {@link #readerIndex()} nor
|
||||
* {@link #writerIndex()}. This method also returns {@code false} for
|
||||
* {@code null} and an object which is not an instance of
|
||||
* {@link ChannelBuffer} type.
|
||||
* {@link ByteBuf} type.
|
||||
*/
|
||||
@Override
|
||||
boolean equals(Object obj);
|
||||
@ -1756,7 +1756,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
* {@code memcmp} and {@link String#compareTo(String)}.
|
||||
*/
|
||||
@Override
|
||||
int compareTo(ChannelBuffer buffer);
|
||||
int compareTo(ByteBuf buffer);
|
||||
|
||||
/**
|
||||
* Returns the string representation of this buffer. This method does not
|
@ -19,34 +19,34 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* A factory that creates or pools {@link ChannelBuffer}s.
|
||||
* A factory that creates or pools {@link ByteBuf}s.
|
||||
*/
|
||||
public interface ChannelBufferFactory {
|
||||
public interface ByteBufFactory {
|
||||
|
||||
/**
|
||||
* Returns a {@link ChannelBuffer} with the specified {@code capacity}.
|
||||
* Returns a {@link ByteBuf} with the specified {@code capacity}.
|
||||
* This method is identical to {@code getBuffer(getDefaultOrder(), capacity)}.
|
||||
*
|
||||
* @param capacity the capacity of the returned {@link ChannelBuffer}
|
||||
* @return a {@link ChannelBuffer} with the specified {@code capacity},
|
||||
* @param capacity the capacity of the returned {@link ByteBuf}
|
||||
* @return a {@link ByteBuf} with the specified {@code capacity},
|
||||
* whose {@code readerIndex} and {@code writerIndex} are {@code 0}
|
||||
*/
|
||||
ChannelBuffer getBuffer(int capacity);
|
||||
ByteBuf getBuffer(int capacity);
|
||||
|
||||
/**
|
||||
* Returns a {@link ChannelBuffer} with the specified {@code endianness}
|
||||
* Returns a {@link ByteBuf} with the specified {@code endianness}
|
||||
* and {@code capacity}.
|
||||
*
|
||||
* @param endianness the endianness of the returned {@link ChannelBuffer}
|
||||
* @param capacity the capacity of the returned {@link ChannelBuffer}
|
||||
* @return a {@link ChannelBuffer} with the specified {@code endianness} and
|
||||
* @param endianness the endianness of the returned {@link ByteBuf}
|
||||
* @param capacity the capacity of the returned {@link ByteBuf}
|
||||
* @return a {@link ByteBuf} with the specified {@code endianness} and
|
||||
* {@code capacity}, whose {@code readerIndex} and {@code writerIndex}
|
||||
* are {@code 0}
|
||||
*/
|
||||
ChannelBuffer getBuffer(ByteOrder endianness, int capacity);
|
||||
ByteBuf getBuffer(ByteOrder endianness, int capacity);
|
||||
|
||||
/**
|
||||
* Returns a {@link ChannelBuffer} whose content is equal to the sub-region
|
||||
* Returns a {@link ByteBuf} whose content is equal to the sub-region
|
||||
* of the specified {@code array}. Depending on the factory implementation,
|
||||
* the returned buffer could wrap the {@code array} or create a new copy of
|
||||
* the {@code array}.
|
||||
@ -56,48 +56,48 @@ public interface ChannelBufferFactory {
|
||||
* @param offset the offset of the byte array
|
||||
* @param length the length of the byte array
|
||||
*
|
||||
* @return a {@link ChannelBuffer} with the specified content,
|
||||
* @return a {@link ByteBuf} with the specified content,
|
||||
* whose {@code readerIndex} and {@code writerIndex}
|
||||
* are {@code 0} and {@code (length - offset)} respectively
|
||||
*/
|
||||
ChannelBuffer getBuffer(byte[] array, int offset, int length);
|
||||
ByteBuf getBuffer(byte[] array, int offset, int length);
|
||||
|
||||
/**
|
||||
* Returns a {@link ChannelBuffer} whose content is equal to the sub-region
|
||||
* Returns a {@link ByteBuf} whose content is equal to the sub-region
|
||||
* of the specified {@code array}. Depending on the factory implementation,
|
||||
* the returned buffer could wrap the {@code array} or create a new copy of
|
||||
* the {@code array}.
|
||||
*
|
||||
* @param endianness the endianness of the returned {@link ChannelBuffer}
|
||||
* @param endianness the endianness of the returned {@link ByteBuf}
|
||||
* @param array the byte array
|
||||
* @param offset the offset of the byte array
|
||||
* @param length the length of the byte array
|
||||
*
|
||||
* @return a {@link ChannelBuffer} with the specified content,
|
||||
* @return a {@link ByteBuf} with the specified content,
|
||||
* whose {@code readerIndex} and {@code writerIndex}
|
||||
* are {@code 0} and {@code (length - offset)} respectively
|
||||
*/
|
||||
ChannelBuffer getBuffer(ByteOrder endianness, byte[] array, int offset, int length);
|
||||
ByteBuf getBuffer(ByteOrder endianness, byte[] array, int offset, int length);
|
||||
|
||||
/**
|
||||
* Returns a {@link ChannelBuffer} whose content is equal to the sub-region
|
||||
* Returns a {@link ByteBuf} whose content is equal to the sub-region
|
||||
* of the specified {@code nioBuffer}. Depending on the factory
|
||||
* implementation, the returned buffer could wrap the {@code nioBuffer} or
|
||||
* create a new copy of the {@code nioBuffer}.
|
||||
*
|
||||
* @param nioBuffer the NIO {@link ByteBuffer}
|
||||
*
|
||||
* @return a {@link ChannelBuffer} with the specified content,
|
||||
* @return a {@link ByteBuf} with the specified content,
|
||||
* whose {@code readerIndex} and {@code writerIndex}
|
||||
* are {@code 0} and {@code nioBuffer.remaining()} respectively
|
||||
*/
|
||||
ChannelBuffer getBuffer(ByteBuffer nioBuffer);
|
||||
ByteBuf getBuffer(ByteBuffer nioBuffer);
|
||||
|
||||
/**
|
||||
* Returns the default endianness of the {@link ChannelBuffer} which is
|
||||
* Returns the default endianness of the {@link ByteBuf} which is
|
||||
* returned by {@link #getBuffer(int)}.
|
||||
*
|
||||
* @return the default endianness of the {@link ChannelBuffer} which is
|
||||
* @return the default endianness of the {@link ByteBuf} which is
|
||||
* returned by {@link #getBuffer(int)}
|
||||
*/
|
||||
ByteOrder getDefaultOrder();
|
@ -17,16 +17,16 @@ package io.netty.buffer;
|
||||
|
||||
|
||||
/**
|
||||
* Locates an index of data in a {@link ChannelBuffer}.
|
||||
* Locates an index of data in a {@link ByteBuf}.
|
||||
* <p>
|
||||
* This interface enables the sequential search for the data which meets more
|
||||
* complex and dynamic condition than just a simple value matching. Please
|
||||
* refer to {@link ChannelBuffer#indexOf(int, int, ChannelBufferIndexFinder)} and
|
||||
* {@link ChannelBuffer#bytesBefore(int, int, ChannelBufferIndexFinder)}
|
||||
* refer to {@link ByteBuf#indexOf(int, int, ByteBufIndexFinder)} and
|
||||
* {@link ByteBuf#bytesBefore(int, int, ByteBufIndexFinder)}
|
||||
* for more explanation.
|
||||
* @apiviz.uses io.netty.buffer.ChannelBuffer
|
||||
*/
|
||||
public interface ChannelBufferIndexFinder {
|
||||
public interface ByteBufIndexFinder {
|
||||
|
||||
/**
|
||||
* Returns {@code true} if and only if the data is found at the specified
|
||||
@ -36,14 +36,14 @@ public interface ChannelBufferIndexFinder {
|
||||
* exception such as {@link IndexOutOfBoundsException} nor perform
|
||||
* an operation which modifies the content of the buffer.
|
||||
*/
|
||||
boolean find(ChannelBuffer buffer, int guessedIndex);
|
||||
boolean find(ByteBuf buffer, int guessedIndex);
|
||||
|
||||
/**
|
||||
* Index finder which locates a {@code NUL (0x00)} byte.
|
||||
*/
|
||||
ChannelBufferIndexFinder NUL = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder NUL = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
return buffer.getByte(guessedIndex) == 0;
|
||||
}
|
||||
};
|
||||
@ -51,9 +51,9 @@ public interface ChannelBufferIndexFinder {
|
||||
/**
|
||||
* Index finder which locates a non-{@code NUL (0x00)} byte.
|
||||
*/
|
||||
ChannelBufferIndexFinder NOT_NUL = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder NOT_NUL = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
return buffer.getByte(guessedIndex) != 0;
|
||||
}
|
||||
};
|
||||
@ -61,9 +61,9 @@ public interface ChannelBufferIndexFinder {
|
||||
/**
|
||||
* Index finder which locates a {@code CR ('\r')} byte.
|
||||
*/
|
||||
ChannelBufferIndexFinder CR = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder CR = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
return buffer.getByte(guessedIndex) == '\r';
|
||||
}
|
||||
};
|
||||
@ -71,9 +71,9 @@ public interface ChannelBufferIndexFinder {
|
||||
/**
|
||||
* Index finder which locates a non-{@code CR ('\r')} byte.
|
||||
*/
|
||||
ChannelBufferIndexFinder NOT_CR = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder NOT_CR = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
return buffer.getByte(guessedIndex) != '\r';
|
||||
}
|
||||
};
|
||||
@ -81,9 +81,9 @@ public interface ChannelBufferIndexFinder {
|
||||
/**
|
||||
* Index finder which locates a {@code LF ('\n')} byte.
|
||||
*/
|
||||
ChannelBufferIndexFinder LF = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder LF = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
return buffer.getByte(guessedIndex) == '\n';
|
||||
}
|
||||
};
|
||||
@ -91,9 +91,9 @@ public interface ChannelBufferIndexFinder {
|
||||
/**
|
||||
* Index finder which locates a non-{@code LF ('\n')} byte.
|
||||
*/
|
||||
ChannelBufferIndexFinder NOT_LF = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder NOT_LF = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
return buffer.getByte(guessedIndex) != '\n';
|
||||
}
|
||||
};
|
||||
@ -101,9 +101,9 @@ public interface ChannelBufferIndexFinder {
|
||||
/**
|
||||
* Index finder which locates a {@code CR ('\r')} or {@code LF ('\n')}.
|
||||
*/
|
||||
ChannelBufferIndexFinder CRLF = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder CRLF = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
byte b = buffer.getByte(guessedIndex);
|
||||
return b == '\r' || b == '\n';
|
||||
}
|
||||
@ -113,9 +113,9 @@ public interface ChannelBufferIndexFinder {
|
||||
* Index finder which locates a byte which is neither a {@code CR ('\r')}
|
||||
* nor a {@code LF ('\n')}.
|
||||
*/
|
||||
ChannelBufferIndexFinder NOT_CRLF = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder NOT_CRLF = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
byte b = buffer.getByte(guessedIndex);
|
||||
return b != '\r' && b != '\n';
|
||||
}
|
||||
@ -125,9 +125,9 @@ public interface ChannelBufferIndexFinder {
|
||||
* Index finder which locates a linear whitespace
|
||||
* ({@code ' '} and {@code '\t'}).
|
||||
*/
|
||||
ChannelBufferIndexFinder LINEAR_WHITESPACE = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder LINEAR_WHITESPACE = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
byte b = buffer.getByte(guessedIndex);
|
||||
return b == ' ' || b == '\t';
|
||||
}
|
||||
@ -137,9 +137,9 @@ public interface ChannelBufferIndexFinder {
|
||||
* Index finder which locates a byte which is not a linear whitespace
|
||||
* (neither {@code ' '} nor {@code '\t'}).
|
||||
*/
|
||||
ChannelBufferIndexFinder NOT_LINEAR_WHITESPACE = new ChannelBufferIndexFinder() {
|
||||
ByteBufIndexFinder NOT_LINEAR_WHITESPACE = new ByteBufIndexFinder() {
|
||||
@Override
|
||||
public boolean find(ChannelBuffer buffer, int guessedIndex) {
|
||||
public boolean find(ByteBuf buffer, int guessedIndex) {
|
||||
byte b = buffer.getByte(guessedIndex);
|
||||
return b != ' ' && b != '\t';
|
||||
}
|
@ -22,24 +22,24 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* An {@link InputStream} which reads data from a {@link ChannelBuffer}.
|
||||
* An {@link InputStream} which reads data from a {@link ByteBuf}.
|
||||
* <p>
|
||||
* A read operation against this stream will occur at the {@code readerIndex}
|
||||
* of its underlying buffer and the {@code readerIndex} will increase during
|
||||
* the read operation. Please note that it only reads up to the number of
|
||||
* readable bytes determined at the moment of construction. Therefore,
|
||||
* updating {@link ChannelBuffer#writerIndex()} will not affect the return
|
||||
* updating {@link ByteBuf#writerIndex()} will not affect the return
|
||||
* value of {@link #available()}.
|
||||
* <p>
|
||||
* This stream implements {@link DataInput} for your convenience.
|
||||
* The endianness of the stream is not always big endian but depends on
|
||||
* the endianness of the underlying buffer.
|
||||
* @see ChannelBufferOutputStream
|
||||
* @see ByteBufOutputStream
|
||||
* @apiviz.uses io.netty.buffer.ChannelBuffer
|
||||
*/
|
||||
public class ChannelBufferInputStream extends InputStream implements DataInput {
|
||||
public class ByteBufInputStream extends InputStream implements DataInput {
|
||||
|
||||
private final ChannelBuffer buffer;
|
||||
private final ByteBuf buffer;
|
||||
private final int startIndex;
|
||||
private final int endIndex;
|
||||
|
||||
@ -48,7 +48,7 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
|
||||
* starting at the current {@code readerIndex} and ending at the current
|
||||
* {@code writerIndex}.
|
||||
*/
|
||||
public ChannelBufferInputStream(ChannelBuffer buffer) {
|
||||
public ByteBufInputStream(ByteBuf buffer) {
|
||||
this(buffer, buffer.readableBytes());
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
|
||||
* if {@code readerIndex + length} is greater than
|
||||
* {@code writerIndex}
|
||||
*/
|
||||
public ChannelBufferInputStream(ChannelBuffer buffer, int length) {
|
||||
public ByteBufInputStream(ByteBuf buffer, int length) {
|
||||
if (buffer == null) {
|
||||
throw new NullPointerException("buffer");
|
||||
}
|
@ -21,7 +21,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* An {@link OutputStream} which writes data to a {@link ChannelBuffer}.
|
||||
* An {@link OutputStream} which writes data to a {@link ByteBuf}.
|
||||
* <p>
|
||||
* A write operation against this stream will occur at the {@code writerIndex}
|
||||
* of its underlying buffer and the {@code writerIndex} will increase during
|
||||
@ -30,19 +30,19 @@ import java.io.OutputStream;
|
||||
* This stream implements {@link DataOutput} for your convenience.
|
||||
* The endianness of the stream is not always big endian but depends on
|
||||
* the endianness of the underlying buffer.
|
||||
* @see ChannelBufferInputStream
|
||||
* @see ByteBufInputStream
|
||||
* @apiviz.uses io.netty.buffer.ChannelBuffer
|
||||
*/
|
||||
public class ChannelBufferOutputStream extends OutputStream implements DataOutput {
|
||||
public class ByteBufOutputStream extends OutputStream implements DataOutput {
|
||||
|
||||
private final ChannelBuffer buffer;
|
||||
private final ByteBuf buffer;
|
||||
private final int startIndex;
|
||||
private final DataOutputStream utf8out = new DataOutputStream(this);
|
||||
|
||||
/**
|
||||
* Creates a new stream which writes data to the specified {@code buffer}.
|
||||
*/
|
||||
public ChannelBufferOutputStream(ChannelBuffer buffer) {
|
||||
public ByteBufOutputStream(ByteBuf buffer) {
|
||||
if (buffer == null) {
|
||||
throw new NullPointerException("buffer");
|
||||
}
|
||||
@ -140,7 +140,7 @@ public class ChannelBufferOutputStream extends OutputStream implements DataOutpu
|
||||
/**
|
||||
* Returns the buffer where this stream is writing data.
|
||||
*/
|
||||
public ChannelBuffer buffer() {
|
||||
public ByteBuf buffer() {
|
||||
return buffer;
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new {@link ChannelBuffer} by allocating new space or by wrapping
|
||||
* Creates a new {@link ByteBuf} by allocating new space or by wrapping
|
||||
* or copying existing byte arrays, byte buffers and a string.
|
||||
*
|
||||
* <h3>Use static import</h3>
|
||||
@ -39,11 +39,11 @@ import java.util.List;
|
||||
* <pre>
|
||||
* import static io.netty.buffer.{@link ChannelBuffers}.*;
|
||||
*
|
||||
* {@link ChannelBuffer} heapBuffer = buffer(128);
|
||||
* {@link ChannelBuffer} directBuffer = directBuffer(256);
|
||||
* {@link ChannelBuffer} dynamicBuffer = dynamicBuffer(512);
|
||||
* {@link ChannelBuffer} wrappedBuffer = wrappedBuffer(new byte[128], new byte[256]);
|
||||
* {@link ChannelBuffer} copiedBuffe r = copiedBuffer({@link ByteBuffer}.allocate(128));
|
||||
* {@link ByteBuf} heapBuffer = buffer(128);
|
||||
* {@link ByteBuf} directBuffer = directBuffer(256);
|
||||
* {@link ByteBuf} dynamicBuffer = dynamicBuffer(512);
|
||||
* {@link ByteBuf} wrappedBuffer = wrappedBuffer(new byte[128], new byte[256]);
|
||||
* {@link ByteBuf} copiedBuffe r = copiedBuffer({@link ByteBuffer}.allocate(128));
|
||||
* </pre>
|
||||
*
|
||||
* <h3>Allocating a new buffer</h3>
|
||||
@ -99,7 +99,7 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* A buffer whose capacity is {@code 0}.
|
||||
*/
|
||||
public static final ChannelBuffer EMPTY_BUFFER = new BigEndianHeapChannelBuffer(0);
|
||||
public static final ByteBuf EMPTY_BUFFER = new BigEndianHeapByteBuf(0);
|
||||
|
||||
private static final char[] HEXDUMP_TABLE = new char[256 * 4];
|
||||
|
||||
@ -116,7 +116,7 @@ public final class ChannelBuffers {
|
||||
* {@code capacity}. The new buffer's {@code readerIndex} and
|
||||
* {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer buffer(int capacity) {
|
||||
public static ByteBuf buffer(int capacity) {
|
||||
return buffer(BIG_ENDIAN, capacity);
|
||||
}
|
||||
|
||||
@ -125,17 +125,17 @@ public final class ChannelBuffers {
|
||||
* and {@code capacity}. The new buffer's {@code readerIndex} and
|
||||
* {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer buffer(ByteOrder endianness, int capacity) {
|
||||
public static ByteBuf buffer(ByteOrder endianness, int capacity) {
|
||||
if (endianness == BIG_ENDIAN) {
|
||||
if (capacity == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
return new BigEndianHeapChannelBuffer(capacity);
|
||||
return new BigEndianHeapByteBuf(capacity);
|
||||
} else if (endianness == LITTLE_ENDIAN) {
|
||||
if (capacity == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
return new LittleEndianHeapChannelBuffer(capacity);
|
||||
return new LittleEndianHeapByteBuf(capacity);
|
||||
} else {
|
||||
throw new NullPointerException("endianness");
|
||||
}
|
||||
@ -146,7 +146,7 @@ public final class ChannelBuffers {
|
||||
* {@code capacity}. The new buffer's {@code readerIndex} and
|
||||
* {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer directBuffer(int capacity) {
|
||||
public static ByteBuf directBuffer(int capacity) {
|
||||
return directBuffer(BIG_ENDIAN, capacity);
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ public final class ChannelBuffers {
|
||||
* {@code capacity}. The new buffer's {@code readerIndex} and
|
||||
* {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer directBuffer(ByteOrder endianness, int capacity) {
|
||||
public static ByteBuf directBuffer(ByteOrder endianness, int capacity) {
|
||||
if (endianness == null) {
|
||||
throw new NullPointerException("endianness");
|
||||
}
|
||||
@ -163,7 +163,7 @@ public final class ChannelBuffers {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
|
||||
ChannelBuffer buffer = new ByteBufferBackedChannelBuffer(
|
||||
ByteBuf buffer = new NioBufferBackedByteBuf(
|
||||
ByteBuffer.allocateDirect(capacity).order(endianness));
|
||||
buffer.clear();
|
||||
return buffer;
|
||||
@ -174,16 +174,16 @@ public final class ChannelBuffers {
|
||||
* {@code 256} bytes. The new buffer's {@code readerIndex} and
|
||||
* {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer dynamicBuffer() {
|
||||
public static ByteBuf dynamicBuffer() {
|
||||
return dynamicBuffer(BIG_ENDIAN, 256);
|
||||
}
|
||||
|
||||
public static ChannelBuffer dynamicBuffer(ChannelBufferFactory factory) {
|
||||
public static ByteBuf dynamicBuffer(ByteBufFactory factory) {
|
||||
if (factory == null) {
|
||||
throw new NullPointerException("factory");
|
||||
}
|
||||
|
||||
return new DynamicChannelBuffer(factory.getDefaultOrder(), 256, factory);
|
||||
return new DynamicByteBuf(factory.getDefaultOrder(), 256, factory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,7 +192,7 @@ public final class ChannelBuffers {
|
||||
* reallocation overhead. The new buffer's {@code readerIndex} and
|
||||
* {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer dynamicBuffer(int estimatedLength) {
|
||||
public static ByteBuf dynamicBuffer(int estimatedLength) {
|
||||
return dynamicBuffer(BIG_ENDIAN, estimatedLength);
|
||||
}
|
||||
|
||||
@ -202,8 +202,8 @@ public final class ChannelBuffers {
|
||||
* less unexpected reallocation overhead. The new buffer's
|
||||
* {@code readerIndex} and {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer dynamicBuffer(ByteOrder endianness, int estimatedLength) {
|
||||
return new DynamicChannelBuffer(endianness, estimatedLength);
|
||||
public static ByteBuf dynamicBuffer(ByteOrder endianness, int estimatedLength) {
|
||||
return new DynamicByteBuf(endianness, estimatedLength);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -212,12 +212,12 @@ public final class ChannelBuffers {
|
||||
* less unexpected reallocation overhead. The new buffer's {@code readerIndex}
|
||||
* and {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer dynamicBuffer(int estimatedLength, ChannelBufferFactory factory) {
|
||||
public static ByteBuf dynamicBuffer(int estimatedLength, ByteBufFactory factory) {
|
||||
if (factory == null) {
|
||||
throw new NullPointerException("factory");
|
||||
}
|
||||
|
||||
return new DynamicChannelBuffer(factory.getDefaultOrder(), estimatedLength, factory);
|
||||
return new DynamicByteBuf(factory.getDefaultOrder(), estimatedLength, factory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,9 +226,9 @@ public final class ChannelBuffers {
|
||||
* More accurate estimation yields less unexpected reallocation overhead.
|
||||
* The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer dynamicBuffer(
|
||||
ByteOrder endianness, int estimatedLength, ChannelBufferFactory factory) {
|
||||
return new DynamicChannelBuffer(endianness, estimatedLength, factory);
|
||||
public static ByteBuf dynamicBuffer(
|
||||
ByteOrder endianness, int estimatedLength, ByteBufFactory factory) {
|
||||
return new DynamicByteBuf(endianness, estimatedLength, factory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -236,7 +236,7 @@ public final class ChannelBuffers {
|
||||
* A modification on the specified array's content will be visible to the
|
||||
* returned buffer.
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(byte[] array) {
|
||||
public static ByteBuf wrappedBuffer(byte[] array) {
|
||||
return wrappedBuffer(BIG_ENDIAN, array);
|
||||
}
|
||||
|
||||
@ -245,17 +245,17 @@ public final class ChannelBuffers {
|
||||
* specified {@code endianness}. A modification on the specified array's
|
||||
* content will be visible to the returned buffer.
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array) {
|
||||
public static ByteBuf wrappedBuffer(ByteOrder endianness, byte[] array) {
|
||||
if (endianness == BIG_ENDIAN) {
|
||||
if (array.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
return new BigEndianHeapChannelBuffer(array);
|
||||
return new BigEndianHeapByteBuf(array);
|
||||
} else if (endianness == LITTLE_ENDIAN) {
|
||||
if (array.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
return new LittleEndianHeapChannelBuffer(array);
|
||||
return new LittleEndianHeapByteBuf(array);
|
||||
} else {
|
||||
throw new NullPointerException("endianness");
|
||||
}
|
||||
@ -266,7 +266,7 @@ public final class ChannelBuffers {
|
||||
* specified {@code array}. A modification on the specified array's
|
||||
* content will be visible to the returned buffer.
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(byte[] array, int offset, int length) {
|
||||
public static ByteBuf wrappedBuffer(byte[] array, int offset, int length) {
|
||||
return wrappedBuffer(BIG_ENDIAN, array, offset, length);
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ public final class ChannelBuffers {
|
||||
* {@code array} with the specified {@code endianness}. A modification on
|
||||
* the specified array's content will be visible to the returned buffer.
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
|
||||
public static ByteBuf wrappedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
|
||||
if (endianness == null) {
|
||||
throw new NullPointerException("endianness");
|
||||
}
|
||||
@ -286,14 +286,14 @@ public final class ChannelBuffers {
|
||||
if (length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
} else {
|
||||
return new TruncatedChannelBuffer(wrappedBuffer(endianness, array), length);
|
||||
return new TruncatedByteBuf(wrappedBuffer(endianness, array), length);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
} else {
|
||||
return new SlicedChannelBuffer(wrappedBuffer(endianness, array), offset, length);
|
||||
return new SlicedByteBuf(wrappedBuffer(endianness, array), offset, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -303,7 +303,7 @@ public final class ChannelBuffers {
|
||||
* slice. A modification on the specified buffer's content will be
|
||||
* visible to the returned buffer.
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(ByteBuffer buffer) {
|
||||
public static ByteBuf wrappedBuffer(ByteBuffer buffer) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
@ -314,7 +314,7 @@ public final class ChannelBuffers {
|
||||
buffer.arrayOffset() + buffer.position(),
|
||||
buffer.remaining());
|
||||
} else {
|
||||
return new ByteBufferBackedChannelBuffer(buffer);
|
||||
return new NioBufferBackedByteBuf(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,7 +323,7 @@ public final class ChannelBuffers {
|
||||
* A modification on the specified buffer's content will be visible to the
|
||||
* returned buffer.
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(ChannelBuffer buffer) {
|
||||
public static ByteBuf wrappedBuffer(ByteBuf buffer) {
|
||||
if (buffer.readable()) {
|
||||
return buffer.slice();
|
||||
} else {
|
||||
@ -336,7 +336,7 @@ public final class ChannelBuffers {
|
||||
* arrays without copying them. A modification on the specified arrays'
|
||||
* content will be visible to the returned buffer.
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(byte[]... arrays) {
|
||||
public static ByteBuf wrappedBuffer(byte[]... arrays) {
|
||||
return wrappedBuffer(BIG_ENDIAN, arrays);
|
||||
}
|
||||
|
||||
@ -347,7 +347,7 @@ public final class ChannelBuffers {
|
||||
*
|
||||
* @param endianness the endianness of the new buffer
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(ByteOrder endianness, byte[]... arrays) {
|
||||
public static ByteBuf wrappedBuffer(ByteOrder endianness, byte[]... arrays) {
|
||||
switch (arrays.length) {
|
||||
case 0:
|
||||
break;
|
||||
@ -358,7 +358,7 @@ public final class ChannelBuffers {
|
||||
break;
|
||||
default:
|
||||
// Get the list of the component, while guessing the byte order.
|
||||
final List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(arrays.length);
|
||||
final List<ByteBuf> components = new ArrayList<ByteBuf>(arrays.length);
|
||||
for (byte[] a: arrays) {
|
||||
if (a == null) {
|
||||
break;
|
||||
@ -373,15 +373,15 @@ public final class ChannelBuffers {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
|
||||
private static ChannelBuffer compositeBuffer(
|
||||
ByteOrder endianness, List<ChannelBuffer> components) {
|
||||
private static ByteBuf compositeBuffer(
|
||||
ByteOrder endianness, List<ByteBuf> components) {
|
||||
switch (components.size()) {
|
||||
case 0:
|
||||
return EMPTY_BUFFER;
|
||||
case 1:
|
||||
return components.get(0);
|
||||
default:
|
||||
return new CompositeChannelBuffer(endianness, components);
|
||||
return new CompositeByteBuf(endianness, components);
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,7 +394,7 @@ public final class ChannelBuffers {
|
||||
* if the specified buffers' endianness are different from each
|
||||
* other
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(ChannelBuffer... buffers) {
|
||||
public static ByteBuf wrappedBuffer(ByteBuf... buffers) {
|
||||
switch (buffers.length) {
|
||||
case 0:
|
||||
break;
|
||||
@ -405,8 +405,8 @@ public final class ChannelBuffers {
|
||||
break;
|
||||
default:
|
||||
ByteOrder order = null;
|
||||
final List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(buffers.length);
|
||||
for (ChannelBuffer c: buffers) {
|
||||
final List<ByteBuf> components = new ArrayList<ByteBuf>(buffers.length);
|
||||
for (ByteBuf c: buffers) {
|
||||
if (c == null) {
|
||||
break;
|
||||
}
|
||||
@ -419,10 +419,10 @@ public final class ChannelBuffers {
|
||||
} else {
|
||||
order = c.order();
|
||||
}
|
||||
if (c instanceof CompositeChannelBuffer) {
|
||||
if (c instanceof CompositeByteBuf) {
|
||||
// Expand nested composition.
|
||||
components.addAll(
|
||||
((CompositeChannelBuffer) c).decompose(
|
||||
((CompositeByteBuf) c).decompose(
|
||||
c.readerIndex(), c.readableBytes()));
|
||||
} else {
|
||||
// An ordinary buffer (non-composite)
|
||||
@ -444,7 +444,7 @@ public final class ChannelBuffers {
|
||||
* if the specified buffers' endianness are different from each
|
||||
* other
|
||||
*/
|
||||
public static ChannelBuffer wrappedBuffer(ByteBuffer... buffers) {
|
||||
public static ByteBuf wrappedBuffer(ByteBuffer... buffers) {
|
||||
switch (buffers.length) {
|
||||
case 0:
|
||||
break;
|
||||
@ -455,7 +455,7 @@ public final class ChannelBuffers {
|
||||
break;
|
||||
default:
|
||||
ByteOrder order = null;
|
||||
final List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(buffers.length);
|
||||
final List<ByteBuf> components = new ArrayList<ByteBuf>(buffers.length);
|
||||
for (ByteBuffer b: buffers) {
|
||||
if (b == null) {
|
||||
break;
|
||||
@ -483,7 +483,7 @@ public final class ChannelBuffers {
|
||||
* specified {@code array}. The new buffer's {@code readerIndex} and
|
||||
* {@code writerIndex} are {@code 0} and {@code array.length} respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(byte[] array) {
|
||||
public static ByteBuf copiedBuffer(byte[] array) {
|
||||
return copiedBuffer(BIG_ENDIAN, array);
|
||||
}
|
||||
|
||||
@ -493,17 +493,17 @@ public final class ChannelBuffers {
|
||||
* {@code readerIndex} and {@code writerIndex} are {@code 0} and
|
||||
* {@code array.length} respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array) {
|
||||
public static ByteBuf copiedBuffer(ByteOrder endianness, byte[] array) {
|
||||
if (endianness == BIG_ENDIAN) {
|
||||
if (array.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
return new BigEndianHeapChannelBuffer(array.clone());
|
||||
return new BigEndianHeapByteBuf(array.clone());
|
||||
} else if (endianness == LITTLE_ENDIAN) {
|
||||
if (array.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
return new LittleEndianHeapChannelBuffer(array.clone());
|
||||
return new LittleEndianHeapByteBuf(array.clone());
|
||||
} else {
|
||||
throw new NullPointerException("endianness");
|
||||
}
|
||||
@ -515,7 +515,7 @@ public final class ChannelBuffers {
|
||||
* {@code readerIndex} and {@code writerIndex} are {@code 0} and
|
||||
* the specified {@code length} respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(byte[] array, int offset, int length) {
|
||||
public static ByteBuf copiedBuffer(byte[] array, int offset, int length) {
|
||||
return copiedBuffer(BIG_ENDIAN, array, offset, length);
|
||||
}
|
||||
|
||||
@ -525,7 +525,7 @@ public final class ChannelBuffers {
|
||||
* buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and
|
||||
* the specified {@code length} respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
|
||||
public static ByteBuf copiedBuffer(ByteOrder endianness, byte[] array, int offset, int length) {
|
||||
if (endianness == null) {
|
||||
throw new NullPointerException("endianness");
|
||||
}
|
||||
@ -543,7 +543,7 @@ public final class ChannelBuffers {
|
||||
* and {@code writerIndex} are {@code 0} and {@code buffer.remaining}
|
||||
* respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ByteBuffer buffer) {
|
||||
public static ByteBuf copiedBuffer(ByteBuffer buffer) {
|
||||
int length = buffer.remaining();
|
||||
if (length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
@ -564,7 +564,7 @@ public final class ChannelBuffers {
|
||||
* and {@code writerIndex} are {@code 0} and {@code buffer.readableBytes}
|
||||
* respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ChannelBuffer buffer) {
|
||||
public static ByteBuf copiedBuffer(ByteBuf buffer) {
|
||||
if (buffer.readable()) {
|
||||
return buffer.copy();
|
||||
} else {
|
||||
@ -578,7 +578,7 @@ public final class ChannelBuffers {
|
||||
* and {@code writerIndex} are {@code 0} and the sum of all arrays'
|
||||
* {@code length} respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(byte[]... arrays) {
|
||||
public static ByteBuf copiedBuffer(byte[]... arrays) {
|
||||
return copiedBuffer(BIG_ENDIAN, arrays);
|
||||
}
|
||||
|
||||
@ -588,7 +588,7 @@ public final class ChannelBuffers {
|
||||
* buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}
|
||||
* and the sum of all arrays' {@code length} respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ByteOrder endianness, byte[]... arrays) {
|
||||
public static ByteBuf copiedBuffer(ByteOrder endianness, byte[]... arrays) {
|
||||
switch (arrays.length) {
|
||||
case 0:
|
||||
return EMPTY_BUFFER;
|
||||
@ -634,7 +634,7 @@ public final class ChannelBuffers {
|
||||
* if the specified buffers' endianness are different from each
|
||||
* other
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ChannelBuffer... buffers) {
|
||||
public static ByteBuf copiedBuffer(ByteBuf... buffers) {
|
||||
switch (buffers.length) {
|
||||
case 0:
|
||||
return EMPTY_BUFFER;
|
||||
@ -642,7 +642,7 @@ public final class ChannelBuffers {
|
||||
return copiedBuffer(buffers[0]);
|
||||
}
|
||||
|
||||
ChannelBuffer[] copiedBuffers = new ChannelBuffer[buffers.length];
|
||||
ByteBuf[] copiedBuffers = new ByteBuf[buffers.length];
|
||||
for (int i = 0; i < buffers.length; i ++) {
|
||||
copiedBuffers[i] = copiedBuffer(buffers[i]);
|
||||
}
|
||||
@ -659,7 +659,7 @@ public final class ChannelBuffers {
|
||||
* if the specified buffers' endianness are different from each
|
||||
* other
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ByteBuffer... buffers) {
|
||||
public static ByteBuf copiedBuffer(ByteBuffer... buffers) {
|
||||
switch (buffers.length) {
|
||||
case 0:
|
||||
return EMPTY_BUFFER;
|
||||
@ -667,7 +667,7 @@ public final class ChannelBuffers {
|
||||
return copiedBuffer(buffers[0]);
|
||||
}
|
||||
|
||||
ChannelBuffer[] copiedBuffers = new ChannelBuffer[buffers.length];
|
||||
ByteBuf[] copiedBuffers = new ByteBuf[buffers.length];
|
||||
for (int i = 0; i < buffers.length; i ++) {
|
||||
copiedBuffers[i] = copiedBuffer(buffers[i]);
|
||||
}
|
||||
@ -680,7 +680,7 @@ public final class ChannelBuffers {
|
||||
* The new buffer's {@code readerIndex} and {@code writerIndex} are
|
||||
* {@code 0} and the length of the encoded string respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(CharSequence string, Charset charset) {
|
||||
public static ByteBuf copiedBuffer(CharSequence string, Charset charset) {
|
||||
return copiedBuffer(BIG_ENDIAN, string, charset);
|
||||
}
|
||||
|
||||
@ -690,7 +690,7 @@ public final class ChannelBuffers {
|
||||
* The new buffer's {@code readerIndex} and {@code writerIndex} are
|
||||
* {@code 0} and the length of the encoded string respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(
|
||||
public static ByteBuf copiedBuffer(
|
||||
CharSequence string, int offset, int length, Charset charset) {
|
||||
return copiedBuffer(BIG_ENDIAN, string, offset, length, charset);
|
||||
}
|
||||
@ -702,7 +702,7 @@ public final class ChannelBuffers {
|
||||
* {@code writerIndex} are {@code 0} and the length of the encoded string
|
||||
* respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ByteOrder endianness, CharSequence string, Charset charset) {
|
||||
public static ByteBuf copiedBuffer(ByteOrder endianness, CharSequence string, Charset charset) {
|
||||
if (string == null) {
|
||||
throw new NullPointerException("string");
|
||||
}
|
||||
@ -721,7 +721,7 @@ public final class ChannelBuffers {
|
||||
* {@code writerIndex} are {@code 0} and the length of the encoded string
|
||||
* respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(
|
||||
public static ByteBuf copiedBuffer(
|
||||
ByteOrder endianness, CharSequence string, int offset, int length, Charset charset) {
|
||||
if (string == null) {
|
||||
throw new NullPointerException("string");
|
||||
@ -757,7 +757,7 @@ public final class ChannelBuffers {
|
||||
* The new buffer's {@code readerIndex} and {@code writerIndex} are
|
||||
* {@code 0} and the length of the encoded string respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(char[] array, Charset charset) {
|
||||
public static ByteBuf copiedBuffer(char[] array, Charset charset) {
|
||||
return copiedBuffer(BIG_ENDIAN, array, 0, array.length, charset);
|
||||
}
|
||||
|
||||
@ -767,7 +767,7 @@ public final class ChannelBuffers {
|
||||
* The new buffer's {@code readerIndex} and {@code writerIndex} are
|
||||
* {@code 0} and the length of the encoded string respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(
|
||||
public static ByteBuf copiedBuffer(
|
||||
char[] array, int offset, int length, Charset charset) {
|
||||
return copiedBuffer(BIG_ENDIAN, array, offset, length, charset);
|
||||
}
|
||||
@ -779,7 +779,7 @@ public final class ChannelBuffers {
|
||||
* {@code writerIndex} are {@code 0} and the length of the encoded string
|
||||
* respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(ByteOrder endianness, char[] array, Charset charset) {
|
||||
public static ByteBuf copiedBuffer(ByteOrder endianness, char[] array, Charset charset) {
|
||||
return copiedBuffer(endianness, array, 0, array.length, charset);
|
||||
}
|
||||
|
||||
@ -790,7 +790,7 @@ public final class ChannelBuffers {
|
||||
* {@code writerIndex} are {@code 0} and the length of the encoded string
|
||||
* respectively.
|
||||
*/
|
||||
public static ChannelBuffer copiedBuffer(
|
||||
public static ByteBuf copiedBuffer(
|
||||
ByteOrder endianness, char[] array, int offset, int length, Charset charset) {
|
||||
if (array == null) {
|
||||
throw new NullPointerException("array");
|
||||
@ -802,9 +802,9 @@ public final class ChannelBuffers {
|
||||
endianness, CharBuffer.wrap(array, offset, length), charset);
|
||||
}
|
||||
|
||||
private static ChannelBuffer copiedBuffer(ByteOrder endianness, CharBuffer buffer, Charset charset) {
|
||||
private static ByteBuf copiedBuffer(ByteOrder endianness, CharBuffer buffer, Charset charset) {
|
||||
ByteBuffer dst = ChannelBuffers.encodeString(buffer, charset);
|
||||
ChannelBuffer result = wrappedBuffer(endianness, dst.array());
|
||||
ByteBuf result = wrappedBuffer(endianness, dst.array());
|
||||
result.writerIndex(dst.remaining());
|
||||
return result;
|
||||
}
|
||||
@ -815,30 +815,30 @@ public final class ChannelBuffers {
|
||||
* {@code readerIndex} and {@code writerIndex} with the specified
|
||||
* {@code buffer}.
|
||||
*/
|
||||
public static ChannelBuffer unmodifiableBuffer(ChannelBuffer buffer) {
|
||||
if (buffer instanceof ReadOnlyChannelBuffer) {
|
||||
buffer = ((ReadOnlyChannelBuffer) buffer).unwrap();
|
||||
public static ByteBuf unmodifiableBuffer(ByteBuf buffer) {
|
||||
if (buffer instanceof ReadOnlyByteBuf) {
|
||||
buffer = ((ReadOnlyByteBuf) buffer).unwrap();
|
||||
}
|
||||
return new ReadOnlyChannelBuffer(buffer);
|
||||
return new ReadOnlyByteBuf(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new 4-byte buffer that holds the specified 32-bit integer.
|
||||
*/
|
||||
public static ChannelBuffer copyInt(int value) {
|
||||
ChannelBuffer buf = buffer(4);
|
||||
public static ByteBuf copyInt(int value) {
|
||||
ByteBuf buf = buffer(4);
|
||||
buf.writeInt(value);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link ChannelBuffer} that holds all the given values as int's
|
||||
* Create a {@link ByteBuf} that holds all the given values as int's
|
||||
*/
|
||||
public static ChannelBuffer copyInt(int... values) {
|
||||
public static ByteBuf copyInt(int... values) {
|
||||
if (values == null || values.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buffer = buffer(values.length * 4);
|
||||
ByteBuf buffer = buffer(values.length * 4);
|
||||
for (int v: values) {
|
||||
buffer.writeInt(v);
|
||||
}
|
||||
@ -848,8 +848,8 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Creates a new 2-byte buffer that holds the specified 16-bit integer.
|
||||
*/
|
||||
public static ChannelBuffer copyShort(int value) {
|
||||
ChannelBuffer buf = buffer(2);
|
||||
public static ByteBuf copyShort(int value) {
|
||||
ByteBuf buf = buffer(2);
|
||||
buf.writeShort(value);
|
||||
return buf;
|
||||
}
|
||||
@ -857,11 +857,11 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Create a new buffer that holds a sequence of the specified 16-bit integers.
|
||||
*/
|
||||
public static ChannelBuffer copyShort(short... values) {
|
||||
public static ByteBuf copyShort(short... values) {
|
||||
if (values == null || values.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buffer = buffer(values.length * 2);
|
||||
ByteBuf buffer = buffer(values.length * 2);
|
||||
for (int v: values) {
|
||||
buffer.writeShort(v);
|
||||
}
|
||||
@ -871,11 +871,11 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Create a new buffer that holds a sequence of the specified 16-bit integers.
|
||||
*/
|
||||
public static ChannelBuffer copyShort(int... values) {
|
||||
public static ByteBuf copyShort(int... values) {
|
||||
if (values == null || values.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buffer = buffer(values.length * 2);
|
||||
ByteBuf buffer = buffer(values.length * 2);
|
||||
for (int v: values) {
|
||||
buffer.writeShort(v);
|
||||
}
|
||||
@ -885,8 +885,8 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Creates a new 3-byte buffer that holds the specified 24-bit integer.
|
||||
*/
|
||||
public static ChannelBuffer copyMedium(int value) {
|
||||
ChannelBuffer buf = buffer(3);
|
||||
public static ByteBuf copyMedium(int value) {
|
||||
ByteBuf buf = buffer(3);
|
||||
buf.writeMedium(value);
|
||||
return buf;
|
||||
}
|
||||
@ -894,11 +894,11 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Create a new buffer that holds a sequence of the specified 24-bit integers.
|
||||
*/
|
||||
public static ChannelBuffer copyMedium(int... values) {
|
||||
public static ByteBuf copyMedium(int... values) {
|
||||
if (values == null || values.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buffer = buffer(values.length * 3);
|
||||
ByteBuf buffer = buffer(values.length * 3);
|
||||
for (int v: values) {
|
||||
buffer.writeMedium(v);
|
||||
}
|
||||
@ -908,8 +908,8 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Creates a new 8-byte buffer that holds the specified 64-bit integer.
|
||||
*/
|
||||
public static ChannelBuffer copyLong(long value) {
|
||||
ChannelBuffer buf = buffer(8);
|
||||
public static ByteBuf copyLong(long value) {
|
||||
ByteBuf buf = buffer(8);
|
||||
buf.writeLong(value);
|
||||
return buf;
|
||||
}
|
||||
@ -917,11 +917,11 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Create a new buffer that holds a sequence of the specified 64-bit integers.
|
||||
*/
|
||||
public static ChannelBuffer copyLong(long... values) {
|
||||
public static ByteBuf copyLong(long... values) {
|
||||
if (values == null || values.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buffer = buffer(values.length * 8);
|
||||
ByteBuf buffer = buffer(values.length * 8);
|
||||
for (long v: values) {
|
||||
buffer.writeLong(v);
|
||||
}
|
||||
@ -931,8 +931,8 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Creates a new single-byte buffer that holds the specified boolean value.
|
||||
*/
|
||||
public static ChannelBuffer copyBoolean(boolean value) {
|
||||
ChannelBuffer buf = buffer(1);
|
||||
public static ByteBuf copyBoolean(boolean value) {
|
||||
ByteBuf buf = buffer(1);
|
||||
buf.writeBoolean(value);
|
||||
return buf;
|
||||
}
|
||||
@ -940,11 +940,11 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Create a new buffer that holds a sequence of the specified boolean values.
|
||||
*/
|
||||
public static ChannelBuffer copyBoolean(boolean... values) {
|
||||
public static ByteBuf copyBoolean(boolean... values) {
|
||||
if (values == null || values.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buffer = buffer(values.length);
|
||||
ByteBuf buffer = buffer(values.length);
|
||||
for (boolean v: values) {
|
||||
buffer.writeBoolean(v);
|
||||
}
|
||||
@ -954,8 +954,8 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Creates a new 4-byte buffer that holds the specified 32-bit floating point number.
|
||||
*/
|
||||
public static ChannelBuffer copyFloat(float value) {
|
||||
ChannelBuffer buf = buffer(4);
|
||||
public static ByteBuf copyFloat(float value) {
|
||||
ByteBuf buf = buffer(4);
|
||||
buf.writeFloat(value);
|
||||
return buf;
|
||||
}
|
||||
@ -963,11 +963,11 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Create a new buffer that holds a sequence of the specified 32-bit floating point numbers.
|
||||
*/
|
||||
public static ChannelBuffer copyFloat(float... values) {
|
||||
public static ByteBuf copyFloat(float... values) {
|
||||
if (values == null || values.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buffer = buffer(values.length * 4);
|
||||
ByteBuf buffer = buffer(values.length * 4);
|
||||
for (float v: values) {
|
||||
buffer.writeFloat(v);
|
||||
}
|
||||
@ -977,8 +977,8 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Creates a new 8-byte buffer that holds the specified 64-bit floating point number.
|
||||
*/
|
||||
public static ChannelBuffer copyDouble(double value) {
|
||||
ChannelBuffer buf = buffer(8);
|
||||
public static ByteBuf copyDouble(double value) {
|
||||
ByteBuf buf = buffer(8);
|
||||
buf.writeDouble(value);
|
||||
return buf;
|
||||
}
|
||||
@ -986,11 +986,11 @@ public final class ChannelBuffers {
|
||||
/**
|
||||
* Create a new buffer that holds a sequence of the specified 64-bit floating point numbers.
|
||||
*/
|
||||
public static ChannelBuffer copyDouble(double... values) {
|
||||
public static ByteBuf copyDouble(double... values) {
|
||||
if (values == null || values.length == 0) {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer buffer = buffer(values.length * 8);
|
||||
ByteBuf buffer = buffer(values.length * 8);
|
||||
for (double v: values) {
|
||||
buffer.writeDouble(v);
|
||||
}
|
||||
@ -1001,7 +1001,7 @@ public final class ChannelBuffers {
|
||||
* Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a>
|
||||
* of the specified buffer's readable bytes.
|
||||
*/
|
||||
public static String hexDump(ChannelBuffer buffer) {
|
||||
public static String hexDump(ByteBuf buffer) {
|
||||
return hexDump(buffer, buffer.readerIndex(), buffer.readableBytes());
|
||||
}
|
||||
|
||||
@ -1009,7 +1009,7 @@ public final class ChannelBuffers {
|
||||
* Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a>
|
||||
* of the specified buffer's sub-region.
|
||||
*/
|
||||
public static String hexDump(ChannelBuffer buffer, int fromIndex, int length) {
|
||||
public static String hexDump(ByteBuf buffer, int fromIndex, int length) {
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("length: " + length);
|
||||
}
|
||||
@ -1035,7 +1035,7 @@ public final class ChannelBuffers {
|
||||
* Calculates the hash code of the specified buffer. This method is
|
||||
* useful when implementing a new buffer type.
|
||||
*/
|
||||
public static int hashCode(ChannelBuffer buffer) {
|
||||
public static int hashCode(ByteBuf buffer) {
|
||||
final int aLen = buffer.readableBytes();
|
||||
final int intCount = aLen >>> 2;
|
||||
final int byteCount = aLen & 3;
|
||||
@ -1070,7 +1070,7 @@ public final class ChannelBuffers {
|
||||
* identical to each other as described in {@code ChannelBuffer#equals(Object)}.
|
||||
* This method is useful when implementing a new buffer type.
|
||||
*/
|
||||
public static boolean equals(ChannelBuffer bufferA, ChannelBuffer bufferB) {
|
||||
public static boolean equals(ByteBuf bufferA, ByteBuf bufferB) {
|
||||
final int aLen = bufferA.readableBytes();
|
||||
if (aLen != bufferB.readableBytes()) {
|
||||
return false;
|
||||
@ -1112,10 +1112,10 @@ public final class ChannelBuffers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the two specified buffers as described in {@link ChannelBuffer#compareTo(ChannelBuffer)}.
|
||||
* Compares the two specified buffers as described in {@link ByteBuf#compareTo(ByteBuf)}.
|
||||
* This method is useful when implementing a new buffer type.
|
||||
*/
|
||||
public static int compare(ChannelBuffer bufferA, ChannelBuffer bufferB) {
|
||||
public static int compare(ByteBuf bufferA, ByteBuf bufferB) {
|
||||
final int aLen = bufferA.readableBytes();
|
||||
final int bLen = bufferB.readableBytes();
|
||||
final int minLength = Math.min(aLen, bLen);
|
||||
@ -1167,10 +1167,10 @@ public final class ChannelBuffers {
|
||||
}
|
||||
|
||||
/**
|
||||
* The default implementation of {@link ChannelBuffer#indexOf(int, int, byte)}.
|
||||
* The default implementation of {@link ByteBuf#indexOf(int, int, byte)}.
|
||||
* This method is useful when implementing a new buffer type.
|
||||
*/
|
||||
public static int indexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value) {
|
||||
public static int indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value) {
|
||||
if (fromIndex <= toIndex) {
|
||||
return firstIndexOf(buffer, fromIndex, toIndex, value);
|
||||
} else {
|
||||
@ -1179,10 +1179,10 @@ public final class ChannelBuffers {
|
||||
}
|
||||
|
||||
/**
|
||||
* The default implementation of {@link ChannelBuffer#indexOf(int, int, ChannelBufferIndexFinder)}.
|
||||
* The default implementation of {@link ByteBuf#indexOf(int, int, ByteBufIndexFinder)}.
|
||||
* This method is useful when implementing a new buffer type.
|
||||
*/
|
||||
public static int indexOf(ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
public static int indexOf(ByteBuf buffer, int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
|
||||
if (fromIndex <= toIndex) {
|
||||
return firstIndexOf(buffer, fromIndex, toIndex, indexFinder);
|
||||
} else {
|
||||
@ -1220,7 +1220,7 @@ public final class ChannelBuffers {
|
||||
swapInt((int) (value >>> 32)) & 0xffffffffL;
|
||||
}
|
||||
|
||||
private static int firstIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value) {
|
||||
private static int firstIndexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value) {
|
||||
fromIndex = Math.max(fromIndex, 0);
|
||||
if (fromIndex >= toIndex || buffer.capacity() == 0) {
|
||||
return -1;
|
||||
@ -1235,7 +1235,7 @@ public final class ChannelBuffers {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int lastIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value) {
|
||||
private static int lastIndexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value) {
|
||||
fromIndex = Math.min(fromIndex, buffer.capacity());
|
||||
if (fromIndex < 0 || buffer.capacity() == 0) {
|
||||
return -1;
|
||||
@ -1251,7 +1251,7 @@ public final class ChannelBuffers {
|
||||
}
|
||||
|
||||
private static int firstIndexOf(
|
||||
ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
ByteBuf buffer, int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
|
||||
fromIndex = Math.max(fromIndex, 0);
|
||||
if (fromIndex >= toIndex || buffer.capacity() == 0) {
|
||||
return -1;
|
||||
@ -1267,7 +1267,7 @@ public final class ChannelBuffers {
|
||||
}
|
||||
|
||||
private static int lastIndexOf(
|
||||
ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
ByteBuf buffer, int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
|
||||
fromIndex = Math.min(fromIndex, buffer.capacity());
|
||||
if (fromIndex < 0 || buffer.capacity() == 0) {
|
||||
return -1;
|
||||
|
@ -31,17 +31,17 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* A virtual buffer which shows multiple buffers as a single merged buffer. It
|
||||
* is recommended to use {@link ChannelBuffers#wrappedBuffer(ChannelBuffer...)}
|
||||
* is recommended to use {@link ChannelBuffers#wrappedBuffer(ByteBuf...)}
|
||||
* instead of calling the constructor explicitly.
|
||||
*/
|
||||
public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
public class CompositeByteBuf extends AbstractByteBuf {
|
||||
|
||||
private final ByteOrder order;
|
||||
private ChannelBuffer[] components;
|
||||
private ByteBuf[] components;
|
||||
private int[] indices;
|
||||
private int lastAccessedComponentId;
|
||||
|
||||
public CompositeChannelBuffer(ByteOrder endianness, List<ChannelBuffer> buffers) {
|
||||
public CompositeByteBuf(ByteOrder endianness, List<ByteBuf> buffers) {
|
||||
order = endianness;
|
||||
setComponents(buffers);
|
||||
}
|
||||
@ -49,7 +49,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
/**
|
||||
* Same with {@link #slice(int, int)} except that this method returns a list.
|
||||
*/
|
||||
public List<ChannelBuffer> decompose(int index, int length) {
|
||||
public List<ByteBuf> decompose(int index, int length) {
|
||||
if (length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@ -60,13 +60,13 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
int componentId = componentId(index);
|
||||
List<ChannelBuffer> slice = new ArrayList<ChannelBuffer>(components.length);
|
||||
List<ByteBuf> slice = new ArrayList<ByteBuf>(components.length);
|
||||
|
||||
// The first component
|
||||
ChannelBuffer first = components[componentId].duplicate();
|
||||
ByteBuf first = components[componentId].duplicate();
|
||||
first.readerIndex(index - indices[componentId]);
|
||||
|
||||
ChannelBuffer buf = first;
|
||||
ByteBuf buf = first;
|
||||
int bytesToSlice = length;
|
||||
do {
|
||||
int readableBytes = buf.readableBytes();
|
||||
@ -97,16 +97,16 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
/**
|
||||
* Setup this ChannelBuffer from the list
|
||||
*/
|
||||
private void setComponents(List<ChannelBuffer> newComponents) {
|
||||
private void setComponents(List<ByteBuf> newComponents) {
|
||||
assert !newComponents.isEmpty();
|
||||
|
||||
// Clear the cache.
|
||||
lastAccessedComponentId = 0;
|
||||
|
||||
// Build the component array.
|
||||
components = new ChannelBuffer[newComponents.size()];
|
||||
components = new ByteBuf[newComponents.size()];
|
||||
for (int i = 0; i < components.length; i ++) {
|
||||
ChannelBuffer c = newComponents.get(i);
|
||||
ByteBuf c = newComponents.get(i);
|
||||
if (c.order() != order()) {
|
||||
throw new IllegalArgumentException(
|
||||
"All buffers must have the same endianness.");
|
||||
@ -129,7 +129,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
setIndex(0, capacity());
|
||||
}
|
||||
|
||||
private CompositeChannelBuffer(CompositeChannelBuffer buffer) {
|
||||
private CompositeByteBuf(CompositeByteBuf buffer) {
|
||||
order = buffer.order;
|
||||
components = buffer.components.clone();
|
||||
indices = buffer.indices.clone();
|
||||
@ -137,8 +137,8 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
return HeapChannelBufferFactory.getInstance(order());
|
||||
public ByteBufFactory factory() {
|
||||
return HeapByteBufFactory.getInstance(order());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -236,7 +236,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
int i = componentId;
|
||||
while (length > 0) {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
s.getBytes(index - adjustment, dst, dstIndex, localLength);
|
||||
@ -260,7 +260,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
int i = componentId;
|
||||
try {
|
||||
while (length > 0) {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
dst.limit(dst.position() + localLength);
|
||||
@ -275,7 +275,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
int componentId = componentId(index);
|
||||
if (index > capacity() - length || dstIndex > dst.capacity() - length) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be read - Needs "
|
||||
@ -285,7 +285,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
int i = componentId;
|
||||
while (length > 0) {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
s.getBytes(index - adjustment, dst, dstIndex, localLength);
|
||||
@ -324,7 +324,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
int i = componentId;
|
||||
while (length > 0) {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
s.getBytes(index - adjustment, out, localLength);
|
||||
@ -407,7 +407,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
int i = componentId;
|
||||
while (length > 0) {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
s.setBytes(index - adjustment, src, srcIndex, localLength);
|
||||
@ -431,7 +431,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
int i = componentId;
|
||||
try {
|
||||
while (length > 0) {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
src.limit(src.position() + localLength);
|
||||
@ -446,7 +446,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
int componentId = componentId(index);
|
||||
if (index > capacity() - length || srcIndex > src.capacity() - length) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be written - Needs "
|
||||
@ -456,7 +456,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
int i = componentId;
|
||||
while (length > 0) {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
s.setBytes(index - adjustment, src, srcIndex, localLength);
|
||||
@ -480,7 +480,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
int readBytes = 0;
|
||||
|
||||
do {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
int localReadBytes = s.setBytes(index - adjustment, in, localLength);
|
||||
@ -519,7 +519,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
int i = componentId;
|
||||
int readBytes = 0;
|
||||
do {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
int localReadBytes = s.setBytes(index - adjustment, in, localLength);
|
||||
@ -540,31 +540,31 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
ChannelBuffer duplicate = new CompositeChannelBuffer(this);
|
||||
public ByteBuf duplicate() {
|
||||
ByteBuf duplicate = new CompositeByteBuf(this);
|
||||
duplicate.setIndex(readerIndex(), writerIndex());
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
int componentId = componentId(index);
|
||||
if (index > capacity() - length) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to copy - Needs "
|
||||
+ (index + length) + ", maximum is " + capacity());
|
||||
}
|
||||
|
||||
ChannelBuffer dst = factory().getBuffer(order(), length);
|
||||
ByteBuf dst = factory().getBuffer(order(), length);
|
||||
copyTo(index, length, componentId, dst);
|
||||
return dst;
|
||||
}
|
||||
|
||||
private void copyTo(int index, int length, int componentId, ChannelBuffer dst) {
|
||||
private void copyTo(int index, int length, int componentId, ByteBuf dst) {
|
||||
int dstIndex = 0;
|
||||
int i = componentId;
|
||||
|
||||
while (length > 0) {
|
||||
ChannelBuffer s = components[i];
|
||||
ByteBuf s = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
s.getBytes(index - adjustment, dst, dstIndex, localLength);
|
||||
@ -578,7 +578,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
public ByteBuf slice(int index, int length) {
|
||||
if (index == 0) {
|
||||
if (length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
@ -591,14 +591,14 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
|
||||
List<ChannelBuffer> components = decompose(index, length);
|
||||
List<ByteBuf> components = decompose(index, length);
|
||||
switch (components.size()) {
|
||||
case 0:
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
case 1:
|
||||
return components.get(0);
|
||||
default:
|
||||
return new CompositeChannelBuffer(order(), components);
|
||||
return new CompositeByteBuf(order(), components);
|
||||
}
|
||||
}
|
||||
|
||||
@ -636,7 +636,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
int i = componentId;
|
||||
while (length > 0) {
|
||||
ChannelBuffer c = components[i];
|
||||
ByteBuf c = components[i];
|
||||
int adjustment = indices[i];
|
||||
int localLength = Math.min(length, c.capacity() - (index - adjustment));
|
||||
buffers.add(toNioBuffer(c, index - adjustment, localLength));
|
||||
@ -648,7 +648,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
return buffers.toArray(new ByteBuffer[buffers.size()]);
|
||||
}
|
||||
|
||||
private static ByteBuffer toNioBuffer(ChannelBuffer buf, int index, int length) {
|
||||
private static ByteBuffer toNioBuffer(ByteBuf buf, int index, int length) {
|
||||
if (buf.hasNioBuffer()) {
|
||||
return buf.nioBuffer(index, length);
|
||||
} else {
|
||||
@ -696,7 +696,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
int localWriterIndex = this.writerIndex();
|
||||
|
||||
final int bytesToMove = capacity() - localReaderIndex;
|
||||
List<ChannelBuffer> list = decompose(localReaderIndex, bytesToMove);
|
||||
List<ByteBuf> list = decompose(localReaderIndex, bytesToMove);
|
||||
|
||||
|
||||
// If the list is empty we need to assign a new one because
|
||||
@ -704,13 +704,13 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
//
|
||||
// See https://github.com/netty/netty/issues/325
|
||||
if (list.isEmpty()) {
|
||||
list = new ArrayList<ChannelBuffer>(1);
|
||||
list = new ArrayList<ByteBuf>(1);
|
||||
}
|
||||
|
||||
// Add a new buffer so that the capacity of this composite buffer does
|
||||
// not decrease due to the discarded components.
|
||||
// XXX Might create too many components if discarded by small amount.
|
||||
final ChannelBuffer padding = ChannelBuffers.buffer(order(), localReaderIndex);
|
||||
final ByteBuf padding = ChannelBuffers.buffer(order(), localReaderIndex);
|
||||
padding.writerIndex(localReaderIndex);
|
||||
list.add(padding);
|
||||
|
@ -20,7 +20,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* A {@link ChannelBufferFactory} which pre-allocates a large chunk of direct
|
||||
* A {@link ByteBufFactory} which pre-allocates a large chunk of direct
|
||||
* buffer and returns its slice on demand. Direct buffers are reclaimed via
|
||||
* {@link ReferenceQueue} in most JDK implementations, and therefore they are
|
||||
* deallocated less efficiently than an ordinary heap buffer. Consequently,
|
||||
@ -30,19 +30,19 @@ import java.nio.ByteOrder;
|
||||
* this problem by allocating a large chunk of pre-allocated direct buffer and
|
||||
* reducing the number of the garbage collected internal direct buffer objects.
|
||||
*/
|
||||
public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
public class DirectByteBufFactory extends AbstractByteBufFactory {
|
||||
|
||||
private static final DirectChannelBufferFactory INSTANCE_BE =
|
||||
new DirectChannelBufferFactory(ByteOrder.BIG_ENDIAN);
|
||||
private static final DirectByteBufFactory INSTANCE_BE =
|
||||
new DirectByteBufFactory(ByteOrder.BIG_ENDIAN);
|
||||
|
||||
private static final DirectChannelBufferFactory INSTANCE_LE =
|
||||
new DirectChannelBufferFactory(ByteOrder.LITTLE_ENDIAN);
|
||||
private static final DirectByteBufFactory INSTANCE_LE =
|
||||
new DirectByteBufFactory(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
public static ChannelBufferFactory getInstance() {
|
||||
public static ByteBufFactory getInstance() {
|
||||
return INSTANCE_BE;
|
||||
}
|
||||
|
||||
public static ChannelBufferFactory getInstance(ByteOrder defaultEndianness) {
|
||||
public static ByteBufFactory getInstance(ByteOrder defaultEndianness) {
|
||||
if (defaultEndianness == ByteOrder.BIG_ENDIAN) {
|
||||
return INSTANCE_BE;
|
||||
} else if (defaultEndianness == ByteOrder.LITTLE_ENDIAN) {
|
||||
@ -57,16 +57,16 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
private final Object bigEndianLock = new Object();
|
||||
private final Object littleEndianLock = new Object();
|
||||
private final int preallocatedBufCapacity;
|
||||
private ChannelBuffer preallocatedBEBuf;
|
||||
private ByteBuf preallocatedBEBuf;
|
||||
private int preallocatedBEBufPos;
|
||||
private ChannelBuffer preallocatedLEBuf;
|
||||
private ByteBuf preallocatedLEBuf;
|
||||
private int preallocatedLEBufPos;
|
||||
|
||||
/**
|
||||
* Creates a new factory whose default {@link ByteOrder} is
|
||||
* {@link ByteOrder#BIG_ENDIAN}.
|
||||
*/
|
||||
public DirectChannelBufferFactory() {
|
||||
public DirectByteBufFactory() {
|
||||
this(ByteOrder.BIG_ENDIAN);
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
* Creates a new factory whose default {@link ByteOrder} is
|
||||
* {@link ByteOrder#BIG_ENDIAN}.
|
||||
*/
|
||||
public DirectChannelBufferFactory(int preallocatedBufferCapacity) {
|
||||
public DirectByteBufFactory(int preallocatedBufferCapacity) {
|
||||
this(ByteOrder.BIG_ENDIAN, preallocatedBufferCapacity);
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
*
|
||||
* @param defaultOrder the default {@link ByteOrder} of this factory
|
||||
*/
|
||||
public DirectChannelBufferFactory(ByteOrder defaultOrder) {
|
||||
public DirectByteBufFactory(ByteOrder defaultOrder) {
|
||||
this(defaultOrder, 1048576);
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
*
|
||||
* @param defaultOrder the default {@link ByteOrder} of this factory
|
||||
*/
|
||||
public DirectChannelBufferFactory(ByteOrder defaultOrder, int preallocatedBufferCapacity) {
|
||||
public DirectByteBufFactory(ByteOrder defaultOrder, int preallocatedBufferCapacity) {
|
||||
super(defaultOrder);
|
||||
if (preallocatedBufferCapacity <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
@ -103,7 +103,7 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getBuffer(ByteOrder order, int capacity) {
|
||||
public ByteBuf getBuffer(ByteOrder order, int capacity) {
|
||||
if (order == null) {
|
||||
throw new NullPointerException("order");
|
||||
}
|
||||
@ -117,7 +117,7 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
return ChannelBuffers.directBuffer(order, capacity);
|
||||
}
|
||||
|
||||
ChannelBuffer slice;
|
||||
ByteBuf slice;
|
||||
if (order == ByteOrder.BIG_ENDIAN) {
|
||||
slice = allocateBigEndianBuffer(capacity);
|
||||
} else {
|
||||
@ -128,7 +128,7 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getBuffer(ByteOrder order, byte[] array, int offset, int length) {
|
||||
public ByteBuf getBuffer(ByteOrder order, byte[] array, int offset, int length) {
|
||||
if (array == null) {
|
||||
throw new NullPointerException("array");
|
||||
}
|
||||
@ -142,26 +142,26 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
throw new IndexOutOfBoundsException("length: " + length);
|
||||
}
|
||||
|
||||
ChannelBuffer buf = getBuffer(order, length);
|
||||
ByteBuf buf = getBuffer(order, length);
|
||||
buf.writeBytes(array, offset, length);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getBuffer(ByteBuffer nioBuffer) {
|
||||
public ByteBuf getBuffer(ByteBuffer nioBuffer) {
|
||||
if (!nioBuffer.isReadOnly() && nioBuffer.isDirect()) {
|
||||
return ChannelBuffers.wrappedBuffer(nioBuffer);
|
||||
}
|
||||
|
||||
ChannelBuffer buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
|
||||
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
|
||||
int pos = nioBuffer.position();
|
||||
buf.writeBytes(nioBuffer);
|
||||
nioBuffer.position(pos);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private ChannelBuffer allocateBigEndianBuffer(int capacity) {
|
||||
ChannelBuffer slice;
|
||||
private ByteBuf allocateBigEndianBuffer(int capacity) {
|
||||
ByteBuf slice;
|
||||
synchronized (bigEndianLock) {
|
||||
if (preallocatedBEBuf == null) {
|
||||
preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
||||
@ -179,8 +179,8 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
return slice;
|
||||
}
|
||||
|
||||
private ChannelBuffer allocateLittleEndianBuffer(int capacity) {
|
||||
ChannelBuffer slice;
|
||||
private ByteBuf allocateLittleEndianBuffer(int capacity) {
|
||||
ByteBuf slice;
|
||||
synchronized (littleEndianLock) {
|
||||
if (preallocatedLEBuf == null) {
|
||||
preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
@ -26,14 +26,14 @@ import java.nio.channels.ScatteringByteChannel;
|
||||
|
||||
/**
|
||||
* A derived buffer which simply forwards all data access requests to its
|
||||
* parent. It is recommended to use {@link ChannelBuffer#duplicate()} instead
|
||||
* parent. It is recommended to use {@link ByteBuf#duplicate()} instead
|
||||
* of calling the constructor explicitly.
|
||||
*/
|
||||
public class DuplicatedChannelBuffer extends AbstractChannelBuffer implements WrappedChannelBuffer {
|
||||
public class DuplicatedByteBuf extends AbstractByteBuf implements WrappedByteBuf {
|
||||
|
||||
private final ChannelBuffer buffer;
|
||||
private final ByteBuf buffer;
|
||||
|
||||
public DuplicatedChannelBuffer(ChannelBuffer buffer) {
|
||||
public DuplicatedByteBuf(ByteBuf buffer) {
|
||||
if (buffer == null) {
|
||||
throw new NullPointerException("buffer");
|
||||
}
|
||||
@ -41,18 +41,18 @@ public class DuplicatedChannelBuffer extends AbstractChannelBuffer implements Wr
|
||||
setIndex(buffer.readerIndex(), buffer.writerIndex());
|
||||
}
|
||||
|
||||
private DuplicatedChannelBuffer(DuplicatedChannelBuffer buffer) {
|
||||
private DuplicatedByteBuf(DuplicatedByteBuf buffer) {
|
||||
this.buffer = buffer.buffer;
|
||||
setIndex(buffer.readerIndex(), buffer.writerIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer unwrap() {
|
||||
public ByteBuf unwrap() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
public ByteBufFactory factory() {
|
||||
return buffer.factory();
|
||||
}
|
||||
|
||||
@ -112,22 +112,22 @@ public class DuplicatedChannelBuffer extends AbstractChannelBuffer implements Wr
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
return new DuplicatedChannelBuffer(this);
|
||||
public ByteBuf duplicate() {
|
||||
return new DuplicatedByteBuf(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
return buffer.copy(index, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
public ByteBuf slice(int index, int length) {
|
||||
return buffer.slice(index, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
buffer.getBytes(index, dst, dstIndex, length);
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ public class DuplicatedChannelBuffer extends AbstractChannelBuffer implements Wr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
buffer.setBytes(index, src, srcIndex, length);
|
||||
}
|
||||
|
@ -29,21 +29,21 @@ import java.nio.channels.ScatteringByteChannel;
|
||||
* recommended to use {@link ChannelBuffers#dynamicBuffer(int)} instead of
|
||||
* calling the constructor explicitly.
|
||||
*/
|
||||
public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
||||
public class DynamicByteBuf extends AbstractByteBuf {
|
||||
|
||||
private final ChannelBufferFactory factory;
|
||||
private final ByteBufFactory factory;
|
||||
private final ByteOrder endianness;
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
public DynamicChannelBuffer(int estimatedLength) {
|
||||
public DynamicByteBuf(int estimatedLength) {
|
||||
this(ByteOrder.BIG_ENDIAN, estimatedLength);
|
||||
}
|
||||
|
||||
public DynamicChannelBuffer(ByteOrder endianness, int estimatedLength) {
|
||||
this(endianness, estimatedLength, HeapChannelBufferFactory.getInstance(endianness));
|
||||
public DynamicByteBuf(ByteOrder endianness, int estimatedLength) {
|
||||
this(endianness, estimatedLength, HeapByteBufFactory.getInstance(endianness));
|
||||
}
|
||||
|
||||
public DynamicChannelBuffer(ByteOrder endianness, int estimatedLength, ChannelBufferFactory factory) {
|
||||
public DynamicByteBuf(ByteOrder endianness, int estimatedLength, ByteBufFactory factory) {
|
||||
if (estimatedLength < 0) {
|
||||
throw new IllegalArgumentException("estimatedLength: " + estimatedLength);
|
||||
}
|
||||
@ -82,13 +82,13 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
ChannelBuffer newBuffer = factory().getBuffer(order(), newCapacity);
|
||||
ByteBuf newBuffer = factory().getBuffer(order(), newCapacity);
|
||||
newBuffer.writeBytes(buffer, 0, writerIndex());
|
||||
buffer = newBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
public ByteBufFactory factory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
buffer.getBytes(index, dst, dstIndex, length);
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
buffer.setBytes(index, src, srcIndex, length);
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(ChannelBuffer src, int srcIndex, int length) {
|
||||
public void writeBytes(ByteBuf src, int srcIndex, int length) {
|
||||
ensureWritableBytes(length);
|
||||
super.writeBytes(src, srcIndex, length);
|
||||
}
|
||||
@ -294,30 +294,30 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
return new DuplicatedChannelBuffer(this);
|
||||
public ByteBuf duplicate() {
|
||||
return new DuplicatedByteBuf(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
DynamicChannelBuffer copiedBuffer = new DynamicChannelBuffer(order(), Math.max(length, 64), factory());
|
||||
public ByteBuf copy(int index, int length) {
|
||||
DynamicByteBuf copiedBuffer = new DynamicByteBuf(order(), Math.max(length, 64), factory());
|
||||
copiedBuffer.buffer = buffer.copy(index, length);
|
||||
copiedBuffer.setIndex(0, length);
|
||||
return copiedBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
public ByteBuf slice(int index, int length) {
|
||||
if (index == 0) {
|
||||
if (length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
return new TruncatedChannelBuffer(this, length);
|
||||
return new TruncatedByteBuf(this, length);
|
||||
} else {
|
||||
if (length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
return new SlicedChannelBuffer(this, index, length);
|
||||
return new SlicedByteBuf(this, index, length);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import java.nio.channels.ScatteringByteChannel;
|
||||
/**
|
||||
* A skeletal implementation for Java heap buffers.
|
||||
*/
|
||||
public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
|
||||
public abstract class HeapByteBuf extends AbstractByteBuf {
|
||||
|
||||
/**
|
||||
* The underlying heap byte array that this buffer is wrapping.
|
||||
@ -40,7 +40,7 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
|
||||
*
|
||||
* @param length the length of the new byte array
|
||||
*/
|
||||
public HeapChannelBuffer(int length) {
|
||||
public HeapByteBuf(int length) {
|
||||
this(new byte[length], 0, 0);
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
|
||||
*
|
||||
* @param array the byte array to wrap
|
||||
*/
|
||||
public HeapChannelBuffer(byte[] array) {
|
||||
public HeapByteBuf(byte[] array) {
|
||||
this(array, 0, array.length);
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
|
||||
* @param readerIndex the initial reader index of this buffer
|
||||
* @param writerIndex the initial writer index of this buffer
|
||||
*/
|
||||
protected HeapChannelBuffer(byte[] array, int readerIndex, int writerIndex) {
|
||||
protected HeapByteBuf(byte[] array, int readerIndex, int writerIndex) {
|
||||
if (array == null) {
|
||||
throw new NullPointerException("array");
|
||||
}
|
||||
@ -100,9 +100,9 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
if (dst instanceof HeapChannelBuffer) {
|
||||
getBytes(index, ((HeapChannelBuffer) dst).array, dstIndex, length);
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
if (dst instanceof HeapByteBuf) {
|
||||
getBytes(index, ((HeapByteBuf) dst).array, dstIndex, length);
|
||||
} else {
|
||||
dst.setBytes(dstIndex, array, index, length);
|
||||
}
|
||||
@ -136,9 +136,9 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
if (src instanceof HeapChannelBuffer) {
|
||||
setBytes(index, ((HeapChannelBuffer) src).array, srcIndex, length);
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
if (src instanceof HeapByteBuf) {
|
||||
setBytes(index, ((HeapByteBuf) src).array, srcIndex, length);
|
||||
} else {
|
||||
src.getBytes(srcIndex, array, index, length);
|
||||
}
|
||||
@ -169,23 +169,23 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
public ByteBuf slice(int index, int length) {
|
||||
if (index == 0) {
|
||||
if (length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
if (length == array.length) {
|
||||
ChannelBuffer slice = duplicate();
|
||||
ByteBuf slice = duplicate();
|
||||
slice.setIndex(0, length);
|
||||
return slice;
|
||||
} else {
|
||||
return new TruncatedChannelBuffer(this, length);
|
||||
return new TruncatedByteBuf(this, length);
|
||||
}
|
||||
} else {
|
||||
if (length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
return new SlicedChannelBuffer(this, index, length);
|
||||
return new SlicedByteBuf(this, index, length);
|
||||
}
|
||||
}
|
||||
|
@ -19,24 +19,24 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* A {@link ChannelBufferFactory} which merely allocates a heap buffer with
|
||||
* the specified capacity. {@link HeapChannelBufferFactory} should perform
|
||||
* A {@link ByteBufFactory} which merely allocates a heap buffer with
|
||||
* the specified capacity. {@link HeapByteBufFactory} should perform
|
||||
* very well in most situations because it relies on the JVM garbage collector,
|
||||
* which is highly optimized for heap allocation.
|
||||
*/
|
||||
public class HeapChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
public class HeapByteBufFactory extends AbstractByteBufFactory {
|
||||
|
||||
private static final HeapChannelBufferFactory INSTANCE_BE =
|
||||
new HeapChannelBufferFactory(ByteOrder.BIG_ENDIAN);
|
||||
private static final HeapByteBufFactory INSTANCE_BE =
|
||||
new HeapByteBufFactory(ByteOrder.BIG_ENDIAN);
|
||||
|
||||
private static final HeapChannelBufferFactory INSTANCE_LE =
|
||||
new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN);
|
||||
private static final HeapByteBufFactory INSTANCE_LE =
|
||||
new HeapByteBufFactory(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
public static ChannelBufferFactory getInstance() {
|
||||
public static ByteBufFactory getInstance() {
|
||||
return INSTANCE_BE;
|
||||
}
|
||||
|
||||
public static ChannelBufferFactory getInstance(ByteOrder endianness) {
|
||||
public static ByteBufFactory getInstance(ByteOrder endianness) {
|
||||
if (endianness == ByteOrder.BIG_ENDIAN) {
|
||||
return INSTANCE_BE;
|
||||
} else if (endianness == ByteOrder.LITTLE_ENDIAN) {
|
||||
@ -52,7 +52,7 @@ public class HeapChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
* Creates a new factory whose default {@link ByteOrder} is
|
||||
* {@link ByteOrder#BIG_ENDIAN}.
|
||||
*/
|
||||
public HeapChannelBufferFactory() {
|
||||
public HeapByteBufFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,27 +60,27 @@ public class HeapChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
*
|
||||
* @param defaultOrder the default {@link ByteOrder} of this factory
|
||||
*/
|
||||
public HeapChannelBufferFactory(ByteOrder defaultOrder) {
|
||||
public HeapByteBufFactory(ByteOrder defaultOrder) {
|
||||
super(defaultOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getBuffer(ByteOrder order, int capacity) {
|
||||
public ByteBuf getBuffer(ByteOrder order, int capacity) {
|
||||
return ChannelBuffers.buffer(order, capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getBuffer(ByteBuffer nioBuffer) {
|
||||
public ByteBuf getBuffer(ByteBuffer nioBuffer) {
|
||||
if (nioBuffer.hasArray()) {
|
||||
return ChannelBuffers.wrappedBuffer(nioBuffer);
|
||||
}
|
||||
|
||||
ChannelBuffer buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
|
||||
ByteBuf buf = getBuffer(nioBuffer.order(), nioBuffer.remaining());
|
||||
int pos = nioBuffer.position();
|
||||
buf.writeBytes(nioBuffer);
|
||||
nioBuffer.position(pos);
|
@ -23,14 +23,14 @@ import java.nio.ByteOrder;
|
||||
* and {@link ChannelBuffers#wrappedBuffer(ByteOrder, byte[])} instead of
|
||||
* calling the constructor explicitly.
|
||||
*/
|
||||
public class LittleEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
public class LittleEndianHeapByteBuf extends HeapByteBuf {
|
||||
|
||||
/**
|
||||
* Creates a new little-endian heap buffer with a newly allocated byte array.
|
||||
*
|
||||
* @param length the length of the new byte array
|
||||
*/
|
||||
public LittleEndianHeapChannelBuffer(int length) {
|
||||
public LittleEndianHeapByteBuf(int length) {
|
||||
super(length);
|
||||
}
|
||||
|
||||
@ -39,17 +39,17 @@ public class LittleEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
*
|
||||
* @param array the byte array to wrap
|
||||
*/
|
||||
public LittleEndianHeapChannelBuffer(byte[] array) {
|
||||
public LittleEndianHeapByteBuf(byte[] array) {
|
||||
super(array);
|
||||
}
|
||||
|
||||
private LittleEndianHeapChannelBuffer(byte[] array, int readerIndex, int writerIndex) {
|
||||
private LittleEndianHeapByteBuf(byte[] array, int readerIndex, int writerIndex) {
|
||||
super(array, readerIndex, writerIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
return HeapChannelBufferFactory.getInstance(ByteOrder.LITTLE_ENDIAN);
|
||||
public ByteBufFactory factory() {
|
||||
return HeapByteBufFactory.getInstance(ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -123,12 +123,12 @@ public class LittleEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
return new LittleEndianHeapChannelBuffer(array, readerIndex(), writerIndex());
|
||||
public ByteBuf duplicate() {
|
||||
return new LittleEndianHeapByteBuf(array, readerIndex(), writerIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
if (index < 0 || length < 0 || index + length > array.length) {
|
||||
throw new IndexOutOfBoundsException("Copy could not be completed. Bytes needed: "
|
||||
+ (index + length) + ", maximum: " + array.length);
|
||||
@ -136,6 +136,6 @@ public class LittleEndianHeapChannelBuffer extends HeapChannelBuffer {
|
||||
|
||||
byte[] copiedArray = new byte[length];
|
||||
System.arraycopy(array, index, copiedArray, 0, length);
|
||||
return new LittleEndianHeapChannelBuffer(copiedArray);
|
||||
return new LittleEndianHeapByteBuf(copiedArray);
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ import java.nio.channels.ScatteringByteChannel;
|
||||
* and {@link ChannelBuffers#wrappedBuffer(ByteBuffer)} instead of calling the
|
||||
* constructor explicitly.
|
||||
*/
|
||||
public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
public class NioBufferBackedByteBuf extends AbstractByteBuf {
|
||||
|
||||
private final ByteBuffer buffer;
|
||||
private final ByteBuffer tmpBuf;
|
||||
@ -39,7 +39,7 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
/**
|
||||
* Creates a new buffer which wraps the specified buffer's slice.
|
||||
*/
|
||||
public ByteBufferBackedChannelBuffer(ByteBuffer buffer) {
|
||||
public NioBufferBackedByteBuf(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
throw new NullPointerException("buffer");
|
||||
}
|
||||
@ -51,7 +51,7 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
writerIndex(capacity);
|
||||
}
|
||||
|
||||
private ByteBufferBackedChannelBuffer(ByteBufferBackedChannelBuffer buffer) {
|
||||
private NioBufferBackedByteBuf(NioBufferBackedByteBuf buffer) {
|
||||
this.buffer = buffer.buffer;
|
||||
tmpBuf = this.buffer.duplicate();
|
||||
order = buffer.order;
|
||||
@ -60,11 +60,11 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
public ByteBufFactory factory() {
|
||||
if (buffer.isDirect()) {
|
||||
return DirectChannelBufferFactory.getInstance(order());
|
||||
return DirectByteBufFactory.getInstance(order());
|
||||
} else {
|
||||
return HeapChannelBufferFactory.getInstance(order());
|
||||
return HeapByteBufFactory.getInstance(order());
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,9 +126,9 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
if (dst instanceof ByteBufferBackedChannelBuffer) {
|
||||
ByteBufferBackedChannelBuffer bbdst = (ByteBufferBackedChannelBuffer) dst;
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
if (dst instanceof NioBufferBackedByteBuf) {
|
||||
NioBufferBackedByteBuf bbdst = (NioBufferBackedByteBuf) dst;
|
||||
ByteBuffer data = bbdst.tmpBuf;
|
||||
data.clear().position(dstIndex).limit(dstIndex + length);
|
||||
getBytes(index, data);
|
||||
@ -190,9 +190,9 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
if (src instanceof ByteBufferBackedChannelBuffer) {
|
||||
ByteBufferBackedChannelBuffer bbsrc = (ByteBufferBackedChannelBuffer) src;
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
if (src instanceof NioBufferBackedByteBuf) {
|
||||
NioBufferBackedByteBuf bbsrc = (NioBufferBackedByteBuf) src;
|
||||
ByteBuffer data = bbsrc.tmpBuf;
|
||||
|
||||
data.clear().position(srcIndex).limit(srcIndex + length);
|
||||
@ -292,28 +292,28 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
public ByteBuf slice(int index, int length) {
|
||||
if (index == 0 && length == capacity()) {
|
||||
ChannelBuffer slice = duplicate();
|
||||
ByteBuf slice = duplicate();
|
||||
slice.setIndex(0, length);
|
||||
return slice;
|
||||
} else {
|
||||
if (index >= 0 && length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
return new ByteBufferBackedChannelBuffer(
|
||||
return new NioBufferBackedByteBuf(
|
||||
((ByteBuffer) tmpBuf.clear().position(
|
||||
index).limit(index + length)).order(order()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
return new ByteBufferBackedChannelBuffer(this);
|
||||
public ByteBuf duplicate() {
|
||||
return new NioBufferBackedByteBuf(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
ByteBuffer src;
|
||||
try {
|
||||
src = (ByteBuffer) tmpBuf.clear().position(index).limit(index + length);
|
||||
@ -326,6 +326,6 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
|
||||
dst.put(src);
|
||||
dst.order(order());
|
||||
dst.clear();
|
||||
return new ByteBufferBackedChannelBuffer(dst);
|
||||
return new NioBufferBackedByteBuf(dst);
|
||||
}
|
||||
}
|
@ -26,14 +26,14 @@ import java.nio.channels.ScatteringByteChannel;
|
||||
|
||||
/**
|
||||
* A derived buffer which forbids any write requests to its parent. It is
|
||||
* recommended to use {@link ChannelBuffers#unmodifiableBuffer(ChannelBuffer)}
|
||||
* recommended to use {@link ChannelBuffers#unmodifiableBuffer(ByteBuf)}
|
||||
* instead of calling the constructor explicitly.
|
||||
*/
|
||||
public class ReadOnlyChannelBuffer extends AbstractChannelBuffer implements WrappedChannelBuffer {
|
||||
public class ReadOnlyByteBuf extends AbstractByteBuf implements WrappedByteBuf {
|
||||
|
||||
private final ChannelBuffer buffer;
|
||||
private final ByteBuf buffer;
|
||||
|
||||
public ReadOnlyChannelBuffer(ChannelBuffer buffer) {
|
||||
public ReadOnlyByteBuf(ByteBuf buffer) {
|
||||
if (buffer == null) {
|
||||
throw new NullPointerException("buffer");
|
||||
}
|
||||
@ -41,18 +41,18 @@ public class ReadOnlyChannelBuffer extends AbstractChannelBuffer implements Wrap
|
||||
setIndex(buffer.readerIndex(), buffer.writerIndex());
|
||||
}
|
||||
|
||||
private ReadOnlyChannelBuffer(ReadOnlyChannelBuffer buffer) {
|
||||
private ReadOnlyByteBuf(ReadOnlyByteBuf buffer) {
|
||||
this.buffer = buffer.buffer;
|
||||
setIndex(buffer.readerIndex(), buffer.writerIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer unwrap() {
|
||||
public ByteBuf unwrap() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
public ByteBufFactory factory() {
|
||||
return buffer.factory();
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public class ReadOnlyChannelBuffer extends AbstractChannelBuffer implements Wrap
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
throw new ReadOnlyBufferException();
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ public class ReadOnlyChannelBuffer extends AbstractChannelBuffer implements Wrap
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
buffer.getBytes(index, dst, dstIndex, length);
|
||||
}
|
||||
|
||||
@ -166,18 +166,18 @@ public class ReadOnlyChannelBuffer extends AbstractChannelBuffer implements Wrap
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
return new ReadOnlyChannelBuffer(this);
|
||||
public ByteBuf duplicate() {
|
||||
return new ReadOnlyByteBuf(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
return buffer.copy(index, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
return new ReadOnlyChannelBuffer(buffer.slice(index, length));
|
||||
public ByteBuf slice(int index, int length) {
|
||||
return new ReadOnlyByteBuf(buffer.slice(index, length));
|
||||
}
|
||||
|
||||
@Override
|
@ -26,17 +26,17 @@ import java.nio.channels.ScatteringByteChannel;
|
||||
|
||||
/**
|
||||
* A derived buffer which exposes its parent's sub-region only. It is
|
||||
* recommended to use {@link ChannelBuffer#slice()} and
|
||||
* {@link ChannelBuffer#slice(int, int)} instead of calling the constructor
|
||||
* recommended to use {@link ByteBuf#slice()} and
|
||||
* {@link ByteBuf#slice(int, int)} instead of calling the constructor
|
||||
* explicitly.
|
||||
*/
|
||||
public class SlicedChannelBuffer extends AbstractChannelBuffer implements WrappedChannelBuffer {
|
||||
public class SlicedByteBuf extends AbstractByteBuf implements WrappedByteBuf {
|
||||
|
||||
private final ChannelBuffer buffer;
|
||||
private final ByteBuf buffer;
|
||||
private final int adjustment;
|
||||
private final int length;
|
||||
|
||||
public SlicedChannelBuffer(ChannelBuffer buffer, int index, int length) {
|
||||
public SlicedByteBuf(ByteBuf buffer, int index, int length) {
|
||||
if (index < 0 || index > buffer.capacity()) {
|
||||
throw new IndexOutOfBoundsException("Invalid index of " + index
|
||||
+ ", maximum is " + buffer.capacity());
|
||||
@ -54,12 +54,12 @@ public class SlicedChannelBuffer extends AbstractChannelBuffer implements Wrappe
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer unwrap() {
|
||||
public ByteBuf unwrap() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
public ByteBufFactory factory() {
|
||||
return buffer.factory();
|
||||
}
|
||||
|
||||
@ -124,29 +124,29 @@ public class SlicedChannelBuffer extends AbstractChannelBuffer implements Wrappe
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
ChannelBuffer duplicate = new SlicedChannelBuffer(buffer, adjustment, length);
|
||||
public ByteBuf duplicate() {
|
||||
ByteBuf duplicate = new SlicedByteBuf(buffer, adjustment, length);
|
||||
duplicate.setIndex(readerIndex(), writerIndex());
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
checkIndex(index, length);
|
||||
return buffer.copy(index + adjustment, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
public ByteBuf slice(int index, int length) {
|
||||
checkIndex(index, length);
|
||||
if (length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
return new SlicedChannelBuffer(buffer, index + adjustment, length);
|
||||
return new SlicedByteBuf(buffer, index + adjustment, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
checkIndex(index, length);
|
||||
buffer.getBytes(index + adjustment, dst, dstIndex, length);
|
||||
}
|
||||
@ -200,7 +200,7 @@ public class SlicedChannelBuffer extends AbstractChannelBuffer implements Wrappe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
checkIndex(index, length);
|
||||
buffer.setBytes(index + adjustment, src, srcIndex, length);
|
||||
}
|
@ -26,16 +26,16 @@ import java.nio.channels.ScatteringByteChannel;
|
||||
|
||||
/**
|
||||
* A derived buffer which hides its parent's tail data beyond a certain index.
|
||||
* It is recommended to use {@link ChannelBuffer#slice()} and
|
||||
* {@link ChannelBuffer#slice(int, int)} instead of calling the constructor
|
||||
* It is recommended to use {@link ByteBuf#slice()} and
|
||||
* {@link ByteBuf#slice(int, int)} instead of calling the constructor
|
||||
* explicitly.
|
||||
*/
|
||||
public class TruncatedChannelBuffer extends AbstractChannelBuffer implements WrappedChannelBuffer {
|
||||
public class TruncatedByteBuf extends AbstractByteBuf implements WrappedByteBuf {
|
||||
|
||||
private final ChannelBuffer buffer;
|
||||
private final ByteBuf buffer;
|
||||
private final int length;
|
||||
|
||||
public TruncatedChannelBuffer(ChannelBuffer buffer, int length) {
|
||||
public TruncatedByteBuf(ByteBuf buffer, int length) {
|
||||
if (length > buffer.capacity()) {
|
||||
throw new IndexOutOfBoundsException("Length is too large, got "
|
||||
+ length + " but can't go higher than " + buffer.capacity());
|
||||
@ -47,12 +47,12 @@ public class TruncatedChannelBuffer extends AbstractChannelBuffer implements Wra
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer unwrap() {
|
||||
public ByteBuf unwrap() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
public ByteBufFactory factory() {
|
||||
return buffer.factory();
|
||||
}
|
||||
|
||||
@ -117,20 +117,20 @@ public class TruncatedChannelBuffer extends AbstractChannelBuffer implements Wra
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
ChannelBuffer duplicate = new TruncatedChannelBuffer(buffer, length);
|
||||
public ByteBuf duplicate() {
|
||||
ByteBuf duplicate = new TruncatedByteBuf(buffer, length);
|
||||
duplicate.setIndex(readerIndex(), writerIndex());
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
checkIndex(index, length);
|
||||
return buffer.copy(index, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
public ByteBuf slice(int index, int length) {
|
||||
checkIndex(index, length);
|
||||
if (length == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
@ -139,7 +139,7 @@ public class TruncatedChannelBuffer extends AbstractChannelBuffer implements Wra
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
checkIndex(index, length);
|
||||
buffer.getBytes(index, dst, dstIndex, length);
|
||||
}
|
||||
@ -193,7 +193,7 @@ public class TruncatedChannelBuffer extends AbstractChannelBuffer implements Wra
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
checkIndex(index, length);
|
||||
buffer.setBytes(index, src, srcIndex, length);
|
||||
}
|
@ -19,9 +19,9 @@ package io.netty.buffer;
|
||||
* The common interface for buffer wrappers and derived buffers. Most users won't
|
||||
* need to use this interface. It is used internally in most cases.
|
||||
*/
|
||||
public interface WrappedChannelBuffer extends ChannelBuffer {
|
||||
public interface WrappedByteBuf extends ByteBuf {
|
||||
/**
|
||||
* Returns this buffer's parent that this buffer is wrapping.
|
||||
*/
|
||||
ChannelBuffer unwrap();
|
||||
ByteBuf unwrap();
|
||||
}
|
@ -21,7 +21,7 @@
|
||||
* Netty uses its own buffer API instead of NIO {@link java.nio.ByteBuffer} to
|
||||
* represent a sequence of bytes. This approach has significant advantage over
|
||||
* using {@link java.nio.ByteBuffer}. Netty's new buffer type,
|
||||
* {@link io.netty.buffer.ChannelBuffer}, has been designed from ground
|
||||
* {@link io.netty.buffer.ByteBuf}, has been designed from ground
|
||||
* up to address the problems of {@link java.nio.ByteBuffer} and to meet the
|
||||
* daily needs of network application developers. To list a few cool features:
|
||||
* <ul>
|
||||
@ -35,13 +35,13 @@
|
||||
*
|
||||
* <h3>Extensibility</h3>
|
||||
*
|
||||
* {@link io.netty.buffer.ChannelBuffer} has rich set of operations
|
||||
* {@link io.netty.buffer.ByteBuf} has rich set of operations
|
||||
* optimized for rapid protocol implementation. For example,
|
||||
* {@link io.netty.buffer.ChannelBuffer} provides various operations
|
||||
* {@link io.netty.buffer.ByteBuf} provides various operations
|
||||
* for accessing unsigned values and strings and searching for certain byte
|
||||
* sequence in a buffer. You can also extend or wrap existing buffer type
|
||||
* to add convenient accessors. The custom buffer type still implements
|
||||
* {@link io.netty.buffer.ChannelBuffer} interface rather than
|
||||
* {@link io.netty.buffer.ByteBuf} interface rather than
|
||||
* introducing an incompatible type.
|
||||
*
|
||||
* <h3>Transparent Zero Copy</h3>
|
||||
@ -70,7 +70,7 @@
|
||||
* // The composite type is incompatible with the component type.
|
||||
* ByteBuffer[] message = new ByteBuffer[] { header, body };
|
||||
* </pre>
|
||||
* By contrast, {@link io.netty.buffer.ChannelBuffer} does not have such
|
||||
* By contrast, {@link io.netty.buffer.ByteBuf} does not have such
|
||||
* caveats because it is fully extensible and has a built-in composite buffer
|
||||
* type.
|
||||
* <pre>
|
||||
@ -120,7 +120,7 @@
|
||||
* <h3>Better Performance</h3>
|
||||
*
|
||||
* Most frequently used buffer implementation of
|
||||
* {@link io.netty.buffer.ChannelBuffer} is a very thin wrapper of a
|
||||
* {@link io.netty.buffer.ByteBuf} is a very thin wrapper of a
|
||||
* byte array (i.e. {@code byte[]}). Unlike {@link java.nio.ByteBuffer}, it has
|
||||
* no complicated boundary check and index compensation, and therefore it is
|
||||
* easier for a JVM to optimize the buffer access. More complicated buffer
|
||||
|
@ -42,10 +42,10 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
private long seed;
|
||||
private Random random;
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
protected abstract ChannelBuffer newBuffer(int capacity);
|
||||
protected abstract ChannelBuffer[] components();
|
||||
protected abstract ByteBuf newBuffer(int capacity);
|
||||
protected abstract ByteBuf[] components();
|
||||
|
||||
protected boolean discardReadBytesDoesNotMoveWritableBytes() {
|
||||
return true;
|
||||
@ -763,7 +763,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
buffer.getBytes(i, value);
|
||||
@ -783,7 +783,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
int valueOffset = random.nextInt(BLOCK_SIZE);
|
||||
@ -797,7 +797,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testRandomHeapBufferTransfer1() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE];
|
||||
ChannelBuffer value = wrappedBuffer(valueContent);
|
||||
ByteBuf value = wrappedBuffer(valueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(valueContent);
|
||||
value.setIndex(0, BLOCK_SIZE);
|
||||
@ -808,7 +808,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
value.clear();
|
||||
@ -824,7 +824,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testRandomHeapBufferTransfer2() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer value = wrappedBuffer(valueContent);
|
||||
ByteBuf value = wrappedBuffer(valueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(valueContent);
|
||||
buffer.setBytes(i, value, random.nextInt(BLOCK_SIZE), BLOCK_SIZE);
|
||||
@ -832,7 +832,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
int valueOffset = random.nextInt(BLOCK_SIZE);
|
||||
@ -846,7 +846,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testRandomDirectBufferTransfer() {
|
||||
byte[] tmp = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer value = directBuffer(BLOCK_SIZE * 2);
|
||||
ByteBuf value = directBuffer(BLOCK_SIZE * 2);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(tmp);
|
||||
value.setBytes(0, tmp, 0, value.capacity());
|
||||
@ -854,7 +854,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
}
|
||||
|
||||
random.setSeed(seed);
|
||||
ChannelBuffer expectedValue = directBuffer(BLOCK_SIZE * 2);
|
||||
ByteBuf expectedValue = directBuffer(BLOCK_SIZE * 2);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(tmp);
|
||||
expectedValue.setBytes(0, tmp, 0, expectedValue.capacity());
|
||||
@ -943,7 +943,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testSequentialHeapBufferTransfer1() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer value = wrappedBuffer(valueContent);
|
||||
ByteBuf value = wrappedBuffer(valueContent);
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(valueContent);
|
||||
@ -956,7 +956,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
int valueOffset = random.nextInt(BLOCK_SIZE);
|
||||
@ -974,7 +974,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testSequentialHeapBufferTransfer2() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer value = wrappedBuffer(valueContent);
|
||||
ByteBuf value = wrappedBuffer(valueContent);
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(valueContent);
|
||||
@ -990,7 +990,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
int valueOffset = random.nextInt(BLOCK_SIZE);
|
||||
@ -1010,7 +1010,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testSequentialDirectBufferTransfer1() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer value = directBuffer(BLOCK_SIZE * 2);
|
||||
ByteBuf value = directBuffer(BLOCK_SIZE * 2);
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(valueContent);
|
||||
@ -1024,7 +1024,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
int valueOffset = random.nextInt(BLOCK_SIZE);
|
||||
@ -1043,7 +1043,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testSequentialDirectBufferTransfer2() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer value = directBuffer(BLOCK_SIZE * 2);
|
||||
ByteBuf value = directBuffer(BLOCK_SIZE * 2);
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(valueContent);
|
||||
@ -1061,7 +1061,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
value.setBytes(0, valueContent);
|
||||
@ -1082,7 +1082,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testSequentialByteBufferBackedHeapBufferTransfer1() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
|
||||
ByteBuf value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
|
||||
value.writerIndex(0);
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
@ -1097,7 +1097,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
int valueOffset = random.nextInt(BLOCK_SIZE);
|
||||
@ -1116,7 +1116,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
@Test
|
||||
public void testSequentialByteBufferBackedHeapBufferTransfer2() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
|
||||
ByteBuf value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
|
||||
value.writerIndex(0);
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
@ -1135,7 +1135,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
value.setBytes(0, valueContent);
|
||||
@ -1195,7 +1195,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
random.nextBytes(expectedValue);
|
||||
assertEquals(i, buffer.readerIndex());
|
||||
assertEquals(CAPACITY, buffer.writerIndex());
|
||||
ChannelBuffer actualValue = buffer.readBytes(BLOCK_SIZE);
|
||||
ByteBuf actualValue = buffer.readBytes(BLOCK_SIZE);
|
||||
assertEquals(wrappedBuffer(expectedValue), actualValue);
|
||||
|
||||
// Make sure if it is a copied buffer.
|
||||
@ -1221,7 +1221,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
random.nextBytes(expectedValue);
|
||||
assertEquals(i, buffer.readerIndex());
|
||||
assertEquals(CAPACITY, buffer.writerIndex());
|
||||
ChannelBuffer actualValue = buffer.readSlice(BLOCK_SIZE);
|
||||
ByteBuf actualValue = buffer.readSlice(BLOCK_SIZE);
|
||||
assertEquals(wrappedBuffer(expectedValue), actualValue);
|
||||
|
||||
// Make sure if it is a sliced buffer.
|
||||
@ -1265,7 +1265,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
for (int i = 0; i < buffer.capacity(); i += 4) {
|
||||
buffer.writeInt(i);
|
||||
}
|
||||
ChannelBuffer copy = copiedBuffer(buffer);
|
||||
ByteBuf copy = copiedBuffer(buffer);
|
||||
|
||||
// Make sure there's no effect if called when readerIndex is 0.
|
||||
buffer.readerIndex(CAPACITY / 4);
|
||||
@ -1317,7 +1317,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
for (int i = 0; i < buffer.capacity(); i ++) {
|
||||
buffer.writeByte((byte) i);
|
||||
}
|
||||
ChannelBuffer copy = copiedBuffer(buffer);
|
||||
ByteBuf copy = copiedBuffer(buffer);
|
||||
|
||||
// Discard the first (CAPACITY / 2 - 1) bytes.
|
||||
buffer.setIndex(CAPACITY / 2 - 1, CAPACITY - 1);
|
||||
@ -1383,7 +1383,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
buffer.setIndex(readerIndex, writerIndex);
|
||||
|
||||
// Make sure all properties are copied.
|
||||
ChannelBuffer copy = buffer.copy();
|
||||
ByteBuf copy = buffer.copy();
|
||||
assertEquals(0, copy.readerIndex());
|
||||
assertEquals(buffer.readableBytes(), copy.writerIndex());
|
||||
assertEquals(buffer.readableBytes(), copy.capacity());
|
||||
@ -1411,7 +1411,7 @@ public abstract class AbstractChannelBufferTest {
|
||||
buffer.setIndex(readerIndex, writerIndex);
|
||||
|
||||
// Make sure all properties are copied.
|
||||
ChannelBuffer duplicate = buffer.duplicate();
|
||||
ByteBuf duplicate = buffer.duplicate();
|
||||
assertEquals(buffer.readerIndex(), duplicate.readerIndex());
|
||||
assertEquals(buffer.writerIndex(), duplicate.writerIndex());
|
||||
assertEquals(buffer.capacity(), duplicate.capacity());
|
||||
@ -1581,12 +1581,12 @@ public abstract class AbstractChannelBufferTest {
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
ChannelBuffer elemA = buffer(15);
|
||||
ChannelBuffer elemB = directBuffer(15);
|
||||
ByteBuf elemA = buffer(15);
|
||||
ByteBuf elemB = directBuffer(15);
|
||||
elemA.writeBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 });
|
||||
elemB.writeBytes(new byte[] { 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9 });
|
||||
|
||||
Set<ChannelBuffer> set = new HashSet<ChannelBuffer>();
|
||||
Set<ByteBuf> set = new HashSet<ByteBuf>();
|
||||
set.add(elemA);
|
||||
set.add(elemB);
|
||||
|
||||
|
@ -40,12 +40,12 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
private List<ChannelBuffer> buffers;
|
||||
private ChannelBuffer buffer;
|
||||
private List<ByteBuf> buffers;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
buffers = new ArrayList<ChannelBuffer>();
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffers = new ArrayList<ByteBuf>();
|
||||
for (int i = 0; i < length; i += 10) {
|
||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
||||
buffers.add(ChannelBuffers.wrappedBuffer(order, new byte[1]));
|
||||
@ -68,7 +68,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
buffers.add(ChannelBuffers.EMPTY_BUFFER);
|
||||
}
|
||||
|
||||
buffer = ChannelBuffers.wrappedBuffer(buffers.toArray(new ChannelBuffer[buffers.size()]));
|
||||
buffer = ChannelBuffers.wrappedBuffer(buffers.toArray(new ByteBuf[buffers.size()]));
|
||||
buffer.writerIndex(length);
|
||||
buffer = ChannelBuffers.wrappedBuffer(buffer);
|
||||
assertEquals(length, buffer.capacity());
|
||||
@ -79,8 +79,8 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return buffers.toArray(new ChannelBuffer[buffers.size()]);
|
||||
protected ByteBuf[] components() {
|
||||
return buffers.toArray(new ByteBuf[buffers.size()]);
|
||||
}
|
||||
|
||||
// Composite buffer does not waste bandwidth on discardReadBytes, but
|
||||
@ -92,7 +92,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
|
||||
@Test
|
||||
public void testDiscardReadBytes3() {
|
||||
ChannelBuffer a, b;
|
||||
ByteBuf a, b;
|
||||
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, 5, 6, 7, 8, 9, 10 }, 0, 5),
|
||||
@ -131,13 +131,13 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
|
||||
@Test
|
||||
public void testCompositeWrappedBuffer() {
|
||||
ChannelBuffer header = dynamicBuffer(order, 12);
|
||||
ChannelBuffer payload = dynamicBuffer(order, 512);
|
||||
ByteBuf header = dynamicBuffer(order, 12);
|
||||
ByteBuf payload = dynamicBuffer(order, 512);
|
||||
|
||||
header.writeBytes(new byte[12]);
|
||||
payload.writeBytes(new byte[512]);
|
||||
|
||||
ChannelBuffer buffer = wrappedBuffer(header, payload);
|
||||
ByteBuf buffer = wrappedBuffer(header, payload);
|
||||
|
||||
assertTrue(header.readableBytes() == 12);
|
||||
assertTrue(payload.readableBytes() == 512);
|
||||
@ -148,7 +148,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
|
||||
@Test
|
||||
public void testSeveralBuffersEquals() {
|
||||
ChannelBuffer a, b;
|
||||
ByteBuf a, b;
|
||||
//XXX Same tests with several buffers in wrappedCheckedBuffer
|
||||
// Different length.
|
||||
a = wrappedBuffer(order, new byte[] { 1 });
|
||||
@ -224,7 +224,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(order, new byte[] { 1, 2, 3 })),
|
||||
wrappedBuffer(new ChannelBuffer[] {
|
||||
wrappedBuffer(new ByteBuf[] {
|
||||
wrappedBuffer(order, new byte[] { 1, 2, 3 })
|
||||
}));
|
||||
|
||||
@ -251,7 +251,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
||||
@Test
|
||||
public void testWrittenBuffersEquals() {
|
||||
//XXX Same tests than testEquals with written AggregateChannelBuffers
|
||||
ChannelBuffer a, b;
|
||||
ByteBuf a, b;
|
||||
// Different length.
|
||||
a = wrappedBuffer(order, new byte[] { 1 });
|
||||
b = wrappedBuffer(wrappedBuffer(order, new byte[] { 1 }, new byte[1]));
|
||||
|
@ -24,10 +24,10 @@ import java.nio.ByteOrder;
|
||||
*/
|
||||
public class BigEndianDirectChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, length);
|
||||
assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
|
||||
assertEquals(0, buffer.writerIndex());
|
||||
@ -35,7 +35,7 @@ public class BigEndianDirectChannelBufferTest extends AbstractChannelBufferTest
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
}
|
||||
|
@ -24,22 +24,22 @@ import org.junit.Test;
|
||||
*/
|
||||
public class BigEndianHeapChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = ChannelBuffers.buffer(length);
|
||||
assertEquals(0, buffer.writerIndex());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldNotAllowNullInConstructor() {
|
||||
new BigEndianHeapChannelBuffer(null);
|
||||
new BigEndianHeapByteBuf(null);
|
||||
}
|
||||
}
|
||||
|
@ -24,21 +24,21 @@ import org.junit.Test;
|
||||
*/
|
||||
public class ByteBufferBackedHeapChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
buffer = new ByteBufferBackedChannelBuffer(ByteBuffer.allocate(length));
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = new NioBufferBackedByteBuf(ByteBuffer.allocate(length));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldNotAllowNullInConstructor() {
|
||||
new ByteBufferBackedChannelBuffer(null);
|
||||
new NioBufferBackedByteBuf(null);
|
||||
}
|
||||
}
|
||||
|
@ -28,39 +28,39 @@ public class ChannelBufferIndexFinderTest {
|
||||
|
||||
@Test
|
||||
public void testForward() {
|
||||
ChannelBuffer buf = ChannelBuffers.copiedBuffer(
|
||||
ByteBuf buf = ChannelBuffers.copiedBuffer(
|
||||
"abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx",
|
||||
CharsetUtil.ISO_8859_1);
|
||||
|
||||
assertEquals(3, buf.indexOf(Integer.MIN_VALUE, buf.capacity(), ChannelBufferIndexFinder.CRLF));
|
||||
assertEquals(6, buf.indexOf(3, buf.capacity(), ChannelBufferIndexFinder.NOT_CRLF));
|
||||
assertEquals(9, buf.indexOf(6, buf.capacity(), ChannelBufferIndexFinder.CR));
|
||||
assertEquals(11, buf.indexOf(9, buf.capacity(), ChannelBufferIndexFinder.NOT_CR));
|
||||
assertEquals(14, buf.indexOf(11, buf.capacity(), ChannelBufferIndexFinder.LF));
|
||||
assertEquals(16, buf.indexOf(14, buf.capacity(), ChannelBufferIndexFinder.NOT_LF));
|
||||
assertEquals(19, buf.indexOf(16, buf.capacity(), ChannelBufferIndexFinder.NUL));
|
||||
assertEquals(21, buf.indexOf(19, buf.capacity(), ChannelBufferIndexFinder.NOT_NUL));
|
||||
assertEquals(24, buf.indexOf(21, buf.capacity(), ChannelBufferIndexFinder.LINEAR_WHITESPACE));
|
||||
assertEquals(28, buf.indexOf(24, buf.capacity(), ChannelBufferIndexFinder.NOT_LINEAR_WHITESPACE));
|
||||
assertEquals(-1, buf.indexOf(28, buf.capacity(), ChannelBufferIndexFinder.LINEAR_WHITESPACE));
|
||||
assertEquals(3, buf.indexOf(Integer.MIN_VALUE, buf.capacity(), ByteBufIndexFinder.CRLF));
|
||||
assertEquals(6, buf.indexOf(3, buf.capacity(), ByteBufIndexFinder.NOT_CRLF));
|
||||
assertEquals(9, buf.indexOf(6, buf.capacity(), ByteBufIndexFinder.CR));
|
||||
assertEquals(11, buf.indexOf(9, buf.capacity(), ByteBufIndexFinder.NOT_CR));
|
||||
assertEquals(14, buf.indexOf(11, buf.capacity(), ByteBufIndexFinder.LF));
|
||||
assertEquals(16, buf.indexOf(14, buf.capacity(), ByteBufIndexFinder.NOT_LF));
|
||||
assertEquals(19, buf.indexOf(16, buf.capacity(), ByteBufIndexFinder.NUL));
|
||||
assertEquals(21, buf.indexOf(19, buf.capacity(), ByteBufIndexFinder.NOT_NUL));
|
||||
assertEquals(24, buf.indexOf(21, buf.capacity(), ByteBufIndexFinder.LINEAR_WHITESPACE));
|
||||
assertEquals(28, buf.indexOf(24, buf.capacity(), ByteBufIndexFinder.NOT_LINEAR_WHITESPACE));
|
||||
assertEquals(-1, buf.indexOf(28, buf.capacity(), ByteBufIndexFinder.LINEAR_WHITESPACE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackward() {
|
||||
ChannelBuffer buf = ChannelBuffers.copiedBuffer(
|
||||
ByteBuf buf = ChannelBuffers.copiedBuffer(
|
||||
"abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx",
|
||||
CharsetUtil.ISO_8859_1);
|
||||
|
||||
assertEquals(27, buf.indexOf(Integer.MAX_VALUE, 0, ChannelBufferIndexFinder.LINEAR_WHITESPACE));
|
||||
assertEquals(23, buf.indexOf(28, 0, ChannelBufferIndexFinder.NOT_LINEAR_WHITESPACE));
|
||||
assertEquals(20, buf.indexOf(24, 0, ChannelBufferIndexFinder.NUL));
|
||||
assertEquals(18, buf.indexOf(21, 0, ChannelBufferIndexFinder.NOT_NUL));
|
||||
assertEquals(15, buf.indexOf(19, 0, ChannelBufferIndexFinder.LF));
|
||||
assertEquals(13, buf.indexOf(16, 0, ChannelBufferIndexFinder.NOT_LF));
|
||||
assertEquals(10, buf.indexOf(14, 0, ChannelBufferIndexFinder.CR));
|
||||
assertEquals(8, buf.indexOf(11, 0, ChannelBufferIndexFinder.NOT_CR));
|
||||
assertEquals(5, buf.indexOf(9, 0, ChannelBufferIndexFinder.CRLF));
|
||||
assertEquals(2, buf.indexOf(6, 0, ChannelBufferIndexFinder.NOT_CRLF));
|
||||
assertEquals(-1, buf.indexOf(3, 0, ChannelBufferIndexFinder.CRLF));
|
||||
assertEquals(27, buf.indexOf(Integer.MAX_VALUE, 0, ByteBufIndexFinder.LINEAR_WHITESPACE));
|
||||
assertEquals(23, buf.indexOf(28, 0, ByteBufIndexFinder.NOT_LINEAR_WHITESPACE));
|
||||
assertEquals(20, buf.indexOf(24, 0, ByteBufIndexFinder.NUL));
|
||||
assertEquals(18, buf.indexOf(21, 0, ByteBufIndexFinder.NOT_NUL));
|
||||
assertEquals(15, buf.indexOf(19, 0, ByteBufIndexFinder.LF));
|
||||
assertEquals(13, buf.indexOf(16, 0, ByteBufIndexFinder.NOT_LF));
|
||||
assertEquals(10, buf.indexOf(14, 0, ByteBufIndexFinder.CR));
|
||||
assertEquals(8, buf.indexOf(11, 0, ByteBufIndexFinder.NOT_CR));
|
||||
assertEquals(5, buf.indexOf(9, 0, ByteBufIndexFinder.CRLF));
|
||||
assertEquals(2, buf.indexOf(6, 0, ByteBufIndexFinder.NOT_CRLF));
|
||||
assertEquals(-1, buf.indexOf(3, 0, ByteBufIndexFinder.CRLF));
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,16 @@ public class ChannelBufferStreamTest {
|
||||
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
|
||||
ByteBuf buf = ChannelBuffers.dynamicBuffer();
|
||||
|
||||
try {
|
||||
new ChannelBufferOutputStream(null);
|
||||
new ByteBufOutputStream(null);
|
||||
fail();
|
||||
} catch (NullPointerException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
ChannelBufferOutputStream out = new ChannelBufferOutputStream(buf);
|
||||
ByteBufOutputStream out = new ByteBufOutputStream(buf);
|
||||
assertSame(buf, out.buffer());
|
||||
out.writeBoolean(true);
|
||||
out.writeBoolean(false);
|
||||
@ -61,32 +61,32 @@ public class ChannelBufferStreamTest {
|
||||
out.close();
|
||||
|
||||
try {
|
||||
new ChannelBufferInputStream(null);
|
||||
new ByteBufInputStream(null);
|
||||
fail();
|
||||
} catch (NullPointerException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
new ChannelBufferInputStream(null, 0);
|
||||
new ByteBufInputStream(null, 0);
|
||||
fail();
|
||||
} catch (NullPointerException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
new ChannelBufferInputStream(buf, -1);
|
||||
new ByteBufInputStream(buf, -1);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
new ChannelBufferInputStream(buf, buf.capacity() + 1);
|
||||
new ByteBufInputStream(buf, buf.capacity() + 1);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
ChannelBufferInputStream in = new ChannelBufferInputStream(buf);
|
||||
ByteBufInputStream in = new ByteBufInputStream(buf);
|
||||
|
||||
assertTrue(in.markSupported());
|
||||
in.mark(Integer.MAX_VALUE);
|
||||
@ -171,8 +171,8 @@ public class ChannelBufferStreamTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyReadLine() throws Exception {
|
||||
ChannelBuffer buf = ChannelBuffers.buffer(0);
|
||||
ChannelBufferInputStream in = new ChannelBufferInputStream(buf);
|
||||
ByteBuf buf = ChannelBuffers.buffer(0);
|
||||
ByteBufInputStream in = new ByteBufInputStream(buf);
|
||||
|
||||
String s = in.readLine();
|
||||
assertEquals(0, s.length());
|
||||
|
@ -37,13 +37,13 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testCompositeWrappedBuffer() {
|
||||
ChannelBuffer header = dynamicBuffer(12);
|
||||
ChannelBuffer payload = dynamicBuffer(512);
|
||||
ByteBuf header = dynamicBuffer(12);
|
||||
ByteBuf payload = dynamicBuffer(512);
|
||||
|
||||
header.writeBytes(new byte[12]);
|
||||
payload.writeBytes(new byte[512]);
|
||||
|
||||
ChannelBuffer buffer = wrappedBuffer(header, payload);
|
||||
ByteBuf buffer = wrappedBuffer(header, payload);
|
||||
|
||||
assertTrue(header.readableBytes() == 12);
|
||||
assertTrue(payload.readableBytes() == 512);
|
||||
@ -73,7 +73,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
ChannelBuffer a, b;
|
||||
ByteBuf a, b;
|
||||
|
||||
// Different length.
|
||||
a = wrappedBuffer(new byte[] { 1 });
|
||||
@ -123,7 +123,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testCompare() {
|
||||
List<ChannelBuffer> expected = new ArrayList<ChannelBuffer>();
|
||||
List<ByteBuf> expected = new ArrayList<ByteBuf>();
|
||||
expected.add(wrappedBuffer(new byte[] { 1 }));
|
||||
expected.add(wrappedBuffer(new byte[] { 1, 2 }));
|
||||
expected.add(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }));
|
||||
@ -173,8 +173,8 @@ public class ChannelBuffersTest {
|
||||
assertSame(EMPTY_BUFFER, wrappedBuffer(new ByteBuffer[0]));
|
||||
assertSame(EMPTY_BUFFER, wrappedBuffer(new ByteBuffer[] { ByteBuffer.allocate(0) }));
|
||||
assertSame(EMPTY_BUFFER, wrappedBuffer(ByteBuffer.allocate(0), ByteBuffer.allocate(0)));
|
||||
assertSame(EMPTY_BUFFER, wrappedBuffer(new ChannelBuffer[0]));
|
||||
assertSame(EMPTY_BUFFER, wrappedBuffer(new ChannelBuffer[] { buffer(0) }));
|
||||
assertSame(EMPTY_BUFFER, wrappedBuffer(new ByteBuf[0]));
|
||||
assertSame(EMPTY_BUFFER, wrappedBuffer(new ByteBuf[] { buffer(0) }));
|
||||
assertSame(EMPTY_BUFFER, wrappedBuffer(buffer(0), buffer(0)));
|
||||
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(new byte[0]));
|
||||
@ -190,8 +190,8 @@ public class ChannelBuffersTest {
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(new ByteBuffer[0]));
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(new ByteBuffer[] { ByteBuffer.allocate(0) }));
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(ByteBuffer.allocate(0), ByteBuffer.allocate(0)));
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(new ChannelBuffer[0]));
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(new ChannelBuffer[] { buffer(0) }));
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(new ByteBuf[0]));
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(new ByteBuf[] { buffer(0) }));
|
||||
assertSame(EMPTY_BUFFER, copiedBuffer(buffer(0), buffer(0)));
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void shouldAllowEmptyBufferToCreateCompositeBuffer() {
|
||||
ChannelBuffer buf = wrappedBuffer(
|
||||
ByteBuf buf = wrappedBuffer(
|
||||
EMPTY_BUFFER,
|
||||
wrappedBuffer(LITTLE_ENDIAN, new byte[16]),
|
||||
EMPTY_BUFFER);
|
||||
@ -254,7 +254,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(new byte[] { 1, 2, 3 }),
|
||||
wrappedBuffer(new ChannelBuffer[] {
|
||||
wrappedBuffer(new ByteBuf[] {
|
||||
wrappedBuffer(new byte[] { 1, 2, 3 })
|
||||
}));
|
||||
|
||||
@ -296,7 +296,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(new byte[] { 1, 2, 3 }),
|
||||
copiedBuffer(new ChannelBuffer[] {
|
||||
copiedBuffer(new ByteBuf[] {
|
||||
wrappedBuffer(new byte[] { 1, 2, 3 })
|
||||
}));
|
||||
|
||||
@ -345,7 +345,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testUnmodifiableBuffer() throws Exception {
|
||||
ChannelBuffer buf = unmodifiableBuffer(buffer(16));
|
||||
ByteBuf buf = unmodifiableBuffer(buffer(16));
|
||||
|
||||
try {
|
||||
buf.discardReadBytes();
|
||||
@ -427,7 +427,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapSingleInt() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyInt(42);
|
||||
ByteBuf buffer = ChannelBuffers.copyInt(42);
|
||||
assertEquals(4, buffer.capacity());
|
||||
assertEquals(42, buffer.readInt());
|
||||
assertFalse(buffer.readable());
|
||||
@ -435,7 +435,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapInt() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyInt(1, 4);
|
||||
ByteBuf buffer = ChannelBuffers.copyInt(1, 4);
|
||||
assertEquals(8, buffer.capacity());
|
||||
assertEquals(1, buffer.readInt());
|
||||
assertEquals(4, buffer.readInt());
|
||||
@ -447,7 +447,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapSingleShort() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyShort(42);
|
||||
ByteBuf buffer = ChannelBuffers.copyShort(42);
|
||||
assertEquals(2, buffer.capacity());
|
||||
assertEquals(42, buffer.readShort());
|
||||
assertFalse(buffer.readable());
|
||||
@ -455,7 +455,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapShortFromShortArray() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyShort(new short[] { 1, 4 });
|
||||
ByteBuf buffer = ChannelBuffers.copyShort(new short[] { 1, 4 });
|
||||
assertEquals(4, buffer.capacity());
|
||||
assertEquals(1, buffer.readShort());
|
||||
assertEquals(4, buffer.readShort());
|
||||
@ -467,7 +467,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapShortFromIntArray() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyShort(1, 4);
|
||||
ByteBuf buffer = ChannelBuffers.copyShort(1, 4);
|
||||
assertEquals(4, buffer.capacity());
|
||||
assertEquals(1, buffer.readShort());
|
||||
assertEquals(4, buffer.readShort());
|
||||
@ -479,7 +479,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapSingleMedium() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyMedium(42);
|
||||
ByteBuf buffer = ChannelBuffers.copyMedium(42);
|
||||
assertEquals(3, buffer.capacity());
|
||||
assertEquals(42, buffer.readMedium());
|
||||
assertFalse(buffer.readable());
|
||||
@ -487,7 +487,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapMedium() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyMedium(1, 4);
|
||||
ByteBuf buffer = ChannelBuffers.copyMedium(1, 4);
|
||||
assertEquals(6, buffer.capacity());
|
||||
assertEquals(1, buffer.readMedium());
|
||||
assertEquals(4, buffer.readMedium());
|
||||
@ -499,7 +499,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapSingleLong() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyLong(42);
|
||||
ByteBuf buffer = ChannelBuffers.copyLong(42);
|
||||
assertEquals(8, buffer.capacity());
|
||||
assertEquals(42, buffer.readLong());
|
||||
assertFalse(buffer.readable());
|
||||
@ -507,7 +507,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapLong() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyLong(1, 4);
|
||||
ByteBuf buffer = ChannelBuffers.copyLong(1, 4);
|
||||
assertEquals(16, buffer.capacity());
|
||||
assertEquals(1, buffer.readLong());
|
||||
assertEquals(4, buffer.readLong());
|
||||
@ -519,7 +519,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapSingleFloat() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyFloat(42);
|
||||
ByteBuf buffer = ChannelBuffers.copyFloat(42);
|
||||
assertEquals(4, buffer.capacity());
|
||||
assertEquals(42, buffer.readFloat(), 0.01);
|
||||
assertFalse(buffer.readable());
|
||||
@ -527,7 +527,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapFloat() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyFloat(1, 4);
|
||||
ByteBuf buffer = ChannelBuffers.copyFloat(1, 4);
|
||||
assertEquals(8, buffer.capacity());
|
||||
assertEquals(1, buffer.readFloat(), 0.01);
|
||||
assertEquals(4, buffer.readFloat(), 0.01);
|
||||
@ -539,7 +539,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapSingleDouble() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyDouble(42);
|
||||
ByteBuf buffer = ChannelBuffers.copyDouble(42);
|
||||
assertEquals(8, buffer.capacity());
|
||||
assertEquals(42, buffer.readDouble(), 0.01);
|
||||
assertFalse(buffer.readable());
|
||||
@ -547,7 +547,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapDouble() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyDouble(1, 4);
|
||||
ByteBuf buffer = ChannelBuffers.copyDouble(1, 4);
|
||||
assertEquals(16, buffer.capacity());
|
||||
assertEquals(1, buffer.readDouble(), 0.01);
|
||||
assertEquals(4, buffer.readDouble(), 0.01);
|
||||
@ -559,7 +559,7 @@ public class ChannelBuffersTest {
|
||||
|
||||
@Test
|
||||
public void testWrapBoolean() {
|
||||
ChannelBuffer buffer = ChannelBuffers.copyBoolean(true, false);
|
||||
ByteBuf buffer = ChannelBuffers.copyBoolean(true, false);
|
||||
assertEquals(2, buffer.capacity());
|
||||
assertEquals(true, buffer.readBoolean());
|
||||
assertEquals(false, buffer.readBoolean());
|
||||
|
@ -24,22 +24,22 @@ import org.junit.Test;
|
||||
*/
|
||||
public class DuplicateChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
buffer = new DuplicatedChannelBuffer(ChannelBuffers.buffer(length));
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = new DuplicatedByteBuf(ChannelBuffers.buffer(length));
|
||||
assertEquals(0, buffer.writerIndex());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldNotAllowNullInConstructor() {
|
||||
new DuplicatedChannelBuffer(null);
|
||||
new DuplicatedByteBuf(null);
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ import org.junit.Test;
|
||||
*/
|
||||
public class DynamicChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = ChannelBuffers.dynamicBuffer(length);
|
||||
|
||||
assertEquals(0, buffer.readerIndex());
|
||||
@ -40,28 +40,28 @@ public class DynamicChannelBufferTest extends AbstractChannelBufferTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldNotAllowNullInConstructor() {
|
||||
new DynamicChannelBuffer(null, 0);
|
||||
new DynamicByteBuf(null, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotFailOnInitialIndexUpdate() {
|
||||
new DynamicChannelBuffer(ByteOrder.BIG_ENDIAN, 10).setIndex(0, 10);
|
||||
new DynamicByteBuf(ByteOrder.BIG_ENDIAN, 10).setIndex(0, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotFailOnInitialIndexUpdate2() {
|
||||
new DynamicChannelBuffer(ByteOrder.BIG_ENDIAN, 10).writerIndex(10);
|
||||
new DynamicByteBuf(ByteOrder.BIG_ENDIAN, 10).writerIndex(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotFailOnInitialIndexUpdate3() {
|
||||
ChannelBuffer buf = new DynamicChannelBuffer(ByteOrder.BIG_ENDIAN, 10);
|
||||
ByteBuf buf = new DynamicByteBuf(ByteOrder.BIG_ENDIAN, 10);
|
||||
buf.writerIndex(10);
|
||||
buf.readerIndex(10);
|
||||
}
|
||||
|
@ -24,10 +24,10 @@ import java.nio.ByteOrder;
|
||||
*/
|
||||
public class LittleEndianDirectChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
|
||||
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
||||
assertEquals(0, buffer.writerIndex());
|
||||
@ -35,7 +35,7 @@ public class LittleEndianDirectChannelBufferTest extends AbstractChannelBufferTe
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
}
|
||||
|
@ -26,22 +26,22 @@ import org.junit.Test;
|
||||
*/
|
||||
public class LittleEndianHeapChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, length);
|
||||
assertEquals(0, buffer.writerIndex());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldNotAllowNullInConstructor() {
|
||||
new LittleEndianHeapChannelBuffer(null);
|
||||
new LittleEndianHeapByteBuf(null);
|
||||
}
|
||||
}
|
||||
|
@ -35,44 +35,44 @@ public class ReadOnlyChannelBufferTest {
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldNotAllowNullInConstructor() {
|
||||
new ReadOnlyChannelBuffer(null);
|
||||
new ReadOnlyByteBuf(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmodifiableBuffer() {
|
||||
assertTrue(ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1)) instanceof ReadOnlyChannelBuffer);
|
||||
assertTrue(ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1)) instanceof ReadOnlyByteBuf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnwrap() {
|
||||
ChannelBuffer buf = ChannelBuffers.buffer(1);
|
||||
assertSame(buf, ((WrappedChannelBuffer) ChannelBuffers.unmodifiableBuffer(buf)).unwrap());
|
||||
ByteBuf buf = ChannelBuffers.buffer(1);
|
||||
assertSame(buf, ((WrappedByteBuf) ChannelBuffers.unmodifiableBuffer(buf)).unwrap());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveSameByteOrder() {
|
||||
ChannelBuffer buf = ChannelBuffers.buffer(ChannelBuffers.LITTLE_ENDIAN, 1);
|
||||
ByteBuf buf = ChannelBuffers.buffer(ChannelBuffers.LITTLE_ENDIAN, 1);
|
||||
assertSame(ChannelBuffers.LITTLE_ENDIAN, ChannelBuffers.unmodifiableBuffer(buf).order());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnReadOnlyDerivedBuffer() {
|
||||
ChannelBuffer buf = ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1));
|
||||
assertTrue(buf.duplicate() instanceof ReadOnlyChannelBuffer);
|
||||
assertTrue(buf.slice() instanceof ReadOnlyChannelBuffer);
|
||||
assertTrue(buf.slice(0, 1) instanceof ReadOnlyChannelBuffer);
|
||||
assertTrue(buf.duplicate() instanceof ReadOnlyChannelBuffer);
|
||||
ByteBuf buf = ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1));
|
||||
assertTrue(buf.duplicate() instanceof ReadOnlyByteBuf);
|
||||
assertTrue(buf.slice() instanceof ReadOnlyByteBuf);
|
||||
assertTrue(buf.slice(0, 1) instanceof ReadOnlyByteBuf);
|
||||
assertTrue(buf.duplicate() instanceof ReadOnlyByteBuf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnWritableCopy() {
|
||||
ChannelBuffer buf = ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1));
|
||||
assertFalse(buf.copy() instanceof ReadOnlyChannelBuffer);
|
||||
ByteBuf buf = ChannelBuffers.unmodifiableBuffer(ChannelBuffers.buffer(1));
|
||||
assertFalse(buf.copy() instanceof ReadOnlyByteBuf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldForwardReadCallsBlindly() throws Exception {
|
||||
ChannelBuffer buf = createStrictMock(ChannelBuffer.class);
|
||||
ByteBuf buf = createStrictMock(ByteBuf.class);
|
||||
expect(buf.readerIndex()).andReturn(0).anyTimes();
|
||||
expect(buf.writerIndex()).andReturn(0).anyTimes();
|
||||
expect(buf.capacity()).andReturn(0).anyTimes();
|
||||
@ -80,7 +80,7 @@ public class ReadOnlyChannelBufferTest {
|
||||
expect(buf.getBytes(1, (GatheringByteChannel) null, 2)).andReturn(3);
|
||||
buf.getBytes(4, (OutputStream) null, 5);
|
||||
buf.getBytes(6, (byte[]) null, 7, 8);
|
||||
buf.getBytes(9, (ChannelBuffer) null, 10, 11);
|
||||
buf.getBytes(9, (ByteBuf) null, 10, 11);
|
||||
buf.getBytes(12, (ByteBuffer) null);
|
||||
expect(buf.getByte(13)).andReturn(Byte.valueOf((byte) 14));
|
||||
expect(buf.getShort(15)).andReturn(Short.valueOf((short) 16));
|
||||
@ -95,11 +95,11 @@ public class ReadOnlyChannelBufferTest {
|
||||
|
||||
replay(buf);
|
||||
|
||||
ChannelBuffer roBuf = unmodifiableBuffer(buf);
|
||||
ByteBuf roBuf = unmodifiableBuffer(buf);
|
||||
assertEquals(3, roBuf.getBytes(1, (GatheringByteChannel) null, 2));
|
||||
roBuf.getBytes(4, (OutputStream) null, 5);
|
||||
roBuf.getBytes(6, (byte[]) null, 7, 8);
|
||||
roBuf.getBytes(9, (ChannelBuffer) null, 10, 11);
|
||||
roBuf.getBytes(9, (ByteBuf) null, 10, 11);
|
||||
roBuf.getBytes(12, (ByteBuffer) null);
|
||||
assertEquals((byte) 14, roBuf.getByte(13));
|
||||
assertEquals((short) 16, roBuf.getShort(15));
|
||||
@ -163,7 +163,7 @@ public class ReadOnlyChannelBufferTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void shouldRejectSetBytes4() {
|
||||
unmodifiableBuffer(EMPTY_BUFFER).setBytes(0, (ChannelBuffer) null, 0, 0);
|
||||
unmodifiableBuffer(EMPTY_BUFFER).setBytes(0, (ByteBuf) null, 0, 0);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
|
@ -27,10 +27,10 @@ import org.junit.Test;
|
||||
public class SlicedChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private final Random random = new Random();
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = ChannelBuffers.wrappedBuffer(
|
||||
new byte[length * 2], random.nextInt(length - 1) + 1, length);
|
||||
assertEquals(length, buffer.writerIndex());
|
||||
@ -38,12 +38,12 @@ public class SlicedChannelBufferTest extends AbstractChannelBufferTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldNotAllowNullInConstructor() {
|
||||
new SlicedChannelBuffer(null, 0, 0);
|
||||
new SlicedByteBuf(null, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,10 @@ import org.junit.Test;
|
||||
*/
|
||||
public class TruncatedChannelBufferTest extends AbstractChannelBufferTest {
|
||||
|
||||
private ChannelBuffer buffer;
|
||||
private ByteBuf buffer;
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newBuffer(int length) {
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = ChannelBuffers.wrappedBuffer(
|
||||
new byte[length * 2], 0, length);
|
||||
assertEquals(length, buffer.writerIndex());
|
||||
@ -35,12 +35,12 @@ public class TruncatedChannelBufferTest extends AbstractChannelBufferTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer[] components() {
|
||||
return new ChannelBuffer[] { buffer };
|
||||
protected ByteBuf[] components() {
|
||||
return new ByteBuf[] { buffer };
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldNotAllowNullInConstructor() {
|
||||
new TruncatedChannelBuffer(null, 0);
|
||||
new TruncatedByteBuf(null, 0);
|
||||
}
|
||||
}
|
||||
|
@ -15,31 +15,31 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* The default {@link HttpChunk} implementation.
|
||||
*/
|
||||
public class DefaultHttpChunk implements HttpChunk {
|
||||
|
||||
private ChannelBuffer content;
|
||||
private ByteBuf content;
|
||||
private boolean last;
|
||||
|
||||
/**
|
||||
* Creates a new instance with the specified chunk content. If an empty
|
||||
* buffer is specified, this chunk becomes the 'end of content' marker.
|
||||
*/
|
||||
public DefaultHttpChunk(ChannelBuffer content) {
|
||||
public DefaultHttpChunk(ByteBuf content) {
|
||||
setContent(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getContent() {
|
||||
public ByteBuf getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContent(ChannelBuffer content) {
|
||||
public void setContent(ByteBuf content) {
|
||||
if (content == null) {
|
||||
throw new NullPointerException("content");
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
import java.util.List;
|
||||
@ -96,12 +96,12 @@ public class DefaultHttpChunkTrailer implements HttpChunkTrailer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getContent() {
|
||||
public ByteBuf getContent() {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContent(ChannelBuffer content) {
|
||||
public void setContent(ByteBuf content) {
|
||||
throw new IllegalStateException("read-only");
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
@ -30,7 +30,7 @@ public class DefaultHttpMessage implements HttpMessage {
|
||||
|
||||
private final HttpHeaders headers = new HttpHeaders();
|
||||
private HttpVersion version;
|
||||
private ChannelBuffer content = ChannelBuffers.EMPTY_BUFFER;
|
||||
private ByteBuf content = ChannelBuffers.EMPTY_BUFFER;
|
||||
private boolean chunked;
|
||||
|
||||
/**
|
||||
@ -83,7 +83,7 @@ public class DefaultHttpMessage implements HttpMessage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContent(ChannelBuffer content) {
|
||||
public void setContent(ByteBuf content) {
|
||||
if (content == null) {
|
||||
content = ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
@ -133,7 +133,7 @@ public class DefaultHttpMessage implements HttpMessage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getContent() {
|
||||
public ByteBuf getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
|
||||
@ -40,12 +40,12 @@ public interface HttpChunk {
|
||||
*/
|
||||
HttpChunkTrailer LAST_CHUNK = new HttpChunkTrailer() {
|
||||
@Override
|
||||
public ChannelBuffer getContent() {
|
||||
public ByteBuf getContent() {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContent(ChannelBuffer content) {
|
||||
public void setContent(ByteBuf content) {
|
||||
throw new IllegalStateException("read-only");
|
||||
}
|
||||
|
||||
@ -115,11 +115,11 @@ public interface HttpChunk {
|
||||
* Returns the content of this chunk. If this is the 'end of content'
|
||||
* marker, {@link ChannelBuffers#EMPTY_BUFFER} will be returned.
|
||||
*/
|
||||
ChannelBuffer getContent();
|
||||
ByteBuf getContent();
|
||||
|
||||
/**
|
||||
* Sets the content of this chunk. If an empty buffer is specified,
|
||||
* this chunk becomes the 'end of content' marker.
|
||||
*/
|
||||
void setContent(ChannelBuffer content);
|
||||
void setContent(ByteBuf content);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@ -48,7 +48,7 @@ import java.util.Map.Entry;
|
||||
*/
|
||||
public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMessage> {
|
||||
|
||||
private static final ChannelBuffer CONTINUE = ChannelBuffers.copiedBuffer(
|
||||
private static final ByteBuf CONTINUE = ChannelBuffers.copiedBuffer(
|
||||
"HTTP/1.1 100 Continue\r\n\r\n", CharsetUtil.US_ASCII);
|
||||
|
||||
private final int maxContentLength;
|
||||
@ -119,7 +119,7 @@ public class HttpChunkAggregator extends MessageToMessageDecoder<Object, HttpMes
|
||||
|
||||
// Merge the received chunk into the content of the current message.
|
||||
HttpChunk chunk = (HttpChunk) msg;
|
||||
ChannelBuffer content = currentMessage.getContent();
|
||||
ByteBuf content = currentMessage.getContent();
|
||||
|
||||
if (content.readableBytes() > maxContentLength - chunk.getContent().readableBytes()) {
|
||||
// TODO: Respond with 413 Request Entity Too Large
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.CombinedChannelHandler;
|
||||
@ -83,7 +83,7 @@ public class HttpClientCodec extends CombinedChannelHandler {
|
||||
private final class Encoder extends HttpRequestEncoder {
|
||||
@Override
|
||||
public void encode(
|
||||
ChannelHandlerContext ctx, Object msg, ChannelBuffer out) throws Exception {
|
||||
ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
|
||||
if (msg instanceof HttpRequest && !done) {
|
||||
queue.offer(((HttpRequest) msg).getMethod());
|
||||
}
|
||||
@ -110,7 +110,7 @@ public class HttpClientCodec extends CombinedChannelHandler {
|
||||
|
||||
@Override
|
||||
public Object decode(
|
||||
ChannelHandlerContext ctx, ChannelBuffer buffer) throws Exception {
|
||||
ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
|
||||
if (done) {
|
||||
return buffer.readBytes(actualReadableBytes());
|
||||
} else {
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||
@ -38,7 +38,7 @@ import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
* <p>
|
||||
* This handler must be placed after {@link HttpMessageDecoder} in the pipeline
|
||||
* so that this handler can intercept HTTP requests after {@link HttpMessageDecoder}
|
||||
* converts {@link ChannelBuffer}s into HTTP requests.
|
||||
* converts {@link ByteBuf}s into HTTP requests.
|
||||
*/
|
||||
public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object, Object> {
|
||||
|
||||
@ -82,9 +82,9 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
||||
getTargetContentEncoding(contentEncoding));
|
||||
|
||||
if (!m.isChunked()) {
|
||||
ChannelBuffer content = m.getContent();
|
||||
ByteBuf content = m.getContent();
|
||||
// Decode the content
|
||||
ChannelBuffer newContent = ChannelBuffers.dynamicBuffer();
|
||||
ByteBuf newContent = ChannelBuffers.dynamicBuffer();
|
||||
decode(content, newContent);
|
||||
finishDecode(newContent);
|
||||
|
||||
@ -99,12 +99,12 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
||||
}
|
||||
} else if (msg instanceof HttpChunk) {
|
||||
HttpChunk c = (HttpChunk) msg;
|
||||
ChannelBuffer content = c.getContent();
|
||||
ByteBuf content = c.getContent();
|
||||
|
||||
// Decode the chunk if necessary.
|
||||
if (decoder != null) {
|
||||
if (!c.isLast()) {
|
||||
ChannelBuffer newContent = ChannelBuffers.dynamicBuffer();
|
||||
ByteBuf newContent = ChannelBuffers.dynamicBuffer();
|
||||
decode(content, newContent);
|
||||
if (newContent.readable()) {
|
||||
c.setContent(newContent);
|
||||
@ -112,7 +112,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
ChannelBuffer lastProduct = ChannelBuffers.dynamicBuffer();
|
||||
ByteBuf lastProduct = ChannelBuffers.dynamicBuffer();
|
||||
finishDecode(lastProduct);
|
||||
|
||||
// Generate an additional chunk if the decoder produced
|
||||
@ -151,21 +151,21 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
|
||||
return HttpHeaders.Values.IDENTITY;
|
||||
}
|
||||
|
||||
private void decode(ChannelBuffer in, ChannelBuffer out) {
|
||||
private void decode(ByteBuf in, ByteBuf out) {
|
||||
decoder.writeInbound(in);
|
||||
fetchDecoderOutput(out);
|
||||
}
|
||||
|
||||
private void finishDecode(ChannelBuffer out) {
|
||||
private void finishDecode(ByteBuf out) {
|
||||
if (decoder.finish()) {
|
||||
fetchDecoderOutput(out);
|
||||
}
|
||||
decoder = null;
|
||||
}
|
||||
|
||||
private void fetchDecoderOutput(ChannelBuffer out) {
|
||||
private void fetchDecoderOutput(ByteBuf out) {
|
||||
for (;;) {
|
||||
ChannelBuffer buf = (ChannelBuffer) decoder.readInbound();
|
||||
ByteBuf buf = (ByteBuf) decoder.readInbound();
|
||||
if (buf == null) {
|
||||
break;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||
@ -44,7 +44,7 @@ import java.util.Queue;
|
||||
* <p>
|
||||
* This handler must be placed after {@link HttpMessageEncoder} in the pipeline
|
||||
* so that this handler can intercept HTTP responses before {@link HttpMessageEncoder}
|
||||
* converts them into {@link ChannelBuffer}s.
|
||||
* converts them into {@link ByteBuf}s.
|
||||
*/
|
||||
public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessage, HttpMessage, Object, Object> {
|
||||
|
||||
@ -115,9 +115,9 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
||||
result.getTargetContentEncoding());
|
||||
|
||||
if (!m.isChunked()) {
|
||||
ChannelBuffer content = m.getContent();
|
||||
ByteBuf content = m.getContent();
|
||||
// Encode the content.
|
||||
ChannelBuffer newContent = ChannelBuffers.dynamicBuffer();
|
||||
ByteBuf newContent = ChannelBuffers.dynamicBuffer();
|
||||
encode(content, newContent);
|
||||
finishEncode(newContent);
|
||||
|
||||
@ -131,12 +131,12 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
||||
}
|
||||
} else if (msg instanceof HttpChunk) {
|
||||
HttpChunk c = (HttpChunk) msg;
|
||||
ChannelBuffer content = c.getContent();
|
||||
ByteBuf content = c.getContent();
|
||||
|
||||
// Encode the chunk if necessary.
|
||||
if (encoder != null) {
|
||||
if (!c.isLast()) {
|
||||
ChannelBuffer newContent = ChannelBuffers.dynamicBuffer();
|
||||
ByteBuf newContent = ChannelBuffers.dynamicBuffer();
|
||||
encode(content, newContent);
|
||||
if (content.readable()) {
|
||||
c.setContent(newContent);
|
||||
@ -144,7 +144,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
ChannelBuffer lastProduct = ChannelBuffers.dynamicBuffer();
|
||||
ByteBuf lastProduct = ChannelBuffers.dynamicBuffer();
|
||||
finishEncode(lastProduct);
|
||||
|
||||
// Generate an additional chunk if the decoder produced
|
||||
@ -176,21 +176,21 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
|
||||
*/
|
||||
protected abstract Result beginEncode(HttpMessage msg, String acceptEncoding) throws Exception;
|
||||
|
||||
private void encode(ChannelBuffer in, ChannelBuffer out) {
|
||||
private void encode(ByteBuf in, ByteBuf out) {
|
||||
encoder.writeOutbound(in);
|
||||
fetchEncoderOutput(out);
|
||||
}
|
||||
|
||||
private void finishEncode(ChannelBuffer out) {
|
||||
private void finishEncode(ByteBuf out) {
|
||||
if (encoder.finish()) {
|
||||
fetchEncoderOutput(out);
|
||||
}
|
||||
encoder = null;
|
||||
}
|
||||
|
||||
private void fetchEncoderOutput(ChannelBuffer out) {
|
||||
private void fetchEncoderOutput(ByteBuf out) {
|
||||
for (;;) {
|
||||
ChannelBuffer buf = encoder.readOutbound();
|
||||
ByteBuf buf = encoder.readOutbound();
|
||||
if (buf == null) {
|
||||
break;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
import java.util.Calendar;
|
||||
@ -85,13 +85,13 @@ public interface HttpMessage {
|
||||
* {@link #isChunked()} returns {@code true}, an
|
||||
* {@link ChannelBuffers#EMPTY_BUFFER} is returned.
|
||||
*/
|
||||
ChannelBuffer getContent();
|
||||
ByteBuf getContent();
|
||||
|
||||
/**
|
||||
* Sets the content of this message. If {@code null} is specified,
|
||||
* the content of this message will be set to {@link ChannelBuffers#EMPTY_BUFFER}.
|
||||
*/
|
||||
void setContent(ChannelBuffer content);
|
||||
void setContent(ByteBuf content);
|
||||
|
||||
/**
|
||||
* Adds a new header with the specified name and value.
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
@ -25,7 +25,7 @@ import io.netty.handler.codec.TooLongFrameException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Decodes {@link ChannelBuffer}s into {@link HttpMessage}s and
|
||||
* Decodes {@link ByteBuf}s into {@link HttpMessage}s and
|
||||
* {@link HttpChunk}s.
|
||||
*
|
||||
* <h3>Parameters that prevents excessive memory consumption</h3>
|
||||
@ -103,7 +103,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
private final int maxHeaderSize;
|
||||
private final int maxChunkSize;
|
||||
private HttpMessage message;
|
||||
private ChannelBuffer content;
|
||||
private ByteBuf content;
|
||||
private long chunkSize;
|
||||
private int headerSize;
|
||||
private int contentRead;
|
||||
@ -166,7 +166,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ChannelHandlerContext ctx, ChannelBuffer buffer) throws Exception {
|
||||
public Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
|
||||
switch (state()) {
|
||||
case SKIP_CONTROL_CHARS: {
|
||||
try {
|
||||
@ -409,7 +409,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
|
||||
private Object reset() {
|
||||
HttpMessage message = this.message;
|
||||
ChannelBuffer content = this.content;
|
||||
ByteBuf content = this.content;
|
||||
|
||||
if (content != null) {
|
||||
message.setContent(content);
|
||||
@ -421,7 +421,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
return message;
|
||||
}
|
||||
|
||||
private static void skipControlCharacters(ChannelBuffer buffer) {
|
||||
private static void skipControlCharacters(ByteBuf buffer) {
|
||||
for (;;) {
|
||||
char c = (char) buffer.readUnsignedByte();
|
||||
if (!Character.isISOControl(c) &&
|
||||
@ -432,7 +432,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
}
|
||||
}
|
||||
|
||||
private Object readFixedLengthContent(ChannelBuffer buffer) {
|
||||
private Object readFixedLengthContent(ByteBuf buffer) {
|
||||
//we have a content-length so we just read the correct number of bytes
|
||||
long length = HttpHeaders.getContentLength(message, -1);
|
||||
assert length <= Integer.MAX_VALUE;
|
||||
@ -457,7 +457,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
return reset();
|
||||
}
|
||||
|
||||
private State readHeaders(ChannelBuffer buffer) throws TooLongFrameException {
|
||||
private State readHeaders(ByteBuf buffer) throws TooLongFrameException {
|
||||
headerSize = 0;
|
||||
final HttpMessage message = this.message;
|
||||
String line = readHeader(buffer);
|
||||
@ -507,7 +507,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
return nextState;
|
||||
}
|
||||
|
||||
private HttpChunkTrailer readTrailingHeaders(ChannelBuffer buffer) throws TooLongFrameException {
|
||||
private HttpChunkTrailer readTrailingHeaders(ByteBuf buffer) throws TooLongFrameException {
|
||||
headerSize = 0;
|
||||
String line = readHeader(buffer);
|
||||
String lastHeader = null;
|
||||
@ -544,7 +544,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
return HttpChunk.LAST_CHUNK;
|
||||
}
|
||||
|
||||
private String readHeader(ChannelBuffer buffer) throws TooLongFrameException {
|
||||
private String readHeader(ByteBuf buffer) throws TooLongFrameException {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
int headerSize = this.headerSize;
|
||||
|
||||
@ -600,7 +600,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
|
||||
return Integer.parseInt(hex, 16);
|
||||
}
|
||||
|
||||
private static String readLine(ChannelBuffer buffer, int maxLineLength) throws TooLongFrameException {
|
||||
private static String readLine(ByteBuf buffer, int maxLineLength) throws TooLongFrameException {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
int lineLength = 0;
|
||||
while (true) {
|
||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.http;
|
||||
|
||||
import static io.netty.buffer.ChannelBuffers.*;
|
||||
import static io.netty.handler.codec.http.HttpConstants.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import io.netty.handler.codec.UnsupportedMessageTypeException;
|
||||
@ -30,7 +30,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* Encodes an {@link HttpMessage} or an {@link HttpChunk} into
|
||||
* a {@link ChannelBuffer}.
|
||||
* a {@link ByteBuf}.
|
||||
*
|
||||
* <h3>Extensibility</h3>
|
||||
*
|
||||
@ -44,7 +44,7 @@ import java.util.Map;
|
||||
*/
|
||||
public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
|
||||
private static final ChannelBuffer LAST_CHUNK =
|
||||
private static final ByteBuf LAST_CHUNK =
|
||||
copiedBuffer("0\r\n\r\n", CharsetUtil.US_ASCII);
|
||||
|
||||
private volatile boolean chunked;
|
||||
@ -61,7 +61,7 @@ public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx, Object msg, ChannelBuffer out) throws Exception {
|
||||
public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
|
||||
if (msg instanceof HttpMessage) {
|
||||
HttpMessage m = (HttpMessage) msg;
|
||||
boolean chunked;
|
||||
@ -81,7 +81,7 @@ public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
out.writeByte(CR);
|
||||
out.writeByte(LF);
|
||||
|
||||
ChannelBuffer content = m.getContent();
|
||||
ByteBuf content = m.getContent();
|
||||
if (content.readable()) {
|
||||
if (chunked) {
|
||||
out.resetWriterIndex();
|
||||
@ -108,7 +108,7 @@ public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
out.writeBytes(LAST_CHUNK, LAST_CHUNK.readerIndex(), LAST_CHUNK.readableBytes());
|
||||
}
|
||||
} else {
|
||||
ChannelBuffer content = chunk.getContent();
|
||||
ByteBuf content = chunk.getContent();
|
||||
int contentLength = content.readableBytes();
|
||||
out.writeBytes(copiedBuffer(Integer.toHexString(contentLength), CharsetUtil.US_ASCII));
|
||||
out.writeByte(CR);
|
||||
@ -119,7 +119,7 @@ public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
} else {
|
||||
if (!chunk.isLast()) {
|
||||
ChannelBuffer chunkContent = chunk.getContent();
|
||||
ByteBuf chunkContent = chunk.getContent();
|
||||
out.writeBytes(chunkContent, chunkContent.readerIndex(), chunkContent.readableBytes());
|
||||
}
|
||||
}
|
||||
@ -128,7 +128,7 @@ public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private static void encodeHeaders(ChannelBuffer buf, HttpMessage message) {
|
||||
private static void encodeHeaders(ByteBuf buf, HttpMessage message) {
|
||||
try {
|
||||
for (Map.Entry<String, String> h: message.getHeaders()) {
|
||||
encodeHeader(buf, h.getKey(), h.getValue());
|
||||
@ -138,7 +138,7 @@ public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private static void encodeTrailingHeaders(ChannelBuffer buf, HttpChunkTrailer trailer) {
|
||||
private static void encodeTrailingHeaders(ByteBuf buf, HttpChunkTrailer trailer) {
|
||||
try {
|
||||
for (Map.Entry<String, String> h: trailer.getHeaders()) {
|
||||
encodeHeader(buf, h.getKey(), h.getValue());
|
||||
@ -148,7 +148,7 @@ public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private static void encodeHeader(ChannelBuffer buf, String header, String value)
|
||||
private static void encodeHeader(ByteBuf buf, String header, String value)
|
||||
throws UnsupportedEncodingException {
|
||||
buf.writeBytes(header.getBytes("ASCII"));
|
||||
buf.writeByte(COLON);
|
||||
@ -158,5 +158,5 @@ public abstract class HttpMessageEncoder extends MessageToByteEncoder<Object> {
|
||||
buf.writeByte(LF);
|
||||
}
|
||||
|
||||
protected abstract void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception;
|
||||
protected abstract void encodeInitialLine(ByteBuf buf, HttpMessage message) throws Exception;
|
||||
}
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
|
||||
|
||||
/**
|
||||
* Decodes {@link ChannelBuffer}s into {@link HttpRequest}s and {@link HttpChunk}s.
|
||||
* Decodes {@link ByteBuf}s into {@link HttpRequest}s and {@link HttpChunk}s.
|
||||
*
|
||||
* <h3>Parameters that prevents excessive memory consumption</h3>
|
||||
* <table border="1">
|
||||
|
@ -16,11 +16,11 @@
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpConstants.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Encodes an {@link HttpRequest} or an {@link HttpChunk} into
|
||||
* a {@link ChannelBuffer}.
|
||||
* a {@link ByteBuf}.
|
||||
*/
|
||||
public class HttpRequestEncoder extends HttpMessageEncoder {
|
||||
|
||||
@ -31,7 +31,7 @@ public class HttpRequestEncoder extends HttpMessageEncoder {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception {
|
||||
protected void encodeInitialLine(ByteBuf buf, HttpMessage message) throws Exception {
|
||||
HttpRequest request = (HttpRequest) message;
|
||||
buf.writeBytes(request.getMethod().toString().getBytes("ASCII"));
|
||||
buf.writeByte(SP);
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
|
||||
|
||||
/**
|
||||
* Decodes {@link ChannelBuffer}s into {@link HttpResponse}s and
|
||||
* Decodes {@link ByteBuf}s into {@link HttpResponse}s and
|
||||
* {@link HttpChunk}s.
|
||||
*
|
||||
* <h3>Parameters that prevents excessive memory consumption</h3>
|
||||
|
@ -16,11 +16,11 @@
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpConstants.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Encodes an {@link HttpResponse} or an {@link HttpChunk} into
|
||||
* a {@link ChannelBuffer}.
|
||||
* a {@link ByteBuf}.
|
||||
*/
|
||||
public class HttpResponseEncoder extends HttpMessageEncoder {
|
||||
|
||||
@ -31,7 +31,7 @@ public class HttpResponseEncoder extends HttpMessageEncoder {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception {
|
||||
protected void encodeInitialLine(ByteBuf buf, HttpMessage message) throws Exception {
|
||||
HttpResponse response = (HttpResponse) message;
|
||||
buf.writeBytes(response.getProtocolVersion().toString().getBytes("ASCII"));
|
||||
buf.writeByte(SP);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
/**
|
||||
@ -36,7 +36,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
public BinaryWebSocketFrame(ChannelBuffer binaryData) {
|
||||
public BinaryWebSocketFrame(ByteBuf binaryData) {
|
||||
setBinaryData(binaryData);
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
public BinaryWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData) {
|
||||
public BinaryWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
setBinaryData(binaryData);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
@ -78,7 +78,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
reasonBytes = reasonText.getBytes(CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
ChannelBuffer binaryData = ChannelBuffers.buffer(2 + reasonBytes.length);
|
||||
ByteBuf binaryData = ChannelBuffers.buffer(2 + reasonBytes.length);
|
||||
binaryData.writeShort(statusCode);
|
||||
if (reasonBytes.length > 0) {
|
||||
binaryData.writeBytes(reasonBytes);
|
||||
@ -98,7 +98,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame. Must be 2 byte integer followed by optional UTF-8 encoded string.
|
||||
*/
|
||||
public CloseWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData) {
|
||||
public CloseWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
if (binaryData == null) {
|
||||
@ -113,7 +113,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
* a status code is set, -1 is returned.
|
||||
*/
|
||||
public int getStatusCode() {
|
||||
ChannelBuffer binaryData = getBinaryData();
|
||||
ByteBuf binaryData = getBinaryData();
|
||||
if (binaryData == null || binaryData.capacity() == 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -130,7 +130,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
* text is not supplied, an empty string is returned.
|
||||
*/
|
||||
public String getReasonText() {
|
||||
ChannelBuffer binaryData = getBinaryData();
|
||||
ByteBuf binaryData = getBinaryData();
|
||||
if (binaryData == null || binaryData.capacity() <= 2) {
|
||||
return "";
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
@ -40,7 +40,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
*
|
||||
* @param binaryData the content of the frame.
|
||||
*/
|
||||
public ContinuationWebSocketFrame(ChannelBuffer binaryData) {
|
||||
public ContinuationWebSocketFrame(ByteBuf binaryData) {
|
||||
setBinaryData(binaryData);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
public ContinuationWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData) {
|
||||
public ContinuationWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
setBinaryData(binaryData);
|
||||
@ -74,7 +74,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
* text message
|
||||
*/
|
||||
public ContinuationWebSocketFrame(
|
||||
boolean finalFragment, int rsv, ChannelBuffer binaryData, String aggregatedText) {
|
||||
boolean finalFragment, int rsv, ByteBuf binaryData, String aggregatedText) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
setBinaryData(binaryData);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
/**
|
||||
@ -37,7 +37,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
public PingWebSocketFrame(ChannelBuffer binaryData) {
|
||||
public PingWebSocketFrame(ByteBuf binaryData) {
|
||||
setBinaryData(binaryData);
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
public PingWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData) {
|
||||
public PingWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
setBinaryData(binaryData);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
/**
|
||||
@ -36,7 +36,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
public PongWebSocketFrame(ChannelBuffer binaryData) {
|
||||
public PongWebSocketFrame(ByteBuf binaryData) {
|
||||
setBinaryData(binaryData);
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
public PongWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData) {
|
||||
public PongWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
setBinaryData(binaryData);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
@ -51,7 +51,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame. Must be UTF-8 encoded
|
||||
*/
|
||||
public TextWebSocketFrame(ChannelBuffer binaryData) {
|
||||
public TextWebSocketFrame(ByteBuf binaryData) {
|
||||
setBinaryData(binaryData);
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
* @param binaryData
|
||||
* the content of the frame. Must be UTF-8 encoded
|
||||
*/
|
||||
public TextWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData) {
|
||||
public TextWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
setBinaryData(binaryData);
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ReplayingDecoder;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
import io.netty.util.VoidEnum;
|
||||
|
||||
/**
|
||||
* Decodes {@link ChannelBuffer}s into {@link WebSocketFrame}s.
|
||||
* Decodes {@link ByteBuf}s into {@link WebSocketFrame}s.
|
||||
* <p>
|
||||
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
|
||||
* <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package.
|
||||
@ -53,7 +53,7 @@ public class WebSocket00FrameDecoder extends ReplayingDecoder<WebSocketFrame, Vo
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSocketFrame decode(ChannelHandlerContext ctx, ChannelBuffer in) throws Exception {
|
||||
public WebSocketFrame decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
// Discard all data received if closing handshake was received before.
|
||||
if (receivedClosingHandshake) {
|
||||
in.skipBytes(actualReadableBytes());
|
||||
@ -71,7 +71,7 @@ public class WebSocket00FrameDecoder extends ReplayingDecoder<WebSocketFrame, Vo
|
||||
}
|
||||
}
|
||||
|
||||
private WebSocketFrame decodeBinaryFrame(byte type, ChannelBuffer buffer) throws TooLongFrameException {
|
||||
private WebSocketFrame decodeBinaryFrame(byte type, ByteBuf buffer) throws TooLongFrameException {
|
||||
long frameSize = 0;
|
||||
int lengthFieldSize = 0;
|
||||
byte b;
|
||||
@ -97,7 +97,7 @@ public class WebSocket00FrameDecoder extends ReplayingDecoder<WebSocketFrame, Vo
|
||||
return new BinaryWebSocketFrame(buffer.readBytes((int) frameSize));
|
||||
}
|
||||
|
||||
private WebSocketFrame decodeTextFrame(ChannelBuffer buffer) throws TooLongFrameException {
|
||||
private WebSocketFrame decodeTextFrame(ByteBuf buffer) throws TooLongFrameException {
|
||||
int ridx = buffer.readerIndex();
|
||||
int rbytes = actualReadableBytes();
|
||||
int delimPos = buffer.indexOf(ridx, ridx + rbytes, (byte) 0xFF);
|
||||
@ -117,7 +117,7 @@ public class WebSocket00FrameDecoder extends ReplayingDecoder<WebSocketFrame, Vo
|
||||
throw new TooLongFrameException();
|
||||
}
|
||||
|
||||
ChannelBuffer binaryData = buffer.readBytes(frameSize);
|
||||
ByteBuf binaryData = buffer.readBytes(frameSize);
|
||||
buffer.skipBytes(1);
|
||||
|
||||
int ffDelimPos = binaryData.indexOf(binaryData.readerIndex(), binaryData.writerIndex(), (byte) 0xFF);
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
/**
|
||||
* Encodes a {@link WebSocketFrame} into a {@link ChannelBuffer}.
|
||||
* Encodes a {@link WebSocketFrame} into a {@link ByteBuf}.
|
||||
* <p>
|
||||
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
|
||||
* <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package.
|
||||
@ -40,10 +40,10 @@ public class WebSocket00FrameEncoder extends MessageToByteEncoder<WebSocketFrame
|
||||
@Override
|
||||
public void encode(
|
||||
ChannelHandlerContext ctx,
|
||||
WebSocketFrame msg, ChannelBuffer out) throws Exception {
|
||||
WebSocketFrame msg, ByteBuf out) throws Exception {
|
||||
if (msg instanceof TextWebSocketFrame) {
|
||||
// Text frame
|
||||
ChannelBuffer data = msg.getBinaryData();
|
||||
ByteBuf data = msg.getBinaryData();
|
||||
out.writeByte((byte) 0x00);
|
||||
out.writeBytes(data, data.readerIndex(), data.readableBytes());
|
||||
out.writeByte((byte) 0xFF);
|
||||
@ -53,7 +53,7 @@ public class WebSocket00FrameEncoder extends MessageToByteEncoder<WebSocketFrame
|
||||
out.writeByte((byte) 0x00);
|
||||
} else {
|
||||
// Binary frame
|
||||
ChannelBuffer data = msg.getBinaryData();
|
||||
ByteBuf data = msg.getBinaryData();
|
||||
int dataLen = data.readableBytes();
|
||||
out.ensureWritableBytes(dataLen + 5);
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
||||
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@ -86,9 +86,9 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
|
||||
private int frameRsv;
|
||||
private int frameOpcode;
|
||||
private long framePayloadLength;
|
||||
private ChannelBuffer framePayload;
|
||||
private ByteBuf framePayload;
|
||||
private int framePayloadBytesRead;
|
||||
private ChannelBuffer maskingKey;
|
||||
private ByteBuf maskingKey;
|
||||
|
||||
private final boolean allowExtensions;
|
||||
private final boolean maskedPayload;
|
||||
@ -119,7 +119,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
|
||||
|
||||
@Override
|
||||
public WebSocketFrame decode(
|
||||
ChannelHandlerContext ctx, ChannelBuffer in) throws Exception {
|
||||
ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
|
||||
// Discard all data received if closing handshake was received before.
|
||||
if (receivedClosingHandshake) {
|
||||
@ -243,7 +243,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
|
||||
// Sometimes, the payload may not be delivered in 1 nice packet
|
||||
// We need to accumulate the data until we have it all
|
||||
int rbytes = actualReadableBytes();
|
||||
ChannelBuffer payloadBuffer = null;
|
||||
ByteBuf payloadBuffer = null;
|
||||
|
||||
long willHaveReadByteCount = framePayloadBytesRead + rbytes;
|
||||
// logger.debug("Frame rbytes=" + rbytes + " willHaveReadByteCount="
|
||||
@ -359,7 +359,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
|
||||
}
|
||||
}
|
||||
|
||||
private void unmask(ChannelBuffer frame) {
|
||||
private void unmask(ByteBuf frame) {
|
||||
byte[] bytes = frame.array();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
frame.setByte(i, frame.getByte(i) ^ maskingKey.getByte(i % 4));
|
||||
@ -402,7 +402,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
|
||||
}
|
||||
|
||||
protected void checkCloseFrameBody(
|
||||
ChannelHandlerContext ctx, ChannelBuffer buffer) throws CorruptedFrameException {
|
||||
ChannelHandlerContext ctx, ByteBuf buffer) throws CorruptedFrameException {
|
||||
if (buffer == null || buffer.capacity() == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@
|
||||
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
@ -100,11 +100,11 @@ public class WebSocket08FrameEncoder extends MessageToByteEncoder<WebSocketFrame
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx,
|
||||
WebSocketFrame msg, ChannelBuffer out) throws Exception {
|
||||
WebSocketFrame msg, ByteBuf out) throws Exception {
|
||||
byte[] mask;
|
||||
|
||||
WebSocketFrame frame = msg;
|
||||
ChannelBuffer data = frame.getBinaryData();
|
||||
ByteBuf data = frame.getBinaryData();
|
||||
if (data == null) {
|
||||
data = ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Base class for web socket frames
|
||||
@ -36,19 +36,19 @@ public abstract class WebSocketFrame {
|
||||
/**
|
||||
* Contents of this frame
|
||||
*/
|
||||
private ChannelBuffer binaryData;
|
||||
private ByteBuf binaryData;
|
||||
|
||||
/**
|
||||
* Returns binary data
|
||||
*/
|
||||
public ChannelBuffer getBinaryData() {
|
||||
public ByteBuf getBinaryData() {
|
||||
return binaryData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the binary data for this frame
|
||||
*/
|
||||
public void setBinaryData(ChannelBuffer binaryData) {
|
||||
public void setBinaryData(ByteBuf binaryData) {
|
||||
this.binaryData = binaryData;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ package io.netty.handler.codec.http.websocketx;
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
|
||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
@ -154,11 +154,11 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length());
|
||||
int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
|
||||
long c = req.getContent().readLong();
|
||||
ChannelBuffer input = ChannelBuffers.buffer(16);
|
||||
ByteBuf input = ChannelBuffers.buffer(16);
|
||||
input.writeInt(a);
|
||||
input.writeInt(b);
|
||||
input.writeLong(c);
|
||||
ChannelBuffer output = ChannelBuffers.wrappedBuffer(WebSocketUtil.md5(input.array()));
|
||||
ByteBuf output = ChannelBuffers.wrappedBuffer(WebSocketUtil.md5(input.array()));
|
||||
res.setContent(output);
|
||||
} else {
|
||||
// Old Hixie 75 handshake method with no challenge:
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.handler.codec.base64.Base64;
|
||||
import io.netty.util.CharsetUtil;
|
||||
@ -68,7 +68,7 @@ final class WebSocketUtil {
|
||||
* @return encoded string
|
||||
*/
|
||||
static String base64(byte[] bytes) {
|
||||
ChannelBuffer hashed = ChannelBuffers.wrappedBuffer(bytes);
|
||||
ByteBuf hashed = ChannelBuffers.wrappedBuffer(bytes);
|
||||
return Base64.encode(hashed).toString(CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.rtsp;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.embedded.EmbeddedMessageChannel;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
@ -24,7 +24,7 @@ import io.netty.handler.codec.http.HttpMessage;
|
||||
import io.netty.handler.codec.http.HttpMessageDecoder;
|
||||
|
||||
/**
|
||||
* Decodes {@link ChannelBuffer}s into RTSP messages represented in
|
||||
* Decodes {@link ByteBuf}s into RTSP messages represented in
|
||||
* {@link HttpMessage}s.
|
||||
* <p>
|
||||
* <h3>Parameters that prevents excessive memory consumption</h3>
|
||||
@ -75,7 +75,7 @@ public abstract class RtspMessageDecoder extends HttpMessageDecoder {
|
||||
|
||||
|
||||
@Override
|
||||
public Object decode(ChannelHandlerContext ctx, ChannelBuffer buffer) throws Exception {
|
||||
public Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
|
||||
Object o = super.decode(ctx, buffer);
|
||||
if (o != null && aggregator.writeInbound(o)) {
|
||||
return aggregator.readInbound();
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.rtsp;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.UnsupportedMessageTypeException;
|
||||
@ -24,7 +24,7 @@ import io.netty.handler.codec.http.HttpMessageEncoder;
|
||||
|
||||
/**
|
||||
* Encodes an RTSP message represented in {@link HttpMessage} into
|
||||
* a {@link ChannelBuffer}.
|
||||
* a {@link ByteBuf}.
|
||||
|
||||
*
|
||||
* @apiviz.landmark
|
||||
@ -40,7 +40,7 @@ public abstract class RtspMessageEncoder extends HttpMessageEncoder {
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx, Object msg,
|
||||
ChannelBuffer out) throws Exception {
|
||||
ByteBuf out) throws Exception {
|
||||
// Ignore unrelated message types such as HttpChunk.
|
||||
if (!(msg instanceof HttpMessage)) {
|
||||
throw new UnsupportedMessageTypeException(msg, HttpMessage.class);
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package io.netty.handler.codec.rtsp;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpMessage;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
|
||||
/**
|
||||
* Decodes {@link ChannelBuffer}s into RTSP requests represented in
|
||||
* Decodes {@link ByteBuf}s into RTSP requests represented in
|
||||
* {@link HttpRequest}s.
|
||||
* <p>
|
||||
* <h3>Parameters that prevents excessive memory consumption</h3>
|
||||
|
@ -15,19 +15,19 @@
|
||||
*/
|
||||
package io.netty.handler.codec.rtsp;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.handler.codec.http.HttpMessage;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
|
||||
/**
|
||||
* Encodes an RTSP request represented in {@link HttpRequest} into
|
||||
* a {@link ChannelBuffer}.
|
||||
* a {@link ByteBuf}.
|
||||
|
||||
*/
|
||||
public class RtspRequestEncoder extends RtspMessageEncoder {
|
||||
|
||||
@Override
|
||||
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message)
|
||||
protected void encodeInitialLine(ByteBuf buf, HttpMessage message)
|
||||
throws Exception {
|
||||
HttpRequest request = (HttpRequest) message;
|
||||
buf.writeBytes(request.getMethod().toString().getBytes("ASCII"));
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.rtsp;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
import io.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpMessage;
|
||||
@ -23,7 +23,7 @@ import io.netty.handler.codec.http.HttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
|
||||
/**
|
||||
* Decodes {@link ChannelBuffer}s into RTSP responses represented in
|
||||
* Decodes {@link ByteBuf}s into RTSP responses represented in
|
||||
* {@link HttpResponse}s.
|
||||
* <p>
|
||||
* <h3>Parameters that prevents excessive memory consumption</h3>
|
||||
|
@ -15,19 +15,19 @@
|
||||
*/
|
||||
package io.netty.handler.codec.rtsp;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.handler.codec.http.HttpMessage;
|
||||
import io.netty.handler.codec.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* Encodes an RTSP response represented in {@link HttpResponse} into
|
||||
* a {@link ChannelBuffer}.
|
||||
* a {@link ByteBuf}.
|
||||
|
||||
*/
|
||||
public class RtspResponseEncoder extends RtspMessageEncoder {
|
||||
|
||||
@Override
|
||||
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message)
|
||||
protected void encodeInitialLine(ByteBuf buf, HttpMessage message)
|
||||
throws Exception {
|
||||
HttpResponse response = (HttpResponse) message;
|
||||
buf.writeBytes(response.getProtocolVersion().toString().getBytes("ASCII"));
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
@ -27,7 +27,7 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame {
|
||||
private int streamID;
|
||||
private boolean last;
|
||||
private boolean compressed;
|
||||
private ChannelBuffer data = ChannelBuffers.EMPTY_BUFFER;
|
||||
private ByteBuf data = ChannelBuffers.EMPTY_BUFFER;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
@ -73,12 +73,12 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer getData() {
|
||||
public ByteBuf getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(ChannelBuffer data) {
|
||||
public void setData(ByteBuf data) {
|
||||
if (data == null) {
|
||||
data = ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
final class SpdyCodecUtil {
|
||||
|
||||
@ -269,7 +269,7 @@ final class SpdyCodecUtil {
|
||||
/**
|
||||
* Reads a big-endian unsigned short integer from the buffer.
|
||||
*/
|
||||
static int getUnsignedShort(ChannelBuffer buf, int offset) {
|
||||
static int getUnsignedShort(ByteBuf buf, int offset) {
|
||||
return (buf.getByte(offset) & 0xFF) << 8 |
|
||||
buf.getByte(offset + 1) & 0xFF;
|
||||
}
|
||||
@ -277,7 +277,7 @@ final class SpdyCodecUtil {
|
||||
/**
|
||||
* Reads a big-endian unsigned medium integer from the buffer.
|
||||
*/
|
||||
static int getUnsignedMedium(ChannelBuffer buf, int offset) {
|
||||
static int getUnsignedMedium(ByteBuf buf, int offset) {
|
||||
return (buf.getByte(offset) & 0xFF) << 16 |
|
||||
(buf.getByte(offset + 1) & 0xFF) << 8 |
|
||||
buf.getByte(offset + 2) & 0xFF;
|
||||
@ -286,7 +286,7 @@ final class SpdyCodecUtil {
|
||||
/**
|
||||
* Reads a big-endian (31-bit) integer from the buffer.
|
||||
*/
|
||||
static int getUnsignedInt(ChannelBuffer buf, int offset) {
|
||||
static int getUnsignedInt(ByteBuf buf, int offset) {
|
||||
return (buf.getByte(offset) & 0x7F) << 24 |
|
||||
(buf.getByte(offset + 1) & 0xFF) << 16 |
|
||||
(buf.getByte(offset + 2) & 0xFF) << 8 |
|
||||
@ -296,7 +296,7 @@ final class SpdyCodecUtil {
|
||||
/**
|
||||
* Reads a big-endian signed integer from the buffer.
|
||||
*/
|
||||
static int getSignedInt(ChannelBuffer buf, int offset) {
|
||||
static int getSignedInt(ByteBuf buf, int offset) {
|
||||
return (buf.getByte(offset) & 0xFF) << 24 |
|
||||
(buf.getByte(offset + 1) & 0xFF) << 16 |
|
||||
(buf.getByte(offset + 2) & 0xFF) << 8 |
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
/**
|
||||
@ -60,12 +60,12 @@ public interface SpdyDataFrame {
|
||||
* Returns the data payload of this frame. If there is no data payload
|
||||
* {@link ChannelBuffers#EMPTY_BUFFER} is returned.
|
||||
*/
|
||||
ChannelBuffer getData();
|
||||
ByteBuf getData();
|
||||
|
||||
/**
|
||||
* 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 cannot exceed 16777215 bytes.
|
||||
*/
|
||||
void setData(ChannelBuffer data);
|
||||
void setData(ByteBuf data);
|
||||
}
|
||||
|
@ -16,14 +16,14 @@
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
|
||||
/**
|
||||
* Decodes {@link ChannelBuffer}s into SPDY Data and Control Frames.
|
||||
* Decodes {@link ByteBuf}s into SPDY Data and Control Frames.
|
||||
*/
|
||||
public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
|
||||
@ -47,7 +47,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
// Header block decoding fields
|
||||
private int headerSize;
|
||||
private int numHeaders;
|
||||
private ChannelBuffer decompressed;
|
||||
private ByteBuf decompressed;
|
||||
|
||||
private static enum State {
|
||||
READ_COMMON_HEADER,
|
||||
@ -101,7 +101,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decodeLast(ChannelHandlerContext ctx, ChannelBuffer in) throws Exception {
|
||||
public Object decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
try {
|
||||
return decode(ctx, in);
|
||||
} finally {
|
||||
@ -110,7 +110,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ChannelHandlerContext ctx, ChannelBuffer buffer) throws Exception {
|
||||
public Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
|
||||
switch(state) {
|
||||
case READ_COMMON_HEADER:
|
||||
state = readCommonHeader(buffer);
|
||||
@ -317,7 +317,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private State readCommonHeader(ChannelBuffer buffer) {
|
||||
private State readCommonHeader(ByteBuf buffer) {
|
||||
// Wait until entire header is readable
|
||||
if (buffer.readableBytes() < SPDY_HEADER_SIZE) {
|
||||
return State.READ_COMMON_HEADER;
|
||||
@ -376,7 +376,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private Object readControlFrame(ChannelBuffer buffer) {
|
||||
private Object readControlFrame(ByteBuf buffer) {
|
||||
int streamID;
|
||||
int statusCode;
|
||||
switch (type) {
|
||||
@ -435,7 +435,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private SpdyHeaderBlock readHeaderBlockFrame(ChannelBuffer buffer) {
|
||||
private SpdyHeaderBlock readHeaderBlockFrame(ByteBuf buffer) {
|
||||
int minLength;
|
||||
int streamID;
|
||||
switch (type) {
|
||||
@ -548,7 +548,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private void decodeHeaderBlock(ChannelBuffer buffer) throws Exception {
|
||||
private void decodeHeaderBlock(ByteBuf buffer) throws Exception {
|
||||
if (decompressed == null) {
|
||||
// First time we start to decode a header block
|
||||
// Initialize header block decoding fields
|
||||
|
@ -16,7 +16,7 @@
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
@ -28,7 +28,7 @@ import java.nio.ByteOrder;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Encodes a SPDY Data or Control Frame into a {@link ChannelBuffer}.
|
||||
* Encodes a SPDY Data or Control Frame into a {@link ByteBuf}.
|
||||
*/
|
||||
public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
|
||||
@ -91,11 +91,11 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx, Object msg, ChannelBuffer out) throws Exception {
|
||||
public void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
|
||||
if (msg instanceof SpdyDataFrame) {
|
||||
|
||||
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
|
||||
ChannelBuffer data = spdyDataFrame.getData();
|
||||
ByteBuf data = spdyDataFrame.getData();
|
||||
byte flags = spdyDataFrame.isLast() ? SPDY_DATA_FLAG_FIN : 0;
|
||||
out.ensureWritableBytes(SPDY_HEADER_SIZE + data.readableBytes());
|
||||
out.writeInt(spdyDataFrame.getStreamID() & 0x7FFFFFFF);
|
||||
@ -106,7 +106,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
} else if (msg instanceof SpdySynStreamFrame) {
|
||||
|
||||
SpdySynStreamFrame spdySynStreamFrame = (SpdySynStreamFrame) msg;
|
||||
ChannelBuffer data = compressHeaderBlock(
|
||||
ByteBuf data = compressHeaderBlock(
|
||||
encodeHeaderBlock(version, spdySynStreamFrame));
|
||||
byte flags = spdySynStreamFrame.isLast() ? SPDY_FLAG_FIN : 0;
|
||||
if (spdySynStreamFrame.isUnidirectional()) {
|
||||
@ -144,7 +144,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
} else if (msg instanceof SpdySynReplyFrame) {
|
||||
|
||||
SpdySynReplyFrame spdySynReplyFrame = (SpdySynReplyFrame) msg;
|
||||
ChannelBuffer data = compressHeaderBlock(
|
||||
ByteBuf data = compressHeaderBlock(
|
||||
encodeHeaderBlock(version, spdySynReplyFrame));
|
||||
byte flags = spdySynReplyFrame.isLast() ? SPDY_FLAG_FIN : 0;
|
||||
int headerBlockLength = data.readableBytes();
|
||||
@ -249,7 +249,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
} else if (msg instanceof SpdyHeadersFrame) {
|
||||
|
||||
SpdyHeadersFrame spdyHeadersFrame = (SpdyHeadersFrame) msg;
|
||||
ChannelBuffer data = compressHeaderBlock(
|
||||
ByteBuf data = compressHeaderBlock(
|
||||
encodeHeaderBlock(version, spdyHeadersFrame));
|
||||
byte flags = spdyHeadersFrame.isLast() ? SPDY_FLAG_FIN : 0;
|
||||
int headerBlockLength = data.readableBytes();
|
||||
@ -284,7 +284,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeLengthField(int version, ChannelBuffer buffer, int length) {
|
||||
private static void writeLengthField(int version, ByteBuf buffer, int length) {
|
||||
if (version < 3) {
|
||||
buffer.writeShort(length);
|
||||
} else {
|
||||
@ -292,7 +292,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private static void setLengthField(int version, ChannelBuffer buffer, int writerIndex, int length) {
|
||||
private static void setLengthField(int version, ByteBuf buffer, int writerIndex, int length) {
|
||||
if (version < 3) {
|
||||
buffer.setShort(writerIndex, length);
|
||||
} else {
|
||||
@ -300,7 +300,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private static ChannelBuffer encodeHeaderBlock(int version, SpdyHeaderBlock headerFrame)
|
||||
private static ByteBuf encodeHeaderBlock(int version, SpdyHeaderBlock headerFrame)
|
||||
throws Exception {
|
||||
Set<String> names = headerFrame.getHeaderNames();
|
||||
int numHeaders = names.size();
|
||||
@ -311,7 +311,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
throw new IllegalArgumentException(
|
||||
"header block contains too many headers");
|
||||
}
|
||||
ChannelBuffer headerBlock = ChannelBuffers.dynamicBuffer(
|
||||
ByteBuf headerBlock = ChannelBuffers.dynamicBuffer(
|
||||
ByteOrder.BIG_ENDIAN, 256);
|
||||
writeLengthField(version, headerBlock, numHeaders);
|
||||
for (String name: names) {
|
||||
@ -338,12 +338,12 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
|
||||
return headerBlock;
|
||||
}
|
||||
|
||||
private synchronized ChannelBuffer compressHeaderBlock(
|
||||
ChannelBuffer uncompressed) throws Exception {
|
||||
private synchronized ByteBuf compressHeaderBlock(
|
||||
ByteBuf uncompressed) throws Exception {
|
||||
if (uncompressed.readableBytes() == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
ChannelBuffer compressed = ChannelBuffers.dynamicBuffer();
|
||||
ByteBuf compressed = ChannelBuffers.dynamicBuffer();
|
||||
synchronized (headerBlockCompressor) {
|
||||
if (!finished) {
|
||||
headerBlockCompressor.setInput(uncompressed);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.internal.DetectionUtil;
|
||||
|
||||
abstract class SpdyHeaderBlockCompressor {
|
||||
@ -32,7 +32,7 @@ abstract class SpdyHeaderBlockCompressor {
|
||||
}
|
||||
}
|
||||
|
||||
abstract void setInput(ChannelBuffer decompressed);
|
||||
abstract void encode(ChannelBuffer compressed);
|
||||
abstract void setInput(ByteBuf decompressed);
|
||||
abstract void encode(ByteBuf compressed);
|
||||
abstract void end();
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
abstract class SpdyHeaderBlockDecompressor {
|
||||
|
||||
@ -23,7 +23,7 @@ abstract class SpdyHeaderBlockDecompressor {
|
||||
return new SpdyHeaderBlockZlibDecompressor(version);
|
||||
}
|
||||
|
||||
abstract void setInput(ChannelBuffer compressed);
|
||||
abstract void decode(ChannelBuffer decompressed) throws Exception;
|
||||
abstract void setInput(ByteBuf compressed);
|
||||
abstract void decode(ByteBuf decompressed) throws Exception;
|
||||
abstract void end();
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.handler.codec.compression.CompressionException;
|
||||
import io.netty.util.internal.jzlib.JZlib;
|
||||
import io.netty.util.internal.jzlib.ZStream;
|
||||
@ -63,7 +63,7 @@ class SpdyHeaderBlockJZlibCompressor extends SpdyHeaderBlockCompressor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInput(ChannelBuffer decompressed) {
|
||||
public void setInput(ByteBuf decompressed) {
|
||||
byte[] in = new byte[decompressed.readableBytes()];
|
||||
decompressed.readBytes(in);
|
||||
z.next_in = in;
|
||||
@ -72,7 +72,7 @@ class SpdyHeaderBlockJZlibCompressor extends SpdyHeaderBlockCompressor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelBuffer compressed) {
|
||||
public void encode(ByteBuf compressed) {
|
||||
try {
|
||||
byte[] out = new byte[(int) Math.ceil(z.next_in.length * 1.001) + 12];
|
||||
z.next_out = out;
|
||||
|
@ -16,7 +16,7 @@
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
@ -43,14 +43,14 @@ class SpdyHeaderBlockZlibCompressor extends SpdyHeaderBlockCompressor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInput(ChannelBuffer decompressed) {
|
||||
public void setInput(ByteBuf decompressed) {
|
||||
byte[] in = new byte[decompressed.readableBytes()];
|
||||
decompressed.readBytes(in);
|
||||
compressor.setInput(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelBuffer compressed) {
|
||||
public void encode(ByteBuf compressed) {
|
||||
while (!compressor.needsInput()) {
|
||||
int numBytes = compressor.deflate(out, 0, out.length, Deflater.SYNC_FLUSH);
|
||||
compressed.writeBytes(out, 0, numBytes);
|
||||
|
@ -16,7 +16,7 @@
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
@ -36,14 +36,14 @@ class SpdyHeaderBlockZlibDecompressor extends SpdyHeaderBlockDecompressor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInput(ChannelBuffer compressed) {
|
||||
public void setInput(ByteBuf compressed) {
|
||||
byte[] in = new byte[compressed.readableBytes()];
|
||||
compressed.readBytes(in);
|
||||
decompressor.setInput(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ChannelBuffer decompressed) throws Exception {
|
||||
public void decode(ByteBuf decompressed) throws Exception {
|
||||
try {
|
||||
int numBytes = decompressor.inflate(out);
|
||||
if (numBytes == 0 && decompressor.needsDictionary()) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
@ -197,14 +197,14 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<Object, HttpMessage
|
||||
return null;
|
||||
}
|
||||
|
||||
ChannelBuffer content = httpMessage.getContent();
|
||||
ByteBuf content = httpMessage.getContent();
|
||||
if (content.readableBytes() > maxContentLength - spdyDataFrame.getData().readableBytes()) {
|
||||
messageMap.remove(streamID);
|
||||
throw new TooLongFrameException(
|
||||
"HTTP content length exceeded " + maxContentLength + " bytes.");
|
||||
}
|
||||
|
||||
ChannelBuffer spdyDataFrameData = spdyDataFrame.getData();
|
||||
ByteBuf spdyDataFrameData = spdyDataFrame.getData();
|
||||
int spdyDataFrameDataLen = spdyDataFrameData.readableBytes();
|
||||
if (content == ChannelBuffers.EMPTY_BUFFER) {
|
||||
content = ChannelBuffers.dynamicBuffer(spdyDataFrameDataLen);
|
||||
|
@ -18,7 +18,7 @@ package io.netty.handler.codec.http.websocketx;
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
|
||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.DefaultChannelFuture;
|
||||
@ -71,7 +71,7 @@ public class WebSocketServerHandshaker00Test {
|
||||
req.setHeader(Names.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00");
|
||||
req.setHeader(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
|
||||
|
||||
ChannelBuffer buffer = ChannelBuffers.copiedBuffer("^n:ds[4U", Charset.defaultCharset());
|
||||
ByteBuf buffer = ChannelBuffers.copiedBuffer("^n:ds[4U", Charset.defaultCharset());
|
||||
req.setContent(buffer);
|
||||
|
||||
WebSocketServerHandshaker00 handsaker = new WebSocketServerHandshaker00("ws://example.com/chat", "chat", Integer.MAX_VALUE);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerAdapter;
|
||||
@ -31,7 +31,7 @@ public abstract class ByteToByteCodec
|
||||
@Override
|
||||
public void encode(
|
||||
ChannelHandlerContext ctx,
|
||||
ChannelBuffer in, ChannelBuffer out) throws Exception {
|
||||
ByteBuf in, ByteBuf out) throws Exception {
|
||||
ByteToByteCodec.this.encode(ctx, in, out);
|
||||
}
|
||||
};
|
||||
@ -40,7 +40,7 @@ public abstract class ByteToByteCodec
|
||||
@Override
|
||||
public void decode(
|
||||
ChannelHandlerContext ctx,
|
||||
ChannelBuffer in, ChannelBuffer out) throws Exception {
|
||||
ByteBuf in, ByteBuf out) throws Exception {
|
||||
ByteToByteCodec.this.decode(ctx, in, out);
|
||||
}
|
||||
};
|
||||
@ -70,9 +70,9 @@ public abstract class ByteToByteCodec
|
||||
|
||||
public abstract void encode(
|
||||
ChannelHandlerContext ctx,
|
||||
ChannelBuffer in, ChannelBuffer out) throws Exception;
|
||||
ByteBuf in, ByteBuf out) throws Exception;
|
||||
|
||||
public abstract void decode(
|
||||
ChannelHandlerContext ctx,
|
||||
ChannelBuffer in, ChannelBuffer out) throws Exception;
|
||||
ByteBuf in, ByteBuf out) throws Exception;
|
||||
}
|
||||
|
@ -15,21 +15,21 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundByteHandlerAdapter;
|
||||
|
||||
public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter {
|
||||
|
||||
@Override
|
||||
public void inboundBufferUpdated(ChannelHandlerContext ctx, ChannelBuffer in) throws Exception {
|
||||
public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
callDecode(ctx, in, ctx.nextOutboundByteBuffer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
ChannelBuffer in = ctx.inboundByteBuffer();
|
||||
ChannelBuffer out = ctx.nextInboundByteBuffer();
|
||||
ByteBuf in = ctx.inboundByteBuffer();
|
||||
ByteBuf out = ctx.nextInboundByteBuffer();
|
||||
if (!in.readable()) {
|
||||
callDecode(ctx, in, out);
|
||||
}
|
||||
@ -53,7 +53,7 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
|
||||
ctx.fireChannelInactive();
|
||||
}
|
||||
|
||||
private void callDecode(ChannelHandlerContext ctx, ChannelBuffer in, ChannelBuffer out) {
|
||||
private void callDecode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) {
|
||||
int oldOutSize = out.readableBytes();
|
||||
while (in.readable()) {
|
||||
int oldInSize = in.readableBytes();
|
||||
@ -77,9 +77,9 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void decode(ChannelHandlerContext ctx, ChannelBuffer in, ChannelBuffer out) throws Exception;
|
||||
public abstract void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception;
|
||||
|
||||
public void decodeLast(ChannelHandlerContext ctx, ChannelBuffer in, ChannelBuffer out) throws Exception {
|
||||
public void decodeLast(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
|
||||
decode(ctx, in, out);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundByteHandlerAdapter;
|
||||
@ -24,8 +24,8 @@ public abstract class ByteToByteEncoder extends ChannelOutboundByteHandlerAdapte
|
||||
|
||||
@Override
|
||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||
ChannelBuffer in = ctx.outboundByteBuffer();
|
||||
ChannelBuffer out = ctx.nextOutboundByteBuffer();
|
||||
ByteBuf in = ctx.outboundByteBuffer();
|
||||
ByteBuf out = ctx.nextOutboundByteBuffer();
|
||||
|
||||
int oldOutSize = out.readableBytes();
|
||||
while (in.readable()) {
|
||||
@ -50,5 +50,5 @@ public abstract class ByteToByteEncoder extends ChannelOutboundByteHandlerAdapte
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void encode(ChannelHandlerContext ctx, ChannelBuffer in, ChannelBuffer out) throws Exception;
|
||||
public abstract void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerAdapter;
|
||||
@ -32,7 +32,7 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
|
||||
@Override
|
||||
public void encode(
|
||||
ChannelHandlerContext ctx,
|
||||
OUTBOUND_IN msg, ChannelBuffer out) throws Exception {
|
||||
OUTBOUND_IN msg, ByteBuf out) throws Exception {
|
||||
ByteToMessageCodec.this.encode(ctx, msg, out);
|
||||
}
|
||||
};
|
||||
@ -41,7 +41,7 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
|
||||
new ByteToMessageDecoder<INBOUND_OUT>() {
|
||||
@Override
|
||||
public INBOUND_OUT decode(
|
||||
ChannelHandlerContext ctx, ChannelBuffer in) throws Exception {
|
||||
ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
return ByteToMessageCodec.this.decode(ctx, in);
|
||||
}
|
||||
};
|
||||
@ -71,8 +71,8 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
|
||||
|
||||
public abstract void encode(
|
||||
ChannelHandlerContext ctx,
|
||||
OUTBOUND_IN msg, ChannelBuffer out) throws Exception;
|
||||
OUTBOUND_IN msg, ByteBuf out) throws Exception;
|
||||
|
||||
public abstract INBOUND_OUT decode(
|
||||
ChannelHandlerContext ctx, ChannelBuffer in) throws Exception;
|
||||
ChannelHandlerContext ctx, ByteBuf in) throws Exception;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@ -45,7 +45,7 @@ public abstract class ByteToMessageDecoder<O> extends ChannelInboundHandlerAdapt
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
ChannelBuffer in = ctx.inboundByteBuffer();
|
||||
ByteBuf in = ctx.inboundByteBuffer();
|
||||
if (in.readable()) {
|
||||
callDecode(ctx);
|
||||
}
|
||||
@ -67,7 +67,7 @@ public abstract class ByteToMessageDecoder<O> extends ChannelInboundHandlerAdapt
|
||||
}
|
||||
|
||||
protected void callDecode(ChannelHandlerContext ctx) {
|
||||
ChannelBuffer in = ctx.inboundByteBuffer();
|
||||
ByteBuf in = ctx.inboundByteBuffer();
|
||||
|
||||
boolean decoded = false;
|
||||
for (;;) {
|
||||
@ -127,7 +127,7 @@ public abstract class ByteToMessageDecoder<O> extends ChannelInboundHandlerAdapt
|
||||
// the new handler.
|
||||
ctx.pipeline().addAfter(ctx.name(), newHandlerName, newHandler);
|
||||
|
||||
ChannelBuffer in = ctx.inboundByteBuffer();
|
||||
ByteBuf in = ctx.inboundByteBuffer();
|
||||
try {
|
||||
if (in.readable()) {
|
||||
ctx.nextInboundByteBuffer().writeBytes(ctx.inboundByteBuffer());
|
||||
@ -138,9 +138,9 @@ public abstract class ByteToMessageDecoder<O> extends ChannelInboundHandlerAdapt
|
||||
}
|
||||
}
|
||||
|
||||
public abstract O decode(ChannelHandlerContext ctx, ChannelBuffer in) throws Exception;
|
||||
public abstract O decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception;
|
||||
|
||||
public O decodeLast(ChannelHandlerContext ctx, ChannelBuffer in) throws Exception {
|
||||
public O decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
return decode(ctx, in);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.NoSuchBufferException;
|
||||
|
||||
@ -52,9 +52,9 @@ final class CodecUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg instanceof ChannelBuffer && ctx.hasNextInboundByteBuffer()) {
|
||||
ChannelBuffer altDst = ctx.nextInboundByteBuffer();
|
||||
ChannelBuffer src = (ChannelBuffer) msg;
|
||||
if (msg instanceof ByteBuf && ctx.hasNextInboundByteBuffer()) {
|
||||
ByteBuf altDst = ctx.nextInboundByteBuffer();
|
||||
ByteBuf src = (ByteBuf) msg;
|
||||
altDst.writeBytes(src, src.readerIndex(), src.readableBytes());
|
||||
return true;
|
||||
}
|
||||
@ -64,9 +64,9 @@ final class CodecUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg instanceof ChannelBuffer && ctx.hasNextOutboundByteBuffer()) {
|
||||
ChannelBuffer altDst = ctx.nextOutboundByteBuffer();
|
||||
ChannelBuffer src = (ChannelBuffer) msg;
|
||||
if (msg instanceof ByteBuf && ctx.hasNextOutboundByteBuffer()) {
|
||||
ByteBuf altDst = ctx.nextOutboundByteBuffer();
|
||||
ByteBuf src = (ByteBuf) msg;
|
||||
altDst.writeBytes(src, src.readerIndex(), src.readableBytes());
|
||||
return true;
|
||||
}
|
||||
|
@ -15,11 +15,11 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* A decoder that splits the received {@link ChannelBuffer}s by one or more
|
||||
* A decoder that splits the received {@link ByteBuf}s by one or more
|
||||
* delimiters. It is particularly useful for decoding the frames which ends
|
||||
* with a delimiter such as {@link Delimiters#nulDelimiter() NUL} or
|
||||
* {@linkplain Delimiters#lineDelimiter() newline characters}.
|
||||
@ -56,7 +56,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
*/
|
||||
public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
|
||||
private final ChannelBuffer[] delimiters;
|
||||
private final ByteBuf[] delimiters;
|
||||
private final int maxFrameLength;
|
||||
private final boolean stripDelimiter;
|
||||
private final boolean failFast;
|
||||
@ -71,7 +71,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
* the length of the frame exceeds this value.
|
||||
* @param delimiter the delimiter
|
||||
*/
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, ChannelBuffer delimiter) {
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, ByteBuf delimiter) {
|
||||
this(maxFrameLength, true, delimiter);
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
* @param delimiter the delimiter
|
||||
*/
|
||||
public DelimiterBasedFrameDecoder(
|
||||
int maxFrameLength, boolean stripDelimiter, ChannelBuffer delimiter) {
|
||||
int maxFrameLength, boolean stripDelimiter, ByteBuf delimiter) {
|
||||
this(maxFrameLength, stripDelimiter, true, delimiter);
|
||||
}
|
||||
|
||||
@ -109,10 +109,10 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
*/
|
||||
public DelimiterBasedFrameDecoder(
|
||||
int maxFrameLength, boolean stripDelimiter, boolean failFast,
|
||||
ChannelBuffer delimiter) {
|
||||
ByteBuf delimiter) {
|
||||
validateMaxFrameLength(maxFrameLength);
|
||||
validateDelimiter(delimiter);
|
||||
delimiters = new ChannelBuffer[] {
|
||||
delimiters = new ByteBuf[] {
|
||||
delimiter.slice(
|
||||
delimiter.readerIndex(), delimiter.readableBytes())
|
||||
};
|
||||
@ -129,7 +129,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
* the length of the frame exceeds this value.
|
||||
* @param delimiters the delimiters
|
||||
*/
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, ChannelBuffer... delimiters) {
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, ByteBuf... delimiters) {
|
||||
this(maxFrameLength, true, delimiters);
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
* @param delimiters the delimiters
|
||||
*/
|
||||
public DelimiterBasedFrameDecoder(
|
||||
int maxFrameLength, boolean stripDelimiter, ChannelBuffer... delimiters) {
|
||||
int maxFrameLength, boolean stripDelimiter, ByteBuf... delimiters) {
|
||||
this(maxFrameLength, stripDelimiter, true, delimiters);
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
* @param delimiters the delimiters
|
||||
*/
|
||||
public DelimiterBasedFrameDecoder(
|
||||
int maxFrameLength, boolean stripDelimiter, boolean failFast, ChannelBuffer... delimiters) {
|
||||
int maxFrameLength, boolean stripDelimiter, boolean failFast, ByteBuf... delimiters) {
|
||||
validateMaxFrameLength(maxFrameLength);
|
||||
if (delimiters == null) {
|
||||
throw new NullPointerException("delimiters");
|
||||
@ -174,9 +174,9 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
if (delimiters.length == 0) {
|
||||
throw new IllegalArgumentException("empty delimiters");
|
||||
}
|
||||
this.delimiters = new ChannelBuffer[delimiters.length];
|
||||
this.delimiters = new ByteBuf[delimiters.length];
|
||||
for (int i = 0; i < delimiters.length; i ++) {
|
||||
ChannelBuffer d = delimiters[i];
|
||||
ByteBuf d = delimiters[i];
|
||||
validateDelimiter(d);
|
||||
this.delimiters[i] = d.slice(d.readerIndex(), d.readableBytes());
|
||||
}
|
||||
@ -186,11 +186,11 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ChannelHandlerContext ctx, ChannelBuffer buffer) throws Exception {
|
||||
public Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
|
||||
// Try all delimiters and choose the delimiter which yields the shortest frame.
|
||||
int minFrameLength = Integer.MAX_VALUE;
|
||||
ChannelBuffer minDelim = null;
|
||||
for (ChannelBuffer delim: delimiters) {
|
||||
ByteBuf minDelim = null;
|
||||
for (ByteBuf delim: delimiters) {
|
||||
int frameLength = indexOf(buffer, delim);
|
||||
if (frameLength >= 0 && frameLength < minFrameLength) {
|
||||
minFrameLength = frameLength;
|
||||
@ -200,7 +200,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
|
||||
if (minDelim != null) {
|
||||
int minDelimLength = minDelim.capacity();
|
||||
ChannelBuffer frame;
|
||||
ByteBuf frame;
|
||||
|
||||
if (discardingTooLongFrame) {
|
||||
// We've just finished discarding a very large frame.
|
||||
@ -270,7 +270,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
* the first needle found in the haystack. -1 is returned if no needle is
|
||||
* found in the haystack.
|
||||
*/
|
||||
private static int indexOf(ChannelBuffer haystack, ChannelBuffer needle) {
|
||||
private static int indexOf(ByteBuf haystack, ByteBuf needle) {
|
||||
for (int i = haystack.readerIndex(); i < haystack.writerIndex(); i ++) {
|
||||
int haystackIndex = i;
|
||||
int needleIndex;
|
||||
@ -294,7 +294,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static void validateDelimiter(ChannelBuffer delimiter) {
|
||||
private static void validateDelimiter(ByteBuf delimiter) {
|
||||
if (delimiter == null) {
|
||||
throw new NullPointerException("delimiter");
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
/**
|
||||
@ -27,8 +27,8 @@ public final class Delimiters {
|
||||
* Returns a {@code NUL (0x00)} delimiter, which could be used for
|
||||
* Flash XML socket or any similar protocols.
|
||||
*/
|
||||
public static ChannelBuffer[] nulDelimiter() {
|
||||
return new ChannelBuffer[] {
|
||||
public static ByteBuf[] nulDelimiter() {
|
||||
return new ByteBuf[] {
|
||||
ChannelBuffers.wrappedBuffer(new byte[] { 0 }) };
|
||||
}
|
||||
|
||||
@ -36,8 +36,8 @@ public final class Delimiters {
|
||||
* Returns {@code CR ('\r')} and {@code LF ('\n')} delimiters, which could
|
||||
* be used for text-based line protocols.
|
||||
*/
|
||||
public static ChannelBuffer[] lineDelimiter() {
|
||||
return new ChannelBuffer[] {
|
||||
public static ByteBuf[] lineDelimiter() {
|
||||
return new ByteBuf[] {
|
||||
ChannelBuffers.wrappedBuffer(new byte[] { '\r', '\n' }),
|
||||
ChannelBuffers.wrappedBuffer(new byte[] { '\n' }),
|
||||
};
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* A decoder that splits the received {@link ChannelBuffer}s by the fixed number
|
||||
* A decoder that splits the received {@link ByteBuf}s by the fixed number
|
||||
* of bytes. For example, if you received the following four fragmented packets:
|
||||
* <pre>
|
||||
* +---+----+------+----+
|
||||
@ -55,7 +55,7 @@ public class FixedLengthFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
* @param frameLength
|
||||
* the length of the frame
|
||||
* @param allocateFullBuffer
|
||||
* <code>true</code> if the cumulative {@link ChannelBuffer} should use the
|
||||
* <code>true</code> if the cumulative {@link ByteBuf} should use the
|
||||
* {@link #frameLength} as its initial size
|
||||
*/
|
||||
public FixedLengthFrameDecoder(int frameLength, boolean allocateFullBuffer) {
|
||||
@ -78,7 +78,7 @@ public class FixedLengthFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ChannelHandlerContext ctx, ChannelBuffer in) throws Exception {
|
||||
public Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
if (in.readableBytes() < frameLength) {
|
||||
return null;
|
||||
} else {
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBufferFactory;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufFactory;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.serialization.ObjectDecoder;
|
||||
|
||||
/**
|
||||
* A decoder that splits the received {@link ChannelBuffer}s dynamically by the
|
||||
* A decoder that splits the received {@link ByteBuf}s dynamically by the
|
||||
* value of the length field in the message. It is particularly useful when you
|
||||
* decode a binary message which has an integer header field that represents the
|
||||
* length of the message body or the whole message.
|
||||
@ -54,7 +54,7 @@ import io.netty.handler.codec.serialization.ObjectDecoder;
|
||||
* <h3>2 bytes length field at offset 0, strip header</h3>
|
||||
*
|
||||
* Because we can get the length of the content by calling
|
||||
* {@link ChannelBuffer#readableBytes()}, you might want to strip the length
|
||||
* {@link ByteBuf#readableBytes()}, you might want to strip the length
|
||||
* field by specifying <tt>initialBytesToStrip</tt>. In this example, we
|
||||
* specified <tt>2</tt>, that is same with the length of the length field, to
|
||||
* strip the first two bytes.
|
||||
@ -307,7 +307,7 @@ public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ChannelHandlerContext ctx, ChannelBuffer in) throws Exception {
|
||||
public Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
if (discardingTooLongFrame) {
|
||||
long bytesToDiscard = this.bytesToDiscard;
|
||||
int localBytesToDiscard = (int) Math.min(bytesToDiscard, in.readableBytes());
|
||||
@ -386,7 +386,7 @@ public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
// extract frame
|
||||
int readerIndex = in.readerIndex();
|
||||
int actualFrameLength = frameLengthInt - initialBytesToStrip;
|
||||
ChannelBuffer frame = extractFrame(in, readerIndex, actualFrameLength);
|
||||
ByteBuf frame = extractFrame(in, readerIndex, actualFrameLength);
|
||||
in.readerIndex(readerIndex + actualFrameLength);
|
||||
return frame;
|
||||
}
|
||||
@ -413,21 +413,21 @@ public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||
|
||||
/**
|
||||
* Extract the sub-region of the specified buffer. This method is called by
|
||||
* {@link #decode(ChannelInboundHandlerContext, ChannelBuffer)} for each
|
||||
* {@link #decode(ChannelInboundHandlerContext, ByteBuf)} for each
|
||||
* frame. The default implementation returns a copy of the sub-region.
|
||||
* For example, you could override this method to use an alternative
|
||||
* {@link ChannelBufferFactory}.
|
||||
* {@link ByteBufFactory}.
|
||||
* <p>
|
||||
* If you are sure that the frame and its content are not accessed after
|
||||
* the current {@link #decode(ChannelInboundHandlerContext, ChannelBuffer)}
|
||||
* the current {@link #decode(ChannelInboundHandlerContext, ByteBuf)}
|
||||
* call returns, you can even avoid memory copy by returning the sliced
|
||||
* sub-region (i.e. <tt>return buffer.slice(index, length)</tt>).
|
||||
* It's often useful when you convert the extracted frame into an object.
|
||||
* Refer to the source code of {@link ObjectDecoder} to see how this method
|
||||
* is overridden to avoid memory copy.
|
||||
*/
|
||||
protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length) {
|
||||
ChannelBuffer frame = buffer.factory().getBuffer(length);
|
||||
protected ByteBuf extractFrame(ByteBuf buffer, int index, int length) {
|
||||
ByteBuf frame = buffer.factory().getBuffer(length);
|
||||
frame.writeBytes(buffer, index, length);
|
||||
return frame;
|
||||
}
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBufferFactory;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufFactory;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
@ -26,7 +26,7 @@ import java.nio.ByteOrder;
|
||||
* An encoder that prepends the length of the message. The length value is
|
||||
* prepended as a binary form. It is encoded in either big endian or little
|
||||
* endian depending on the default {@link ByteOrder} of the current
|
||||
* {@link ChannelBufferFactory}.
|
||||
* {@link ByteBufFactory}.
|
||||
* <p>
|
||||
* For example, <tt>{@link LengthFieldPrepender}(2)</tt> will encode the
|
||||
* following 12-bytes string:
|
||||
@ -51,7 +51,7 @@ import java.nio.ByteOrder;
|
||||
* </pre>
|
||||
*/
|
||||
@Sharable
|
||||
public class LengthFieldPrepender extends MessageToByteEncoder<ChannelBuffer> {
|
||||
public class LengthFieldPrepender extends MessageToByteEncoder<ByteBuf> {
|
||||
|
||||
private final int lengthFieldLength;
|
||||
private final boolean lengthIncludesLengthFieldLength;
|
||||
@ -98,13 +98,13 @@ public class LengthFieldPrepender extends MessageToByteEncoder<ChannelBuffer> {
|
||||
|
||||
@Override
|
||||
public boolean isEncodable(Object msg) throws Exception {
|
||||
return msg instanceof ChannelBuffer;
|
||||
return msg instanceof ByteBuf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(
|
||||
ChannelHandlerContext ctx,
|
||||
ChannelBuffer msg, ChannelBuffer out) throws Exception {
|
||||
ByteBuf msg, ByteBuf out) throws Exception {
|
||||
|
||||
int length = lengthIncludesLengthFieldLength?
|
||||
msg.readableBytes() + lengthFieldLength : msg.readableBytes();
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundMessageHandlerAdapter;
|
||||
@ -27,7 +27,7 @@ public abstract class MessageToByteEncoder<I> extends ChannelOutboundMessageHand
|
||||
@Override
|
||||
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception {
|
||||
Queue<I> in = ctx.outboundMessageBuffer();
|
||||
ChannelBuffer out = ctx.nextOutboundByteBuffer();
|
||||
ByteBuf out = ctx.nextOutboundByteBuffer();
|
||||
|
||||
boolean notify = false;
|
||||
int oldOutSize = out.readableBytes();
|
||||
@ -70,5 +70,5 @@ public abstract class MessageToByteEncoder<I> extends ChannelOutboundMessageHand
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void encode(ChannelHandlerContext ctx, I msg, ChannelBuffer out) throws Exception;
|
||||
public abstract void encode(ChannelHandlerContext ctx, I msg, ByteBuf out) throws Exception;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelBufferHolder;
|
||||
import io.netty.channel.ChannelBufferHolders;
|
||||
@ -41,7 +41,7 @@ import io.netty.util.VoidEnum;
|
||||
* {@code @Override}
|
||||
* protected Object decode({@link ChannelHandlerContext} ctx,
|
||||
* {@link Channel} channel,
|
||||
* {@link ChannelBuffer} buf) throws Exception {
|
||||
* {@link ByteBuf} buf) throws Exception {
|
||||
*
|
||||
* if (buf.readableBytes() < 4) {
|
||||
* return <strong>null</strong>;
|
||||
@ -66,7 +66,7 @@ import io.netty.util.VoidEnum;
|
||||
*
|
||||
* protected Object decode({@link ChannelHandlerContext} ctx,
|
||||
* {@link Channel} channel,
|
||||
* {@link ChannelBuffer} buf,
|
||||
* {@link ByteBuf} buf,
|
||||
* {@link VoidEnum} state) throws Exception {
|
||||
*
|
||||
* return buf.readBytes(buf.readInt());
|
||||
@ -76,7 +76,7 @@ import io.netty.util.VoidEnum;
|
||||
*
|
||||
* <h3>How does this work?</h3>
|
||||
* <p>
|
||||
* {@link ReplayingDecoder} passes a specialized {@link ChannelBuffer}
|
||||
* {@link ReplayingDecoder} passes a specialized {@link ByteBuf}
|
||||
* implementation which throws an {@link Error} of certain type when there's not
|
||||
* enough data in the buffer. In the {@code IntegerHeaderFrameDecoder} above,
|
||||
* you just assumed that there will be 4 or more bytes in the buffer when
|
||||
@ -111,7 +111,7 @@ import io.netty.util.VoidEnum;
|
||||
* private final Queue<Integer> values = new LinkedList<Integer>();
|
||||
*
|
||||
* {@code @Override}
|
||||
* public Object decode(.., {@link ChannelBuffer} buffer, ..) throws Exception {
|
||||
* public Object decode(.., {@link ByteBuf} buffer, ..) throws Exception {
|
||||
*
|
||||
* // A message contains 2 integers.
|
||||
* values.offer(buffer.readInt());
|
||||
@ -131,7 +131,7 @@ import io.netty.util.VoidEnum;
|
||||
* private final Queue<Integer> values = new LinkedList<Integer>();
|
||||
*
|
||||
* {@code @Override}
|
||||
* public Object decode(.., {@link ChannelBuffer} buffer, ..) throws Exception {
|
||||
* public Object decode(.., {@link ByteBuf} buffer, ..) throws Exception {
|
||||
*
|
||||
* // Revert the state of the variable that might have been changed
|
||||
* // since the last partial decode.
|
||||
@ -185,7 +185,7 @@ import io.netty.util.VoidEnum;
|
||||
* {@code @Override}
|
||||
* protected Object decode({@link ChannelHandlerContext} ctx,
|
||||
* {@link Channel} channel,
|
||||
* {@link ChannelBuffer} buf,
|
||||
* {@link ByteBuf} buf,
|
||||
* <b>MyDecoderState</b> state) throws Exception {
|
||||
* switch (state) {
|
||||
* case READ_LENGTH:
|
||||
@ -215,7 +215,7 @@ import io.netty.util.VoidEnum;
|
||||
* {@code @Override}
|
||||
* protected Object decode({@link ChannelHandlerContext} ctx,
|
||||
* {@link Channel} channel,
|
||||
* {@link ChannelBuffer} buf,
|
||||
* {@link ByteBuf} buf,
|
||||
* {@link VoidEnum} state) throws Exception {
|
||||
* if (!readLength) {
|
||||
* length = buf.readInt();
|
||||
@ -251,7 +251,7 @@ import io.netty.util.VoidEnum;
|
||||
* {@code @Override}
|
||||
* protected Object decode({@link ChannelHandlerContext} ctx,
|
||||
* {@link Channel} ch,
|
||||
* {@link ChannelBuffer} buf,
|
||||
* {@link ByteBuf} buf,
|
||||
* {@link VoidEnum} state) {
|
||||
* ...
|
||||
* // Decode the first message
|
||||
@ -283,7 +283,7 @@ public abstract class ReplayingDecoder<O, S extends Enum<S>> extends ByteToMessa
|
||||
static final Signal REPLAY = new Signal(ReplayingDecoder.class.getName() + ".REPLAY");
|
||||
|
||||
private final ChannelBufferHolder<Byte> in = ChannelBufferHolders.byteBuffer();
|
||||
private final ChannelBuffer cumulation = in.byteBuffer();
|
||||
private final ByteBuf cumulation = in.byteBuffer();
|
||||
private final ReplayingDecoderBuffer replayable = new ReplayingDecoderBuffer(cumulation);
|
||||
private S state;
|
||||
private int checkpoint = -1;
|
||||
@ -352,7 +352,7 @@ public abstract class ReplayingDecoder<O, S extends Enum<S>> extends ByteToMessa
|
||||
* do not need to access the internal buffer directly to write a decoder.
|
||||
* Use it only when you must use it at your own risk.
|
||||
*/
|
||||
protected ChannelBuffer internalBuffer() {
|
||||
protected ByteBuf internalBuffer() {
|
||||
return cumulation;
|
||||
}
|
||||
|
||||
@ -370,7 +370,7 @@ public abstract class ReplayingDecoder<O, S extends Enum<S>> extends ByteToMessa
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
replayable.terminate();
|
||||
ChannelBuffer in = cumulation;
|
||||
ByteBuf in = cumulation;
|
||||
if (in.readable()) {
|
||||
callDecode(ctx);
|
||||
}
|
||||
@ -395,7 +395,7 @@ public abstract class ReplayingDecoder<O, S extends Enum<S>> extends ByteToMessa
|
||||
|
||||
@Override
|
||||
protected void callDecode(ChannelHandlerContext ctx) {
|
||||
ChannelBuffer in = cumulation;
|
||||
ByteBuf in = cumulation;
|
||||
boolean decoded = false;
|
||||
while (in.readable()) {
|
||||
try {
|
||||
@ -462,7 +462,7 @@ public abstract class ReplayingDecoder<O, S extends Enum<S>> extends ByteToMessa
|
||||
}
|
||||
}
|
||||
|
||||
private void fireInboundBufferUpdated(ChannelHandlerContext ctx, ChannelBuffer in) {
|
||||
private void fireInboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) {
|
||||
checkpoint -= in.readerIndex();
|
||||
in.discardReadBytes();
|
||||
ctx.fireInboundBufferUpdated();
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBufferFactory;
|
||||
import io.netty.buffer.ChannelBufferIndexFinder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufFactory;
|
||||
import io.netty.buffer.ByteBufIndexFinder;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.Signal;
|
||||
|
||||
@ -30,11 +30,11 @@ import java.nio.channels.GatheringByteChannel;
|
||||
import java.nio.channels.ScatteringByteChannel;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
class ReplayingDecoderBuffer implements ByteBuf {
|
||||
|
||||
private static final Signal REPLAY = ReplayingDecoder.REPLAY;
|
||||
|
||||
private final ChannelBuffer buffer;
|
||||
private final ByteBuf buffer;
|
||||
private boolean terminated;
|
||||
|
||||
public static ReplayingDecoderBuffer EMPTY_BUFFER = new ReplayingDecoderBuffer(ChannelBuffers.EMPTY_BUFFER);
|
||||
@ -43,7 +43,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
EMPTY_BUFFER.terminate();
|
||||
}
|
||||
|
||||
ReplayingDecoderBuffer(ChannelBuffer buffer) {
|
||||
ReplayingDecoderBuffer(ByteBuf buffer) {
|
||||
this.buffer = buffer;
|
||||
}
|
||||
|
||||
@ -91,17 +91,17 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ChannelBuffer buffer) {
|
||||
public int compareTo(ByteBuf buffer) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy() {
|
||||
public ByteBuf copy() {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer copy(int index, int length) {
|
||||
public ByteBuf copy(int index, int length) {
|
||||
checkIndex(index, length);
|
||||
return buffer.copy(index, length);
|
||||
}
|
||||
@ -117,7 +117,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer duplicate() {
|
||||
public ByteBuf duplicate() {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@ -157,18 +157,18 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
||||
checkIndex(index, length);
|
||||
buffer.getBytes(index, dst, dstIndex, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst, int length) {
|
||||
public void getBytes(int index, ByteBuf dst, int length) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBytes(int index, ChannelBuffer dst) {
|
||||
public void getBytes(int index, ByteBuf dst) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@ -260,7 +260,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
|
||||
@Override
|
||||
public int indexOf(int fromIndex, int toIndex,
|
||||
ChannelBufferIndexFinder indexFinder) {
|
||||
ByteBufIndexFinder indexFinder) {
|
||||
int endIndex = buffer.indexOf(fromIndex, toIndex, indexFinder);
|
||||
if (endIndex < 0) {
|
||||
throw REPLAY;
|
||||
@ -278,7 +278,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytesBefore(ChannelBufferIndexFinder indexFinder) {
|
||||
public int bytesBefore(ByteBufIndexFinder indexFinder) {
|
||||
int bytes = buffer.bytesBefore(indexFinder);
|
||||
if (bytes < 0) {
|
||||
throw REPLAY;
|
||||
@ -297,7 +297,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytesBefore(int length, ChannelBufferIndexFinder indexFinder) {
|
||||
public int bytesBefore(int length, ByteBufIndexFinder indexFinder) {
|
||||
checkReadableBytes(length);
|
||||
int bytes = buffer.bytesBefore(length, indexFinder);
|
||||
if (bytes < 0) {
|
||||
@ -317,7 +317,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
|
||||
@Override
|
||||
public int bytesBefore(int index, int length,
|
||||
ChannelBufferIndexFinder indexFinder) {
|
||||
ByteBufIndexFinder indexFinder) {
|
||||
int bytes = buffer.bytesBefore(index, length, indexFinder);
|
||||
if (bytes < 0) {
|
||||
throw REPLAY;
|
||||
@ -336,7 +336,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBufferFactory factory() {
|
||||
public ByteBufFactory factory() {
|
||||
return buffer.factory();
|
||||
}
|
||||
|
||||
@ -395,18 +395,18 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readBytes(ChannelBuffer dst, int dstIndex, int length) {
|
||||
public void readBytes(ByteBuf dst, int dstIndex, int length) {
|
||||
checkReadableBytes(length);
|
||||
buffer.readBytes(dst, dstIndex, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readBytes(ChannelBuffer dst, int length) {
|
||||
public void readBytes(ByteBuf dst, int length) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readBytes(ChannelBuffer dst) {
|
||||
public void readBytes(ByteBuf dst) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@ -417,13 +417,13 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer readBytes(int length) {
|
||||
public ByteBuf readBytes(int length) {
|
||||
checkReadableBytes(length);
|
||||
return buffer.readBytes(length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer readSlice(int length) {
|
||||
public ByteBuf readSlice(int length) {
|
||||
checkReadableBytes(length);
|
||||
return buffer.readSlice(length);
|
||||
}
|
||||
@ -539,17 +539,17 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src, int length) {
|
||||
public void setBytes(int index, ByteBuf src, int length) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBytes(int index, ChannelBuffer src) {
|
||||
public void setBytes(int index, ByteBuf src) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@ -617,12 +617,12 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice() {
|
||||
public ByteBuf slice() {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer slice(int index, int length) {
|
||||
public ByteBuf slice(int index, int length) {
|
||||
checkIndex(index, length);
|
||||
return buffer.slice(index, length);
|
||||
}
|
||||
@ -701,17 +701,17 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(ChannelBuffer src, int srcIndex, int length) {
|
||||
public void writeBytes(ByteBuf src, int srcIndex, int length) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(ChannelBuffer src, int length) {
|
||||
public void writeBytes(ByteBuf src, int length) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(ChannelBuffer src) {
|
||||
public void writeBytes(ByteBuf src) {
|
||||
throw new UnreplayableOperationException();
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,11 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* An {@link Exception} which is thrown when a user calls an unsupported
|
||||
* operation on a {@link ChannelBuffer} in a {@link ReplayingDecoder}
|
||||
* operation on a {@link ByteBuf} in a {@link ReplayingDecoder}
|
||||
* implementation.
|
||||
*/
|
||||
public class UnreplayableOperationException extends UnsupportedOperationException {
|
||||
|
@ -19,12 +19,12 @@
|
||||
*/
|
||||
package io.netty.handler.codec.base64;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBufferFactory;
|
||||
import io.netty.buffer.HeapChannelBufferFactory;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufFactory;
|
||||
import io.netty.buffer.HeapByteBufFactory;
|
||||
|
||||
/**
|
||||
* Utility class for {@link ChannelBuffer} that encodes and decodes to and from
|
||||
* Utility class for {@link ByteBuf} that encodes and decodes to and from
|
||||
* <a href="http://en.wikipedia.org/wiki/Base64">Base64</a> notation.
|
||||
* <p>
|
||||
* The encoding and decoding algorithm in this class has been derived from
|
||||
@ -70,88 +70,88 @@ public final class Base64 {
|
||||
return dialect.breakLinesByDefault;
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(ChannelBuffer src) {
|
||||
public static ByteBuf encode(ByteBuf src) {
|
||||
return encode(src, Base64Dialect.STANDARD);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(ChannelBuffer src, Base64Dialect dialect) {
|
||||
public static ByteBuf encode(ByteBuf src, Base64Dialect dialect) {
|
||||
return encode(src, breakLines(dialect), dialect);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, ByteBufFactory bufferFactory) {
|
||||
return encode(src, Base64Dialect.STANDARD, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, Base64Dialect dialect, ByteBufFactory bufferFactory) {
|
||||
return encode(src, breakLines(dialect), dialect, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(ChannelBuffer src, boolean breakLines) {
|
||||
public static ByteBuf encode(ByteBuf src, boolean breakLines) {
|
||||
return encode(src, breakLines, Base64Dialect.STANDARD);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, boolean breakLines, Base64Dialect dialect) {
|
||||
return encode(src, breakLines, dialect, HeapChannelBufferFactory.getInstance());
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, boolean breakLines, Base64Dialect dialect) {
|
||||
return encode(src, breakLines, dialect, HeapByteBufFactory.getInstance());
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, boolean breakLines, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, boolean breakLines, ByteBufFactory bufferFactory) {
|
||||
return encode(src, breakLines, Base64Dialect.STANDARD, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, boolean breakLines, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, boolean breakLines, Base64Dialect dialect, ByteBufFactory bufferFactory) {
|
||||
|
||||
if (src == null) {
|
||||
throw new NullPointerException("src");
|
||||
}
|
||||
|
||||
ChannelBuffer dest = encode(
|
||||
ByteBuf dest = encode(
|
||||
src, src.readerIndex(), src.readableBytes(), breakLines, dialect, bufferFactory);
|
||||
src.readerIndex(src.writerIndex());
|
||||
return dest;
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(ChannelBuffer src, int off, int len) {
|
||||
public static ByteBuf encode(ByteBuf src, int off, int len) {
|
||||
return encode(src, off, len, Base64Dialect.STANDARD);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(ChannelBuffer src, int off, int len, Base64Dialect dialect) {
|
||||
public static ByteBuf encode(ByteBuf src, int off, int len, Base64Dialect dialect) {
|
||||
return encode(src, off, len, breakLines(dialect), dialect);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(ChannelBuffer src, int off, int len, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf encode(ByteBuf src, int off, int len, ByteBufFactory bufferFactory) {
|
||||
return encode(src, off, len, Base64Dialect.STANDARD, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, int off, int len, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, int off, int len, Base64Dialect dialect, ByteBufFactory bufferFactory) {
|
||||
return encode(src, off, len, breakLines(dialect), dialect, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, int off, int len, boolean breakLines) {
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, int off, int len, boolean breakLines) {
|
||||
return encode(src, off, len, breakLines, Base64Dialect.STANDARD);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, int off, int len,
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, int off, int len,
|
||||
boolean breakLines, Base64Dialect dialect) {
|
||||
return encode(src, off, len, breakLines, dialect, HeapChannelBufferFactory.getInstance());
|
||||
return encode(src, off, len, breakLines, dialect, HeapByteBufFactory.getInstance());
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, int off, int len,
|
||||
boolean breakLines, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, int off, int len,
|
||||
boolean breakLines, ByteBufFactory bufferFactory) {
|
||||
return encode(src, off, len, breakLines, Base64Dialect.STANDARD, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, int off, int len,
|
||||
boolean breakLines, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf encode(
|
||||
ByteBuf src, int off, int len,
|
||||
boolean breakLines, Base64Dialect dialect, ByteBufFactory bufferFactory) {
|
||||
|
||||
if (src == null) {
|
||||
throw new NullPointerException("src");
|
||||
@ -164,7 +164,7 @@ public final class Base64 {
|
||||
}
|
||||
|
||||
int len43 = len * 4 / 3;
|
||||
ChannelBuffer dest = bufferFactory.getBuffer(
|
||||
ByteBuf dest = bufferFactory.getBuffer(
|
||||
src.order(),
|
||||
len43 +
|
||||
(len % 3 > 0? 4 : 0) + // Account for padding
|
||||
@ -193,8 +193,8 @@ public final class Base64 {
|
||||
}
|
||||
|
||||
private static void encode3to4(
|
||||
ChannelBuffer src, int srcOffset, int numSigBytes,
|
||||
ChannelBuffer dest, int destOffset, Base64Dialect dialect) {
|
||||
ByteBuf src, int srcOffset, int numSigBytes,
|
||||
ByteBuf dest, int destOffset, Base64Dialect dialect) {
|
||||
|
||||
byte[] ALPHABET = alphabet(dialect);
|
||||
|
||||
@ -236,47 +236,47 @@ public final class Base64 {
|
||||
}
|
||||
}
|
||||
|
||||
public static ChannelBuffer decode(ChannelBuffer src) {
|
||||
public static ByteBuf decode(ByteBuf src) {
|
||||
return decode(src, Base64Dialect.STANDARD);
|
||||
}
|
||||
|
||||
public static ChannelBuffer decode(ChannelBuffer src, Base64Dialect dialect) {
|
||||
return decode(src, dialect, HeapChannelBufferFactory.getInstance());
|
||||
public static ByteBuf decode(ByteBuf src, Base64Dialect dialect) {
|
||||
return decode(src, dialect, HeapByteBufFactory.getInstance());
|
||||
}
|
||||
|
||||
public static ChannelBuffer decode(ChannelBuffer src, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf decode(ByteBuf src, ByteBufFactory bufferFactory) {
|
||||
return decode(src, Base64Dialect.STANDARD, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer decode(ChannelBuffer src, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf decode(ByteBuf src, Base64Dialect dialect, ByteBufFactory bufferFactory) {
|
||||
|
||||
if (src == null) {
|
||||
throw new NullPointerException("src");
|
||||
}
|
||||
|
||||
ChannelBuffer dest = decode(src, src.readerIndex(), src.readableBytes(), dialect, bufferFactory);
|
||||
ByteBuf dest = decode(src, src.readerIndex(), src.readableBytes(), dialect, bufferFactory);
|
||||
src.readerIndex(src.writerIndex());
|
||||
return dest;
|
||||
}
|
||||
|
||||
public static ChannelBuffer decode(
|
||||
ChannelBuffer src, int off, int len) {
|
||||
public static ByteBuf decode(
|
||||
ByteBuf src, int off, int len) {
|
||||
return decode(src, off, len, Base64Dialect.STANDARD);
|
||||
}
|
||||
|
||||
public static ChannelBuffer decode(
|
||||
ChannelBuffer src, int off, int len, Base64Dialect dialect) {
|
||||
return decode(src, off, len, dialect, HeapChannelBufferFactory.getInstance());
|
||||
public static ByteBuf decode(
|
||||
ByteBuf src, int off, int len, Base64Dialect dialect) {
|
||||
return decode(src, off, len, dialect, HeapByteBufFactory.getInstance());
|
||||
}
|
||||
|
||||
public static ChannelBuffer decode(
|
||||
ChannelBuffer src, int off, int len, ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf decode(
|
||||
ByteBuf src, int off, int len, ByteBufFactory bufferFactory) {
|
||||
return decode(src, off, len, Base64Dialect.STANDARD, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer decode(
|
||||
ChannelBuffer src, int off, int len, Base64Dialect dialect,
|
||||
ChannelBufferFactory bufferFactory) {
|
||||
public static ByteBuf decode(
|
||||
ByteBuf src, int off, int len, Base64Dialect dialect,
|
||||
ByteBufFactory bufferFactory) {
|
||||
|
||||
if (src == null) {
|
||||
throw new NullPointerException("src");
|
||||
@ -291,7 +291,7 @@ public final class Base64 {
|
||||
byte[] DECODABET = decodabet(dialect);
|
||||
|
||||
int len34 = len * 3 / 4;
|
||||
ChannelBuffer dest = bufferFactory.getBuffer(src.order(), len34); // Upper limit on size of output
|
||||
ByteBuf dest = bufferFactory.getBuffer(src.order(), len34); // Upper limit on size of output
|
||||
int outBuffPosn = 0;
|
||||
|
||||
byte[] b4 = new byte[4];
|
||||
@ -329,7 +329,7 @@ public final class Base64 {
|
||||
|
||||
private static int decode4to3(
|
||||
byte[] src, int srcOffset,
|
||||
ChannelBuffer dest, int destOffset, Base64Dialect dialect) {
|
||||
ByteBuf dest, int destOffset, Base64Dialect dialect) {
|
||||
|
||||
byte[] DECODABET = decodabet(dialect);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.base64;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
@ -25,8 +25,8 @@ import io.netty.handler.codec.Delimiters;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
|
||||
/**
|
||||
* Decodes a Base64-encoded {@link ChannelBuffer} or US-ASCII {@link String}
|
||||
* into a {@link ChannelBuffer}. Please note that this decoder must be used
|
||||
* Decodes a Base64-encoded {@link ByteBuf} or US-ASCII {@link String}
|
||||
* into a {@link ByteBuf}. Please note that this decoder must be used
|
||||
* with a proper {@link ByteToMessageDecoder} such as {@link DelimiterBasedFrameDecoder}
|
||||
* if you are using a stream-based transport such as TCP/IP. A typical decoder
|
||||
* setup for TCP/IP would be:
|
||||
@ -44,7 +44,7 @@ import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
* @apiviz.uses io.netty.handler.codec.base64.Base64
|
||||
*/
|
||||
@Sharable
|
||||
public class Base64Decoder extends MessageToMessageDecoder<ChannelBuffer, ChannelBuffer> {
|
||||
public class Base64Decoder extends MessageToMessageDecoder<ByteBuf, ByteBuf> {
|
||||
|
||||
private final Base64Dialect dialect;
|
||||
|
||||
@ -61,11 +61,11 @@ public class Base64Decoder extends MessageToMessageDecoder<ChannelBuffer, Channe
|
||||
|
||||
@Override
|
||||
public boolean isDecodable(Object msg) throws Exception {
|
||||
return msg instanceof ChannelBuffer;
|
||||
return msg instanceof ByteBuf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelBuffer decode(ChannelHandlerContext ctx, ChannelBuffer msg) throws Exception {
|
||||
public ByteBuf decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
|
||||
return Base64.decode(msg, msg.readerIndex(), msg.readableBytes(), dialect);
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user