本文整理汇总了Java中com.squareup.okhttp.RequestBody.contentType方法的典型用法代码示例。如果您正苦于以下问题:Java RequestBody.contentType方法的具体用法?Java RequestBody.contentType怎么用?Java RequestBody.contentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.RequestBody
的用法示例。
在下文中一共展示了RequestBody.contentType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gzip
import com.squareup.okhttp.RequestBody; //导入方法依赖的package包/类
private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override public MediaType contentType() {
return body.contentType();
}
@Override public long contentLength() {
return -1; // 无法知道压缩后的数据大小
}
@Override public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
示例2: forceContentLength
import com.squareup.okhttp.RequestBody; //导入方法依赖的package包/类
/**
* https://github.com/square/okhttp/issues/350
*/
private RequestBody forceContentLength(final RequestBody requestBody) throws IOException {
final Buffer buffer = new Buffer();
requestBody.writeTo(buffer);
return new RequestBody() {
@Override
public MediaType contentType() {
return requestBody.contentType();
}
@Override
public long contentLength() {
return buffer.size();
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
sink.write(buffer.snapshot());
}
};
}
示例3: gzip
import com.squareup.okhttp.RequestBody; //导入方法依赖的package包/类
private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override
public MediaType contentType() {
return body.contentType();
}
@Override
public long contentLength() {
return -1; // We don't know the compressed length in advance!
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
示例4: ProgressRequestBody
import com.squareup.okhttp.RequestBody; //导入方法依赖的package包/类
ProgressRequestBody(RequestBody real, String mediaType, ProgressListener progressListener) {
this.real = real;
this.progressListener = progressListener;
if (TextUtils.isEmpty(mediaType)) {
this.mediaType = real.contentType();
} else {
this.mediaType = MediaType.parse(mediaType);
}
}