Skip to content

Instantly share code, notes, and snippets.

@sujee
Created August 26, 2011 23:38
Show Gist options
  • Save sujee/1174701 to your computer and use it in GitHub Desktop.
Save sujee/1174701 to your computer and use it in GitHub Desktop.
HBase utilities : Bytes.toBytes
// -------- Bytes.toBytes() : converting objects to bytes ------
int i = 10000;
byte [] intBytes = Bytes.toBytes(i);
System.out.println ("int " + i + " in bytes : " + Arrays.toString(intBytes));
float f = (float) 999.993;
byte [] floatBytes = Bytes.toBytes(f);
System.out.println ("float " + f + " in bytes : " + Arrays.toString(floatBytes));
String s = "foobar";
byte [] stringBytes = Bytes.toBytes(s);
System.out.println ("string " + s + " in bytes : " + Arrays.toString(stringBytes));
/* output:
int 10000 in bytes : [0, 0, 39, 16]
float 999.993 in bytes : [68, 121, -1, -115]
string foobar in bytes : [102, 111, 111, 98, 97, 114]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment