Respect ByteBuffer position and limits in ByteUtils.getBytes(ByteBuffer).
We now properly extract the byte array from a ByteBuffer by copying its content respecting the read position and limits. Closes #2204 Original Pull Request: #2213
This commit is contained in:
committed by
Christoph Strobl
parent
9a56c38e2c
commit
3ca2191445
@@ -129,7 +129,8 @@ public final class ByteUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a byte array from {@link ByteBuffer} without consuming it.
|
||||
* Extract a byte array from {@link ByteBuffer} without consuming it. The resulting {@code byte[]} is a copy of the
|
||||
* buffer's contents and not updated upon changes within the buffer.
|
||||
*
|
||||
* @param byteBuffer must not be {@literal null}.
|
||||
* @return
|
||||
@@ -139,10 +140,6 @@ public final class ByteUtils {
|
||||
|
||||
Assert.notNull(byteBuffer, "ByteBuffer must not be null!");
|
||||
|
||||
if (byteBuffer.hasArray()) {
|
||||
return byteBuffer.array();
|
||||
}
|
||||
|
||||
ByteBuffer duplicate = byteBuffer.duplicate();
|
||||
byte[] bytes = new byte[duplicate.remaining()];
|
||||
duplicate.get(bytes);
|
||||
|
||||
Reference in New Issue
Block a user