classes

16:33:29.869 INFO  jd.cli.Main - Decompiling classes.jar
package com.squareup.okhttp;

import com.squareup.okhttp.internal.Util;
import java.net.Proxy;
import java.net.UnknownHostException;
import java.util.List;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;

public final class Address
{
  final Proxy proxy;
  final String uriHost;
  final int uriPort;
  final SSLSocketFactory sslSocketFactory;
  final HostnameVerifier hostnameVerifier;
  final OkAuthenticator authenticator;
  final List<String> transports;
  
  public Address(String uriHost, int uriPort, SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier, OkAuthenticator authenticator, Proxy proxy, List<String> transports)
    throws UnknownHostException
  {
    if (uriHost == null) {
      throw new NullPointerException("uriHost == null");
    }
    if (uriPort <= 0) {
      throw new IllegalArgumentException("uriPort <= 0: " + uriPort);
    }
    if (authenticator == null) {
      throw new IllegalArgumentException("authenticator == null");
    }
    if (transports == null) {
      throw new IllegalArgumentException("transports == null");
    }
    this.proxy = proxy;
    this.uriHost = uriHost;
    this.uriPort = uriPort;
    this.sslSocketFactory = sslSocketFactory;
    this.hostnameVerifier = hostnameVerifier;
    this.authenticator = authenticator;
    this.transports = Util.immutableList(transports);
  }
  
  public String getUriHost()
  {
    return uriHost;
  }
  
  public int getUriPort()
  {
    return uriPort;
  }
  
  public SSLSocketFactory getSslSocketFactory()
  {
    return sslSocketFactory;
  }
  
  public HostnameVerifier getHostnameVerifier()
  {
    return hostnameVerifier;
  }
  
  public OkAuthenticator getAuthenticator()
  {
    return authenticator;
  }
  
  public List<String> getTransports()
  {
    return transports;
  }
  
  public Proxy getProxy()
  {
    return proxy;
  }
  
  public boolean equals(Object other)
  {
    if ((other instanceof Address))
    {
      Address that = (Address)other;
      return (Util.equal(proxy, proxy)) && (uriHost.equals(uriHost)) && (uriPort == uriPort) && (Util.equal(sslSocketFactory, sslSocketFactory)) && (Util.equal(hostnameVerifier, hostnameVerifier)) && (Util.equal(authenticator, authenticator)) && (Util.equal(transports, transports));
    }
    return false;
  }
  
  public int hashCode()
  {
    int result = 17;
    result = 31 * result + uriHost.hashCode();
    result = 31 * result + uriPort;
    result = 31 * result + (sslSocketFactory != null ? sslSocketFactory.hashCode() : 0);
    result = 31 * result + (hostnameVerifier != null ? hostnameVerifier.hashCode() : 0);
    result = 31 * result + (authenticator != null ? authenticator.hashCode() : 0);
    result = 31 * result + (proxy != null ? proxy.hashCode() : 0);
    result = 31 * result + transports.hashCode();
    return result;
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.Address
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.Platform;
import com.squareup.okhttp.internal.http.HttpAuthenticator;
import com.squareup.okhttp.internal.http.HttpEngine;
import com.squareup.okhttp.internal.http.HttpTransport;
import com.squareup.okhttp.internal.http.RawHeaders;
import com.squareup.okhttp.internal.http.SpdyTransport;
import com.squareup.okhttp.internal.spdy.SpdyConnection;
import com.squareup.okhttp.internal.spdy.SpdyConnection.Builder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

public final class Connection
  implements Closeable
{
  private static final byte[] NPN_PROTOCOLS = { 6, 115, 112, 100, 121, 47, 51, 8, 104, 116, 116, 112, 47, 49, 46, 49 };
  private static final byte[] SPDY3 = { 115, 112, 100, 121, 47, 51 };
  private static final byte[] HTTP_11 = { 104, 116, 116, 112, 47, 49, 46, 49 };
  private final Route route;
  private Socket socket;
  private InputStream in;
  private OutputStream out;
  private boolean connected = false;
  private SpdyConnection spdyConnection;
  private int httpMinorVersion = 1;
  private long idleStartTimeNs;
  
  public Connection(Route route)
  {
    this.route = route;
  }
  
  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;
  }
  
  private void upgradeToTls(TunnelRequest tunnelRequest)
    throws IOException
  {
    Platform platform = Platform.get();
    if (requiresTunnel()) {
      makeTunnel(tunnelRequest);
    }
    socket = route.address.sslSocketFactory.createSocket(socket, route.address.uriHost, route.address.uriPort, true);
    
    SSLSocket sslSocket = (SSLSocket)socket;
    if (route.modernTls) {
      platform.enableTlsExtensions(sslSocket, route.address.uriHost);
    } else {
      platform.supportTlsIntolerantServer(sslSocket);
    }
    boolean useNpn = (route.modernTls) && (route.address.transports.contains("spdy/3"));
    if (useNpn) {
      platform.setNpnProtocols(sslSocket, NPN_PROTOCOLS);
    }
    sslSocket.startHandshake();
    if (!route.address.hostnameVerifier.verify(route.address.uriHost, sslSocket.getSession())) {
      throw new IOException("Hostname '" + route.address.uriHost + "' was not verified");
    }
    out = sslSocket.getOutputStream();
    in = sslSocket.getInputStream();
    streamWrapper();
    byte[] selectedProtocol;
    if ((useNpn) && ((selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null)) {
      if (Arrays.equals(selectedProtocol, SPDY3))
      {
        sslSocket.setSoTimeout(0);
        spdyConnection = new SpdyConnection.Builder(route.address.getUriHost(), true, in, out).build();
        
        spdyConnection.sendConnectionHeader();
      }
      else if (!Arrays.equals(selectedProtocol, HTTP_11))
      {
        throw new IOException("Unexpected NPN transport " + new String(selectedProtocol, "ISO-8859-1"));
      }
    }
  }
  
  public boolean isConnected()
  {
    return connected;
  }
  
  public void close()
    throws IOException
  {
    socket.close();
  }
  
  public Route getRoute()
  {
    return route;
  }
  
  public Socket getSocket()
  {
    return socket;
  }
  
  public boolean isAlive()
  {
    return (!socket.isClosed()) && (!socket.isInputShutdown()) && (!socket.isOutputShutdown());
  }
  
  public boolean isReadable()
  {
    if (!(in instanceof BufferedInputStream)) {
      return true;
    }
    if (isSpdy()) {
      return true;
    }
    BufferedInputStream bufferedInputStream = (BufferedInputStream)in;
    try
    {
      int readTimeout = socket.getSoTimeout();
      try
      {
        socket.setSoTimeout(1);
        bufferedInputStream.mark(1);
        boolean bool;
        if (bufferedInputStream.read() == -1) {
          return false;
        }
        bufferedInputStream.reset();
        return true;
      }
      finally
      {
        socket.setSoTimeout(readTimeout);
      }
      return false;
    }
    catch (SocketTimeoutException ignored)
    {
      return true;
    }
    catch (IOException e) {}
  }
  
  public void resetIdleStartTime()
  {
    if (spdyConnection != null) {
      throw new IllegalStateException("spdyConnection != null");
    }
    idleStartTimeNs = System.nanoTime();
  }
  
  public boolean isIdle()
  {
    return (spdyConnection == null) || (spdyConnection.isIdle());
  }
  
  public boolean isExpired(long keepAliveDurationNs)
  {
    return getIdleStartTimeNs() < System.nanoTime() - keepAliveDurationNs;
  }
  
  public long getIdleStartTimeNs()
  {
    return spdyConnection == null ? idleStartTimeNs : spdyConnection.getIdleStartTimeNs();
  }
  
  public Object newTransport(HttpEngine httpEngine)
    throws IOException
  {
    return spdyConnection != null ? new SpdyTransport(httpEngine, spdyConnection) : new HttpTransport(httpEngine, out, in);
  }
  
  public boolean isSpdy()
  {
    return spdyConnection != null;
  }
  
  public SpdyConnection getSpdyConnection()
  {
    return spdyConnection;
  }
  
  public int getHttpMinorVersion()
  {
    return httpMinorVersion;
  }
  
  public void setHttpMinorVersion(int httpMinorVersion)
  {
    this.httpMinorVersion = httpMinorVersion;
  }
  
  public boolean requiresTunnel()
  {
    return (route.address.sslSocketFactory != null) && (route.proxy.type() == Proxy.Type.HTTP);
  }
  
  public void updateReadTimeout(int newTimeout)
    throws IOException
  {
    if (!connected) {
      throw new IllegalStateException("updateReadTimeout - not connected");
    }
    socket.setSoTimeout(newTimeout);
  }
  
  private void makeTunnel(TunnelRequest tunnelRequest)
    throws IOException
  {
    RawHeaders requestHeaders = tunnelRequest.getRequestHeaders();
    RawHeaders responseHeaders;
    boolean credentialsFound;
    do
    {
      out.write(requestHeaders.toBytes());
      responseHeaders = RawHeaders.fromBytes(in);
      switch (responseHeaders.getResponseCode())
      {
      case 200: 
        return;
      case 407: 
        requestHeaders = new RawHeaders(requestHeaders);
        URL url = new URL("https", host, port, "/");
        credentialsFound = HttpAuthenticator.processAuthHeader(route.address.authenticator, 407, responseHeaders, requestHeaders, route.proxy, url);
      }
    } while (credentialsFound);
    throw new IOException("Failed to authenticate with proxy");
    
    throw new IOException("Unexpected response code for CONNECT: " + responseHeaders.getResponseCode());
  }
  
  private void streamWrapper()
    throws IOException
  {
    in = new BufferedInputStream(in, 4096);
    out = new BufferedOutputStream(out, 256);
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.Connection
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.Util;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.Callable;

class ConnectionPool$1
  implements Callable<Void>
{
  ConnectionPool$1(ConnectionPool paramConnectionPool) {}
  
  public Void call()
    throws Exception
  {
    List<Connection> expiredConnections = new ArrayList(2);
    int idleConnectionCount = 0;
    synchronized (this$0)
    {
      ListIterator<Connection> i = ConnectionPool.access$000(this$0).listIterator(ConnectionPool.access$000(this$0).size());
      while (i.hasPrevious())
      {
        Connection connection = (Connection)i.previous();
        if ((!connection.isAlive()) || (connection.isExpired(ConnectionPool.access$100(this$0))))
        {
          i.remove();
          expiredConnections.add(connection);
          if (expiredConnections.size() == 2) {
            break;
          }
        }
        else if (connection.isIdle())
        {
          idleConnectionCount++;
        }
      }
      ListIterator<Connection> i = ConnectionPool.access$000(this$0).listIterator(ConnectionPool.access$000(this$0).size());
      while ((i.hasPrevious()) && (idleConnectionCount > ConnectionPool.access$200(this$0)))
      {
        Connection connection = (Connection)i.previous();
        if (connection.isIdle())
        {
          expiredConnections.add(connection);
          i.remove();
          idleConnectionCount--;
        }
      }
    }
    for (Connection expiredConnection : expiredConnections) {
      Util.closeQuietly(expiredConnection);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.ConnectionPool.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

class ConnectionPool$2
  implements Runnable
{
  ConnectionPool$2(ConnectionPool paramConnectionPool) {}
  
  public void run() {}
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.ConnectionPool.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.Platform;
import com.squareup.okhttp.internal.Util;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ConnectionPool
{
  private static final int MAX_CONNECTIONS_TO_CLEANUP = 2;
  private static final long DEFAULT_KEEP_ALIVE_DURATION_MS = 300000L;
  private static final ConnectionPool systemDefault;
  private final int maxIdleConnections;
  private final long keepAliveDurationNs;
  
  static
  {
    String keepAlive = System.getProperty("http.keepAlive");
    String keepAliveDuration = System.getProperty("http.keepAliveDuration");
    String maxIdleConnections = System.getProperty("http.maxConnections");
    long keepAliveDurationMs = keepAliveDuration != null ? Long.parseLong(keepAliveDuration) : 300000L;
    if ((keepAlive != null) && (!Boolean.parseBoolean(keepAlive))) {
      systemDefault = new ConnectionPool(0, keepAliveDurationMs);
    } else if (maxIdleConnections != null) {
      systemDefault = new ConnectionPool(Integer.parseInt(maxIdleConnections), keepAliveDurationMs);
    } else {
      systemDefault = new ConnectionPool(5, keepAliveDurationMs);
    }
  }
  
  private final LinkedList<Connection> connections = new LinkedList();
  private final ExecutorService executorService = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(), Util.daemonThreadFactory("OkHttp ConnectionPool"));
  private final Callable<Void> connectionsCleanupCallable = new Callable()
  {
    public Void call()
      throws Exception
    {
      List<Connection> expiredConnections = new ArrayList(2);
      int idleConnectionCount = 0;
      synchronized (ConnectionPool.this)
      {
        ListIterator<Connection> i = connections.listIterator(connections.size());
        while (i.hasPrevious())
        {
          Connection connection = (Connection)i.previous();
          if ((!connection.isAlive()) || (connection.isExpired(keepAliveDurationNs)))
          {
            i.remove();
            expiredConnections.add(connection);
            if (expiredConnections.size() == 2) {
              break;
            }
          }
          else if (connection.isIdle())
          {
            idleConnectionCount++;
          }
        }
        ListIterator<Connection> i = connections.listIterator(connections.size());
        while ((i.hasPrevious()) && (idleConnectionCount > maxIdleConnections))
        {
          Connection connection = (Connection)i.previous();
          if (connection.isIdle())
          {
            expiredConnections.add(connection);
            i.remove();
            idleConnectionCount--;
          }
        }
      }
      for (Connection expiredConnection : expiredConnections) {
        Util.closeQuietly(expiredConnection);
      }
      return null;
    }
  };
  
  public ConnectionPool(int maxIdleConnections, long keepAliveDurationMs)
  {
    this.maxIdleConnections = maxIdleConnections;
    keepAliveDurationNs = (keepAliveDurationMs * 1000L * 1000L);
  }
  
  private void waitForCleanupCallableToRun()
  {
    try
    {
      executorService.submit(new Runnable()
      {
        public void run() {}
      }).get();
    }
    catch (Exception e)
    {
      throw new AssertionError();
    }
  }
  
  public static ConnectionPool getDefault()
  {
    return systemDefault;
  }
  
  public synchronized int getConnectionCount()
  {
    return connections.size();
  }
  
  public synchronized int getSpdyConnectionCount()
  {
    int total = 0;
    for (Connection connection : connections) {
      if (connection.isSpdy()) {
        total++;
      }
    }
    return total;
  }
  
  public synchronized int getHttpConnectionCount()
  {
    int total = 0;
    for (Connection connection : connections) {
      if (!connection.isSpdy()) {
        total++;
      }
    }
    return total;
  }
  
  public synchronized Connection get(Address address)
  {
    Connection foundConnection = null;
    ListIterator<Connection> i = connections.listIterator(connections.size());
    while (i.hasPrevious())
    {
      Connection connection = (Connection)i.previous();
      if ((connection.getRoute().getAddress().equals(address)) && (connection.isAlive()) && (System.nanoTime() - connection.getIdleStartTimeNs() < keepAliveDurationNs))
      {
        i.remove();
        if (!connection.isSpdy())
        {
          try
          {
            Platform.get().tagSocket(connection.getSocket());
          }
          catch (SocketException e)
          {
            Util.closeQuietly(connection);
            
            Platform.get().logW("Unable to tagSocket(): " + e);
          }
          continue;
        }
        foundConnection = connection;
      }
    }
    if ((foundConnection != null) && (foundConnection.isSpdy())) {
      connections.addFirst(foundConnection);
    }
    executorService.submit(connectionsCleanupCallable);
    return foundConnection;
  }
  
  public void recycle(Connection connection)
  {
    if (connection.isSpdy()) {
      return;
    }
    if (!connection.isAlive())
    {
      Util.closeQuietly(connection);
      return;
    }
    try
    {
      Platform.get().untagSocket(connection.getSocket());
    }
    catch (SocketException e)
    {
      Platform.get().logW("Unable to untagSocket(): " + e);
      Util.closeQuietly(connection);
      return;
    }
    synchronized (this)
    {
      connections.addFirst(connection);
      connection.resetIdleStartTime();
    }
    executorService.submit(connectionsCleanupCallable);
  }
  
  public void maybeShare(Connection connection)
  {
    executorService.submit(connectionsCleanupCallable);
    if (!connection.isSpdy()) {
      return;
    }
    if (connection.isAlive()) {
      synchronized (this)
      {
        connections.addFirst(connection);
      }
    }
  }
  
  public void evictAll()
  {
    List<Connection> connections;
    synchronized (this)
    {
      connections = new ArrayList(this.connections);
      this.connections.clear();
    }
    for (Connection connection : connections) {
      Util.closeQuietly(connection);
    }
  }
  
  /* Error */
  List<Connection> getConnections()
  {
    // Byte code:
    //   0: aload_0
    //   1: invokespecial 22	com/squareup/okhttp/ConnectionPool:waitForCleanupCallableToRun	()V
    //   4: aload_0
    //   5: dup
    //   6: astore_1
    //   7: monitorenter
    //   8: new 23	java/util/ArrayList
    //   11: dup
    //   12: aload_0
    //   13: getfield 3	com/squareup/okhttp/ConnectionPool:connections	Ljava/util/LinkedList;
    //   16: invokespecial 24	java/util/ArrayList:<init>	(Ljava/util/Collection;)V
    //   19: aload_1
    //   20: monitorexit
    //   21: areturn
    //   22: astore_2
    //   23: aload_1
    //   24: monitorexit
    //   25: aload_2
    //   26: athrow
    // Line number table:
    //   Java source line #130	-> byte code offset #0
    //   Java source line #131	-> byte code offset #4
    //   Java source line #132	-> byte code offset #8
    //   Java source line #133	-> byte code offset #22
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	27	0	this	ConnectionPool
    //   6	18	1	Ljava/lang/Object;	Object
    //   22	4	2	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   8	21	22	finally
    //   22	25	22	finally
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.ConnectionPool
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.http.ResponseHeaders;
import java.io.IOException;
import java.io.InputStream;

class Dispatcher$RealResponseBody
  extends Response.Body
{
  private final ResponseHeaders responseHeaders;
  private final InputStream in;
  
  Dispatcher$RealResponseBody(ResponseHeaders responseHeaders, InputStream in)
  {
    this.responseHeaders = responseHeaders;
    this.in = in;
  }
  
  public boolean ready()
    throws IOException
  {
    return true;
  }
  
  public MediaType contentType()
  {
    String contentType = responseHeaders.getContentType();
    return contentType != null ? MediaType.parse(contentType) : null;
  }
  
  public long contentLength()
  {
    return responseHeaders.getContentLength();
  }
  
  public InputStream byteStream()
    throws IOException
  {
    return in;
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.Dispatcher.RealResponseBody
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.http.ResponseHeaders;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

final class Dispatcher
{
  private final ThreadPoolExecutor executorService;
  private final Map<Object, List<Job>> enqueuedJobs;
  
  Dispatcher()
  {
    executorService = new ThreadPoolExecutor(8, 8, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue());
    
    enqueuedJobs = new LinkedHashMap();
  }
  
  public synchronized void enqueue(OkHttpClient client, Request request, Response.Receiver responseReceiver)
  {
    Job job = new Job(this, client, request, responseReceiver);
    List<Job> jobsForTag = (List)enqueuedJobs.get(request.tag());
    if (jobsForTag == null)
    {
      jobsForTag = new ArrayList(2);
      enqueuedJobs.put(request.tag(), jobsForTag);
    }
    jobsForTag.add(job);
    executorService.execute(job);
  }
  
  public synchronized void cancel(Object tag)
  {
    List<Job> jobs = (List)enqueuedJobs.remove(tag);
    if (jobs == null) {
      return;
    }
    for (Job job : jobs) {
      executorService.remove(job);
    }
  }
  
  synchronized void finished(Job job)
  {
    List<Job> jobs = (List)enqueuedJobs.get(job.tag());
    if (jobs != null) {
      jobs.remove(job);
    }
  }
  
  static class RealResponseBody
    extends Response.Body
  {
    private final ResponseHeaders responseHeaders;
    private final InputStream in;
    
    RealResponseBody(ResponseHeaders responseHeaders, InputStream in)
    {
      this.responseHeaders = responseHeaders;
      this.in = in;
    }
    
    public boolean ready()
      throws IOException
    {
      return true;
    }
    
    public MediaType contentType()
    {
      String contentType = responseHeaders.getContentType();
      return contentType != null ? MediaType.parse(contentType) : null;
    }
    
    public long contentLength()
    {
      return responseHeaders.getContentLength();
    }
    
    public InputStream byteStream()
      throws IOException
    {
      return in;
    }
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.Dispatcher
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

class Failure$1 {}

/* Location:
 * Qualified Name:     com.squareup.okhttp.Failure.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

public class Failure$Builder
{
  private Request request;
  private Throwable exception;
  
  public Builder request(Request request)
  {
    this.request = request;
    return this;
  }
  
  public Builder exception(Throwable exception)
  {
    this.exception = exception;
    return this;
  }
  
  public Failure build()
  {
    return new Failure(this, null);
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.Failure.Builder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

class Failure
{
  private final Request request;
  private final Throwable exception;
  
  private Failure(Builder builder)
  {
    request = request;
    exception = exception;
  }
  
  public Request request()
  {
    return request;
  }
  
  public Throwable exception()
  {
    return exception;
  }
  
  public static class Builder
  {
    private Request request;
    private Throwable exception;
    
    public Builder request(Request request)
    {
      this.request = request;
      return this;
    }
    
    public Builder exception(Throwable exception)
    {
      this.exception = exception;
      return this;
    }
    
    public Failure build()
    {
      return new Failure(this, null);
    }
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.Failure
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import java.io.IOException;
import java.net.CacheRequest;
import java.net.CacheResponse;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

class HttpResponseCache$1
  implements OkResponseCache
{
  HttpResponseCache$1(HttpResponseCache paramHttpResponseCache) {}
  
  public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders)
    throws IOException
  {
    return this$0.get(uri, requestMethod, requestHeaders);
  }
  
  public CacheRequest put(URI uri, URLConnection connection)
    throws IOException
  {
    return this$0.put(uri, connection);
  }
  
  public void maybeRemove(String requestMethod, URI uri)
    throws IOException
  {
    HttpResponseCache.access$000(this$0, requestMethod, uri);
  }
  
  public void update(CacheResponse conditionalCacheHit, HttpURLConnection connection)
    throws IOException
  {
    HttpResponseCache.access$100(this$0, conditionalCacheHit, connection);
  }
  
  public void trackConditionalCacheHit()
  {
    HttpResponseCache.access$200(this$0);
  }
  
  public void trackResponse(ResponseSource source)
  {
    HttpResponseCache.access$300(this$0, source);
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.HttpResponseCache.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.DiskLruCache.Snapshot;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

final class HttpResponseCache$2
  extends FilterInputStream
{
  HttpResponseCache$2(InputStream x0, DiskLruCache.Snapshot paramSnapshot)
  {
    super(x0);
  }
  
  public void close()
    throws IOException
  {
    val$snapshot.close();
    super.close();
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.HttpResponseCache.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

class HttpResponseCache$3 {}

/* Location:
 * Qualified Name:     com.squareup.okhttp.HttpResponseCache.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.DiskLruCache.Editor;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

class HttpResponseCache$CacheRequestImpl$1
  extends FilterOutputStream
{
  HttpResponseCache$CacheRequestImpl$1(HttpResponseCache.CacheRequestImpl paramCacheRequestImpl, OutputStream x0, HttpResponseCache paramHttpResponseCache, DiskLruCache.Editor paramEditor)
  {
    super(x0);
  }
  
  public void close()
    throws IOException
  {
    synchronized (this$1.this$0)
    {
      if (HttpResponseCache.CacheRequestImpl.access$700(this$1)) {
        return;
      }
      HttpResponseCache.CacheRequestImpl.access$702(this$1, true);
      HttpResponseCache.access$808(this$1.this$0);
    }
    super.close();
    val$editor.commit();
  }
  
  public void write(byte[] buffer, int offset, int length)
    throws IOException
  {
    out.write(buffer, offset, length);
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.HttpResponseCache.CacheRequestImpl.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.DiskLruCache.Editor;
import com.squareup.okhttp.internal.Util;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.CacheRequest;

final class HttpResponseCache$CacheRequestImpl
  extends CacheRequest
{
  private final DiskLruCache.Editor editor;
  private OutputStream cacheOut;
  private boolean done;
  private OutputStream body;
  
  public HttpResponseCache$CacheRequestImpl(final HttpResponseCache paramHttpResponseCache, final DiskLruCache.Editor editor)
    throws IOException
  {
    this.editor = editor;
    cacheOut = editor.newOutputStream(1);
    body = new FilterOutputStream(cacheOut)
    {
      public void close()
        throws IOException
      {
        synchronized (this$0)
        {
          if (done) {
            return;
          }
          done = true;
          HttpResponseCache.access$808(this$0);
        }
        super.close();
        editor.commit();
      }
      
      public void write(byte[] buffer, int offset, int length)
        throws IOException
      {
        out.write(buffer, offset, length);
      }
    };
  }
  
  public void abort()
  {
    synchronized (this$0)
    {
      if (done) {
        return;
      }
      done = true;
      HttpResponseCache.access$908(this$0);
    }
    Util.closeQuietly(cacheOut);
    try
    {
      editor.abort();
    }
    catch (IOException ignored) {}
  }
  
  public OutputStream getBody()
    throws IOException
  {
    return body;
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.HttpResponseCache.CacheRequestImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.Base64;
import com.squareup.okhttp.internal.DiskLruCache.Editor;
import com.squareup.okhttp.internal.StrictLineReader;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.http.HttpEngine;
import com.squareup.okhttp.internal.http.HttpURLConnectionImpl;
import com.squareup.okhttp.internal.http.HttpsEngine;
import com.squareup.okhttp.internal.http.HttpsURLConnectionImpl;
import com.squareup.okhttp.internal.http.RawHeaders;
import com.squareup.okhttp.internal.http.ResponseHeaders;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URI;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.List;
import java.util.Map;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;

final class HttpResponseCache$Entry
{
  private final String uri;
  private final RawHeaders varyHeaders;
  private final String requestMethod;
  private final RawHeaders responseHeaders;
  private final String cipherSuite;
  private final Certificate[] peerCertificates;
  private final Certificate[] localCertificates;
  
  public HttpResponseCache$Entry(InputStream in)
    throws IOException
  {
    try
    {
      StrictLineReader reader = new StrictLineReader(in, Util.US_ASCII);
      uri = reader.readLine();
      requestMethod = reader.readLine();
      varyHeaders = new RawHeaders();
      int varyRequestHeaderLineCount = reader.readInt();
      for (int i = 0; i < varyRequestHeaderLineCount; i++) {
        varyHeaders.addLine(reader.readLine());
      }
      responseHeaders = new RawHeaders();
      responseHeaders.setStatusLine(reader.readLine());
      int responseHeaderLineCount = reader.readInt();
      for (int i = 0; i < responseHeaderLineCount; i++) {
        responseHeaders.addLine(reader.readLine());
      }
      if (isHttps())
      {
        String blank = reader.readLine();
        if (blank.length() > 0) {
          throw new IOException("expected \"\" but was \"" + blank + "\"");
        }
        cipherSuite = reader.readLine();
        peerCertificates = readCertArray(reader);
        localCertificates = readCertArray(reader);
      }
      else
      {
        cipherSuite = null;
        peerCertificates = null;
        localCertificates = null;
      }
    }
    finally
    {
      in.close();
    }
  }
  
  public HttpResponseCache$Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException
  {
    this.uri = uri.toString();
    this.varyHeaders = varyHeaders;
    requestMethod = httpConnection.getRequestMethod();
    responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);
    
    SSLSocket sslSocket = getSslSocket(httpConnection);
    if (sslSocket != null)
    {
      cipherSuite = sslSocket.getSession().getCipherSuite();
      Certificate[] peerCertificatesNonFinal = null;
      try
      {
        peerCertificatesNonFinal = sslSocket.getSession().getPeerCertificates();
      }
      catch (SSLPeerUnverifiedException ignored) {}
      peerCertificates = peerCertificatesNonFinal;
      localCertificates = sslSocket.getSession().getLocalCertificates();
    }
    else
    {
      cipherSuite = null;
      peerCertificates = null;
      localCertificates = null;
    }
  }
  
  private SSLSocket getSslSocket(HttpURLConnection httpConnection)
  {
    HttpEngine engine = (httpConnection instanceof HttpsURLConnectionImpl) ? ((HttpsURLConnectionImpl)httpConnection).getHttpEngine() : ((HttpURLConnectionImpl)httpConnection).getHttpEngine();
    
    return (engine instanceof HttpsEngine) ? ((HttpsEngine)engine).getSslSocket() : null;
  }
  
  public void writeTo(DiskLruCache.Editor editor)
    throws IOException
  {
    OutputStream out = editor.newOutputStream(0);
    Writer writer = new BufferedWriter(new OutputStreamWriter(out, Util.UTF_8));
    
    writer.write(uri + '\n');
    writer.write(requestMethod + '\n');
    writer.write(Integer.toString(varyHeaders.length()) + '\n');
    for (int i = 0; i < varyHeaders.length(); i++) {
      writer.write(varyHeaders.getFieldName(i) + ": " + varyHeaders.getValue(i) + '\n');
    }
    writer.write(responseHeaders.getStatusLine() + '\n');
    writer.write(Integer.toString(responseHeaders.length()) + '\n');
    for (int i = 0; i < responseHeaders.length(); i++) {
      writer.write(responseHeaders.getFieldName(i) + ": " + responseHeaders.getValue(i) + '\n');
    }
    if (isHttps())
    {
      writer.write(10);
      writer.write(cipherSuite + '\n');
      writeCertArray(writer, peerCertificates);
      writeCertArray(writer, localCertificates);
    }
    writer.close();
  }
  
  private boolean isHttps()
  {
    return uri.startsWith("https://");
  }
  
  private Certificate[] readCertArray(StrictLineReader reader)
    throws IOException
  {
    int length = reader.readInt();
    if (length == -1) {
      return null;
    }
    try
    {
      CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
      Certificate[] result = new Certificate[length];
      for (int i = 0; i < result.length; i++)
      {
        String line = reader.readLine();
        byte[] bytes = Base64.decode(line.getBytes("US-ASCII"));
        result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
      }
      return result;
    }
    catch (CertificateException e)
    {
      throw new IOException(e.getMessage());
    }
  }
  
  private void writeCertArray(Writer writer, Certificate[] certificates)
    throws IOException
  {
    if (certificates == null)
    {
      writer.write("-1\n");
      return;
    }
    try
    {
      writer.write(Integer.toString(certificates.length) + '\n');
      for (Certificate certificate : certificates)
      {
        byte[] bytes = certificate.getEncoded();
        String line = Base64.encode(bytes);
        writer.write(line + '\n');
      }
    }
    catch (CertificateEncodingException e)
    {
      throw new IOException(e.getMessage());
    }
  }
  
  public boolean matches(URI uri, String requestMethod, Map<String, List<String>> requestHeaders)
  {
    return (this.uri.equals(uri.toString())) && (this.requestMethod.equals(requestMethod)) && (new ResponseHeaders(uri, responseHeaders).varyMatches(varyHeaders.toMultimap(false), requestHeaders));
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.HttpResponseCache.Entry
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.DiskLruCache.Snapshot;
import com.squareup.okhttp.internal.http.RawHeaders;
import java.io.InputStream;
import java.net.CacheResponse;
import java.util.List;
import java.util.Map;

class HttpResponseCache$EntryCacheResponse
  extends CacheResponse
{
  private final HttpResponseCache.Entry entry;
  private final DiskLruCache.Snapshot snapshot;
  private final InputStream in;
  
  public HttpResponseCache$EntryCacheResponse(HttpResponseCache.Entry entry, DiskLruCache.Snapshot snapshot)
  {
    this.entry = entry;
    this.snapshot = snapshot;
    in = HttpResponseCache.access$1000(snapshot);
  }
  
  public Map<String, List<String>> getHeaders()
  {
    return HttpResponseCache.Entry.access$1100(entry).toMultimap(true);
  }
  
  public InputStream getBody()
  {
    return in;
  }
}

/* Location:
 * Qualified Name:     com.squareup.okhttp.HttpResponseCache.EntryCacheResponse
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.squareup.okhttp;

import com.squareup.okhttp.internal.DiskLruCache.Snapshot;
import com.squareup.okhttp.internal.http.RawHeaders;
import java.io.InputStream;
import java.net.SecureCacheResponse;
import java.security.Principal;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.net.ssl.SSLPeerUnverifiedException;

class HttpResponseCache$EntrySecureCacheResponse
  extends SecureCacheResponse
{
  private final HttpResponseCache.Entry entry;
  private final DiskLruCache.Snapshot snapshot;
  private final InputStream in;
  
  public HttpResponseCache$EntrySecureCacheResponse(HttpResponseCache.Entry entry, DiskLruCache.Snapshot snapshot)
  {
    this.entry = entry;
    this.snapshot = snapshot;
    in = HttpResponseCache.access$1000(snapshot);
  }
  
  public Map<String, List<String>> getHeaders()
  {
    return HttpResponseCache.Entry.access$1100(entry).toMultimap(true);
  }
  
  public InputStream getBody()
  {
    return in;
  }
  
  public String getCipherSuite()
  {
    return HttpResponseCache.Entry.access$1200(entry);
  }
  
  public List<Certificate> getServerCertificateChain()
    throws SSLPeerUnverifiedException
  {
    if ((HttpResponseCache.Entry.access$1300(entry) == null) || (HttpResponseCache.Entry.access$1300(entry).length
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd