public final class Util extends Object
Modifier and Type | Field and Description |
---|---|
static byte[] |
EMPTY_BYTE_ARRAY |
static String[] |
EMPTY_STRING_ARRAY |
static Charset |
UTF_8
A cheap and type-safe constant for the UTF-8 Charset.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkOffsetAndCount(long arrayLength,
long offset,
long count) |
static void |
closeAll(Closeable a,
Closeable b)
Closes
a and b . |
static void |
closeQuietly(Closeable closeable)
Closes
closeable , ignoring any checked exceptions. |
static void |
closeQuietly(ServerSocket serverSocket)
Closes
serverSocket , ignoring any checked exceptions. |
static void |
closeQuietly(Socket socket)
Closes
socket , ignoring any checked exceptions. |
static String[] |
concat(String[] array,
String value) |
static boolean |
contains(String[] array,
String value) |
static boolean |
discard(okio.Source source,
int timeout,
TimeUnit timeUnit)
Attempts to exhaust
source , returning true if successful. |
static boolean |
equal(Object a,
Object b)
Returns true if two possibly-null objects are equal.
|
static String |
hostHeader(HttpUrl url) |
static <T> List<T> |
immutableList(List<T> list)
Returns an immutable copy of
list . |
static <T> List<T> |
immutableList(T... elements)
Returns an immutable list containing
elements . |
static <K,V> Map<K,V> |
immutableMap(Map<K,V> map)
Returns an immutable copy of
map . |
static <T> T[] |
intersect(Class<T> arrayType,
T[] first,
T[] second)
Returns an array containing containing only elements found in
first and also in
second . |
static boolean |
isAndroidGetsocknameError(AssertionError e)
Returns true if
e is due to a firmware bug fixed after Android 4.2.2. |
static String |
md5Hex(String s)
Returns a 32 character string containing an MD5 hash of
s . |
static okio.ByteString |
sha1(okio.ByteString s)
Returns a SHA-1 hash of
s . |
static String |
shaBase64(String s)
Returns a Base 64-encoded string containing a SHA-1 hash of
s . |
static boolean |
skipAll(okio.Source source,
int duration,
TimeUnit timeUnit)
Reads until
in is exhausted or the deadline has been reached. |
static ThreadFactory |
threadFactory(String name,
boolean daemon) |
static String |
toHumanReadableAscii(String s)
Returns
s with control characters and non-ASCII characters replaced with '?'. |
public static final byte[] EMPTY_BYTE_ARRAY
public static final String[] EMPTY_STRING_ARRAY
public static final Charset UTF_8
public static void checkOffsetAndCount(long arrayLength, long offset, long count)
public static boolean equal(Object a, Object b)
public static void closeQuietly(Closeable closeable)
closeable
, ignoring any checked exceptions. Does nothing
if closeable
is null.public static void closeQuietly(Socket socket)
socket
, ignoring any checked exceptions. Does nothing if
socket
is null.public static void closeQuietly(ServerSocket serverSocket)
serverSocket
, ignoring any checked exceptions. Does nothing if
serverSocket
is null.public static void closeAll(Closeable a, Closeable b) throws IOException
a
and b
. If either close fails, this completes
the other close and rethrows the first encountered exception.IOException
public static boolean discard(okio.Source source, int timeout, TimeUnit timeUnit)
source
, returning true if successful. This is useful when reading
a complete source is helpful, such as when doing so completes a cache body or frees a socket
connection for reuse.public static boolean skipAll(okio.Source source, int duration, TimeUnit timeUnit) throws IOException
in
is exhausted or the deadline has been reached. This is careful to not
extend the deadline if one exists already.IOException
public static String md5Hex(String s)
s
.public static String shaBase64(String s)
s
.public static okio.ByteString sha1(okio.ByteString s)
s
.public static <T> List<T> immutableList(List<T> list)
list
.public static <T> List<T> immutableList(T... elements)
elements
.public static <K,V> Map<K,V> immutableMap(Map<K,V> map)
map
.public static ThreadFactory threadFactory(String name, boolean daemon)
public static <T> T[] intersect(Class<T> arrayType, T[] first, T[] second)
first
and also in
second
. The returned elements are in the same order as in first
.public static String toHumanReadableAscii(String s)
s
with control characters and non-ASCII characters replaced with '?'.public static boolean isAndroidGetsocknameError(AssertionError e)
e
is due to a firmware bug fixed after Android 4.2.2.
https://code.google.com/p/android/issues/detail?id=54072Copyright © 2016. All rights reserved.