Package com.facebook.openwifi.rrm
Class Utils
- java.lang.Object
-
- com.facebook.openwifi.rrm.Utils
-
public class Utils extends Object
Generic utility methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUtils.LruCache<K,V>Simple LRU cache, adapted from: https://stackoverflow.com/a/1953516static classUtils.NamedThreadFactoryThread factory based on DefaultThreadFactory supporting name prefix.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbytesToHex(byte[] b)Return a hex representation of the given byte array.static <T> TdeepCopy(T obj, Class<T> classOfT)Return a deep copy using gson.static StringgenerateServiceKey(RRMConfig.ServiceConfig serviceConfig)Generate the RRM service key.static voidjsonMerge(org.json.JSONObject a, org.json.JSONObject b)Recursively merge JSONObject 'b' into 'a'.static StringlongToMac(long addr)Convert a MAC address in integer (6-byte) representation to string notation.static longmacToLong(String addr)Convert a MAC address to an integer (6-byte) representation.static StringreadFile(File f)Read a file to a UTF-8 string.static StringreadResourceToString(String path)Read a resource to a UTF-8 string.static voidwriteFile(File f, String s)Write a string to a file.static voidwriteJsonFile(File f, Object o)Write an object to a file as pretty-printed JSON.
-
-
-
Method Detail
-
readFile
public static String readFile(File f) throws IOException
Read a file to a UTF-8 string.- Throws:
IOException
-
writeFile
public static void writeFile(File f, String s) throws FileNotFoundException
Write a string to a file.- Throws:
FileNotFoundException
-
writeJsonFile
public static void writeJsonFile(File f, Object o) throws FileNotFoundException
Write an object to a file as pretty-printed JSON.- Throws:
FileNotFoundException
-
readResourceToString
public static String readResourceToString(String path)
Read a resource to a UTF-8 string.
-
jsonMerge
public static void jsonMerge(org.json.JSONObject a, org.json.JSONObject b)Recursively merge JSONObject 'b' into 'a'.
-
macToLong
public static long macToLong(String addr) throws IllegalArgumentException
Convert a MAC address to an integer (6-byte) representation. If the MAC address could not be parsed, throws IllegalArgumentException.- Throws:
IllegalArgumentException
-
longToMac
public static String longToMac(long addr)
Convert a MAC address in integer (6-byte) representation to string notation.
-
bytesToHex
public static String bytesToHex(byte[] b)
Return a hex representation of the given byte array.
-
deepCopy
public static <T> T deepCopy(T obj, Class<T> classOfT)Return a deep copy using gson. DO NOT USE if performance is critical.
-
generateServiceKey
public static String generateServiceKey(RRMConfig.ServiceConfig serviceConfig)
Generate the RRM service key.
-
-