當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestBody.contentType方法代碼示例

本文整理匯總了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();
        }
    };
}
 
開發者ID:PengSen,項目名稱:VoV,代碼行數:18,代碼來源:GzipRequestInterceptor.java

示例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());
        }
    };
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:24,代碼來源:SendFeedBack.java

示例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();
        }
    };
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:21,代碼來源:SendFeedBack.java

示例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);
    }
}
 
開發者ID:alexclin0188,項目名稱:httplite,代碼行數:10,代碼來源:Ok2Factory.java


注:本文中的com.squareup.okhttp.RequestBody.contentType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。