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 class
Utils.LruCache<K,V>
Simple LRU cache, adapted from: https://stackoverflow.com/a/1953516static class
Utils.NamedThreadFactory
Thread factory based on DefaultThreadFactory supporting name prefix.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
bytesToHex(byte[] b)
Return a hex representation of the given byte array.static <T> T
deepCopy(T obj, Class<T> classOfT)
Return a deep copy using gson.static String
generateServiceKey(RRMConfig.ServiceConfig serviceConfig)
Generate the RRM service key.static void
jsonMerge(org.json.JSONObject a, org.json.JSONObject b)
Recursively merge JSONObject 'b' into 'a'.static String
longToMac(long addr)
Convert a MAC address in integer (6-byte) representation to string notation.static long
macToLong(String addr)
Convert a MAC address to an integer (6-byte) representation.static String
readFile(File f)
Read a file to a UTF-8 string.static String
readResourceToString(String path)
Read a resource to a UTF-8 string.static void
writeFile(File f, String s)
Write a string to a file.static void
writeJsonFile(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.
-
-