类com.squareup.okhttp.internal.Platform源码实例Demo

下面列出了怎么用com.squareup.okhttp.internal.Platform的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: L.TileLayer.Cordova   文件: Connection.java
public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest)
    throws IOException {
  if (connected) throw new IllegalStateException("already connected");

  socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket();
  Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout);
  socket.setSoTimeout(readTimeout);
  in = socket.getInputStream();
  out = socket.getOutputStream();

  if (route.address.sslSocketFactory != null) {
    upgradeToTls(tunnelRequest);
  } else {
    streamWrapper();
  }
  connected = true;
}
 
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(newValue, false /* append */);
  } else {
    rawRequestHeaders.set(field, newValue);
  }
}
 
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(value, true /* append */);
  } else {
    rawRequestHeaders.add(field, value);
  }
}
 
源代码4 项目: wildfly-samples   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *     creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 *     immediately prior to this request/response pair, such as a same-host
 *     redirect. This engine assumes ownership of the connection and must
 *     release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.client = client;
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
源代码5 项目: IoTgo_Android_App   文件: Connection.java
public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest)
    throws IOException {
  if (connected) throw new IllegalStateException("already connected");

  socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket();
  Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout);
  socket.setSoTimeout(readTimeout);
  in = socket.getInputStream();
  out = socket.getOutputStream();

  if (route.address.sslSocketFactory != null) {
    upgradeToTls(tunnelRequest);
  } else {
    streamWrapper();
  }
  connected = true;
}
 
源代码6 项目: IoTgo_Android_App   文件: HttpURLConnectionImpl.java
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(newValue, false /* append */);
  } else {
    rawRequestHeaders.set(field, newValue);
  }
}
 
源代码7 项目: IoTgo_Android_App   文件: HttpURLConnectionImpl.java
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(value, true /* append */);
  } else {
    rawRequestHeaders.add(field, value);
  }
}
 
源代码8 项目: IoTgo_Android_App   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *     creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 *     immediately prior to this request/response pair, such as a same-host
 *     redirect. This engine assumes ownership of the connection and must
 *     release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.client = client;
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
源代码9 项目: android-discourse   文件: HttpURLConnectionImpl.java
@Override
public final 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().logW("Ignoring header " + field + " because its value was null.");
        return;
    }

    if ("X-Android-Transports".equals(field)) {
        setTransports(newValue, false /* append */);
    } else {
        rawRequestHeaders.set(field, newValue);
    }
}
 
源代码10 项目: android-discourse   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *                       creates a private copy that it can mutate.
 * @param connection     the connection used for an intermediate response
 *                       immediately prior to this request/response pair, such as a same-host
 *                       redirect. This engine assumes ownership of the connection and must
 *                       release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders, Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
    this.client = client;
    this.policy = policy;
    this.method = method;
    this.connection = connection;
    this.requestBodyOut = requestBodyOut;

    try {
        uri = Platform.get().toUriLenient(policy.getURL());
    } catch (URISyntaxException e) {
        throw new IOException(e.getMessage());
    }

    this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
源代码11 项目: bluemix-parking-meter   文件: Connection.java
public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest)
    throws IOException {
  if (connected) throw new IllegalStateException("already connected");

  socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket();
  Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout);
  socket.setSoTimeout(readTimeout);
  in = socket.getInputStream();
  out = socket.getOutputStream();

  if (route.address.sslSocketFactory != null) {
    upgradeToTls(tunnelRequest);
  } else {
    streamWrapper();
  }
  connected = true;
}
 
源代码12 项目: wildfly-samples   文件: HttpURLConnectionImpl.java
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(value, true /* append */);
  } else {
    rawRequestHeaders.add(field, value);
  }
}
 
源代码13 项目: bluemix-parking-meter   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *     creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 *     immediately prior to this request/response pair, such as a same-host
 *     redirect. This engine assumes ownership of the connection and must
 *     release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.client = client;
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
源代码14 项目: reader   文件: Connection.java
public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest)
    throws IOException {
  if (connected) throw new IllegalStateException("already connected");

  socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket();
  Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout);
  socket.setSoTimeout(readTimeout);
  in = socket.getInputStream();
  out = socket.getOutputStream();

  if (route.address.sslSocketFactory != null) {
    upgradeToTls(tunnelRequest);
  } else {
    streamWrapper();
  }
  connected = true;
}
 
源代码15 项目: reader   文件: HttpURLConnectionImpl.java
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(newValue, false /* append */);
  } else {
    rawRequestHeaders.set(field, newValue);
  }
}
 
源代码16 项目: reader   文件: HttpURLConnectionImpl.java
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(value, true /* append */);
  } else {
    rawRequestHeaders.add(field, value);
  }
}
 
源代码17 项目: reader   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *     creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 *     immediately prior to this request/response pair, such as a same-host
 *     redirect. This engine assumes ownership of the connection and must
 *     release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.client = client;
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
/**
 * @param requestHeaders the client's supplied request headers. This class
 * creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 * immediately prior to this request/response pair, such as a same-host
 * redirect. This engine assumes ownership of the connection and must
 * release it when it is unneeded.
 */
public HttpEngine(HttpURLConnectionImpl policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
源代码19 项目: reader   文件: HttpURLConnectionImpl.java
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(newValue, false /* append */);
  } else {
    rawRequestHeaders.set(field, newValue);
  }
}
 
源代码20 项目: reader   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *     creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 *     immediately prior to this request/response pair, such as a same-host
 *     redirect. This engine assumes ownership of the connection and must
 *     release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.client = client;
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
源代码21 项目: cordova-amazon-fireos   文件: Connection.java
public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest)
    throws IOException {
  if (connected) throw new IllegalStateException("already connected");

  socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket();
  Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout);
  socket.setSoTimeout(readTimeout);
  in = socket.getInputStream();
  out = socket.getOutputStream();

  if (route.address.sslSocketFactory != null) {
    upgradeToTls(tunnelRequest);
  } else {
    streamWrapper();
  }
  connected = true;
}
 
源代码22 项目: crosswalk-cordova-android   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *     creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 *     immediately prior to this request/response pair, such as a same-host
 *     redirect. This engine assumes ownership of the connection and must
 *     release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.client = client;
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(newValue, false /* append */);
  } else {
    rawRequestHeaders.set(field, newValue);
  }
}
 
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(value, true /* append */);
  } else {
    rawRequestHeaders.add(field, value);
  }
}
 
源代码25 项目: cordova-amazon-fireos   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *     creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 *     immediately prior to this request/response pair, such as a same-host
 *     redirect. This engine assumes ownership of the connection and must
 *     release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.client = client;
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
源代码26 项目: phonegapbootcampsite   文件: Connection.java
public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest)
    throws IOException {
  if (connected) throw new IllegalStateException("already connected");

  socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket();
  Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout);
  socket.setSoTimeout(readTimeout);
  in = socket.getInputStream();
  out = socket.getOutputStream();

  if (route.address.sslSocketFactory != null) {
    upgradeToTls(tunnelRequest);
  } else {
    streamWrapper();
  }
  connected = true;
}
 
源代码27 项目: crosswalk-cordova-android   文件: Connection.java
public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest)
    throws IOException {
  if (connected) throw new IllegalStateException("already connected");

  socket = (route.proxy.type() != Proxy.Type.HTTP) ? new Socket(route.proxy) : new Socket();
  Platform.get().connectSocket(socket, route.inetSocketAddress, connectTimeout);
  socket.setSoTimeout(readTimeout);
  in = socket.getInputStream();
  out = socket.getOutputStream();

  if (route.address.sslSocketFactory != null) {
    upgradeToTls(tunnelRequest);
  } else {
    streamWrapper();
  }
  connected = true;
}
 
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(value, true /* append */);
  } else {
    rawRequestHeaders.add(field, value);
  }
}
 
@Override public final 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().logW("Ignoring header " + field + " because its value was null.");
    return;
  }

  if ("X-Android-Transports".equals(field)) {
    setTransports(value, true /* append */);
  } else {
    rawRequestHeaders.add(field, value);
  }
}
 
源代码30 项目: phonegapbootcampsite   文件: HttpEngine.java
/**
 * @param requestHeaders the client's supplied request headers. This class
 *     creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 *     immediately prior to this request/response pair, such as a same-host
 *     redirect. This engine assumes ownership of the connection and must
 *     release it when it is unneeded.
 */
public HttpEngine(OkHttpClient client, Policy policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.client = client;
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
 类所在包
 同包方法