当前位置: 首页>>代码示例>>Java>>正文


Java Platform类代码示例

本文整理汇总了Java中okhttp3.internal.platform.Platform的典型用法代码示例。如果您正苦于以下问题:Java Platform类的具体用法?Java Platform怎么用?Java Platform使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Platform类属于okhttp3.internal.platform包,在下文中一共展示了Platform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
@Override protected void execute() {
  boolean signalledCallback = false;
  try {
    Response response = getResponseWithInterceptorChain();
    if (retryAndFollowUpInterceptor.isCanceled()) {
      signalledCallback = true;
      responseCallback.onFailure(RealCall.this, new IOException("Canceled"));
    } else {
      signalledCallback = true;
      responseCallback.onResponse(RealCall.this, response);
    }
  } catch (IOException e) {
    if (signalledCallback) {
      // Do not signal the callback twice!
      Platform.get().log(INFO, "Callback failure for " + toLoggableString(), e);
    } else {
      responseCallback.onFailure(RealCall.this, e);
    }
  } finally {
    client.dispatcher().finished(this);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RealCall.java

示例2: connectSocket

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */
private void connectSocket(int connectTimeout, int readTimeout) throws IOException {
  Proxy proxy = route.proxy();
  Address address = route.address();

  rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP
      ? address.socketFactory().createSocket()
      : new Socket(proxy);

  rawSocket.setSoTimeout(readTimeout);
  try {
    Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout);
  } catch (ConnectException e) {
    ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress());
    ce.initCause(e);
    throw ce;
  }
  source = Okio.buffer(Okio.source(rawSocket));
  sink = Okio.buffer(Okio.sink(rawSocket));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RealConnection.java

示例3: setRequestProperty

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
@Override public void setRequestProperty(String field, String newValue) {
  if (connected) {
    throw new IllegalStateException("Cannot set request property after connection is made");
  }
  if (field == null) {
    throw new NullPointerException("field == null");
  }
  if (newValue == null) {
    // Silently ignore null header values for backwards compatibility with older
    // android versions as well as with other URLConnection implementations.
    //
    // Some implementations send a malformed HTTP header when faced with
    // such requests, we respect the spec and ignore the header.
    Platform.get().log(WARN, "Ignoring header " + field + " because its value was null.", null);
    return;
  }

  requestHeaders.set(field, newValue);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:OkHttpURLConnection.java

示例4: addRequestProperty

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
@Override public void addRequestProperty(String field, String value) {
  if (connected) {
    throw new IllegalStateException("Cannot add request property after connection is made");
  }
  if (field == null) {
    throw new NullPointerException("field == null");
  }
  if (value == null) {
    // Silently ignore null header values for backwards compatibility with older
    // android versions as well as with other URLConnection implementations.
    //
    // Some implementations send a malformed HTTP header when faced with
    // such requests, we respect the spec and ignore the header.
    Platform.get().log(WARN, "Ignoring header " + field + " because its value was null.", null);
    return;
  }

  requestHeaders.add(field, value);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:OkHttpURLConnection.java

示例5: execute

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
@Override protected void execute() {
  boolean signalledCallback = false;
  try {
    Response response = getResponseWithInterceptorChain();
    if (retryAndFollowUpInterceptor.isCanceled()) {
      signalledCallback = true;
      responseCallback.onFailure(RealCall.this, new IOException("Canceled"));
    } else {
      signalledCallback = true;
      responseCallback.onResponse(RealCall.this, response);
    }
  } catch (IOException e) {
    if (signalledCallback) {
      // Do not signal the callback twice!
      Platform.get().log(INFO, "Callback failure for " + toLoggableString(), e);
    } else {
      eventListener.callFailed(RealCall.this, e);
      responseCallback.onFailure(RealCall.this, e);
    }
  } finally {
    client.dispatcher().finished(this);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:RealCall.java

示例6: ApiClient

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
ApiClient() {
    mRetrofitBuilder = new Retrofit.Builder()
            .baseUrl("http://op.juhe.cn/")
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create());

    mOkHttpClientBuilder = new OkHttpClient.Builder();
    mOkHttpClientBuilder.connectTimeout(15, TimeUnit.SECONDS);
    if (BuildConfig.DEBUG) {
        mOkHttpClientBuilder.addNetworkInterceptor(
                new LoggingInterceptor.Builder()
                        .loggable(BuildConfig.DEBUG)
                        .setLevel(Level.BODY)
                        .log(Platform.INFO)
                        .request("Request")
                        .response("Response")
                        .build()
        );
    }
}
 
开发者ID:woxingxiao,项目名称:GracefulMovies,代码行数:21,代码来源:ApiClient.java

示例7: provideOkHttpClient

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
@Provides
    @Singleton
    OkHttpClient provideOkHttpClient() {
        OkHttpClient.Builder client = new OkHttpClient.Builder();
        client.addInterceptor(new LoggingInterceptor.Builder()
                .loggable(BuildConfig.DEBUG)
                .setLevel(Level.BASIC)
                .log(Platform.INFO)
                .tag("LoggingI")
                .request("Request")
                .response("Response")
                .addHeader("version", BuildConfig.VERSION_NAME)
                .addQueryParam("query", "0")
//                .logger((level, tag, msg) -> Log.w(tag, msg))
                .build());
        return client.build();
    }
 
开发者ID:ihsanbal,项目名称:LoggingInterceptor,代码行数:18,代码来源:NetModule.java

示例8: createRetrofitBuilder

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
/**
 * 提供Https请求的ApiBuilder
 * <p>此方法为本地存放证书时使用</p>
 * */
public static RetrofitApiBuilder createRetrofitBuilder(int[] certificates, String serverUrl) {
    SSLSocketFactory sslSocketFactory = getSSLSocketFactory(QDFApplication.getAppContext(), certificates);
    X509TrustManager trustManager = Platform.get().trustManager(sslSocketFactory);
    if (sslSocketFactory == null) {
        Logger.e(TAG, "sslSocketFactory is null");
        return null;
    }
    if (trustManager == null) {
        Logger.e(TAG, "trustManager is null");
        return null;
    }
    return new RetrofitApiBuilder()
            .setServerUrl(serverUrl)
            .setSSLSocketFactory(sslSocketFactory, trustManager);
}
 
开发者ID:ShonLin,项目名称:QuickDevFramework,代码行数:20,代码来源:RetrofitManager.java

示例9: pruneAndGetAllocationCount

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
/**
 * Prunes any leaked allocations and then returns the number of remaining live allocations on
 * {@code connection}. Allocations are leaked if the connection is tracking them but the
 * application code has abandoned them. Leak detection is imprecise and relies on garbage
 * collection.
 */
private int pruneAndGetAllocationCount(RealConnection connection, long now) {
  List<Reference<StreamAllocation>> references = connection.allocations;
  for (int i = 0; i < references.size(); ) {
    Reference<StreamAllocation> reference = references.get(i);

    if (reference.get() != null) {
      i++;
      continue;
    }

    // We've discovered a leaked allocation. This is an application bug.
    Platform.get().log(WARN, "A connection to " + connection.route().address().url()
        + " was leaked. Did you forget to close a response body?", null);
    references.remove(i);
    connection.noNewStreams = true;

    // If this was the last allocation, the connection is eligible for immediate eviction.
    if (references.isEmpty()) {
      connection.idleAtNanos = now - keepAliveDurationNs;
      return 0;
    }
  }

  return references.size();
}
 
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:32,代码来源:ConnectionPool.java

示例10: execute

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
@Override
protected void execute() {
    boolean signalledCallback = false;
    try {
        Response response = getResponseWithInterceptorChain();
        if (retryAndFollowUpInterceptor.isCanceled()) {
            signalledCallback = true;
            responseCallback.onFailure(RealCall.this, new IOException("Canceled"));
        } else {
            signalledCallback = true;
            responseCallback.onResponse(RealCall.this, response);
        }
    } catch (IOException e) {
        if (signalledCallback) {
            // Do not signal the callback twice!
            Platform.get().log(INFO, "Callback failure for " + toLoggableString(), e);
        } else {
            responseCallback.onFailure(RealCall.this, e);
        }
    } finally {
        client.dispatcher().finished(this);
    }
}
 
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:24,代码来源:RealCall.java

示例11: connectSocket

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
private void connectSocket(int connectTimeout, int readTimeout) throws IOException {
  Proxy proxy = route.proxy();
  Address address = route.address();

  rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP
      ? address.socketFactory().createSocket()
      : new Socket(proxy);

  rawSocket.setSoTimeout(readTimeout);
  try {
    Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout);
  } catch (ConnectException e) {
    throw new ConnectException("Failed to connect to " + route.socketAddress());
  }
  source = Okio.buffer(Okio.source(rawSocket));
  sink = Okio.buffer(Okio.sink(rawSocket));
}
 
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:18,代码来源:RealConnection.java

示例12: pruneAndGetAllocationCount

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
/**
 * Prunes any leaked allocations and then returns the number of remaining live allocations on
 * {@code connection}. Allocations are leaked if the connection is tracking them but the
 * application code has abandoned them. Leak detection is imprecise and relies on garbage
 * collection.
 */
private int pruneAndGetAllocationCount(RealConnection connection, long now) {
  List<Reference<StreamAllocation>> references = connection.allocations;
  for (int i = 0; i < references.size(); ) {
    Reference<StreamAllocation> reference = references.get(i);

    if (reference.get() != null) {
      i++;
      continue;
    }

    // We've discovered a leaked allocation. This is an application bug.
    StreamAllocation.StreamAllocationReference streamAllocRef =
        (StreamAllocation.StreamAllocationReference) reference;
    String message = "A connection to " + connection.route().address().url()
        + " was leaked. Did you forget to close a response body?";
    Platform.get().logCloseableLeak(message, streamAllocRef.callStackTrace);

    references.remove(i);
    connection.noNewStreams = true;

    // If this was the last allocation, the connection is eligible for immediate eviction.
    if (references.isEmpty()) {
      connection.idleAtNanos = now - keepAliveDurationNs;
      return 0;
    }
  }

  return references.size();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:ConnectionPool.java

示例13: readTheList

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
private void readTheList() {
  byte[] publicSuffixListBytes = null;
  byte[] publicSuffixExceptionListBytes = null;

  InputStream is = PublicSuffixDatabase.class.getClassLoader().getResourceAsStream(
      PUBLIC_SUFFIX_RESOURCE);

  if (is != null) {
    BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(is)));
    try {
      int totalBytes = bufferedSource.readInt();
      publicSuffixListBytes = new byte[totalBytes];
      bufferedSource.readFully(publicSuffixListBytes);

      int totalExceptionBytes = bufferedSource.readInt();
      publicSuffixExceptionListBytes = new byte[totalExceptionBytes];
      bufferedSource.readFully(publicSuffixExceptionListBytes);
    } catch (IOException e) {
      Platform.get().log(Platform.WARN, "Failed to read public suffix list", e);
      publicSuffixListBytes = null;
      publicSuffixExceptionListBytes = null;
    } finally {
      closeQuietly(bufferedSource);
    }
  }

  synchronized (this) {
    this.publicSuffixListBytes = publicSuffixListBytes;
    this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes;
  }

  readCompleteLatch.countDown();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:PublicSuffixDatabase.java

示例14: testGoldenCacheHttpResponseOkHttp30

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
@Test public void testGoldenCacheHttpResponseOkHttp30() throws Exception {
  HttpUrl url = server.url("/");
  String urlKey = Cache.key(url);
  String prefix = Platform.get().getPrefix();
  String entryMetadata = ""
      + "" + url + "\n"
      + "GET\n"
      + "0\n"
      + "HTTP/1.1 200 OK\n"
      + "4\n"
      + "Cache-Control: max-age=60\n"
      + "Content-Length: 3\n"
      + prefix + "-Received-Millis: " + System.currentTimeMillis() + "\n"
      + prefix + "-Sent-Millis: " + System.currentTimeMillis() + "\n";
  String entryBody = "abc";
  String journalBody = ""
      + "libcore.io.DiskLruCache\n"
      + "1\n"
      + "201105\n"
      + "2\n"
      + "\n"
      + "DIRTY " + urlKey + "\n"
      + "CLEAN " + urlKey + " " + entryMetadata.length() + " " + entryBody.length() + "\n";
  writeFile(cache.directory(), urlKey + ".0", entryMetadata);
  writeFile(cache.directory(), urlKey + ".1", entryBody);
  writeFile(cache.directory(), "journal", journalBody);
  cache.close();
  cache = new Cache(cache.directory(), Integer.MAX_VALUE, fileSystem);
  client = client.newBuilder()
      .cache(cache)
      .build();

  Response response = get(url);
  assertEquals(entryBody, response.body().string());
  assertEquals("3", response.header("Content-Length"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:CacheTest.java

示例15: onOpen

import okhttp3.internal.platform.Platform; //导入依赖的package包/类
@Override public void onOpen(WebSocket webSocket, Response response) {
  Platform.get().log(Platform.INFO, "[WS " + name + "] onOpen", null);

  WebSocketListener delegate = this.delegate;
  if (delegate != null) {
    this.delegate = null;
    delegate.onOpen(webSocket, response);
  } else {
    events.add(new Open(webSocket, response));
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:WebSocketRecorder.java


注:本文中的okhttp3.internal.platform.Platform类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。