Skip to content

Commit

Permalink
fix readFrom bytebuffer error (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
schernichkin authored Nov 25, 2022
1 parent 6baebc6 commit 400d232
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public int readFrom(byte[] src, int srcOffset, long destOffset, int length) {
* @return the number of bytes read
*/
public int readFrom(ByteBuffer src, long destOffset) {
if (src.remaining() + destOffset >= size())
if (src.remaining() + destOffset > size())
throw new BufferOverflowException();
int readLen = src.remaining();
ByteBuffer b = toDirectByteBuffer(destOffset, readLen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,12 @@ class LBufferTest extends LArraySpec {

}

"read from ByteBuffer" in {
val bytes = Array[Byte](1, 2, 3)
val byteBuffer = ByteBuffer.wrap(bytes)
val lbuffer = new LBuffer(3)
lbuffer.readFrom(byteBuffer, 0)
byteBuffer.array() === lbuffer.toArray
}
}
}

0 comments on commit 400d232

Please sign in to comment.