本文整理汇总了Java中com.android.volley.Response.error方法的典型用法代码示例。如果您正苦于以下问题:Java Response.error方法的具体用法?Java Response.error怎么用?Java Response.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.volley.Response
的用法示例。
在下文中一共展示了Response.error方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doParse
import com.android.volley.Response; //导入方法依赖的package包/类
/**
* The real guts of parseNetworkResponse. Broken out for readability.
*/
private Response<Bitmap> doParse(NetworkResponse response) {
byte[] data = response.data;
BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
Bitmap bitmap = null;
if (mMaxWidth == 0 && mMaxHeight == 0) {
if (mDecodeConfig != null) {
decodeOptions.inPreferredConfig = mDecodeConfig;
}
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
} else {
bitmap = ImageUtils.compressBitmap(data, mMaxWidth, mMaxHeight);
}
if (bitmap == null) {
return Response.error(new ParseError());
} else {
return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
}
}
示例2: parseNetworkResponse
import com.android.volley.Response; //导入方法依赖的package包/类
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
return Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
示例3: parseNetworkResponse
import com.android.volley.Response; //导入方法依赖的package包/类
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
return Response.success(new JSONArray(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
示例4: parseNetworkResponse
import com.android.volley.Response; //导入方法依赖的package包/类
@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
// Serialize all decode on a global lock to reduce concurrent heap usage.
synchronized (sDecodeLock) {
try {
return doParse(response);
} catch (OutOfMemoryError e) {
VolleyLog.e("Caught OOM for %d byte image, url=%s", response.data.length, getUrl());
return Response.error(new ParseError(e));
}
}
}
示例5: parseNetworkResponse
import com.android.volley.Response; //导入方法依赖的package包/类
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
return Response.success(jsonString,
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (Exception je) {
return Response.error(new ParseError(je));
}
}
示例6: setUp
import com.android.volley.Response; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
url = "http://neopixl.com/";
headers.put("If-Range", "Wed, 21 Oct 2017 07:28:00 GMT");
headers.put("X-ApiKey", "azerty");
headers.put("Authorization", "Bearer 1000:2b52d2ccfd6007d7a8d58d8cabb32bc0");
dummyData = new RequestData("neopixl.jpg", new byte[16]);
byte[] data = new byte[16];
Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
mDelivery = new ImmediateResponseDelivery();
mSuccessResponse = Response.success(dummyResponse, cacheEntry);
volleyError = new ServerError();
mErrorResponse = Response.error(volleyError);
}
示例7: doParse
import com.android.volley.Response; //导入方法依赖的package包/类
private Response<Bitmap> doParse(NetworkResponse response) {
Bitmap bitmap;
byte[] data = response.data;
Options decodeOptions = new Options();
if (this.mMaxWidth == 0 && this.mMaxHeight == 0) {
decodeOptions.inPreferredConfig = this.mDecodeConfig;
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
} else {
decodeOptions.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
int actualWidth = decodeOptions.outWidth;
int actualHeight = decodeOptions.outHeight;
int desiredWidth = getResizedDimension(this.mMaxWidth, this.mMaxHeight, actualWidth, actualHeight, this.mScaleType);
int desiredHeight = getResizedDimension(this.mMaxHeight, this.mMaxWidth, actualHeight, actualWidth, this.mScaleType);
decodeOptions.inJustDecodeBounds = false;
decodeOptions.inSampleSize = findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
Bitmap tempBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
if (tempBitmap == null || (tempBitmap.getWidth() <= desiredWidth && tempBitmap.getHeight() <= desiredHeight)) {
bitmap = tempBitmap;
} else {
bitmap = Bitmap.createScaledBitmap(tempBitmap, desiredWidth, desiredHeight, true);
tempBitmap.recycle();
}
}
if (bitmap == null) {
return Response.error(new ParseError(response));
}
return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
}
示例8: parseNetworkResponse
import com.android.volley.Response; //导入方法依赖的package包/类
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
示例9: parseNetworkResponse
import com.android.volley.Response; //导入方法依赖的package包/类
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString =
new String(response.data, HttpHeaderParser.parseCharset(response.headers));
return Response.success(new JSONArray(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
示例10: parseNetworkResponse
import com.android.volley.Response; //导入方法依赖的package包/类
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
Response<Bitmap> doParse;
synchronized (sDecodeLock) {
try {
doParse = doParse(response);
} catch (Throwable e) {
VolleyLog.e("Caught OOM for %d byte image, url=%s", Integer.valueOf(response.data.length), getUrl());
doParse = Response.error(new ParseError(e));
}
}
return doParse;
}
示例11: setUp
import com.android.volley.Response; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
parameters.put("page", "1");
parameters.put("limit", "50");
headers.put("If-Range", "Wed, 21 Oct 2017 07:28:00 GMT");
headers.put("X-ApiKey", "azerty");
headers.put("Authorization", "Bearer 1000:2b52d2ccfd6007d7a8d58d8cabb32bc0");
headersWithContentType.putAll(headers);
headersWithContentType.put("Content-Type", "application/json");
byte[] data = new byte[16];
Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
mDelivery = new ImmediateResponseDelivery();
mSuccessResponse = Response.success(dummyResponse, cacheEntry);
volleyError = new ServerError();
mErrorResponse = Response.error(volleyError);
}
示例12: parseNetworkResponse
import com.android.volley.Response; //导入方法依赖的package包/类
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
return Response.success(new JSONObject(new String(response.data, HttpHeaderParser.parseCharset(response.headers, Constants.UTF_8))), HttpHeaderParser.parseCacheHeaders(response));
} catch (Throwable e) {
return Response.error(new ParseError(e));
} catch (Throwable je) {
return Response.error(new ParseError(je));
}
}
示例13: doParse
import com.android.volley.Response; //导入方法依赖的package包/类
/**
* The real guts of parseNetworkResponse. Broken out for readability.
*/
private Response<Bitmap> doParse(NetworkResponse response) {
byte[] data = response.data;
BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
Bitmap bitmap = null;
if (mMaxWidth == 0 && mMaxHeight == 0) {
decodeOptions.inPreferredConfig = mDecodeConfig;
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
} else {
// If we have to resize this image, first get the natural bounds.
decodeOptions.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
int actualWidth = decodeOptions.outWidth;
int actualHeight = decodeOptions.outHeight;
// Then compute the dimensions we would ideally like to decode to.
int desiredWidth = getResizedDimension(mMaxWidth, mMaxHeight,
actualWidth, actualHeight);
int desiredHeight = getResizedDimension(mMaxHeight, mMaxWidth,
actualHeight, actualWidth);
// Decode to the nearest power of two scaling factor.
decodeOptions.inJustDecodeBounds = false;
// TODO(ficus): Do we need this or is it okay since API 8 doesn't support it?
// decodeOptions.inPreferQualityOverSpeed = PREFER_QUALITY_OVER_SPEED;
decodeOptions.inSampleSize =
findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
Bitmap tempBitmap =
BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
// If necessary, scale down to the maximal acceptable size.
if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth ||
tempBitmap.getHeight() > desiredHeight)) {
bitmap = Bitmap.createScaledBitmap(tempBitmap,
desiredWidth, desiredHeight, true);
tempBitmap.recycle();
} else {
bitmap = tempBitmap;
}
}
if (bitmap == null) {
return Response.error(new ParseError(response));
} else {
return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
}
}
示例14: doParse
import com.android.volley.Response; //导入方法依赖的package包/类
/**
* The real guts of parseNetworkResponse. Broken out for readability.
*/
private Response<Bitmap> doParse(NetworkResponse response) {
byte[] data = response.data;
BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
Bitmap bitmap = null;
if (mMaxWidth == 0 && mMaxHeight == 0) {
decodeOptions.inPreferredConfig = mDecodeConfig;
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
} else {
// If we have to resize this image, first get the natural bounds.
decodeOptions.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
int actualWidth = decodeOptions.outWidth;
int actualHeight = decodeOptions.outHeight;
// Then compute the dimensions we would ideally like to decode to.
int desiredWidth = getResizedDimension(mMaxWidth, mMaxHeight,
actualWidth, actualHeight, mScaleType);
int desiredHeight = getResizedDimension(mMaxHeight, mMaxWidth,
actualHeight, actualWidth, mScaleType);
// Decode to the nearest power of two scaling factor.
decodeOptions.inJustDecodeBounds = false;
// TODO(ficus): Do we need this or is it okay since API 8 doesn't support it?
// decodeOptions.inPreferQualityOverSpeed = PREFER_QUALITY_OVER_SPEED;
decodeOptions.inSampleSize =
findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
Bitmap tempBitmap =
BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
// If necessary, scale down to the maximal acceptable size.
if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth ||
tempBitmap.getHeight() > desiredHeight)) {
bitmap = Bitmap.createScaledBitmap(tempBitmap,
desiredWidth, desiredHeight, true);
tempBitmap.recycle();
} else {
bitmap = tempBitmap;
}
}
if (bitmap == null) {
return Response.error(new ParseError(response));
} else {
return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
}
}