类 Util

java.lang.Object
com.lark.oapi.okhttp.internal.Util

public final class Util extends Object
Junk drawer of utility methods.
  • 字段详细资料

    • EMPTY_BYTE_ARRAY

      public static final byte[] EMPTY_BYTE_ARRAY
    • EMPTY_STRING_ARRAY

      public static final String[] EMPTY_STRING_ARRAY
    • EMPTY_HEADERS

      public static final Headers EMPTY_HEADERS
    • EMPTY_RESPONSE

      public static final ResponseBody EMPTY_RESPONSE
    • EMPTY_REQUEST

      public static final RequestBody EMPTY_REQUEST
    • UTC

      public static final TimeZone UTC
      GMT and UTC are equivalent for our purposes.
    • NATURAL_ORDER

      public static final Comparator<String> NATURAL_ORDER
  • 方法详细资料

    • addSuppressedIfPossible

      public static void addSuppressedIfPossible(Throwable e, Throwable suppressed)
    • checkOffsetAndCount

      public static void checkOffsetAndCount(long arrayLength, long offset, long count)
    • closeQuietly

      public static void closeQuietly(Closeable closeable)
      Closes closeable, ignoring any checked exceptions. Does nothing if closeable is null.
    • closeQuietly

      public static void closeQuietly(Socket socket)
      Closes socket, ignoring any checked exceptions. Does nothing if socket is null.
    • closeQuietly

      public static void closeQuietly(ServerSocket serverSocket)
      Closes serverSocket, ignoring any checked exceptions. Does nothing if serverSocket is null.
    • discard

      public static boolean discard(Source source, int timeout, TimeUnit timeUnit)
      Attempts to exhaust 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.
    • skipAll

      public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException
      Reads until in is exhausted or the deadline has been reached. This is careful to not extend the deadline if one exists already.
      抛出:
      IOException
    • immutableList

      public static <T> List<T> immutableList(List<T> list)
      Returns an immutable copy of list.
    • immutableMap

      public static <K, V> Map<K,V> immutableMap(Map<K,V> map)
      Returns an immutable copy of map.
    • immutableList

      @SafeVarargs public static <T> List<T> immutableList(T... elements)
      Returns an immutable list containing elements.
    • threadFactory

      public static ThreadFactory threadFactory(String name, boolean daemon)
    • intersect

      public static String[] intersect(Comparator<? super String> comparator, String[] first, String[] second)
      Returns an array containing only elements found in first and also in second. The returned elements are in the same order as in first.
    • nonEmptyIntersection

      public static boolean nonEmptyIntersection(Comparator<String> comparator, String[] first, String[] second)
      Returns true if there is an element in first that is also in second. This method terminates if any intersection is found. The sizes of both arguments are assumed to be so small, and the likelihood of an intersection so great, that it is not worth the CPU cost of sorting or the memory cost of hashing.
    • hostHeader

      public static String hostHeader(HttpUrl url, boolean includeDefaultPort)
    • isAndroidGetsocknameError

      public static boolean isAndroidGetsocknameError(AssertionError e)
      Returns true if e is due to a firmware bug fixed after Android 4.2.2. https://code.google.com/p/android/issues/detail?id=54072
    • indexOf

      public static int indexOf(Comparator<String> comparator, String[] array, String value)
    • concat

      public static String[] concat(String[] array, String value)
    • skipLeadingAsciiWhitespace

      public static int skipLeadingAsciiWhitespace(String input, int pos, int limit)
      Increments pos until input[pos] is not ASCII whitespace. Stops at limit.
    • skipTrailingAsciiWhitespace

      public static int skipTrailingAsciiWhitespace(String input, int pos, int limit)
      Decrements limit until input[limit - 1] is not ASCII whitespace. Stops at pos.
    • trimSubstring

      public static String trimSubstring(String string, int pos, int limit)
      Equivalent to string.substring(pos, limit).trim().
    • delimiterOffset

      public static int delimiterOffset(String input, int pos, int limit, String delimiters)
      Returns the index of the first character in input that contains a character in delimiters. Returns limit if there is no such character.
    • delimiterOffset

      public static int delimiterOffset(String input, int pos, int limit, char delimiter)
      Returns the index of the first character in input that is delimiter. Returns limit if there is no such character.
    • canonicalizeHost

      public static String canonicalizeHost(String host)
      If host is an IP address, this returns the IP address in canonical form.

      Otherwise this performs IDN ToASCII encoding and canonicalize the result to lowercase. For example this converts ☃.net to xn--n3h.net, and WwW.GoOgLe.cOm to www.google.com. null will be returned if the host cannot be ToASCII encoded or if the result contains unsupported ASCII characters.

    • indexOfControlOrNonAscii

      public static int indexOfControlOrNonAscii(String input)
      Returns the index of the first character in input that is either a control character (like or \n) or a non-ASCII character. Returns -1 if input has no such characters.
    • verifyAsIpAddress

      public static boolean verifyAsIpAddress(String host)
      Returns true if host is not a host name and might be an IP address.
    • format

      public static String format(String format, Object... args)
      Returns a Locale.US formatted String.
    • bomAwareCharset

      public static Charset bomAwareCharset(BufferedSource source, Charset charset) throws IOException
      抛出:
      IOException
    • checkDuration

      public static int checkDuration(String name, long duration, TimeUnit unit)
    • decodeHexDigit

      public static int decodeHexDigit(char c)
    • platformTrustManager

      public static X509TrustManager platformTrustManager()
    • toHeaders

      public static Headers toHeaders(List<Header> headerBlock)
    • toHeaderBlock

      public static List<Header> toHeaderBlock(Headers headers)
    • getSystemProperty

      public static String getSystemProperty(String key, @Nullable String defaultValue)
      Returns the system property, or defaultValue if the system property is null or cannot be read (e.g. because of security policy restrictions).
    • sameConnection

      public static boolean sameConnection(HttpUrl a, HttpUrl b)
      Returns true if an HTTP request for a and b can reuse a connection.