[#1943] Unpooled.copiedBuffer(ByteBuf pooled) should always return unpooled ByteBuf
This commit is contained in:
parent
ceab146b54
commit
4ce49a6195
@ -408,8 +408,16 @@ public final class Unpooled {
|
|||||||
* respectively.
|
* respectively.
|
||||||
*/
|
*/
|
||||||
public static ByteBuf copiedBuffer(ByteBuf buffer) {
|
public static ByteBuf copiedBuffer(ByteBuf buffer) {
|
||||||
if (buffer.isReadable()) {
|
int readable = buffer.readableBytes();
|
||||||
return buffer.copy();
|
if (readable > 0) {
|
||||||
|
ByteBuf copy;
|
||||||
|
if (buffer.isDirect()) {
|
||||||
|
copy = directBuffer(readable);
|
||||||
|
} else {
|
||||||
|
copy = buffer(readable);
|
||||||
|
}
|
||||||
|
copy.writeBytes(buffer, buffer.readerIndex(), readable);
|
||||||
|
return copy;
|
||||||
} else {
|
} else {
|
||||||
return EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user