I’m writing a Hadoop/HBase job. I needed to transform a Java String into a byte array. Is there any differences between Java’s String.getBytes() and Hadoop’s Bytes.toBytes()?
I’m writing a Hadoop/HBase job. I needed to transform a Java String into a
Share
According to its documentation
Bytes.toBytes()converts the parameter to abyte[]using UTF-8.String.getBytes()(without arguments) will convert theStringtobyte[]using the platform default encoding. That encoding can vary depending on the OS and user settings. Use of that method should generally be avoided.You could use
String.getBytes(String)(or theCharsetvariant) to specify the encoding to be used.