本文整理汇总了Java中com.yanzhenjie.nohttp.Headers类的典型用法代码示例。如果您正苦于以下问题:Java Headers类的具体用法?Java Headers怎么用?Java Headers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Headers类属于com.yanzhenjie.nohttp包,在下文中一共展示了Headers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSucceed
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public void onSucceed(int what, Response<String> response) {
if (what == NOHTTP_WHAT_TEST) {// 根据what判断是哪个请求的返回,这样就可以用一个OnResponseListener来接受多个请求的结果。
int responseCode = response.getHeaders().getResponseCode();// 服务器响应码。
String result = response.get();// 响应结果。
mTvResult.setText(result);
Object tag = response.getTag();// 拿到请求时设置的tag。
// 响应头
Headers headers = response.getHeaders();
String headResult = getString(R.string.request_original_result);
headResult = String.format(Locale.getDefault(), headResult, headers.getResponseCode(),
response.getNetworkMillis());
mTvResult.setText(headResult);
}
}
示例2: toString
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
Headers headers = getHeaders();
if (headers != null) {
Set<String> keys = headers.keySet();
for (String key : keys) {
List<String> values = headers.getValues(key);
for (String value : values) {
if (key != null) {
builder.append(key).append(": ");
}
builder.append(value).append("\n");
}
}
}
T result = get();
if (result != null)
builder.append(result.toString());
return builder.toString();
}
示例3: setRequestCacheHeader
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
/**
* Perform the handle before, Handle the cache headers.
*
* @param request the handle object.
* @param cacheEntity cached entities.
*/
private void setRequestCacheHeader(BasicRequest<?> request, CacheEntity cacheEntity) {
if (cacheEntity == null) {
request.getHeaders().remove(Headers.HEAD_KEY_IF_NONE_MATCH);
request.getHeaders().remove(Headers.HEAD_KEY_IF_MODIFIED_SINCE);
} else {
Headers headers = cacheEntity.getResponseHeaders();
String eTag = headers.getETag();
if (eTag != null)
request.getHeaders().set(Headers.HEAD_KEY_IF_NONE_MATCH, eTag);
long lastModified = headers.getLastModified();
if (lastModified > 0)
request.getHeaders().set(Headers.HEAD_KEY_IF_MODIFIED_SINCE, HeaderUtils.formatMillisToGMT(lastModified));
}
}
示例4: parseResponse
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public Bitmap parseResponse(Headers responseHeaders, byte[] responseBody) throws Exception {
synchronized (DECODE_LOCK) {
Bitmap bitmap = null;
if (responseBody != null) {
try {
bitmap = doResponse(responseBody);
} catch (OutOfMemoryError e) {
String errorMessage = String.format(Locale.US, "Caught OOM for %d byte image, url=%s",
responseBody.length, url());
Logger.e(e, errorMessage);
}
}
return bitmap;
}
}
示例5: parseResponse
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public List<T> parseResponse(Headers responseHeaders, byte[] responseBody) {
String response = StringRequest.parseResponseString(responseHeaders, responseBody);
// 这里如果数据格式错误,或者解析失败,会在失败的回调方法中返回 ParseError 异常。
return JSON.parseArray(response, clazz);
}
示例6: onStart
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public void onStart(int what, boolean isResume, long beforeLength, Headers headers, long allCount) {
int progress = AppConfig.getInstance().getInt(PROGRESS_KEY, 0);
if (allCount != 0) {
progress = (int) (beforeLength * 100 / allCount);
}
updateProgress(what, progress, 0);
}
示例7: onStart
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public void onStart(int what, boolean isResume, long beforeLength, Headers headers, long allCount) {
int progress = AppConfig.getInstance().getInt(PROGRESS_KEY, 0);
if (allCount != 0) {
progress = (int) (beforeLength * 100 / allCount);
mProgressBar.setProgress(progress);
}
updateProgress(progress, 0);
mBtnStart.setText(R.string.download_status_pause);
mBtnStart.setEnabled(true);
}
示例8: onSucceed
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public void onSucceed(int what, Response<String> response) {
Headers headers = response.getHeaders();
if (headers.getResponseCode() == 302 || headers.getResponseCode() == 301 || headers.getResponseCode() ==
307) {
String message = getString(R.string.request_redirect_location);
message = String.format(Locale.getDefault(), message, headers.getLocation());
showMessageDialog(R.string.request_succeed, message);
} else if (headers.getResponseCode() == 200) {
showMessageDialog(R.string.request_succeed, response.get());
}
}
示例9: parseResponse
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
@Override
public T parseResponse(Headers responseHeaders, byte[] responseBody) throws Exception {
String response = StringRequest.parseResponseString(responseHeaders, responseBody);
// 这里如果数据格式错误,或者解析失败,会在失败的回调方法中返回 ParseError 异常。
return JSON.parseObject(response, clazz);
}
示例10: getConnectionRetry
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
private Connection getConnectionRetry(DownloadRequest downloadRequest) throws Exception {
Connection connection = mHttpConnection.getConnection(downloadRequest);
Exception exception = connection.exception();
if (exception != null)
throw exception;
Headers responseHeaders = connection.responseHeaders();
int responseCode = responseHeaders.getResponseCode();
if (responseCode == 416) {
downloadRequest.removeHeader("Range");
return mHttpConnection.getConnection(downloadRequest);
}
return connection;
}
示例11: getRealFileName
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
private String getRealFileName(DownloadRequest request, Headers responseHeaders) throws IOException {
String fileName = null;
String contentDisposition = responseHeaders.getContentDisposition();
if (!TextUtils.isEmpty(contentDisposition)) {
fileName = HeaderUtils.parseHeadValue(contentDisposition, "filename", null);
if (!TextUtils.isEmpty(fileName)) {
try {
fileName = URLDecoder.decode(fileName, request.getParamsEncoding());
} catch (UnsupportedEncodingException e) {
// Do nothing.
}
if (fileName.startsWith("\"") && fileName.endsWith("\"")) {
fileName = fileName.substring(1, fileName.length() - 1);
}
}
}
// From url.
if (TextUtils.isEmpty(fileName)) {
String url = request.url();
URI uri = URI.create(url);
String path = uri.getPath();
if (TextUtils.isEmpty(path)) {
fileName = Integer.toString(url.hashCode());
} else {
String[] slash = path.split("/");
fileName = slash[slash.length - 1];
}
}
return fileName;
}
示例12: start
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
Poster start(boolean isResume, long beforeLength, Headers headers, long allCount) {
this.command = -1;
this.isResume = isResume;
this.beforeLength = beforeLength;
this.headers = headers;
this.allCount = allCount;
return this;
}
示例13: CacheEntity
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
/**
* @param id id.
* @param key key.
* @param responseHeaders http response headers.
* @param data http response data.
* @param localExpire local expire time.
*/
public CacheEntity(long id, String key, Headers responseHeaders, byte[] data, long localExpire) {
this.id = id;
this.key = key;
this.responseHeaders = responseHeaders;
this.data = data;
this.localExpire = localExpire;
}
示例14: Result
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
public Result(boolean isSucceed, Result result, Headers headers, String error) {
this.isSucceed = isSucceed;
this.result = result;
this.headers = headers;
this.error = error;
}
示例15: getHeaders
import com.yanzhenjie.nohttp.Headers; //导入依赖的package包/类
public Headers getHeaders() {
return headers;
}