本文整理匯總了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);
}
}