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


Java RequestBody.writeTo方法代碼示例

本文整理匯總了Java中com.squareup.okhttp.RequestBody.writeTo方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestBody.writeTo方法的具體用法?Java RequestBody.writeTo怎麽用?Java RequestBody.writeTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.okhttp.RequestBody的用法示例。


在下文中一共展示了RequestBody.writeTo方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例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: extractBodyParams

import com.squareup.okhttp.RequestBody; //導入方法依賴的package包/類
static Map<String, String> extractBodyParams(RequestBody body) {
    // extract form-encoded HTTP body params
    final Map<String, String> bodyParams = new HashMap<>();
    if (body != null && body.contentType().equals(FORM_CONTENT_TYPE)) {
        final Buffer buffer = new Buffer();
        try {
            body.writeTo(buffer);

            while (!buffer.exhausted()) {
                long keyEnd = buffer.indexOf((byte) '=');
                if (keyEnd == -1)
                    throw new IllegalStateException("Key with no value: " + buffer.readUtf8());
                String key = buffer.readUtf8(keyEnd);
                buffer.skip(1); // Equals.

                long valueEnd = buffer.indexOf((byte) '&');
                String value = valueEnd == -1 ? buffer.readUtf8() : buffer.readUtf8(valueEnd);
                if (valueEnd != -1) buffer.skip(1); // Ampersand.

                bodyParams.put(key, value);
            }
        } catch (IOException e) {
        }
    }

    return bodyParams;
}
 
開發者ID:dherges,項目名稱:okhttp-oauth,代碼行數:28,代碼來源:OkHttpOAuthRequest.java

示例5: extractBodyParams

import com.squareup.okhttp.RequestBody; //導入方法依賴的package包/類
static Map<String, String> extractBodyParams(RequestBody body) {
    // extract form-encoded HTTP body params
    final Map<String, String> bodyParams = new HashMap<>();
    if (body != null && body.contentType().equals(FORM_CONTENT_TYPE)) {
        final Buffer buffer = new Buffer();
        try {
            body.writeTo(buffer);

            while (!buffer.exhausted()) {
                long keyEnd = buffer.indexOf((byte) '=');
                if (keyEnd == -1)
                    throw new IllegalStateException("Key with no value: " + buffer.readUtf8());
                String key = buffer.readUtf8(keyEnd);
                buffer.skip(1); // Equals.

                long valueEnd = buffer.indexOf((byte) '&');
                String value = valueEnd == -1 ? buffer.readUtf8() : buffer.readUtf8(valueEnd);
                if (valueEnd != -1) buffer.skip(1); // Ampersand.

                bodyParams.put(PercentEncoder.decode(key), value);
            }
        } catch (IOException e) {
        }
    }

    return bodyParams;
}
 
開發者ID:dherges,項目名稱:okhttp-oauth,代碼行數:28,代碼來源:OAuthRequest.java


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