You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by ChingShen <ch...@gmail.com> on 2009/10/31 16:02:43 UTC
Why does the "getBytes()" method of org.apache.hadoop.io.Text not
return actually bytes?
Hi,
I use the org.apache.hadoop.io.Text object to set its value "測試" in
chinese text(six bytes in UTF-8 encoding), and when I invoke its
"getBytes()" method that return the raw bytes (11 bytes), but it's actually
only six bytes. I knew that object involves the "getLength()" method.
My question is that the "getBytes()" method why not return actually bytes?
Why should not be:
public byte[] getBytes() {
//return bytes
return Arrays.copyOf(bytes,getLength());
}
thanks in advance
Shen
Re: Why does the "getBytes()" method of org.apache.hadoop.io.Text not
return actually bytes?
Posted by Todd Lipcon <to...@cloudera.com>.
On Sat, Oct 31, 2009 at 8:02 AM, ChingShen <ch...@gmail.com> wrote:
> Hi,
>
> I use the org.apache.hadoop.io.Text object to set its value "測試" in
> chinese text(six bytes in UTF-8 encoding), and when I invoke its
> "getBytes()" method that return the raw bytes (11 bytes), but it's actually
> only six bytes. I knew that object involves the "getLength()" method.
> My question is that the "getBytes()" method why not return actually bytes?
>
> Why should not be:
> public byte[] getBytes() {
> //return bytes
> return Arrays.copyOf(bytes,getLength());
> }
>
>
Simply to avoid the extra copy which slows down performance needlessly for a
lot of use cases. You're always free to do this yourself.
-Todd