com.crashlytics.tools.android_2.1.0

rn response;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.execchain.TunnelRefusedException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

public enum CacheResponseStatus
{
  CACHE_MODULE_RESPONSE,  CACHE_HIT,  CACHE_MISS,  VALIDATED;
  
  private CacheResponseStatus() {}
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.CacheResponseStatus
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import org.apache.http.annotation.Immutable;

@Immutable
public class HeaderConstants
{
  public static final String GET_METHOD = "GET";
  public static final String HEAD_METHOD = "HEAD";
  public static final String OPTIONS_METHOD = "OPTIONS";
  public static final String PUT_METHOD = "PUT";
  public static final String DELETE_METHOD = "DELETE";
  public static final String TRACE_METHOD = "TRACE";
  public static final String LAST_MODIFIED = "Last-Modified";
  public static final String IF_MATCH = "If-Match";
  public static final String IF_RANGE = "If-Range";
  public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
  public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
  public static final String IF_NONE_MATCH = "If-None-Match";
  public static final String PRAGMA = "Pragma";
  public static final String MAX_FORWARDS = "Max-Forwards";
  public static final String ETAG = "ETag";
  public static final String EXPIRES = "Expires";
  public static final String AGE = "Age";
  public static final String VARY = "Vary";
  public static final String ALLOW = "Allow";
  public static final String VIA = "Via";
  public static final String PUBLIC = "public";
  public static final String PRIVATE = "private";
  public static final String CACHE_CONTROL = "Cache-Control";
  public static final String CACHE_CONTROL_NO_STORE = "no-store";
  public static final String CACHE_CONTROL_NO_CACHE = "no-cache";
  public static final String CACHE_CONTROL_MAX_AGE = "max-age";
  public static final String CACHE_CONTROL_MAX_STALE = "max-stale";
  public static final String CACHE_CONTROL_MIN_FRESH = "min-fresh";
  public static final String CACHE_CONTROL_MUST_REVALIDATE = "must-revalidate";
  public static final String CACHE_CONTROL_PROXY_REVALIDATE = "proxy-revalidate";
  public static final String STALE_IF_ERROR = "stale-if-error";
  public static final String STALE_WHILE_REVALIDATE = "stale-while-revalidate";
  public static final String WARNING = "Warning";
  public static final String RANGE = "Range";
  public static final String CONTENT_RANGE = "Content-Range";
  public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
  public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";
  public static final String AUTHORIZATION = "Authorization";
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HeaderConstants
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;

@NotThreadSafe
public class HttpCacheContext
  extends HttpClientContext
{
  public static final String CACHE_RESPONSE_STATUS = "http.cache.response.status";
  
  public static HttpCacheContext adapt(HttpContext context)
  {
    if ((context instanceof HttpCacheContext)) {
      return (HttpCacheContext)context;
    }
    return new HttpCacheContext(context);
  }
  
  public static HttpCacheContext create()
  {
    return new HttpCacheContext(new BasicHttpContext());
  }
  
  public HttpCacheContext(HttpContext context)
  {
    super(context);
  }
  
  public HttpCacheContext() {}
  
  public CacheResponseStatus getCacheResponseStatus()
  {
    return (CacheResponseStatus)getAttribute("http.cache.response.status", CacheResponseStatus.class);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HttpCacheContext
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.Header;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.utils.DateUtils;
import org.apache.http.message.HeaderGroup;
import org.apache.http.util.Args;

@Immutable
public class HttpCacheEntry
  implements Serializable
{
  private static final long serialVersionUID = -6300496422359477413L;
  private final Date requestDate;
  private final Date responseDate;
  private final StatusLine statusLine;
  private final HeaderGroup responseHeaders;
  private final Resource resource;
  private final Map<String, String> variantMap;
  private final Date date;
  
  public HttpCacheEntry(Date requestDate, Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, Map<String, String> variantMap)
  {
    Args.notNull(requestDate, "Request date");
    Args.notNull(responseDate, "Response date");
    Args.notNull(statusLine, "Status line");
    Args.notNull(responseHeaders, "Response headers");
    this.requestDate = requestDate;
    this.responseDate = responseDate;
    this.statusLine = statusLine;
    this.responseHeaders = new HeaderGroup();
    this.responseHeaders.setHeaders(responseHeaders);
    this.resource = resource;
    this.variantMap = (variantMap != null ? new HashMap(variantMap) : null);
    
    date = parseDate();
  }
  
  public HttpCacheEntry(Date requestDate, Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource)
  {
    this(requestDate, responseDate, statusLine, responseHeaders, resource, new HashMap());
  }
  
  private Date parseDate()
  {
    Header dateHdr = getFirstHeader("Date");
    if (dateHdr == null) {
      return null;
    }
    return DateUtils.parseDate(dateHdr.getValue());
  }
  
  public StatusLine getStatusLine()
  {
    return statusLine;
  }
  
  public ProtocolVersion getProtocolVersion()
  {
    return statusLine.getProtocolVersion();
  }
  
  public String getReasonPhrase()
  {
    return statusLine.getReasonPhrase();
  }
  
  public int getStatusCode()
  {
    return statusLine.getStatusCode();
  }
  
  public Date getRequestDate()
  {
    return requestDate;
  }
  
  public Date getResponseDate()
  {
    return responseDate;
  }
  
  public Header[] getAllHeaders()
  {
    return responseHeaders.getAllHeaders();
  }
  
  public Header getFirstHeader(String name)
  {
    return responseHeaders.getFirstHeader(name);
  }
  
  public Header[] getHeaders(String name)
  {
    return responseHeaders.getHeaders(name);
  }
  
  public Date getDate()
  {
    return date;
  }
  
  public Resource getResource()
  {
    return resource;
  }
  
  public boolean hasVariants()
  {
    return getFirstHeader("Vary") != null;
  }
  
  public Map<String, String> getVariantMap()
  {
    return Collections.unmodifiableMap(variantMap);
  }
  
  public String toString()
  {
    return "[request date=" + requestDate + "; response date=" + responseDate + "; statusLine=" + statusLine + "]";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HttpCacheEntry
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import java.io.IOException;

public class HttpCacheEntrySerializationException
  extends IOException
{
  private static final long serialVersionUID = 9219188365878433519L;
  
  public HttpCacheEntrySerializationException(String message) {}
  
  public HttpCacheEntrySerializationException(String message, Throwable cause)
  {
    super(message);
    initCause(cause);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HttpCacheEntrySerializationException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public abstract interface HttpCacheEntrySerializer
{
  public abstract void writeTo(HttpCacheEntry paramHttpCacheEntry, OutputStream paramOutputStream)
    throws IOException;
  
  public abstract HttpCacheEntry readFrom(InputStream paramInputStream)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HttpCacheEntrySerializer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;

public abstract interface HttpCacheInvalidator
{
  public abstract void flushInvalidatedCacheEntries(HttpHost paramHttpHost, HttpRequest paramHttpRequest);
  
  public abstract void flushInvalidatedCacheEntries(HttpHost paramHttpHost, HttpRequest paramHttpRequest, HttpResponse paramHttpResponse);
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HttpCacheInvalidator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import java.io.IOException;

public abstract interface HttpCacheStorage
{
  public abstract void putEntry(String paramString, HttpCacheEntry paramHttpCacheEntry)
    throws IOException;
  
  public abstract HttpCacheEntry getEntry(String paramString)
    throws IOException;
  
  public abstract void removeEntry(String paramString)
    throws IOException;
  
  public abstract void updateEntry(String paramString, HttpCacheUpdateCallback paramHttpCacheUpdateCallback)
    throws IOException, HttpCacheUpdateException;
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HttpCacheStorage
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import java.io.IOException;

public abstract interface HttpCacheUpdateCallback
{
  public abstract HttpCacheEntry update(HttpCacheEntry paramHttpCacheEntry)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HttpCacheUpdateCallback
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

public class HttpCacheUpdateException
  extends Exception
{
  private static final long serialVersionUID = 823573584868632876L;
  
  public HttpCacheUpdateException(String message)
  {
    super(message);
  }
  
  public HttpCacheUpdateException(String message, Throwable cause)
  {
    super(message);
    initCause(cause);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.HttpCacheUpdateException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import org.apache.http.annotation.NotThreadSafe;

@NotThreadSafe
public class InputLimit
{
  private final long value;
  private boolean reached;
  
  public InputLimit(long value)
  {
    this.value = value;
    reached = false;
  }
  
  public long getValue()
  {
    return value;
  }
  
  public void reached()
  {
    reached = true;
  }
  
  public boolean isReached()
  {
    return reached;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.InputLimit
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;

public abstract interface Resource
  extends Serializable
{
  public abstract InputStream getInputStream()
    throws IOException;
  
  public abstract long length();
  
  public abstract void dispose();
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.Resource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.cache;

import java.io.IOException;
import java.io.InputStream;

public abstract interface ResourceFactory
{
  public abstract Resource generate(String paramString, InputStream paramInputStream, InputLimit paramInputLimit)
    throws IOException;
  
  public abstract Resource copy(String paramString, Resource paramResource)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.apache.http.client.cache.ResourceFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;

class AsynchronousValidationRequest
  implements Runnable
{
  private final AsynchronousValidator parent;
  private final CachingExec cachingExec;
  private final HttpRoute route;
  private final HttpRequestWrapper request;
  private final HttpClientContext context;
  private final HttpExecutionAware execAware;
  private final HttpCacheEntry cacheEntry;
  private final String identifier;
  private final int consecutiveFailedAttempts;
  private final Log log = LogFactory.getLog(getClass());
  
  AsynchronousValidationRequest(AsynchronousValidator parent, CachingExec cachingExec, HttpRoute route, HttpRequestWrapper request, HttpClientContext context, HttpExecutionAware execAware, HttpCacheEntry cacheEntry, String identifier, int consecutiveFailedAttempts)
  {
    this.parent = parent;
    this.cachingExec = cachingExec;
    this.route = route;
    this.request = request;
    this.context = context;
    this.execAware = execAware;
    this.cacheEntry = cacheEntry;
    this.identifier = identifier;
    this.consecutiveFailedAttempts = consecutiveFailedAttempts;
  }
  
  public void run()
  {
    try
    {
      if (revalidateCacheEntry()) {
        parent.jobSuccessful(identifier);
      } else {
        parent.jobFailed(identifier);
      }
    }
    finally
    {
      parent.markComplete(identifier);
    }
  }
  
  protected boolean revalidateCacheEntry()
  {
    try
    {
      HttpResponse httpResponse = cachingExec.revalidateCacheEntry(route, request, context, execAware, cacheEntry);
      int statusCode = httpResponse.getStatusLine().getStatusCode();
      return (isNotServerError(statusCode)) && (isNotStale(httpResponse));
    }
    catch (IOException ioe)
    {
      log.debug("Asynchronous revalidation failed due to I/O error", ioe);
      return false;
    }
    catch (HttpException pe)
    {
      log.error("HTTP protocol exception during asynchronous revalidation", pe);
      return false;
    }
    catch (RuntimeException re)
    {
      log.error("RuntimeException thrown during asynchronous revalidation: " + re);
    }
    return false;
  }
  
  private boolean isNotServerError(int statusCode)
  {
    return statusCode < 500;
  }
  
  private boolean isNotStale(HttpResponse httpResponse)
  {
    Header[] warnings = httpResponse.getHeaders("Warning");
    if (warnings != null) {
      for (Header warning : warnings)
      {
        String warningValue = warning.getValue();
        if ((warningValue.startsWith("110")) || (warningValue.startsWith("111"))) {
          return false;
        }
      }
    }
    return true;
  }
  
  String getIdentifier()
  {
    return identifier;
  }
  
  public int getConsecutiveFailedAttempts()
  {
    return consecutiveFailedAttempts;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.AsynchronousValidationRequest
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.RejectedExecutionException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;

class AsynchronousValidator
  implements Closeable
{
  private final SchedulingStrategy schedulingStrategy;
  private final Set<String> queued;
  private final CacheKeyGenerator cacheKeyGenerator;
  private final FailureCache failureCache;
  private final Log log = LogFactory.getLog(getClass());
  
  public AsynchronousValidator(CacheConfig config)
  {
    this(new ImmediateSchedulingStrategy(config));
  }
  
  AsynchronousValidator(SchedulingStrategy schedulingStrategy)
  {
    this.schedulingStrategy = schedulingStrategy;
    queued = new HashSet();
    cacheKeyGenerator = new CacheKeyGenerator();
    failureCache = new DefaultFailureCache();
  }
  
  public void close()
    throws IOException
  {
    schedulingStrategy.close();
  }
  
  public synchronized void revalidateCacheEntry(CachingExec cachingExec, HttpRoute route, HttpRequestWrapper request, HttpClientContext context, HttpExecutionAware execAware, HttpCacheEntry entry)
  {
    String uri = cacheKeyGenerator.getVariantURI(route.getTargetHost(), request, entry);
    if (!queued.contains(uri))
    {
      int consecutiveFailedAttempts = failureCache.getErrorCount(uri);
      AsynchronousValidationRequest revalidationRequest = new AsynchronousValidationRequest(this, cachingExec, route, request, context, execAware, entry, uri, consecutiveFailedAttempts);
      try
      {
        schedulingStrategy.schedule(revalidationRequest);
        queued.add(uri);
      }
      catch (RejectedExecutionException ree)
      {
        log.debug("Revalidation for [" + uri + "] not scheduled: " + ree);
      }
    }
  }
  
  synchronized void markComplete(String identifier)
  {
    queued.remove(identifier);
  }
  
  void jobSuccessful(String identifier)
  {
    failureCache.resetErrorCount(identifier);
  }
  
  void jobFailed(String identifier)
  {
    failureCache.increaseErrorCount(identifier);
  }
  
  Set<String> getScheduledIdentifiers()
  {
    return Collections.unmodifiableSet(queued);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.AsynchronousValidator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.IOException;
import org.apache.http.HttpRequest;
import org.apache.http.RequestLine;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.cache.HttpCacheUpdateCallback;

class BasicHttpCache$1
  implements HttpCacheUpdateCallback
{
  BasicHttpCache$1(BasicHttpCache paramBasicHttpCache, HttpRequest paramHttpRequest, HttpCacheEntry paramHttpCacheEntry, String paramString) {}
  
  public HttpCacheEntry update(HttpCacheEntry existing)
    throws IOException
  {
    return this$0.doGetUpdatedParentEntry(val$req.getRequestLine().getUri(), existing, val$entry, BasicHttpCache.access$000(this$0).getVariantKey(val$req, val$entry), val$variantURI);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.BasicHttpCache.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.IOException;
import org.apache.http.HttpRequest;
import org.apache.http.RequestLine;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.cache.HttpCacheUpdateCallback;

class BasicHttpCache$2
  implements HttpCacheUpdateCallback
{
  BasicHttpCache$2(BasicHttpCache paramBasicHttpCache, HttpRequest paramHttpRequest, HttpCacheEntry paramHttpCacheEntry, String paramString1, String paramString2) {}
  
  public HttpCacheEntry update(HttpCacheEntry existing)
    throws IOException
  {
    return this$0.doGetUpdatedParentEntry(val$req.getRequestLine().getUri(), existing, val$entry, val$variantKey, val$variantCacheKey);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.BasicHttpCache.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.RequestLine;
import org.apache.http.StatusLine;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.cache.HttpCacheInvalidator;
import org.apache.http.client.cache.HttpCacheStorage;
import org.apache.http.client.cache.HttpCacheUpdateCallback;
import org.apache.http.client.cache.HttpCacheUpdateException;
import org.apache.http.client.cache.Resource;
import org.apache.http.client.cache.ResourceFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.util.EntityUtils;

class BasicHttpCache
  implements HttpCache
{
  private static final Set<String> safeRequestMethods = new HashSet(Arrays.asList(new String[] { "HEAD", "GET", "OPTIONS", "TRACE" }));
  private final CacheKeyGenerator uriExtractor;
  private final ResourceFactory resourceFactory;
  private final long maxObjectSizeBytes;
  private final CacheEntryUpdater cacheEntryUpdater;
  private final CachedHttpResponseGenerator responseGenerator;
  private final HttpCacheInvalidator cacheInvalidator;
  private final HttpCacheStorage storage;
  private final Log log = LogFactory.getLog(getClass());
  
  public BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config, CacheKeyGenerator uriExtractor, HttpCacheInvalidator cacheInvalidator)
  {
    this.resourceFactory = resourceFactory;
    this.uriExtractor = uriExtractor;
    cacheEntryUpdater = new CacheEntryUpdater(resourceFactory);
    maxObjectSizeBytes = config.getMaxObjectSize();
    responseGenerator = new CachedHttpResponseGenerator();
    this.storage = storage;
    this.cacheInvalidator = cacheInvalidator;
  }
  
  public BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config, CacheKeyGenerator uriExtractor)
  {
    this(resourceFactory, storage, config, uriExtractor, new CacheInvalidator(uriExtractor, storage));
  }
  
  public BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config)
  {
    this(resourceFactory, storage, config, new CacheKeyGenerator());
  }
  
  public BasicHttpCache(CacheConfig config)
  {
    this(new HeapResourceFactory(), new BasicHttpCacheStorage(config), config);
  }
  
  public BasicHttpCache()
  {
    this(CacheConfig.DEFAULT);
  }
  
  public void flushCacheEntriesFor(HttpHost host, HttpRequest request)
    throws IOException
  {
    if (!safeRequestMethods.contains(request.getRequestLine().getMethod()))
    {
      String uri = uriExtractor.getURI(host, request);
      storage.removeEntry(uri);
    }
  }
  
  public void flushInvalidatedCacheEntriesFor(HttpHost host, HttpRequest request, HttpResponse response)
  {
    if (!safeRequestMethods.contains(request.getRequestLine().getMethod())) {
      cacheInvalidator.flushInvalidatedCacheEntries(host, request, response);
    }
  }
  
  void storeInCache(HttpHost target, HttpRequest request, HttpCacheEntry entry)
    throws IOException
  {
    if (entry.hasVariants()) {
      storeVariantEntry(target, request, entry);
    } else {
      storeNonVariantEntry(target, request, entry);
    }
  }
  
  void storeNonVariantEntry(HttpHost target, HttpRequest req, HttpCacheEntry entry)
    throws IOException
  {
    String uri = uriExtractor.getURI(target, req);
    storage.putEntry(uri, entry);
  }
  
  void storeVariantEntry(HttpHost target, final HttpRequest req, final HttpCacheEntry entry)
    throws IOException
  {
    String parentURI = uriExtractor.getURI(target, req);
    final String variantURI = uriExtractor.getVariantURI(target, req, entry);
    storage.putEntry(variantURI, entry);
    
    HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback()
    {
      public HttpCacheEntry update(HttpCacheEntry existing)
        throws IOException
      {
        return doGetUpdatedParentEntry(req.getRequestLine().getUri(), existing, entry, uriExtractor.getVariantKey(req, entry), variantURI);
      }
    };
    try
    {
      storage.updateEntry(parentURI, callback);
    }
    catch (HttpCacheUpdateException e)
    {
      log.warn("Could not update key [" + parentURI + "]", e);
    }
  }
  
  public void reuseVariantEntryFor(HttpHost target, final HttpRequest req, Variant variant)
    throws IOException
  {
    String parentCacheKey = uriExtractor.getURI(target, req);
    final HttpCacheEntry entry = variant.getEntry();
    final String variantKey = uriExtractor.getVariantKey(req, entry);
    final String variantCacheKey = variant.getCacheKey();
    
    HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback()
    {
      public HttpCacheEntry update(HttpCacheEntry existing)
        throws IOException
      {
        return doGetUpdatedParentEntry(req.getRequestLine().getUri(), existing, entry, variantKey, variantCacheKey);
      }
    };
    try
    {
      storage.updateEntry(parentCacheKey, callback);
    }
    catch (HttpCacheUpdateException e)
    {
      log.warn("Could not update key [" + parentCacheKey + "]", e);
    }
  }
  
  boolean isIncompleteResponse(HttpResponse resp, Resource resource)
  {
    int status = resp.getStatusLine().getStatusCode();
    if ((status != 200) && (status != 206)) {
      return false;
    }
    Header hdr = resp.getFirstHeader("Content-Length");
    if (hdr == null) {
      return false;
    }
    int contentLength;
    try
    {
      contentLength = Integer.parseInt(hdr.getValue());
    }
    catch (NumberFormatException nfe)
    {
      return false;
    }
    return resource.length() < contentLength;
  }
  
  HttpResponse generateIncompleteResponseError(HttpResponse response, Resource resource)
  {
    int contentLength = Integer.parseInt(response.getFirstHeader("Content-Length").getValue());
    HttpResponse error = new BasicHttpResponse(HttpVersion.HTTP_1_1, 502, "Bad Gateway");
    
    error.setHeader("Content-Type", "text/plain;charset=UTF-8");
    String msg = String.format("Received incomplete response with Content-Length %d but actual body length %d", new Object[] { Integer.valueOf(contentLength), Long.valueOf(resource.length()) });
    
    byte[] msgBytes = msg.getBytes();
    error.setHeader("Content-Length", Integer.toString(msgBytes.length));
    error.setEntity(new ByteArrayEntity(msgBytes));
    return error;
  }
  
  HttpCacheEntry doGetUpdatedParentEntry(String requestId, HttpCacheEntry existing, HttpCacheEntry entry, String variantKey, String variantCacheKey)
    throws IOException
  {
    HttpCacheEntry src = existing;
    if (src == null) {
      src = entry;
    }
    Resource resource = null;
    if (src.getResource() != null) {
      resource = resourceFactory.copy(requestId, src.getResource());
    }
    Map<String, String> variantMap = new HashMap(src.getVariantMap());
    variantMap.put(variantKey, variantCacheKey);
    return new HttpCacheEntry(src.getRequestDate(), src.getResponseDate(), src.getStatusLine(), src.getAllHeaders(), resource, variantMap);
  }
  
  public HttpCacheEntry updateCacheEntry(HttpHost target, HttpRequest request, HttpCacheEntry stale, HttpResponse originResponse, Date requestSent, Date responseReceived)
    throws IOException
  {
    HttpCacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry(request.getRequestLine().getUri(), stale, requestSent, responseReceived, originResponse);
    
    storeInCache(target, request, updatedEntry);
    return updatedEntry;
  }
  
  public HttpCacheEntry updateVariantCacheEntry(HttpHost target, HttpRequest request, HttpCacheEntry stale, HttpResponse originResponse, Date requestSent, Date responseReceived, String cacheKey)
    throws IOException
  {
    HttpCacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry(request.getRequestLine().getUri(), stale, requestSent, responseReceived, originResponse);
    
    storage.putEntry(cacheKey, updatedEntry);
    return updatedEntry;
  }
  
  public HttpResponse cacheAndReturnResponse(HttpHost host, HttpRequest request, HttpResponse originResponse, Date requestSent, Date responseReceived)
    throws IOException
  {
    SizeLimitedResponseReader responseReader = getResponseReader(request, originResponse);
    try
    {
      responseReader.readResponse();
      if (responseReader.isLimitReached()) {
        return responseReader.getReconstructedResponse();
      }
      Resource resource = responseReader.getResource();
      if (isIncompleteResponse(originResponse, resource)) {
        return generateIncompleteResponseError(originResponse, resource);
      }
      HttpCacheEntry entry = new HttpCacheEntry(requestSent, responseReceived, originResponse.getStatusLine(), originResponse.getAllHeaders(), resource);
      
      storeInCache(host, request, entry);
      return responseGenerator.generateResponse(entry);
    }
    catch (IOException ex)
    {
      EntityUtils.consume(originResponse.getEntity());
      throw ex;
    }
    catch (RuntimeException ex)
    {
      EntityUtils.consumeQuietly(originResponse.getEntity());
      throw ex;
    }
  }
  
  SizeLimitedResponseReader getResponseReader(HttpRequest request, HttpResponse backEndResponse)
  {
    return new SizeLimitedResponseReader(resourceFactory, maxObjectSizeBytes, request, backEndResponse);
  }
  
  public HttpCacheEntry getCacheEntry(HttpHost host, HttpRequest request)
    throws IOException
  {
    HttpCacheEntry root = storage.getEntry(uriExtractor.getURI(host, request));
    if (root == null) {
      return null;
    }
    if (!root.hasVariants()) {
      return root;
    }
    String variantCacheKey = (String)root.getVariantMap().get(uriExtractor.getVariantKey(request, root));
    if (variantCacheKey == null) {
      return null;
    }
    return storage.getEntry(variantCacheKey);
  }
  
  public void flushInvalidatedCacheEntriesFor(HttpHost host, HttpRequest request)
    throws IOException
  {
    cacheInvalidator.flushInvalidatedCacheEntries(host, request);
  }
  
  public Map<String, Variant> getVariantCacheEntriesWithEtags(HttpHost host, HttpRequest request)
    throws IOException
  {
    Map<String, Variant> variants = new HashMap();
    HttpCacheEntry root = storage.getEntry(uriExtractor.getURI(host, request));
    if ((root == null) || (!root.hasVariants())) {
      return variants;
    }
    for (Map.Entry<String, String> variant : root.getVariantMap().entrySet())
    {
      String variantKey = (String)variant.getKey();
      String variantCacheKey = (String)variant.getValue();
      addVariantWithEtag(variantKey, variantCacheKey, variants);
    }
    return variants;
  }
  
  private void addVariantWithEtag(String variantKey, String variantCacheKey, Map<String, Variant> variants)
    throws IOException
  {
    HttpCacheEntry entry = storage.getEntry(variantCacheKey);
    if (entry == null) {
      return;
    }
    Header etagHeader = entry.getFirstHeader("ETag");
    if (etagHeader == null) {
      return;
    }
    variants.put(etagHeader.getValue(), new Variant(variantKey, variantCacheKey, entry));
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.BasicHttpCache
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.IOException;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.cache.HttpCacheStorage;
import org.apache.http.client.cache.HttpCacheUpdateCallback;

@ThreadSafe
public class BasicHttpCacheStorage
  implements HttpCacheStorage
{
  private final CacheMap entries;
  
  public BasicHttpCacheStorage(CacheConfig config)
  {
    entries = new CacheMap(config.getMaxCacheEntries());
  }
  
  public synchronized void putEntry(String url, HttpCacheEntry entry)
    throws IOException
  {
    entries.put(url, entry);
  }
  
  public synchronized HttpCacheEntry getEntry(String url)
    throws IOException
  {
    return (HttpCacheEntry)entries.get(url);
  }
  
  public synchronized void removeEntry(String url)
    throws IOException
  {
    entries.remove(url);
  }
  
  public synchronized void updateEntry(String url, HttpCacheUpdateCallback callback)
    throws IOException
  {
    HttpCacheEntry existingEntry = (HttpCacheEntry)entries.get(url);
    entries.put(url, callback.update(existingEntry));
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.BasicHttpCacheStorage
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Formatter;
import java.util.Locale;
import org.apache.http.annotation.GuardedBy;
import org.apache.http.annotation.ThreadSafe;

@ThreadSafe
class BasicIdGenerator
{
  private final String hostname;
  private final SecureRandom rnd;
  @GuardedBy("this")
  private long count;
  
  public BasicIdGenerator()
  {
    String hostname;
    try
    {
      hostname = InetAddress.getLocalHost().getHostName();
    }
    catch (UnknownHostException ex)
    {
      hostname = "localhost";
    }
    this.hostname = hostname;
    try
    {
      rnd = SecureRandom.getInstance("SHA1PRNG");
    }
    catch (NoSuchAlgorithmException ex)
    {
      throw new Error(ex);
    }
    rnd.setSeed(System.currentTimeMillis());
  }
  
  public synchronized void generate(StringBuilder buffer)
  {
    count += 1L;
    int rndnum = rnd.nextInt();
    buffer.append(System.currentTimeMillis());
    buffer.append('.');
    Formatter formatter = new Formatter(buffer, Locale.US);
    formatter.format("%1$016x-%2$08x", new Object[] { Long.valueOf(count), Integer.valueOf(rndnum) });
    formatter.close();
    buffer.append('.');
    buffer.append(hostname);
  }
  
  public String generate()
  {
    StringBuilder buffer = new StringBuilder();
    generate(buffer);
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.BasicIdGenerator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

public class CacheConfig$Builder
{
  private long maxObjectSize;
  private int maxCacheEntries;
  private int maxUpdateRetries;
  private boolean allow303Caching;
  private boolean weakETagOnPutDeleteAllowed;
  private boolean heuristicCachingEnabled;
  private float heuristicCoefficient;
  private long heuristicDefaultLifetime;
  private boolean isSharedCache;
  private int asynchronousWorkersMax;
  private int asynchronousWorkersCore;
  private int asynchronousWorkerIdleLifetimeSecs;
  private int revalidationQueueSize;
  private boolean neverCacheHTTP10ResponsesWithQuery;
  
  CacheConfig$Builder()
  {
    maxObjectSize = 8192L;
    maxCacheEntries = 1000;
    maxUpdateRetries = 1;
    allow303Caching = false;
    weakETagOnPutDeleteAllowed = false;
    heuristicCachingEnabled = false;
    heuristicCoefficient = 0.1F;
    heuristicDefaultLifetime = 0L;
    isSharedCache = true;
    asynchronousWorkersMax = 1;
    asynchronousWorkersCore = 1;
    asynchronousWorkerIdleLifetimeSecs = 60;
    revalidationQueueSize = 100;
  }
  
  public Builder setMaxObjectSize(long maxObjectSize)
  {
    this.maxObjectSize = maxObjectSize;
    return this;
  }
  
  public Builder setMaxCacheEntries(int maxCacheEntries)
  {
    this.maxCacheEntries = maxCacheEntries;
    return this;
  }
  
  public Builder setMaxUpdateRetries(int maxUpdateRetries)
  {
    this.maxUpdateRetries = maxUpdateRetries;
    return this;
  }
  
  public Builder setAllow303Caching(boolean allow303Caching)
  {
    this.allow303Caching = allow303Caching;
    return this;
  }
  
  public Builder setWeakETagOnPutDeleteAllowed(boolean weakETagOnPutDeleteAllowed)
  {
    this.weakETagOnPutDeleteAllowed = weakETagOnPutDeleteAllowed;
    return this;
  }
  
  public Builder setHeuristicCachingEnabled(boolean heuristicCachingEnabled)
  {
    this.heuristicCachingEnabled = heuristicCachingEnabled;
    return this;
  }
  
  public Builder setHeuristicCoefficient(float heuristicCoefficient)
  {
    this.heuristicCoefficient = heuristicCoefficient;
    return this;
  }
  
  public Builder setHeuristicDefaultLifetime(long heuristicDefaultLifetime)
  {
    this.heuristicDefaultLifetime = heuristicDefaultLifetime;
    return this;
  }
  
  public Builder setSharedCache(boolean isSharedCache)
  {
    this.isSharedCache = isSharedCache;
    return this;
  }
  
  public Builder setAsynchronousWorkersMax(int asynchronousWorkersMax)
  {
    this.asynchronousWorkersMax = asynchronousWorkersMax;
    return this;
  }
  
  public Builder setAsynchronousWorkersCore(int asynchronousWorkersCore)
  {
    this.asynchronousWorkersCore = asynchronousWorkersCore;
    return this;
  }
  
  public Builder setAsynchronousWorkerIdleLifetimeSecs(int asynchronousWorkerIdleLifetimeSecs)
  {
    this.asynchronousWorkerIdleLifetimeSecs = asynchronousWorkerIdleLifetimeSecs;
    return this;
  }
  
  public Builder setRevalidationQueueSize(int revalidationQueueSize)
  {
    this.revalidationQueueSize = revalidationQueueSize;
    return this;
  }
  
  public Builder setNeverCacheHTTP10ResponsesWithQueryString(boolean neverCacheHTTP10ResponsesWithQuery)
  {
    this.neverCacheHTTP10ResponsesWithQuery = neverCacheHTTP10ResponsesWithQuery;
    return this;
  }
  
  public CacheConfig build()
  {
    return new CacheConfig(maxObjectSize, maxCacheEntries, maxUpdateRetries, allow303Caching, weakETagOnPutDeleteAllowed, heuristicCachingEnabled, heuristicCoefficient, heuristicDefaultLifetime, isSharedCache, asynchronousWorkersMax, asynchronousWorkersCore, asynchronousWorkerIdleLifetimeSecs, revalidationQueueSize, neverCacheHTTP10ResponsesWithQuery);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.CacheConfig.Builder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import org.apache.http.util.Args;

public class CacheConfig
  implements Cloneable
{
  public static final int DEFAULT_MAX_OBJECT_SIZE_BYTES = 8192;
  public static final int DEFAULT_MAX_CACHE_ENTRIES = 1000;
  public static final int DEFAULT_MAX_UPDATE_RETRIES = 1;
  public static final boolean DEFAULT_303_CACHING_ENABLED = false;
  public static final boolean DEFAULT_WEAK_ETAG_ON_PUTDELETE_ALLOWED = false;
  public static final boolean DEFAULT_HEURISTIC_CACHING_ENABLED = false;
  public static final float DEFAULT_HEURISTIC_COEFFICIENT = 0.1F;
  public static final long DEFAULT_HEURISTIC_LIFETIME = 0L;
  public static final int DEFAULT_ASYNCHRONOUS_WORKERS_MAX = 1;
  public static final int DEFAULT_ASYNCHRONOUS_WORKERS_CORE = 1;
  public static final int DEFAULT_ASYNCHRONOUS_WORKER_IDLE_LIFETIME_SECS = 60;
  public static final int DEFAULT_REVALIDATION_QUEUE_SIZE = 100;
  public static final CacheConfig DEFAULT = new Builder().build();
  private long maxObjectSize;
  private int maxCacheEntries;
  private int maxUpdateRetries;
  private boolean allow303Caching;
  private boolean weakETagOnPutDeleteAllowed;
  p
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

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