Created
August 26, 2011 23:38
-
-
Save sujee/1174701 to your computer and use it in GitHub Desktop.
HBase utilities : Bytes.toBytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------- 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