public abstract class Tools extends Object
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
byteBuffertoArray(ByteBuffer buffer)
Returns the contents of
ByteBuffer as byte array. |
static void |
copyDirectory(File src,
File dst)
Copies the specified directory path. Use with great caution since
no attempt is made to check for symbolic links, which could result in
copy of unintended files.
|
static void |
copyDirectory(String src,
String dst)
Copies the specified directory path. Use with great caution since
no attempt is made to check for symbolic links, which could result in
copy of unintended files.
|
static void |
delay(int ms)
Suspends the current thread for a specified number of millis.
|
static void |
delay(int ms,
int nanos)
Suspends the current thread for a specified number of millis and nanos.
|
static <T> CompletableFuture<T> |
exceptionalFuture(Throwable t)
Returns a future that is completed exceptionally.
|
static long |
fromHex(String string)
Converts a string from hex to long.
|
static <T> T |
futureGetOrElse(Future<T> future,
long timeout,
TimeUnit timeUnit,
T defaultValue)
Returns the future value when complete or if future
completes exceptionally returns the defaultValue.
|
static <T> T |
futureGetOrElse(Future<T> future,
T defaultValue)
Returns the future value when complete or if future
completes exceptionally returns the defaultValue.
|
static String |
get(Dictionary<?,?> properties,
String propertyName)
Get property as a string value.
|
static ThreadFactory |
groupedThreads(String groupName,
String pattern)
Returns a thread factory that produces threads named according to the
supplied name pattern and from the specified thread-group.
|
static boolean |
isNullOrEmpty(Collection collection)
Returns true if the collection is null or is empty.
|
static ThreadFactory |
minPriority(ThreadFactory factory)
Returns a thread factory that produces threads with MIN_PRIORITY.
|
static ThreadFactory |
namedThreads(String pattern)
Returns a thread factory that produces threads named according to the
supplied name pattern.
|
static <T> T |
nullIsNotFound(T item,
String message)
Returns the specified item if that items is null; otherwise throws
not found exception.
|
static void |
randomDelay(int ms)
Suspends the current thread for a random number of millis between 0 and
the indicated limit.
|
static void |
removeDirectory(File dir)
Purges the specified directory path. Use with great caution since
no attempt is made to check for symbolic links, which could result in
deletion of unintended files.
|
static void |
removeDirectory(String path)
Purges the specified directory path. Use with great caution since
no attempt is made to check for symbolic links, which could result in
deletion of unintended files.
|
static List<String> |
slurp(File path)
Slurps the contents of a file into a list of strings, one per line.
|
static String |
timeAgo(long unixTime)
Returns a human friendly time ago string for a specified system time.
|
static String |
toHex(long value)
Converts a long value to hex string; 16 wide and sans 0x.
|
static String |
toHex(long value,
int width)
Converts a long value to hex string; 16 wide and sans 0x.
|
public static ThreadFactory namedThreads(String pattern)
pattern - name patternpublic static ThreadFactory groupedThreads(String groupName, String pattern)
onos/intent. The thread names will be produced by converting
the thread group name into dash-delimited format and pre-pended to the
specified pattern.groupName - group name in slash-delimited format to indicate hierarchypattern - name patternpublic static ThreadFactory minPriority(ThreadFactory factory)
factory - backing ThreadFactorypublic static boolean isNullOrEmpty(Collection collection)
collection - collection to testpublic static <T> T nullIsNotFound(T item,
String message)
T - item typeitem - item to checkmessage - not found messageItemNotFoundException - if item is nullpublic static long fromHex(String string)
string - hex number in string form; sans 0xpublic static String toHex(long value)
value - long valuepublic static String toHex(long value, int width)
value - long valuewidth - string width; zero paddedpublic static String get(Dictionary<?,?> properties, String propertyName)
properties - properties to be looked uppropertyName - the name of the property to look uppublic static void delay(int ms)
ms - number of millispublic static void randomDelay(int ms)
ms - max number of millispublic static void delay(int ms,
int nanos)
ms - number of millisnanos - number of nanospublic static List<String> slurp(File path)
path - file pathpublic static void removeDirectory(String path) throws IOException
path - directory to be removedIOException - if unable to remove contentspublic static void removeDirectory(File dir) throws IOException
dir - directory to be removedIOException - if unable to remove contentspublic static String timeAgo(long unixTime)
unixTime - system time in millispublic static void copyDirectory(String src, String dst) throws IOException
src - directory to be copieddst - destination directory to be removedIOException - if unable to remove contentspublic static void copyDirectory(File src, File dst) throws IOException
src - directory to be copieddst - destination directory to be removedIOException - if unable to remove contentspublic static <T> T futureGetOrElse(Future<T> future, T defaultValue)
T - future value typefuture - futuredefaultValue - default valuepublic static <T> T futureGetOrElse(Future<T> future, long timeout, TimeUnit timeUnit, T defaultValue)
T - future value typefuture - futuretimeout - time to wait for successful completiontimeUnit - time unitdefaultValue - default valuepublic static <T> CompletableFuture<T> exceptionalFuture(Throwable t)
T - future value typet - exceptionpublic static byte[] byteBuffertoArray(ByteBuffer buffer)
ByteBuffer as byte array.
WARNING: There is a performance cost due to array copy when using this method.
buffer - byte bufferCopyright © 2015. All rights reserved.