Java 类com.android.volley.toolbox.HttpStack 实例源码

项目:shutterstock-image-browser    文件:VolleySingleton.java   
/**
 * Creates a new Request Queue which caches to the external storage directory
 * @param context
 * @return
 */
private static RequestQueue newRequestQueue(Context context) {
    // define cache folder
    File rootCache = context.getExternalCacheDir();
    if (rootCache == null) {
        Log.w(TAG, "Can't find External Cache Dir, "
                + "switching to application specific cache directory");
        rootCache = context.getCacheDir();
    }

    File cacheDir = new File(rootCache, DEFAULT_CACHE_DIR);
    cacheDir.mkdirs();

    HttpStack stack = new HurlStack();
    Network network = new BasicNetwork(stack);
    DiskBasedCache diskBasedCache = new DiskBasedCache(cacheDir, DEFAULT_DISK_USAGE_BYTES);
    RequestQueue queue = new RequestQueue(diskBasedCache, network);
    queue.start();

    return queue;
}
项目:restafari    文件:RequestService.java   
public void createRequestQueue( RequestServiceOptions requestServiceOptions )
{
    HttpStack httpStack = null;

    if ( null != requestServiceOptions.getProxyHost() && !requestServiceOptions.getProxyHost().isEmpty() )
    {
        httpStack = new ProxiedHurlStack( requestServiceOptions.getProxyHost(), requestServiceOptions.getProxyPort(), requestServiceOptions.getAllowUntrustedConnections());
    }
    else if ( requestServiceOptions.getAllowUntrustedConnections() )
    {
        httpStack = new UntrustedHurlStack();
    }

    // getApplicationContext() is key, it keeps you from leaking the
    // Activity or BroadcastReceiver if someone passes one in.
    requestQueue = Volley.newRequestQueue( context.getApplicationContext(), httpStack );
}
项目:android-project-template    文件:DrupalModel.java   
/**
 * volley's default implementation uses internal cache only so we've implemented our, allowing
 * external cache usage.
 */
@NonNull
private static RequestQueue newRequestQueue(@NonNull final Context context,
        @Nullable HttpStack stack) {

    final VolleyHelperFactory.IVolleyHelper helper = VolleyHelperFactory.newHelper();
    final File cacheDir = helper.getBestCacheDir(context);

    if (stack == null) {
        stack = helper.createHttpStack(context);
    }

    final Network network = new BasicNetwork(stack);
    final RequestQueue queue = new RequestQueue(
            new DiskBasedCache(cacheDir, ApplicationConfig.CACHE_DISK_USAGE_BYTES), network, 1);
    queue.start();
    return queue;
}
项目:android-project-template    文件:Model.java   
/**
 * volley's default implementation uses internal cache only so we've implemented our, allowing
 * external cache usage.
 */
private static RequestQueue newRequestQueue(@NonNull final Context context,
        @Nullable HttpStack stack) {

    final VolleyHelperFactory.IVolleyHelper helper = VolleyHelperFactory.newHelper();
    final File cacheDir = helper.getBestCacheDir(context);

    if (stack == null) {
        stack = helper.createHttpStack(context);
    }

    final Network network = new BasicNetwork(stack);
    final RequestQueue queue = new RequestQueue(
            new DiskBasedCache(cacheDir, ApplicationConfig.CACHE_DISK_USAGE_BYTES), network, 1);
    queue.start();
    return queue;
}
项目:io2014-codelabs    文件:CloudBackendFragment.java   
private RequestQueue newRequestQueue(Context context) {
    // define cache folder
    File rootCache = context.getExternalCacheDir();
    if (rootCache == null) {
        rootCache = context.getCacheDir();
    }

    File cacheDir = new File(rootCache, DEFAULT_CACHE_DIR);
    cacheDir.mkdirs();

    HttpStack stack = new HurlStack();
    Network network = new BasicNetwork(stack);
    DiskBasedCache diskBasedCache = new DiskBasedCache(cacheDir, DEFAULT_DISK_USAGE_BYTES);
    RequestQueue queue = new RequestQueue(diskBasedCache, network);
    queue.start();

    return queue;
}
项目:Qmusic    文件:QMusicRequestManager.java   
/**
 * Use a custom L2 cache,support LRU
 * 
 * @param context
 * @param uniqueName
 * @param diskCacheSize
 * @param memCacheSize
 * @param compressFormat
 * @param quality
 * @param type
 */
private QMusicRequestManager(final Context context, final int diskCacheSize, final int memCacheSize) {
    // ============L2 Cache=============
    HttpStack stack = getHttpStack(false);
    Network network = new BasicNetwork(stack);
    if (L2CacheType == 0) {
        // TODO: this L2 cache implement ignores the HTTP cache headers
        mCacheL2 = new VolleyL2DiskLruCache(new File(context.getCacheDir(), "L2-Cache"), diskCacheSize);
    } else {
        // The build-in L2 cache has no LRU
        mCacheL2 = new DiskBasedCache(new File(context.getCacheDir(), "L2-Cache"), diskCacheSize);
    }
    mRequestQueue = new RequestQueue(mCacheL2, network);
    mRequestQueue.start();
    // ============L1 Cache=============
    if (L1CacheType == 0) {
        mCacheL1 = new VolleyL1MemoryLruImageCache(memCacheSize);
    } else {
        mCacheL1 = new VolleyL1DiskLruImageCache(context, "L1-Cache", diskCacheSize, CompressFormat.JPEG, 80);
    }
    mImageLoader = new ImageLoader(mRequestQueue, mCacheL1);
}
项目:DE-MVP-Clean    文件:DEVolley.java   
private static RequestQueue newCustomRequestQueue(DiskBasedCache cache) {
    HttpStack stack = new HurlStack();
    Network network = new BasicNetwork(stack);
    RequestQueue queue = new RequestQueue(cache, network);
    queue.start();
    return queue;
}
项目:photo-share-android    文件:VolleyHelper.java   
public static RequestQueue getMultipartRequestQueue(Context context) {
    if (mMultipartRequestQueue == null) {
        mMultipartRequestQueue = Volley.newRequestQueue(context, new HttpStack() {
            @Override
            public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
                return null;
            }
        });
    }
    return mMultipartRequestQueue;
}
项目:wasp    文件:WaspBuilderTest.java   
@Test
public void testWaspHttpStackCustom() throws Exception {

  class MyHttpStack implements WaspHttpStack {

    @Override
    public HttpStack getHttpStack() {
      return new OkHttpStack(new OkHttpClient());
    }

    @Override
    public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {

    }

    @Override
    public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) {

    }

    @Override
    public void setCookieHandler(CookieHandler cookieHandler) {

    }
  }

  Wasp.Builder builder = new Wasp.Builder(context)
      .setWaspHttpStack(new MyHttpStack())
      .setEndpoint("http");
  builder.build();

  //default should be NONE
  assertThat(builder.getWaspHttpStack()).isInstanceOf(MyHttpStack.class);
}
项目:MALFriends    文件:RequestHelper.java   
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            httpClient.setRedirectHandler(new DefaultRedirectHandler() {
                @Override
                public boolean isRedirectRequested(HttpResponse response,
                        HttpContext context) {
                    boolean isRedirect = super.isRedirectRequested(
                            response, context);
                    if (!isRedirect) {
                        int responseCode = response.getStatusLine()
                                .getStatusCode();
                        if (responseCode == 301 || responseCode == 302) {
                            return true;
                        }
                    }
                    return isRedirect;
                }
            });
            httpClient.setCookieStore(new BasicCookieStore());
            HttpStack httpStack = new HttpClientStack(httpClient);
            mRequestQueue = Volley.newRequestQueue(MALFriends.getInstance()
                    .getApplicationContext(), httpStack);
        } else {
            HttpURLConnection.setFollowRedirects(true);
            CookieManager manager = new CookieManager(null,
                    CookiePolicy.ACCEPT_ALL);
            CookieHandler.setDefault(manager);
            mRequestQueue = Volley.newRequestQueue(MALFriends.getInstance()
                    .getApplicationContext());
        }

    }
    return mRequestQueue;
}
项目:CrossBow    文件:HttpStackSelector.java   
public static HttpStack createStack() {
    if(hasOkHttp()) {
        OkHttpClient okHttpClient = new OkHttpClient();
        VolleyLog.d("OkHttp found, using okhttp for http stack");
        return new OkHttpStack(okHttpClient);
    }
    else if (useHttpClient()){
        VolleyLog.d("Android version is older than Gingerbread (API 9), using HttpClient");
        return new HttpClientStack(AndroidHttpClient.newInstance(USER_AGENT));
    }
    else {
        VolleyLog.d("Using Default HttpUrlConnection");
        return new HurlStack();
    }
}
项目:Volley-Ball    文件:FileMockNetwork.java   
public FileMockNetwork(Context context, Config config) {
    mContext = context;
    mConfig = config;

    // configure the real network for non mocked requests
    if (config.mRealNetwork == null) {
        HttpStack httpStack = (config.mRealNetworkHttpStack == null) ? ConfigUtils.getDefaultHttpStack(mContext) : config.mRealNetworkHttpStack;
        config.mRealNetwork = ConfigUtils.getDefaultNetwork(httpStack);
    }

    if (!mConfig.mBasePath.equals("") && !mConfig.mBasePath.endsWith("/")) {
        mConfig.mBasePath += "/";
    }
}
项目:Qmusic    文件:QMusicNetwork.java   
/**
 * @param httpStack
 *            HTTP stack to be used
 */
public QMusicNetwork(HttpStack httpStack) {
    // If a pool isn't passed in, then build a small default pool that will
    // give us a lot of
    // benefit and not use too much memory.
    this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE));
}
项目:GeekZone    文件:BaseNetwork.java   
/**
 * @param httpStack HTTP stack to be used
 */
public BaseNetwork(HttpStack httpStack) {
    // If a pool isn't passed in, then build a small default pool that will give us a lot of
    // benefit and not use too much memory.
    this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE));
}
项目:GeekZone    文件:BaseNetwork.java   
/**
 * @param httpStack HTTP stack to be used
 * @param pool      a buffer pool that improves GC performance in copy operations
 */
public BaseNetwork(HttpStack httpStack, ByteArrayPool pool) {
    mHttpStack = httpStack;
    mPool = pool;
}
项目:EsperantoRadio    文件:DrBasicNetwork.java   
/**
 * @param httpStack HTTP stack to be used
 */
public DrBasicNetwork(HttpStack httpStack) {
  // If a pool isn't passed in, then build a small default pool that will give us a lot of
  // benefit and not use too much memory.
  this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE));
}
项目:EsperantoRadio    文件:DrBasicNetwork.java   
/**
 * @param httpStack HTTP stack to be used
 * @param pool      a buffer pool that improves GC performance in copy operations
 */
public DrBasicNetwork(HttpStack httpStack, ByteArrayPool pool) {
  mHttpStack = httpStack;
  mPool = pool;
}
项目:MeifuGO    文件:SBaseNetWork.java   
public SBaseNetWork(HttpStack httpStack) {
    super(httpStack);
}
项目:MeifuGO    文件:SBaseNetWork.java   
public SBaseNetWork(HttpStack httpStack, ByteArrayPool pool) {
    super(httpStack, pool);
}
项目:RestVolley    文件:RestVolley.java   
public static RequestQueue newRequestQueue(Context context, HttpStack stack, int maxDiskCacheBytes, int threadPoolSize) {
    return newRequestQueue(context, stack, maxDiskCacheBytes, threadPoolSize, false);
}
项目:RestVolley    文件:RestVolley.java   
public static RequestQueue newRequestQueue(Context context, HttpStack stack, int threadPoolSize) {
    return newRequestQueue(context, stack, -1, threadPoolSize);
}
项目:RestVolley    文件:RestVolley.java   
public static RequestQueue newRequestQueue(Context context, HttpStack stack, int threadPoolSize, boolean isStreamBasedResponse) {
    return newRequestQueue(context, stack, -1, threadPoolSize, isStreamBasedResponse);
}
项目:RestVolley    文件:StreamBasedNetwork.java   
/**
 * @param httpStack HTTP stack to be used
 */
public StreamBasedNetwork(HttpStack httpStack) {
    super(httpStack);
}
项目:RestVolley    文件:RVNetwork.java   
/**
 * @param httpStack HTTP stack to be used
 */
public RVNetwork(HttpStack httpStack) {
    // If a pool isn't passed in, then build a small default pool that will give us a lot of
    // benefit and not use too much memory.
    this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE));
}
项目:RestVolley    文件:RVNetwork.java   
/**
 * @param httpStack HTTP stack to be used
 * @param pool a buffer pool that improves GC performance in copy operations
 */
public RVNetwork(HttpStack httpStack, ByteArrayPool pool) {
    mHttpStack = httpStack;
    mPool = pool;
}
项目:ApiAbstractionFramework    文件:VolleyRequestExecutor.java   
public VolleyRequestExecutor(Context context, Logger logger, HttpStack httpStack) {
    mRequestQueue = Volley.newRequestQueue(context, httpStack);
    mLogger = logger;
}
项目:FMTech    文件:FinskyApp.java   
private Network createNetwork()
{
  if (Utils.isBackgroundDataEnabled(this))
  {
    FinskyExperiments localFinskyExperiments = getExperiments();
    boolean bool = localFinskyExperiments.isEnabled(12603642L);
    int i;
    if ((localFinskyExperiments.isEnabled(12602748L)) || (localFinskyExperiments.isEnabled(12604235L)) || (localFinskyExperiments.isEnabled(12604236L))) {
      i = 1;
    }
    OkHttpClient localOkHttpClient;
    while ((GooglePlayServicesUtil.isSidewinderDevice(this)) || (((bool) || (i != 0)) && (((Boolean)G.enableOkHttp.get()).booleanValue())))
    {
      Protocol[] arrayOfProtocol = new Protocol[1];
      arrayOfProtocol[0] = Protocol.HTTP_1_1;
      ArrayList localArrayList = Lists.newArrayList(arrayOfProtocol);
      if (!bool) {
        localArrayList.add(Protocol.SPDY_3);
      }
      localOkHttpClient = new OkHttpClient();
      List localList = Util.immutableList(localArrayList);
      if (!localList.contains(Protocol.HTTP_1_1))
      {
        throw new IllegalArgumentException("protocols doesn't contain http/1.1: " + localList);
        i = 0;
      }
      else
      {
        if (localList.contains(Protocol.HTTP_1_0)) {
          throw new IllegalArgumentException("protocols must not contain http/1.0: " + localList);
        }
        if (localList.contains(null)) {
          throw new IllegalArgumentException("protocols must not contain null");
        }
        localOkHttpClient.protocols = Util.immutableList(localList);
        localOkHttpClient.followRedirects = false;
      }
    }
    for (Object localObject = new GoogleOkHttpStack(this, localOkHttpClient, new GoogleUrlRewriter(this), null, ((Boolean)G.enableSensitiveLogging.get()).booleanValue());; localObject = new GoogleHttpClientStack(this, ((Boolean)G.enableSensitiveLogging.get()).booleanValue())) {
      return new BasicNetwork((HttpStack)localObject, new ByteArrayPool(1024 * ((Integer)G.volleyBufferPoolSizeKb.get()).intValue()));
    }
  }
  return new DenyAllNetwork();
}
项目:wordpress_app_android    文件:VolleyUtils.java   
public static HttpStack getHTTPClientStack(final Context ctx) {
    return getHTTPClientStack(ctx, null);
}
项目:wordpress_app_android    文件:VolleyUtils.java   
public static HttpStack getHTTPClientStack(final Context ctx, final Blog currentBlog) {
    return new WPDelayedHurlStack(ctx, currentBlog);
}
项目:android-project-template    文件:VolleyHelperFactory.java   
@Override
public HttpStack createHttpStack(@NonNull final Context context) {
    return new HttpClientStack(createHttpClient(context));
}
项目:android-project-template    文件:VolleyHelperFactory.java   
@Override
public HttpStack createHttpStack(@NonNull final Context context) {
    return new HurlStack();
}
项目:cannon    文件:Cannon.java   
private Cannon(Context context, String appName) {
    try {
        /**
         * We load the cannon as part of the application
         * context to ensure the request queue persists
         * throughout the application lifecycle.
         */
        sApplicationContext = context.getApplicationContext();

        PackageInfo pInfo = sApplicationContext.getPackageManager().getPackageInfo(sApplicationContext.getPackageName(), 0);

        // Set globals
        String appVersion = pInfo.versionName;

        // Build and set the custom user agent string
        // We lock on the safety switch when setting user agent because we this variable
        // is available via a static method and we don't want other threads to read this
        // in the middle of a write operation.
        synchronized (SAFETY_SWITCH) {
            sUserAgent = appName + '/' + appVersion + " (" + Build.MANUFACTURER + " " + Build.MODEL + " " + Build.DEVICE + "; " + Build.VERSION.RELEASE + "; )";
        }
        // Based on com.android.volley.toolbox.Volley.java newRequestQueue method.

        final File cacheDir;
        final int MULTIPLIER;
        if (Environment.isExternalStorageEmulated()) {
            cacheDir = new File(sApplicationContext.getExternalCacheDir(), DISK_CACHE_NAME);
            MULTIPLIER = 2;
        }
        else {
            cacheDir = new File(sApplicationContext.getCacheDir(), DISK_CACHE_NAME);
            MULTIPLIER = 1;
        }

        // Create a DiskBasedCache of 300 MiB for internal storage, 300MiB*2=600MiB for external storage
        DiskBasedCacheOOM diskBasedCache
                = new DiskBasedCacheOOM(cacheDir, MULTIPLIER * DISK_CACHE_MEMORY_ALLOCATION * 1024 * 1024);
        HttpStack httpStack = new OkHttpStack();
        sRequestQueue = new RequestQueue(diskBasedCache, new BasicNetworkOOM(httpStack));
        sRequestQueue.start();

        sImageLoader = new ImageLoader(sRequestQueue, new BitmapLruCache());
    } catch (PackageManager.NameNotFoundException e) {
        // Crashlytics.logException(e);
    }
}
项目:cannon    文件:BasicNetworkOOM.java   
public BasicNetworkOOM(HttpStack httpStack) {
    super(httpStack);
}
项目:cannon    文件:BasicNetworkOOM.java   
public BasicNetworkOOM(HttpStack httpStack, ByteArrayPool pool) {
    super(httpStack, pool);
}
项目:FastLibrary    文件:FastVolley.java   
public static synchronized void init(Context context, HttpStack stack){
    init(context, 5242880, stack);
}
项目:FastLibrary    文件:FastVolley.java   
public static synchronized void init(Context context, int imageCacheSizeLimit, HttpStack stack){
    requestQueue = Volley.newRequestQueue(context.getApplicationContext(), stack);
    imageCache = new LruImageCache(imageCacheSizeLimit);
    imageLoader = new ImageLoader(requestQueue, imageCache);
}
项目:CrossBow    文件:DefaultCrossbowComponents.java   
public Network onCreateNetwork(HttpStack httpStack) {
    return new BasicNetwork(httpStack);
}
项目:CrossBow    文件:DefaultCrossbowComponents.java   
public HttpStack onCreateHttpStack() {
    return HttpStackSelector.createStack();
}
项目:CrossBow    文件:WearCrossbowComponents.java   
@Override
public Network onCreateNetwork(HttpStack httpStack) {
    return new PlayNetwork(getContext());
}
项目:what-stored-in-a-mobile-device-android    文件:HttpPostHandler.java   
public HttpPostHandler(Context context, HttpStack httpStack) {
    this.mContext = context;
    this.mHttpStack = httpStack;
    // the ip of the server that should receive the json
    this.mJSONUrl = SERVER_URL + "submit";
}