File tree Expand file tree Collapse file tree
src/main/java/io/appulse/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232public final class BytesUtil {
3333
3434 public static byte [] asBytes (char value ) {
35- return ByteBuffer .allocate (Character .BYTES ).putChar (value ).array ();
35+ return new byte [] {
36+ (byte ) (value >> 8 ),
37+ (byte ) value
38+ };
3639 }
3740
3841 public static byte [] asBytes (byte value ) {
3942 return new byte [] { value };
4043 }
4144
4245 public static byte [] asBytes (short value ) {
43- return ByteBuffer .allocate (Short .BYTES ).putShort (value ).array ();
46+ return new byte [] {
47+ (byte ) (value >> 8 ),
48+ (byte ) value
49+ };
4450 }
4551
4652 public static byte [] asBytes (int value ) {
47- return ByteBuffer .allocate (Integer .BYTES ).putInt (value ).array ();
53+ return new byte [] {
54+ (byte ) (value >> 24 ),
55+ (byte ) (value >> 16 ),
56+ (byte ) (value >> 8 ),
57+ (byte ) value
58+ };
4859 }
4960
5061 public static byte [] asBytes (long value ) {
51- return ByteBuffer .allocate (Long .BYTES ).putLong (value ).array ();
62+ return new byte [] {
63+ (byte ) (value >> 56 ),
64+ (byte ) (value >> 48 ),
65+ (byte ) (value >> 40 ),
66+ (byte ) (value >> 32 ),
67+ (byte ) (value >> 24 ),
68+ (byte ) (value >> 16 ),
69+ (byte ) (value >> 8 ),
70+ (byte ) value
71+ };
5272 }
5373
5474 public static byte [] asBytes (float value ) {
55- return ByteBuffer . allocate (Float .BYTES ). putFloat (value ). array ( );
75+ return asBytes (Float .floatToRawIntBits (value ));
5676 }
5777
5878 public static byte [] asBytes (double value ) {
59- return ByteBuffer . allocate (Double .BYTES ). putDouble (value ). array ( );
79+ return asBytes (Double .doubleToRawLongBits (value ));
6080 }
6181
6282 public static int asInteger (@ NonNull ByteBuffer buffer , int length ) {
You can’t perform that action at this time.
0 commit comments