org.usergrid.utils
Class ConversionUtils

java.lang.Object
  extended by org.usergrid.utils.ConversionUtils

public class ConversionUtils
extends Object

Convenience methods for converting to and from formats, primarily between byte arrays and UUIDs, Strings, and Longs.


Field Summary
static String ASCII_ENCODING
           
static ByteBuffer HOLDER
           
static String UTF8_ENCODING
           
 
Constructor Summary
ConversionUtils()
           
 
Method Summary
static ByteBuffer appendToByteBuffer(ByteBuffer bb, byte[] bytes, int len)
           
static byte[] ascii(String s)
           
 ByteBuffer asciibuffer(String s)
           
static ByteBuffer bytebuffer(Boolean b)
           
static ByteBuffer bytebuffer(byte[] bytes)
           
static ByteBuffer bytebuffer(ByteBuffer bytes)
           
static ByteBuffer bytebuffer(Long val)
           
static ByteBuffer bytebuffer(Object obj)
           
static ByteBuffer bytebuffer(String s)
           
static ByteBuffer bytebuffer(String s, String encoding)
           
static ByteBuffer bytebuffer(UUID uuid)
           
static List<ByteBuffer> bytebuffers(List<?> l)
           
static byte[] bytes(Boolean b)
           
static byte[] bytes(ByteBuffer bb)
           
static byte[] bytes(Long val)
           
static byte[] bytes(Object obj)
           
static byte[] bytes(String s)
           
static byte[] bytes(String s, String encoding)
           
static byte[] bytes(UUID uuid)
           
static Object coerce(Class<?> type, Object obj)
           
static Map<String,Object> coerceMap(Map<String,Class<?>> types, Map<String,Object> values)
           
static boolean getBoolean(byte[] bytes)
           
static boolean getBoolean(byte[] bytes, int offset)
           
static boolean getBoolean(ByteBuffer bytes)
           
static boolean getBoolean(Object obj)
           
static double getDouble(byte[] bytes)
           
static double getDouble(ByteBuffer bytes)
           
static double getDouble(Object obj)
           
static float getFloat(byte[] bytes)
           
static float getFloat(ByteBuffer bytes)
           
static float getFloat(Object obj)
           
static int getInt(byte[] bytes)
           
static int getInt(ByteBuffer bytes)
           
static int getInt(Object obj)
           
static long getLong(byte[] bytes)
           
static long getLong(ByteBuffer bytes)
           
static long getLong(Object obj)
           
static Object object(Class<?> type, byte[] bytes)
           
static Object object(Class<?> type, ByteBuffer bytes)
           
static String string(byte[] bytes)
           
static String string(byte[] bytes, int offset, int length)
           
static String string(byte[] bytes, int offset, int length, String encoding)
           
static String string(ByteBuffer bytes)
           
static String string(Object obj)
           
static String stringFromLong(byte[] bytes, int offset)
           
static
<T> List<String>
strings(Collection<T> items)
           
static UUID uuid(byte[] uuid)
           
static UUID uuid(byte[] uuid, int offset)
           
static UUID uuid(ByteBuffer bb)
           
static UUID uuid(Object obj)
           
static UUID uuid(Object obj, UUID defaultValue)
           
static UUID uuid(String uuid)
           
static byte[] uuidToBytesNullOk(UUID uuid)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF8_ENCODING

public static final String UTF8_ENCODING
See Also:
Constant Field Values

ASCII_ENCODING

public static final String ASCII_ENCODING
See Also:
Constant Field Values

HOLDER

public static final ByteBuffer HOLDER
Constructor Detail

ConversionUtils

public ConversionUtils()
Method Detail

uuid

public static UUID uuid(byte[] uuid)
Parameters:
uuid -
Returns:

uuid

public static UUID uuid(byte[] uuid,
                        int offset)
Parameters:
uuid -
offset -
Returns:

uuid

public static UUID uuid(ByteBuffer bb)

uuid

public static UUID uuid(String uuid)
Parameters:
uuid -
Returns:

uuid

public static UUID uuid(Object obj)
Parameters:
obj -
Returns:

uuid

public static UUID uuid(Object obj,
                        UUID defaultValue)

bytes

public static byte[] bytes(UUID uuid)
Parameters:
uuid -
Returns:

bytebuffer

public static ByteBuffer bytebuffer(UUID uuid)

uuidToBytesNullOk

public static byte[] uuidToBytesNullOk(UUID uuid)
Parameters:
uuid -
Returns:

bytes

public static byte[] bytes(String s)
Parameters:
s -
Returns:

bytebuffer

public static ByteBuffer bytebuffer(String s)

ascii

public static byte[] ascii(String s)
Parameters:
s -
Returns:

asciibuffer

public ByteBuffer asciibuffer(String s)

bytes

public static byte[] bytes(String s,
                           String encoding)
Parameters:
s -
encoding -
Returns:

bytes

public static byte[] bytes(ByteBuffer bb)

bytebuffer

public static ByteBuffer bytebuffer(String s,
                                    String encoding)

bytes

public static byte[] bytes(Boolean b)
Parameters:
b -
Returns:

bytebuffer

public static ByteBuffer bytebuffer(Boolean b)

bytes

public static byte[] bytes(Long val)
Parameters:
val -
Returns:

bytebuffer

public static ByteBuffer bytebuffer(Long val)

bytes

public static byte[] bytes(Object obj)
Parameters:
obj -
Returns:

bytebuffer

public static ByteBuffer bytebuffer(byte[] bytes)

bytebuffer

public static ByteBuffer bytebuffer(ByteBuffer bytes)

bytebuffer

public static ByteBuffer bytebuffer(Object obj)

bytebuffers

public static List<ByteBuffer> bytebuffers(List<?> l)

getBoolean

public static boolean getBoolean(byte[] bytes)
Parameters:
bytes -
Returns:

getBoolean

public static boolean getBoolean(ByteBuffer bytes)

getBoolean

public static boolean getBoolean(byte[] bytes,
                                 int offset)
Parameters:
bytes -
offset -
Returns:

getBoolean

public static boolean getBoolean(Object obj)

string

public static String string(Object obj)
Parameters:
obj -
Returns:

string

public static String string(byte[] bytes)
Parameters:
bytes -
Returns:

string

public static String string(ByteBuffer bytes)

string

public static String string(byte[] bytes,
                            int offset,
                            int length)
Parameters:
bytes -
offset -
length -
Returns:

string

public static String string(byte[] bytes,
                            int offset,
                            int length,
                            String encoding)
Parameters:
bytes -
offset -
length -
encoding -
Returns:

strings

public static <T> List<String> strings(Collection<T> items)

stringFromLong

public static String stringFromLong(byte[] bytes,
                                    int offset)
Parameters:
bytes -
offset -
Returns:

getLong

public static long getLong(byte[] bytes)
Parameters:
bytes -
Returns:

getLong

public static long getLong(ByteBuffer bytes)

getLong

public static long getLong(Object obj)

getInt

public static int getInt(byte[] bytes)
Parameters:
bytes -
Returns:

getInt

public static int getInt(ByteBuffer bytes)

getInt

public static int getInt(Object obj)

getFloat

public static float getFloat(byte[] bytes)
Parameters:
bytes -
Returns:

getFloat

public static float getFloat(ByteBuffer bytes)

getFloat

public static float getFloat(Object obj)

getDouble

public static double getDouble(byte[] bytes)

getDouble

public static double getDouble(ByteBuffer bytes)

getDouble

public static double getDouble(Object obj)

object

public static Object object(Class<?> type,
                            byte[] bytes)
Parameters:
type -
bytes -
Returns:

object

public static Object object(Class<?> type,
                            ByteBuffer bytes)

appendToByteBuffer

public static ByteBuffer appendToByteBuffer(ByteBuffer bb,
                                            byte[] bytes,
                                            int len)
Parameters:
bb -
bytes -
len -
Returns:

coerce

public static Object coerce(Class<?> type,
                            Object obj)

coerceMap

public static Map<String,Object> coerceMap(Map<String,Class<?>> types,
                                           Map<String,Object> values)


Copyright © 2013. All Rights Reserved.