@Test public void testBytes() { byte[] bytes = ConversionUtils.bytes( true ); assertNotNull( "bytes() on boolean true returned null", bytes ); assertTrue( "bytes() on boolean true returned wrong size byte array:" + bytes.length, bytes.length == 1 ); assertTrue( "bytes() on boolean true returned wrong value:" + bytes[0], bytes[0] == 1 ); bytes = ConversionUtils.bytes( false ); assertNotNull( "bytes() on boolean false returned null", bytes ); assertTrue( "bytes() on boolean false returned wrong size byte array:" + bytes.length, bytes.length == 1 ); assertTrue( "bytes() on boolean false returned wrong value:" + bytes[0], bytes[0] == 0 ); bytes = ConversionUtils.bytes( new UUID( 0, 0 ) ); assertNotNull( "bytes() on uuid(0, 0) returned null", bytes ); assertTrue( "bytes() on uuid(0, 0) returned wrong size byte array:" + bytes.length, bytes.length == 16 ); for ( byte b : bytes ) { assertTrue( "bytes() on uuid(0, 0) returned wrong value:" + b, b == 0 ); } }
public static byte[] bytes( UUID uuid ) { if ( uuid == null ) { return null; } long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for ( int i = 0; i < 8; i++ ) { buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) ); } for ( int i = 8; i < 16; i++ ) { buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) ); } return buffer; }
ConversionUtils { public static byte[] bytes( UUID uuid ) { if ( uuid == null ) { return null; } long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for ( int i = 0; i < 8; i++ ) { buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) ); } for ( int i = 8; i < 16; i++ ) { buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) ); } return buffer; } }
ConversionUtils { public static byte[] bytes( UUID uuid ) { if ( uuid == null ) { return null; } long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for ( int i = 0; i < 8; i++ ) { buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) ); } for ( int i = 8; i < 16; i++ ) { buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) ); } return buffer; }  }
ConversionUtils { public static byte[] bytes( UUID uuid ) { if ( uuid == null ) { return null; } long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for ( int i = 0; i < 8; i++ ) { buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) ); } for ( int i = 8; i < 16; i++ ) { buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) ); } return buffer; }  static UUID uuid( byte[] uuid ); static UUID uuid( byte[] uuid, int offset ); static UUID uuid( ByteBuffer bb ); static UUID uuid( String uuid ); static UUID uuid( Object obj ); static UUID uuid( Object obj, UUID defaultValue ); static byte[] bytes( UUID uuid ); static ByteBuffer bytebuffer( UUID uuid ); static byte[] uuidToBytesNullOk( UUID uuid ); static byte[] bytes( String s ); static ByteBuffer bytebuffer( String s ); static byte[] ascii( String s ); ByteBuffer asciibuffer( String s ); static byte[] bytes( String s, String encoding ); static byte[] bytes( ByteBuffer bb ); static ByteBuffer bytebuffer( String s, String encoding ); static byte[] bytes( Boolean b ); static ByteBuffer bytebuffer( Boolean b ); static byte[] bytes( Long val ); static ByteBuffer bytebuffer( Long val ); static byte[] bytes( Object obj ); static ByteBuffer bytebuffer( byte[] bytes ); static ByteBuffer bytebuffer( ByteBuffer bytes ); static ByteBuffer bytebuffer( Object obj ); static List<ByteBuffer> bytebuffers( List<?> l ); static boolean getBoolean( byte[] bytes ); static boolean getBoolean( ByteBuffer bytes ); static boolean getBoolean( byte[] bytes, int offset ); static boolean getBoolean( Object obj ); static String string( Object obj ); static String string( byte[] bytes ); static String string( ByteBuffer bytes ); static String string( byte[] bytes, int offset, int length ); static String string( byte[] bytes, int offset, int length, String encoding ); static List<String> strings( Collection<T> items ); static String stringFromLong( byte[] bytes, int offset ); static long getLong( byte[] bytes ); static long getLong( ByteBuffer bytes ); static long getLong( Object obj ); static int getInt( byte[] bytes ); static int getInt( ByteBuffer bytes ); static int getInt( Object obj ); static float getFloat( byte[] bytes ); static float getFloat( ByteBuffer bytes ); static float getFloat( Object obj ); static double getDouble( byte[] bytes ); static double getDouble( ByteBuffer bytes ); static double getDouble( Object obj ); static Object object( Class<?> type, byte[] bytes ); static Object object( Class<?> type, ByteBuffer bytes ); static ByteBuffer appendToByteBuffer( ByteBuffer bb, byte[] bytes, int len ); static Object coerce( Class<?> type, Object obj ); static Map<String, Object> coerceMap( Map<String, Class<?>> types, Map<String, Object> values ); }
ConversionUtils { public static byte[] bytes( UUID uuid ) { if ( uuid == null ) { return null; } long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for ( int i = 0; i < 8; i++ ) { buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) ); } for ( int i = 8; i < 16; i++ ) { buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) ); } return buffer; }  static UUID uuid( byte[] uuid ); static UUID uuid( byte[] uuid, int offset ); static UUID uuid( ByteBuffer bb ); static UUID uuid( String uuid ); static UUID uuid( Object obj ); static UUID uuid( Object obj, UUID defaultValue ); static byte[] bytes( UUID uuid ); static ByteBuffer bytebuffer( UUID uuid ); static byte[] uuidToBytesNullOk( UUID uuid ); static byte[] bytes( String s ); static ByteBuffer bytebuffer( String s ); static byte[] ascii( String s ); ByteBuffer asciibuffer( String s ); static byte[] bytes( String s, String encoding ); static byte[] bytes( ByteBuffer bb ); static ByteBuffer bytebuffer( String s, String encoding ); static byte[] bytes( Boolean b ); static ByteBuffer bytebuffer( Boolean b ); static byte[] bytes( Long val ); static ByteBuffer bytebuffer( Long val ); static byte[] bytes( Object obj ); static ByteBuffer bytebuffer( byte[] bytes ); static ByteBuffer bytebuffer( ByteBuffer bytes ); static ByteBuffer bytebuffer( Object obj ); static List<ByteBuffer> bytebuffers( List<?> l ); static boolean getBoolean( byte[] bytes ); static boolean getBoolean( ByteBuffer bytes ); static boolean getBoolean( byte[] bytes, int offset ); static boolean getBoolean( Object obj ); static String string( Object obj ); static String string( byte[] bytes ); static String string( ByteBuffer bytes ); static String string( byte[] bytes, int offset, int length ); static String string( byte[] bytes, int offset, int length, String encoding ); static List<String> strings( Collection<T> items ); static String stringFromLong( byte[] bytes, int offset ); static long getLong( byte[] bytes ); static long getLong( ByteBuffer bytes ); static long getLong( Object obj ); static int getInt( byte[] bytes ); static int getInt( ByteBuffer bytes ); static int getInt( Object obj ); static float getFloat( byte[] bytes ); static float getFloat( ByteBuffer bytes ); static float getFloat( Object obj ); static double getDouble( byte[] bytes ); static double getDouble( ByteBuffer bytes ); static double getDouble( Object obj ); static Object object( Class<?> type, byte[] bytes ); static Object object( Class<?> type, ByteBuffer bytes ); static ByteBuffer appendToByteBuffer( ByteBuffer bb, byte[] bytes, int len ); static Object coerce( Class<?> type, Object obj ); static Map<String, Object> coerceMap( Map<String, Class<?>> types, Map<String, Object> values ); static final String UTF8_ENCODING; static final String ASCII_ENCODING; static final ByteBuffer HOLDER; }