public final class Util extends Object
| Modifier and Type | Field and Description |
|---|---|
static byte[] |
EMPTY_BYTE_ARRAY
|
static String |
EMPTY_STRING_ARRAY
|
static TimeZone |
UTC
GMT and UTC are equivalent for our purposes.
|
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
Closes
a and
b.
|
static void |
closeQuietly(Closeable
Closes
closeable, ignoring any checked exceptions.
|
static void |
closeQuietly(ServerSocket
Closes
serverSocket, ignoring any checked exceptions.
|
static void |
closeQuietly(Socket
Closes
socket, ignoring any checked exceptions.
|
static String |
concat(String
|
static boolean |
contains(String
|
static int |
delimiterOffset(String
Returns the index of the first character in
input that is
delimiter.
|
static int |
delimiterOffset(String
Returns the index of the first character in
input that contains a character in
delimiters.
|
static boolean |
discard(okio
Attempts to exhaust
source, returning true if successful.
|
static String |
domainToAscii(String
Performs IDN ToASCII encoding and canonicalize the result to lowercase.
|
static boolean |
equal(Object
Returns true if two possibly-null objects are equal.
|
static String |
hostHeader(HttpUrl
|
static <T> List |
immutableList(List
Returns an immutable copy of
list.
|
static <T> List |
immutableList(T... elements)
Returns an immutable list containing
elements.
|
static <K |
immutableMap(Map
Returns an immutable copy of
map.
|
static <T> T[] |
intersect(Class
Returns an array containing containing only elements found in
first and also in
second.
|
static boolean |
isAndroidGetsocknameError(AssertionError
Returns true if
e is due to a firmware bug fixed after Android 4.2.2.
|
static String |
md5Hex(String
Returns a 32 character string containing an MD5 hash of
s.
|
static okio |
sha1(okio
Returns a SHA-1 hash of
s.
|
static okio |
sha256(okio
Returns a SHA-256 hash of
s.
|
static String |
shaBase64(String
Returns a Base 64-encoded string containing a SHA-1 hash of
s.
|
static boolean |
skipAll(okio
Reads until
in is exhausted or the deadline has been reached.
|
static int |
skipLeadingAsciiWhitespace(String
Increments
pos until
input[pos] is not ASCII whitespace.
|
static int |
skipTrailingAsciiWhitespace(String
Decrements
limit until
input[limit - 1] is not ASCII whitespace.
|
static ThreadFactory |
threadFactory(String
|
static String |
toHumanReadableAscii(String
Returns
s with control characters and non-ASCII characters replaced with '?'.
|
static String |
trimSubstring(String
Equivalent to
string.substring(pos, limit).trim().
|
static boolean |
verifyAsIpAddress(String
Returns true if
host is not a host name and might be an IP address.
|
public static final byte[] EMPTY_BYTE_ARRAY
public static final String[] EMPTY_STRING_ARRAY
public static final CharsetUTF_8
public static final TimeZoneUTC
public static void checkOffsetAndCount(long arrayLength,
long offset,
long count)public static boolean equal(Objecta, Object b)
public static void closeQuietly(Closeablecloseable)
closeable, ignoring any checked exceptions. Does nothing if
closeable is null.
public static void closeQuietly(Socketsocket)
socket, ignoring any checked exceptions. Does nothing if
socket is null.
public static void closeQuietly(ServerSocketserverSocket)
serverSocket, ignoring any checked exceptions. Does nothing if
serverSocket is null.
public static void closeAll(Closeablea, 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 Stringmd5Hex(String s)
s.
public static StringshaBase64(String s)
s.
public static okio.ByteString sha1(okio .ByteString s)
s.
public static okio.ByteString sha256(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 ThreadFactorythreadFactory(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 StringtoHumanReadableAscii(String s)
s with control characters and non-ASCII characters replaced with '?'.
public static boolean isAndroidGetsocknameError(AssertionErrore)
e is due to a firmware bug fixed after Android 4.2.2. https://code.google.com/p/android/issues/detail?id=54072
public static int skipLeadingAsciiWhitespace(Stringinput, int pos, int limit)
pos until
input[pos] is not ASCII whitespace. Stops at
limit.
public static int skipTrailingAsciiWhitespace(Stringinput, int pos, int limit)
limit until
input[limit - 1] is not ASCII whitespace. Stops at
pos.
public static StringtrimSubstring(String string, int pos, int limit)
string.substring(pos, limit).trim().
public static int delimiterOffset(Stringinput, int pos, int limit, String delimiters)
input that contains a character in
delimiters. Returns limit if there is no such character.
public static int delimiterOffset(Stringinput, int pos, int limit, char delimiter)
input that is
delimiter. Returns limit if there is no such character.
public static StringdomainToAscii(String input)
☃.net to
xn--n3h.net, and
WwW.GoOgLe.cOm to
www.google.com.
null will be returned if the input cannot be ToASCII encoded or if the result contains unsupported ASCII characters.
public static boolean verifyAsIpAddress(Stringhost)
host is not a host name and might be an IP address.