本文整理汇总了Java中com.jess.arms.utils.ZipHelper类的典型用法代码示例。如果您正苦于以下问题:Java ZipHelper类的具体用法?Java ZipHelper怎么用?Java ZipHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipHelper类属于com.jess.arms.utils包,在下文中一共展示了ZipHelper类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseContent
import com.jess.arms.utils.ZipHelper; //导入依赖的package包/类
/**
* 解析服务器响应的内容
*
* @param responseBody
* @param encoding
* @param clone
* @return
*/
private String parseContent(ResponseBody responseBody, String encoding, Buffer clone) {
Charset charset = Charset.forName("UTF-8");
MediaType contentType = responseBody.contentType();
if (contentType != null) {
charset = contentType.charset(charset);
}
if (encoding != null && encoding.equalsIgnoreCase("gzip")) {//content使用gzip压缩
return ZipHelper.decompressForGzip(clone.readByteArray(), convertCharset(charset));//解压
} else if (encoding != null && encoding.equalsIgnoreCase("zlib")) {//content使用zlib压缩
return ZipHelper.decompressToStringForZlib(clone.readByteArray(), convertCharset(charset));//解压
} else {//content没有被压缩
return clone.readString(charset);
}
}
示例2: parseContent
import com.jess.arms.utils.ZipHelper; //导入依赖的package包/类
/**
* 解析服务器响应的内容
*
* @param responseBody
* @param encoding
* @param clone
* @return
*/
private String parseContent(ResponseBody responseBody, String encoding, Buffer clone) {
Charset charset = Charset.forName("UTF-8");
MediaType contentType = responseBody.contentType();
if (contentType != null) {
charset = contentType.charset(charset);
}
if (encoding != null && encoding.equalsIgnoreCase("gzip")) {//content使用gzip压缩
return ZipHelper.decompressForGzip(clone.readByteArray(),convertCharset(charset));//解压
} else if (encoding != null && encoding.equalsIgnoreCase("zlib")) {//content使用zlib压缩
return ZipHelper.decompressToStringForZlib(clone.readByteArray(),convertCharset(charset));//解压
} else {//content没有被压缩
return clone.readString(charset);
}
}
示例3: intercept
import com.jess.arms.utils.ZipHelper; //导入依赖的package包/类
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (mHandler != null)//在请求服务器之前可以拿到request,做一些操作比如给request添加header,如果不做操作则返回参数中的request
request = mHandler.onHttpRequestBefore(chain, request);
Buffer requestbuffer = new Buffer();
if (request.body() != null) {
request.body().writeTo(requestbuffer);
} else {
Timber.tag("Request").w("request.body() == null");
}
//打印url信息
Timber.tag("Request").w("Sending Request %s on %n Params ---> %s%n Connection ---> %s%n Headers ---> %s", request.url()
, request.body() != null ? parseParams(request.body(), requestbuffer) : "null"
, chain.connection()
, request.headers());
long t1 = System.nanoTime();
Response originalResponse = chain.proceed(request);
long t2 = System.nanoTime();
//打印响应时间
Timber.tag("Response").w("Received response in %.1fms%n%s", (t2 - t1) / 1e6d, originalResponse.headers());
//读取服务器返回的结果
ResponseBody responseBody = originalResponse.body();
BufferedSource source = responseBody.source();
source.request(Long.MAX_VALUE); // Buffer the entire body.
Buffer buffer = source.buffer();
//获取content的压缩类型
String encoding = originalResponse
.headers()
.get("Content-Encoding");
Buffer clone = buffer.clone();
String bodyString;
//解析response content
if (encoding != null && encoding.equalsIgnoreCase("gzip")) {//content使用gzip压缩
bodyString = ZipHelper.decompressForGzip(clone.readByteArray());//解压
} else if (encoding != null && encoding.equalsIgnoreCase("zlib")) {//content使用zlib压缩
bodyString = ZipHelper.decompressToStringForZlib(clone.readByteArray());//解压
} else {//content没有被压缩
Charset charset = Charset.forName("UTF-8");
MediaType contentType = responseBody.contentType();
if (contentType != null) {
charset = contentType.charset(charset);
}
bodyString = clone.readString(charset);
}
Timber.tag("Result").w(jsonFormat(bodyString));
if (mHandler != null)//这里可以比客户端提前一步拿到服务器返回的结果,可以做一些操作,比如token超时,重新获取
return mHandler.onHttpResultResponse(bodyString, chain, originalResponse);
return originalResponse;
}