OkHttpDownloader.java 2.91 KB
package com.squareup.picasso;

import android.content.Context;
import android.net.Uri;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.CacheControl;
import com.squareup.okhttp.CacheControl.Builder;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request.Builder;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import java.io.File;
import java.io.IOException;
import sy;

public class OkHttpDownloader
  implements Downloader
{
  private final OkHttpClient a;
  
  public OkHttpDownloader(Context paramContext)
  {
    this(sy.b(paramContext));
  }
  
  public OkHttpDownloader(Context paramContext, long paramLong)
  {
    this(sy.b(paramContext), paramLong);
  }
  
  public OkHttpDownloader(OkHttpClient paramOkHttpClient)
  {
    this.a = paramOkHttpClient;
  }
  
  public OkHttpDownloader(File paramFile)
  {
    this(paramFile, sy.a(paramFile));
  }
  
  public OkHttpDownloader(File paramFile, long paramLong)
  {
    this(localOkHttpClient);
    try
    {
      this.a.setCache(new Cache(paramFile, paramLong));
      return;
    }
    catch (IOException paramFile) {}
  }
  
  protected final OkHttpClient getClient()
  {
    return this.a;
  }
  
  public Downloader.Response load(Uri paramUri, int paramInt)
    throws IOException
  {
    Object localObject = null;
    if (paramInt != 0) {
      if (!NetworkPolicy.isOfflineOnly(paramInt)) {
        break label116;
      }
    }
    for (localObject = CacheControl.FORCE_CACHE;; localObject = ((CacheControl.Builder)localObject).build())
    {
      paramUri = new Request.Builder().url(paramUri.toString());
      if (localObject != null) {
        paramUri.cacheControl((CacheControl)localObject);
      }
      paramUri = this.a.newCall(paramUri.build()).execute();
      int i = paramUri.code();
      if (i < 300) {
        break;
      }
      paramUri.body().close();
      throw new Downloader.ResponseException(i + " " + paramUri.message(), paramInt, i);
      label116:
      localObject = new CacheControl.Builder();
      if (!NetworkPolicy.shouldReadFromDiskCache(paramInt)) {
        ((CacheControl.Builder)localObject).noCache();
      }
      if (!NetworkPolicy.shouldWriteToDiskCache(paramInt)) {
        ((CacheControl.Builder)localObject).noStore();
      }
    }
    if (paramUri.cacheResponse() != null) {}
    for (boolean bool = true;; bool = false)
    {
      paramUri = paramUri.body();
      return new Downloader.Response(paramUri.byteStream(), bool, paramUri.contentLength());
    }
  }
  
  public void shutdown()
  {
    Cache localCache = this.a.getCache();
    if (localCache != null) {}
    try
    {
      localCache.close();
      return;
    }
    catch (IOException localIOException) {}
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/picasso/OkHttpDownloader.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */