public final class Utils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Utils.ComparingByteArrays
Comparator that performs a lexicographical comparison of byte arrays, treating them as unsigned.
|
static class |
Utils.ComparingByteBuffers |
Modifier and Type | Method and Description |
---|---|
static <T> T |
assertNonNull(T object,
String paramName)
|
static ByteBuffer |
clear(ByteBuffer buff)
Equivalent to calling
Buffer.clear() but in a manner which is
safe when compiled on Java 9 or newer but used on Java 8 or older. |
static int |
compareObjectIdentity(Object a,
Object b)
Provides an arbitrary but consistent total ordering over all objects.
|
static ByteBuffer |
flip(ByteBuffer buff)
Equivalent to calling
Buffer.flip() but in a manner which is
safe when compiled on Java 9 or newer but used on Java 8 or older. |
static SecureRandom |
getSecureRandom() |
static ByteBuffer |
limit(ByteBuffer buff,
int newLimit)
Equivalent to calling
Buffer.limit(int) but in a manner which is
safe when compiled on Java 9 or newer but used on Java 8 or older. |
static ByteBuffer |
position(ByteBuffer buff,
int newPosition)
Equivalent to calling
Buffer.position(int) but in a manner which is
safe when compiled on Java 9 or newer but used on Java 8 or older. |
static long |
saturatingAdd(long a,
long b) |
static byte[] |
truncate(byte[] arr,
int len)
Returns a possibly truncated version of
arr which is guaranteed to be exactly
len elements long. |
public static int compareObjectIdentity(Object a, Object b)
a
- b
- public static long saturatingAdd(long a, long b)
public static <T> T assertNonNull(T object, String paramName) throws NullPointerException
object
- value to be null-checkedparamName
- message for the potential NullPointerException
object
NullPointerException
- if object
is nullpublic static byte[] truncate(byte[] arr, int len) throws IllegalArgumentException
arr
which is guaranteed to be exactly
len
elements long. If arr
is already exactly len
elements long, then
arr
is returned without copy or modification. If arr
is longer than
len
, then a truncated copy is returned. If arr
is shorter than len
then this throws an IllegalArgumentException
.IllegalArgumentException
public static SecureRandom getSecureRandom()
public static ByteBuffer flip(ByteBuffer buff)
Buffer.flip()
but in a manner which is
safe when compiled on Java 9 or newer but used on Java 8 or older.public static ByteBuffer clear(ByteBuffer buff)
Buffer.clear()
but in a manner which is
safe when compiled on Java 9 or newer but used on Java 8 or older.public static ByteBuffer position(ByteBuffer buff, int newPosition)
Buffer.position(int)
but in a manner which is
safe when compiled on Java 9 or newer but used on Java 8 or older.public static ByteBuffer limit(ByteBuffer buff, int newLimit)
Buffer.limit(int)
but in a manner which is
safe when compiled on Java 9 or newer but used on Java 8 or older.Copyright © 2019. All rights reserved.