當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。