okhttp3.internal.Util类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(452)

本文整理了Java中okhttp3.internal.Util类的一些代码示例,展示了Util类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util类的具体详情如下:
包路径:okhttp3.internal.Util
类名称:Util

Util介绍

[英]Junk drawer of utility methods.
[中]实用方法的垃圾抽屉。

代码示例

代码示例来源:origin: square/okhttp

public void failWebSocket(Exception e, @Nullable Response response) {
 Streams streamsToClose;
 synchronized (this) {
  if (failed) return; // Already failed.
  failed = true;
  streamsToClose = this.streams;
  this.streams = null;
  if (cancelFuture != null) cancelFuture.cancel(false);
  if (executor != null) executor.shutdown();
 }
 try {
  listener.onFailure(this, e, response);
 } finally {
  closeQuietly(streamsToClose);
 }
}

代码示例来源:origin: square/okhttp

public synchronized ExecutorService executorService() {
 if (executorService == null) {
  executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS,
    new SynchronousQueue<>(), Util.threadFactory("OkHttp Dispatcher", false));
 }
 return executorService;
}

代码示例来源:origin: square/okhttp

public Address(String uriHost, int uriPort, Dns dns, SocketFactory socketFactory,
  @Nullable SSLSocketFactory sslSocketFactory, @Nullable HostnameVerifier hostnameVerifier,
  @Nullable CertificatePinner certificatePinner, Authenticator proxyAuthenticator,
  @Nullable Proxy proxy, List<Protocol> protocols, List<ConnectionSpec> connectionSpecs,
  ProxySelector proxySelector) {
 this.url = new HttpUrl.Builder()
   .scheme(sslSocketFactory != null ? "https" : "http")
   .host(uriHost)
   .port(uriPort)
   .build();
 if (dns == null) throw new NullPointerException("dns == null");
 this.dns = dns;
 if (socketFactory == null) throw new NullPointerException("socketFactory == null");
 this.socketFactory = socketFactory;
 if (proxyAuthenticator == null) {
  throw new NullPointerException("proxyAuthenticator == null");
 }
 this.proxyAuthenticator = proxyAuthenticator;
 if (protocols == null) throw new NullPointerException("protocols == null");
 this.protocols = Util.immutableList(protocols);
 if (connectionSpecs == null) throw new NullPointerException("connectionSpecs == null");
 this.connectionSpecs = Util.immutableList(connectionSpecs);
 if (proxySelector == null) throw new NullPointerException("proxySelector == null");
 this.proxySelector = proxySelector;
 this.proxy = proxy;
 this.sslSocketFactory = sslSocketFactory;
 this.hostnameVerifier = hostnameVerifier;
 this.certificatePinner = certificatePinner;
}

代码示例来源:origin: square/okhttp

/** Returns a new request body that transmits {@code content}. */
public static RequestBody create(final @Nullable MediaType contentType, final byte[] content,
  final int offset, final int byteCount) {
 if (content == null) throw new NullPointerException("content == null");
 Util.checkOffsetAndCount(content.length, offset, byteCount);
 return new RequestBody() {
  @Override public @Nullable MediaType contentType() {
   return contentType;
  }
  @Override public long contentLength() {
   return byteCount;
  }
  @Override public void writeTo(BufferedSink sink) throws IOException {
   sink.write(content, offset, byteCount);
  }
 };
}

代码示例来源:origin: square/okhttp

/**
 * Returns the domain name of this URL's {@link #host()} that is one level beneath the public
 * suffix by consulting the <a href="https://publicsuffix.org">public suffix list</a>. Returns
 * null if this URL's {@link #host()} is an IP address or is considered a public suffix by the
 * public suffix list.
 *
 * <p>In general this method <strong>should not</strong> be used to test whether a domain is valid
 * or routable. Instead, DNS is the recommended source for that information.
 *
 * <p><table summary="">
 *   <tr><th>URL</th><th>{@code topPrivateDomain()}</th></tr>
 *   <tr><td>{@code http://google.com}</td><td>{@code "google.com"}</td></tr>
 *   <tr><td>{@code http://adwords.google.co.uk}</td><td>{@code "google.co.uk"}</td></tr>
 *   <tr><td>{@code http://square}</td><td>null</td></tr>
 *   <tr><td>{@code http://co.uk}</td><td>null</td></tr>
 *   <tr><td>{@code http://localhost}</td><td>null</td></tr>
 *   <tr><td>{@code http://127.0.0.1}</td><td>null</td></tr>
 * </table>
 */
public @Nullable String topPrivateDomain() {
 if (verifyAsIpAddress(host)) return null;
 return PublicSuffixDatabase.get().getEffectiveTldPlusOne(host);
}

代码示例来源:origin: square/okhttp

public void close() {
  for (Source in : sources) {
   Util.closeQuietly(in);
  }
 }
}

代码示例来源:origin: square/okhttp

FormBody(List<String> encodedNames, List<String> encodedValues) {
 this.encodedNames = Util.immutableList(encodedNames);
 this.encodedValues = Util.immutableList(encodedValues);
}

代码示例来源:origin: square/okhttp

/**
 * Returns a copy of this that omits cipher suites and TLS versions not enabled by {@code
 * sslSocket}.
 */
private ConnectionSpec supportedSpec(SSLSocket sslSocket, boolean isFallback) {
 String[] cipherSuitesIntersection = cipherSuites != null
   ? intersect(CipherSuite.ORDER_BY_NAME, sslSocket.getEnabledCipherSuites(), cipherSuites)
   : sslSocket.getEnabledCipherSuites();
 String[] tlsVersionsIntersection = tlsVersions != null
   ? intersect(Util.NATURAL_ORDER, sslSocket.getEnabledProtocols(), tlsVersions)
   : sslSocket.getEnabledProtocols();
 // In accordance with https://tools.ietf.org/html/draft-ietf-tls-downgrade-scsv-00
 // the SCSV cipher is added to signal that a protocol fallback has taken place.
 String[] supportedCipherSuites = sslSocket.getSupportedCipherSuites();
 int indexOfFallbackScsv = indexOf(
   CipherSuite.ORDER_BY_NAME, supportedCipherSuites, "TLS_FALLBACK_SCSV");
 if (isFallback && indexOfFallbackScsv != -1) {
  cipherSuitesIntersection = concat(
    cipherSuitesIntersection, supportedCipherSuites[indexOfFallbackScsv]);
 }
 return new Builder(this)
   .cipherSuites(cipherSuitesIntersection)
   .tlsVersions(tlsVersionsIntersection)
   .build();
}

代码示例来源:origin: square/okhttp

Util.threadFactory(Util.format("OkHttp %s Writer", connectionName), false));
if (builder.pingIntervalMillis != 0) {
 writerExecutor.scheduleAtFixedRate(new PingRunnable(false, 0, 0),
  Util.threadFactory(Util.format("OkHttp %s Push Observer", connectionName), true));
peerSettings.set(Settings.INITIAL_WINDOW_SIZE, DEFAULT_INITIAL_WINDOW_SIZE);
peerSettings.set(Settings.MAX_FRAME_SIZE, Http2.INITIAL_MAX_FRAME_SIZE);

代码示例来源:origin: square/okhttp

private static boolean domainMatch(String urlHost, String domain) {
 if (urlHost.equals(domain)) {
  return true; // As in 'example.com' matching 'example.com'.
 }
 if (urlHost.endsWith(domain)
   && urlHost.charAt(urlHost.length() - domain.length() - 1) == '.'
   && !verifyAsIpAddress(urlHost)) {
  return true; // As in 'example.com' matching 'www.example.com'.
 }
 return false;
}

代码示例来源:origin: huxq17/SwipeCardsView

/**
 * Returns a copy of this that omits cipher suites and TLS versions not enabled by {@code
 * sslSocket}.
 */
private ConnectionSpec supportedSpec(SSLSocket sslSocket, boolean isFallback) {
 String[] cipherSuitesIntersection = cipherSuites != null
   ? intersect(String.class, cipherSuites, sslSocket.getEnabledCipherSuites())
   : sslSocket.getEnabledCipherSuites();
 String[] tlsVersionsIntersection = tlsVersions != null
   ? intersect(String.class, tlsVersions, sslSocket.getEnabledProtocols())
   : sslSocket.getEnabledProtocols();
 // In accordance with https://tools.ietf.org/html/draft-ietf-tls-downgrade-scsv-00
 // the SCSV cipher is added to signal that a protocol fallback has taken place.
 if (isFallback && contains(sslSocket.getSupportedCipherSuites(), "TLS_FALLBACK_SCSV")) {
  cipherSuitesIntersection = concat(cipherSuitesIntersection, "TLS_FALLBACK_SCSV");
 }
 return new Builder(this)
   .cipherSuites(cipherSuitesIntersection)
   .tlsVersions(tlsVersionsIntersection)
   .build();
}

代码示例来源:origin: square/okhttp

@Override public void close() throws IOException {
  if (closed) return;
  if (bytesRemaining != 0 && !Util.discard(this, DISCARD_STREAM_TIMEOUT_MILLIS, MILLISECONDS)) {
   endOfInput(false, null);
  }
  closed = true;
 }
}

代码示例来源:origin: square/okhttp

public NamedRunnable(String format, Object... args) {
 this.name = Util.format(format, args);
}

代码示例来源:origin: square/okhttp

this.protocols = builder.protocols;
this.connectionSpecs = builder.connectionSpecs;
this.interceptors = Util.immutableList(builder.interceptors);
this.networkInterceptors = Util.immutableList(builder.networkInterceptors);
this.eventListenerFactory = builder.eventListenerFactory;
this.proxySelector = builder.proxySelector;
 this.certificateChainCleaner = builder.certificateChainCleaner;
} else {
 X509TrustManager trustManager = Util.platformTrustManager();
 this.sslSocketFactory = newSslSocketFactory(trustManager);
 this.certificateChainCleaner = CertificateChainCleaner.get(trustManager);

代码示例来源:origin: square/okhttp

@Override public void write(Buffer source, long byteCount) throws IOException {
 if (closed) throw new IllegalStateException("closed");
 checkOffsetAndCount(source.size(), 0, byteCount);
 if (byteCount > bytesRemaining) {
  throw new ProtocolException("expected " + bytesRemaining
    + " bytes but received " + byteCount);
 }
 sink.write(source, byteCount);
 bytesRemaining -= byteCount;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/** Returns a new request body that transmits {@code content}. */
public static RequestBody create(final @Nullable MediaType contentType, final byte[] content,
  final int offset, final int byteCount) {
 if (content == null) throw new NullPointerException("content == null");
 Util.checkOffsetAndCount(content.length, offset, byteCount);
 return new RequestBody() {
  @Override public @Nullable MediaType contentType() {
   return contentType;
  }
  @Override public long contentLength() {
   return byteCount;
  }
  @Override public void writeTo(BufferedSink sink) throws IOException {
   sink.write(content, offset, byteCount);
  }
 };
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/**
 * Returns the domain name of this URL's {@link #host()} that is one level beneath the public
 * suffix by consulting the <a href="https://publicsuffix.org">public suffix list</a>. Returns
 * null if this URL's {@link #host()} is an IP address or is considered a public suffix by the
 * public suffix list.
 *
 * <p>In general this method <strong>should not</strong> be used to test whether a domain is valid
 * or routable. Instead, DNS is the recommended source for that information.
 *
 * <p><table summary="">
 *   <tr><th>URL</th><th>{@code topPrivateDomain()}</th></tr>
 *   <tr><td>{@code http://google.com}</td><td>{@code "google.com"}</td></tr>
 *   <tr><td>{@code http://adwords.google.co.uk}</td><td>{@code "google.co.uk"}</td></tr>
 *   <tr><td>{@code http://square}</td><td>null</td></tr>
 *   <tr><td>{@code http://co.uk}</td><td>null</td></tr>
 *   <tr><td>{@code http://localhost}</td><td>null</td></tr>
 *   <tr><td>{@code http://127.0.0.1}</td><td>null</td></tr>
 * </table>
 */
public @Nullable String topPrivateDomain() {
 if (verifyAsIpAddress(host)) return null;
 return PublicSuffixDatabase.get().getEffectiveTldPlusOne(host);
}

代码示例来源:origin: square/okhttp

public void cancel() {
 // Close the raw socket so we don't end up doing synchronous I/O.
 closeQuietly(rawSocket);
}

代码示例来源:origin: square/okhttp

public Builder connectionSpecs(List<ConnectionSpec> connectionSpecs) {
 this.connectionSpecs = Util.immutableList(connectionSpecs);
 return this;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/**
 * Returns a copy of this that omits cipher suites and TLS versions not enabled by {@code
 * sslSocket}.
 */
private ConnectionSpec supportedSpec(SSLSocket sslSocket, boolean isFallback) {
 String[] cipherSuitesIntersection = cipherSuites != null
   ? intersect(CipherSuite.ORDER_BY_NAME, sslSocket.getEnabledCipherSuites(), cipherSuites)
   : sslSocket.getEnabledCipherSuites();
 String[] tlsVersionsIntersection = tlsVersions != null
   ? intersect(Util.NATURAL_ORDER, sslSocket.getEnabledProtocols(), tlsVersions)
   : sslSocket.getEnabledProtocols();
 // In accordance with https://tools.ietf.org/html/draft-ietf-tls-downgrade-scsv-00
 // the SCSV cipher is added to signal that a protocol fallback has taken place.
 String[] supportedCipherSuites = sslSocket.getSupportedCipherSuites();
 int indexOfFallbackScsv = indexOf(
   CipherSuite.ORDER_BY_NAME, supportedCipherSuites, "TLS_FALLBACK_SCSV");
 if (isFallback && indexOfFallbackScsv != -1) {
  cipherSuitesIntersection = concat(
    cipherSuitesIntersection, supportedCipherSuites[indexOfFallbackScsv]);
 }
 return new Builder(this)
   .cipherSuites(cipherSuitesIntersection)
   .tlsVersions(tlsVersionsIntersection)
   .build();
}

相关文章