Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions core/src/main/scala/kafka/utils/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,18 @@ object Utils {

/**
* Read a byte array from the given offset and size in the buffer
* TODO: Should use System.arraycopy
*/
def readBytes(buffer: ByteBuffer, offset: Int, size: Int): Array[Byte] = {
val bytes = new Array[Byte](size)
var i = 0
while(i < size) {
bytes(i) = buffer.get(offset + i)
i += 1
// Save the current position
val oldPosition = buffer.position()
try {
// Set position to the offset and use bulk get
buffer.position(offset)
buffer.get(bytes)
} finally {
// Restore the original position
buffer.position(oldPosition)
}
bytes
}
Expand Down