public final class Util
extends java.lang.Object
| 限定符和类型 | 字段和说明 |
|---|---|
static byte[] |
EMPTY_BYTE_ARRAY
An empty byte array.
|
static java.lang.String |
MANUFACTURER
Like
Build.MANUFACTURER, but in a place where it can be conveniently overridden for
local testing. |
static java.lang.String |
MODEL
Like
Build.MODEL, but in a place where it can be conveniently overridden for local
testing. |
static int |
SDK_INT
Like
Build.VERSION#SDK_INT, but in a place where it can be conveniently
overridden for local testing. |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
areEqual(java.lang.Object o1,
java.lang.Object o2)
Tests two objects for
Object.equals(Object) equality, handling the case where one or
both may be null. |
static <T> T |
castNonNull(T value)
Casts a nullable variable to a non-null variable without runtime null check.
|
static void |
closeQuietly(java.io.Closeable closeable)
Closes a
Closeable, suppressing any IOException that may occur. |
static java.lang.String |
fromUtf8Bytes(byte[] bytes)
Returns a new
String constructed by decoding UTF-8 encoded bytes. |
static java.lang.String |
fromUtf8Bytes(byte[] bytes,
int offset,
int length)
Returns a new
String constructed by decoding UTF-8 encoded bytes in a subarray. |
static byte[] |
getUtf8Bytes(java.lang.String value)
Returns a new byte array containing the code points of a
String encoded using UTF-8. |
static boolean |
isLinebreak(int c)
Returns whether the given character is a carriage return ('\r') or a line feed ('\n').
|
static int |
linearSearch(int[] array,
int value)
Returns the index of the first occurrence of
value in array, or C.INDEX_UNSET if value is not contained in array. |
static <T> T[] |
nullSafeArrayConcatenation(T[] first,
T[] second)
Creates a new array containing the concatenation of two non-null type arrays.
|
static boolean |
postOrRun(android.os.Handler handler,
java.lang.Runnable runnable)
Posts the
Runnable if the calling thread differs with the Looper of the Handler. |
static byte[] |
toByteArray(java.io.InputStream inputStream)
Converts the entirety of an
InputStream to a byte array. |
static long |
toLong(int mostSignificantBits,
int leastSignificantBits)
Return the long that is composed of the bits of the 2 specified integers.
|
static java.lang.String |
toLowerInvariant(java.lang.String text)
Converts text to lower case using
Locale.US. |
static long |
toUnsignedLong(int x)
Converts an integer to a long by unsigned conversion.
|
public static final int SDK_INT
Build.VERSION#SDK_INT, but in a place where it can be conveniently
overridden for local testing.public static final java.lang.String MANUFACTURER
Build.MANUFACTURER, but in a place where it can be conveniently overridden for
local testing.public static final java.lang.String MODEL
Build.MODEL, but in a place where it can be conveniently overridden for local
testing.public static final byte[] EMPTY_BYTE_ARRAY
public static byte[] toByteArray(java.io.InputStream inputStream)
throws java.io.IOException
InputStream to a byte array.inputStream - the InputStream to be read. The input stream is not closed by this
method.java.io.IOException - if an error occurs reading from the stream.public static boolean areEqual(java.lang.Object o1,
java.lang.Object o2)
Object.equals(Object) equality, handling the case where one or
both may be null.o1 - The first object.o2 - The second object.o1 == null ? o2 == null : o1.equals(o2).public static <T> T castNonNull(T value)
Use Assertions.checkNotNull(Object) to throw if the value is null.
public static <T> T[] nullSafeArrayConcatenation(T[] first,
T[] second)
first - The first array.second - The second array.public static boolean postOrRun(android.os.Handler handler,
java.lang.Runnable runnable)
Runnable if the calling thread differs with the Looper of the Handler. Otherwise, runs the Runnable directly.handler - The handler to which the Runnable will be posted.runnable - The runnable to either post or run.true if the Runnable was successfully posted to the Handler or
run. false otherwise.public static void closeQuietly(java.io.Closeable closeable)
Closeable, suppressing any IOException that may occur. Both OutputStream and InputStream are Closeable.closeable - The Closeable to close.public static java.lang.String fromUtf8Bytes(byte[] bytes)
String constructed by decoding UTF-8 encoded bytes.bytes - The UTF-8 encoded bytes to decode.public static java.lang.String fromUtf8Bytes(byte[] bytes,
int offset,
int length)
String constructed by decoding UTF-8 encoded bytes in a subarray.bytes - The UTF-8 encoded bytes to decode.offset - The index of the first byte to decode.length - The number of bytes to decode.public static byte[] getUtf8Bytes(java.lang.String value)
String encoded using UTF-8.value - The String whose bytes should be obtained.public static boolean isLinebreak(int c)
c - The character.public static int linearSearch(int[] array,
int value)
value in array, or C.INDEX_UNSET if value is not contained in array.array - The array to search.value - The value to search for.array, or C.INDEX_UNSET
if value is not contained in array.public static java.lang.String toLowerInvariant(java.lang.String text)
Locale.US.text - The text to convert.text is null.public static long toUnsignedLong(int x)
This method is equivalent to Integer.toUnsignedLong(int) for API 26+.
public static long toLong(int mostSignificantBits,
int leastSignificantBits)
mostSignificantBits - The 32 most significant bits of the long to return.leastSignificantBits - The 32 least significant bits of the long to return.mostSignificantBits bits and its
32 least significant bits are leastSignificantBits.