本文整理汇总了Java中com.squareup.okhttp.internal.Util类的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Util类属于com.squareup.okhttp.internal包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
public static RequestBody create(final MediaType contentType, final byte[] content, final int
offset, final int byteCount) {
if (content == null) {
throw new NullPointerException("content == null");
}
Util.checkOffsetAndCount((long) content.length, (long) offset, (long) byteCount);
return new RequestBody() {
public MediaType contentType() {
return contentType;
}
public long contentLength() {
return (long) byteCount;
}
public void writeTo(BufferedSink sink) throws IOException {
sink.write(content, offset, byteCount);
}
};
}
示例2: get
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
Response get(Request request) {
try {
Closeable snapshot = this.cache.get(urlToKey(request));
if (snapshot == null) {
return null;
}
try {
Entry entry = new Entry(snapshot.getSource(0));
Response response = entry.response(request, snapshot);
if (entry.matches(request, response)) {
return response;
}
Util.closeQuietly(response.body());
return null;
} catch (IOException e) {
Util.closeQuietly(snapshot);
return null;
}
} catch (IOException e2) {
return null;
}
}
示例3: evictAll
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
public void evictAll() {
List<RealConnection> evictedConnections = new ArrayList();
synchronized (this) {
Iterator<RealConnection> i = this.connections.iterator();
while (i.hasNext()) {
RealConnection connection = (RealConnection) i.next();
if (connection.allocations.isEmpty()) {
connection.noNewStreams = true;
evictedConnections.add(connection);
i.remove();
}
}
}
for (RealConnection connection2 : evictedConnections) {
Util.closeQuietly(connection2.getSocket());
}
}
示例4: equals
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
public boolean equals(Object other) {
if (!(other instanceof Address)) {
return false;
}
Address that = (Address) other;
if (this.url.equals(that.url) && this.dns.equals(that.dns) && this.authenticator.equals
(that.authenticator) && this.protocols.equals(that.protocols) && this
.connectionSpecs.equals(that.connectionSpecs) && this.proxySelector.equals(that
.proxySelector) && Util.equal(this.proxy, that.proxy) && Util.equal(this
.sslSocketFactory, that.sslSocketFactory) && Util.equal(this.hostnameVerifier,
that.hostnameVerifier) && Util.equal(this.certificatePinner, that
.certificatePinner)) {
return true;
}
return false;
}
示例5: getFromCache
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
private FilterInputStream getFromCache(String url) throws Exception {
DiskLruCache cache = DiskLruCache.open(CommonUtil.getImageSavePath(), 1, 2, 2*1024*1024);
cache.flush();
String key = Util.hash(url);
final DiskLruCache.Snapshot snapshot;
try {
snapshot = cache.get(key);
if (snapshot == null) {
return null;
}
} catch (IOException e) {
return null;
}
FilterInputStream bodyIn = new FilterInputStream(snapshot.getInputStream(1)) {
@Override
public void close() throws IOException {
snapshot.close();
super.close();
}
};
return bodyIn;
}
示例6: networkRequest
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
private Request networkRequest(Request request) throws IOException {
Request.Builder result = request.newBuilder();
if (request.header("Host") == null) {
result.header("Host", Util.hostHeader(request.httpUrl()));
}
if (request.header("Connection") == null) {
result.header("Connection", "Keep-Alive");
}
if (request.header(AsyncHttpClient.HEADER_ACCEPT_ENCODING) == null) {
this.transparentGzip = true;
result.header(AsyncHttpClient.HEADER_ACCEPT_ENCODING, AsyncHttpClient.ENCODING_GZIP);
}
CookieHandler cookieHandler = this.client.getCookieHandler();
if (cookieHandler != null) {
OkHeaders.addCookies(result, cookieHandler.get(request.uri(), OkHeaders.toMultimap
(result.build().headers(), null)));
}
if (request.header(Network.USER_AGENT) == null) {
result.header(Network.USER_AGENT, Version.userAgent());
}
return result.build();
}
示例7: execute
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
protected void execute() {
ErrorCode connectionErrorCode = ErrorCode.INTERNAL_ERROR;
ErrorCode streamErrorCode = ErrorCode.INTERNAL_ERROR;
try {
if (!FramedConnection.this.client) {
this.frameReader.readConnectionPreface();
}
while (true) {
if (!this.frameReader.nextFrame(this)) {
break;
}
}
connectionErrorCode = ErrorCode.NO_ERROR;
streamErrorCode = ErrorCode.CANCEL;
} catch (IOException e) {
connectionErrorCode = ErrorCode.PROTOCOL_ERROR;
streamErrorCode = ErrorCode.PROTOCOL_ERROR;
} finally {
try {
FramedConnection.this.close(connectionErrorCode, streamErrorCode);
} catch (IOException e2) {
}
Util.closeQuietly(this.frameReader);
}
}
示例8: supportedSpec
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
private ConnectionSpec supportedSpec(SSLSocket sslSocket, boolean isFallback) {
String[] cipherSuitesIntersection;
String[] tlsVersionsIntersection;
if (this.cipherSuites != null) {
cipherSuitesIntersection = (String[]) Util.intersect(String.class, this.cipherSuites,
sslSocket.getEnabledCipherSuites());
} else {
cipherSuitesIntersection = sslSocket.getEnabledCipherSuites();
}
if (this.tlsVersions != null) {
tlsVersionsIntersection = (String[]) Util.intersect(String.class, this.tlsVersions,
sslSocket.getEnabledProtocols());
} else {
tlsVersionsIntersection = sslSocket.getEnabledProtocols();
}
if (isFallback && Util.contains(sslSocket.getSupportedCipherSuites(),
"TLS_FALLBACK_SCSV")) {
cipherSuitesIntersection = Util.concat(cipherSuitesIntersection, "TLS_FALLBACK_SCSV");
}
return new Builder(this).cipherSuites(cipherSuitesIntersection).tlsVersions
(tlsVersionsIntersection).build();
}
示例9: cancel
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
public synchronized void cancel(Object tag) {
for (AsyncCall call : this.readyCalls) {
if (Util.equal(tag, call.tag())) {
call.cancel();
}
}
for (AsyncCall call2 : this.runningCalls) {
if (Util.equal(tag, call2.tag())) {
call2.get().canceled = true;
HttpEngine engine = call2.get().engine;
if (engine != null) {
engine.cancel();
}
}
}
for (Call call3 : this.executedCalls) {
if (Util.equal(tag, call3.tag())) {
call3.cancel();
}
}
}
示例10: get
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
public static Handshake get(SSLSession session) {
String cipherSuite = session.getCipherSuite();
if (cipherSuite == null) {
throw new IllegalStateException("cipherSuite == null");
}
Certificate[] peerCertificates;
List<Certificate> peerCertificatesList;
List<Certificate> localCertificatesList;
try {
peerCertificates = session.getPeerCertificates();
} catch (SSLPeerUnverifiedException e) {
peerCertificates = null;
}
if (peerCertificates != null) {
peerCertificatesList = Util.immutableList(peerCertificates);
} else {
peerCertificatesList = Collections.emptyList();
}
Certificate[] localCertificates = session.getLocalCertificates();
if (localCertificates != null) {
localCertificatesList = Util.immutableList(localCertificates);
} else {
localCertificatesList = Collections.emptyList();
}
return new Handshake(cipherSuite, peerCertificatesList, localCertificatesList);
}
示例11: bytes
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
public final byte[] bytes() throws IOException {
long contentLength = contentLength();
if (contentLength > Integer.MAX_VALUE) {
throw new IOException("Cannot buffer entire body for content length: " + contentLength);
}
if (contentLength != -1) {
byte[] content = new byte[(int) contentLength];
InputStream in = byteStream();
Util.readFully(in, content);
if (in.read() != -1) throw new IOException("Content-Length and stream length disagree");
return content;
} else {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Util.copy(byteStream(), out);
return out.toByteArray();
}
}
示例12: release
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
/**
* Releases this engine so that its resources may be either reused or
* closed. Also call {@link #automaticallyReleaseConnectionToPool} unless
* the connection will be used to follow a redirect.
*/
public final void release(boolean streamCanceled) {
// If the response body comes from the cache, close it.
if (responseBodyIn == cachedResponseBody) {
Util.closeQuietly(responseBodyIn);
}
if (!connectionReleased && connection != null) {
connectionReleased = true;
if (transport == null
|| !transport.makeReusable(streamCanceled, requestBodyOut, responseTransferIn)) {
Util.closeQuietly(connection);
connection = null;
} else if (automaticallyReleaseConnectionToPool) {
client.getConnectionPool().recycle(connection);
connection = null;
}
}
}
示例13: readChunkSize
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
private void readChunkSize() throws IOException {
// read the suffix of the previous chunk
if (bytesRemainingInChunk != NO_CHUNK_YET) {
Util.readAsciiLine(in);
}
String chunkSizeString = Util.readAsciiLine(in);
int index = chunkSizeString.indexOf(";");
if (index != -1) {
chunkSizeString = chunkSizeString.substring(0, index);
}
try {
bytesRemainingInChunk = Integer.parseInt(chunkSizeString.trim(), 16);
} catch (NumberFormatException e) {
throw new ProtocolException("Expected a hex chunk size but was " + chunkSizeString);
}
if (bytesRemainingInChunk == 0) {
hasMoreChunks = false;
RawHeaders rawResponseHeaders = httpEngine.responseHeaders.getHeaders();
RawHeaders.readHeaders(transport.socketIn, rawResponseHeaders);
httpEngine.receiveHeaders(rawResponseHeaders);
endOfInput();
}
}
示例14: discardStream
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
/**
* Discards the response body so that the connection can be reused. This
* needs to be done judiciously, since it delays the current request in
* order to speed up a potential future request that may never occur.
*
* <p>A stream may be discarded to encourage response caching (a response
* cannot be cached unless it is consumed completely) or to enable connection
* reuse.
*/
private static boolean discardStream(HttpEngine httpEngine, InputStream responseBodyIn) {
Connection connection = httpEngine.connection;
if (connection == null) return false;
Socket socket = connection.getSocket();
if (socket == null) return false;
try {
int socketTimeout = socket.getSoTimeout();
socket.setSoTimeout(DISCARD_STREAM_TIMEOUT_MILLIS);
try {
Util.skipAll(responseBodyIn);
return true;
} finally {
socket.setSoTimeout(socketTimeout);
}
} catch (IOException e) {
return false;
}
}
示例15: close
import com.squareup.okhttp.internal.Util; //导入依赖的package包/类
@Override
public void close() throws IOException {
if (!mClosed) {
Util.closeQuietly(mFileOutputStream);
mByteArrayOutputStream.reset();
mClosed = true;
}
}