本文整理汇总了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;
}
示例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 );
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}
示例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 += "/";
}
}
示例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));
}
示例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));
}
示例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));
}