当前位置: 首页>>代码示例>>Java>>正文


Java HttpStack类代码示例

本文整理汇总了Java中com.android.volley.toolbox.HttpStack的典型用法代码示例。如果您正苦于以下问题:Java HttpStack类的具体用法?Java HttpStack怎么用?Java HttpStack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpStack类属于com.android.volley.toolbox包,在下文中一共展示了HttpStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newRequestQueue

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:bilbo7833,项目名称:shutterstock-image-browser,代码行数:26,代码来源:VolleySingleton.java

示例2: createRequestQueue

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
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 );
}
 
开发者ID:SpartanJ,项目名称:restafari,代码行数:18,代码来源:RequestService.java

示例3: newRequestQueue

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lemberg,项目名称:android-project-template,代码行数:22,代码来源:DrupalModel.java

示例4: newRequestQueue

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lemberg,项目名称:android-project-template,代码行数:21,代码来源:Model.java

示例5: newRequestQueue

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
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;
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:19,代码来源:CloudBackendFragment.java

示例6: getRequestQueue

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
@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;
}
 
开发者ID:DandreX,项目名称:MALFriends,代码行数:38,代码来源:RequestHelper.java

示例7: QMusicRequestManager

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:qianweicheng,项目名称:Qmusic,代码行数:33,代码来源:QMusicRequestManager.java

示例8: newCustomRequestQueue

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
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;
}
 
开发者ID:enuoCM,项目名称:DE-MVP-Clean,代码行数:8,代码来源:DEVolley.java

示例9: getMultipartRequestQueue

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
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;
}
 
开发者ID:kakueki61,项目名称:photo-share-android,代码行数:12,代码来源:VolleyHelper.java

示例10: testWaspHttpStackCustom

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
@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);
}
 
开发者ID:orhanobut,项目名称:wasp,代码行数:35,代码来源:WaspBuilderTest.java

示例11: createStack

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
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();
    }
}
 
开发者ID:patrick-doyle,项目名称:CrossBow,代码行数:16,代码来源:HttpStackSelector.java

示例12: FileMockNetwork

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
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 += "/";
    }
}
 
开发者ID:lukaspili,项目名称:Volley-Ball,代码行数:15,代码来源:FileMockNetwork.java

示例13: QMusicNetwork

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
/**
 * @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));
}
 
开发者ID:qianweicheng,项目名称:Qmusic,代码行数:11,代码来源:QMusicNetwork.java

示例14: BaseNetwork

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
/**
 * @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));
}
 
开发者ID:HanyeeWang,项目名称:GeekZone,代码行数:9,代码来源:BaseNetwork.java

示例15: DrBasicNetwork

import com.android.volley.toolbox.HttpStack; //导入依赖的package包/类
/**
 * @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));
}
 
开发者ID:nordfalk,项目名称:EsperantoRadio,代码行数:9,代码来源:DrBasicNetwork.java


注:本文中的com.android.volley.toolbox.HttpStack类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。