+1 on something like getValidBytes(). Just the existence of this would
warn many programmers about getBytes().
Raghu.
Owen O'Malley wrote:
On Feb 6, 2009, at 8:52 AM, Bhupesh Bansal wrote:
Hey Tom,
I got also burned by this ?? Why does BytesWritable.getBytes() returns
non-vaild bytes ?? Or we should add a BytesWritable.getValidBytes()
kind of function.
It does it because continually resizing the array to the "valid" length
is very expensive. It would be a reasonable patch to add a
getValidBytes, but most methods in Java's libraries are aware of this
and let you pass in byte[], offset, and length. So once you realize what
the problem is, you can work around it.
-- Owen