本文整理了Java中okio.Buffer.readByteArray()
方法的一些代码示例,展示了Buffer.readByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.readByteArray()
方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:readByteArray
暂无
代码示例来源:origin: square/okhttp
/**
* Returns the concatenation of 8-bit, length prefixed protocol names.
* http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
*/
static byte[] concatLengthPrefixed(List<Protocol> protocols) {
Buffer result = new Buffer();
for (int i = 0, size = protocols.size(); i < size; i++) {
Protocol protocol = protocols.get(i);
if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
result.writeByte(protocol.toString().length());
result.writeUtf8(protocol.toString());
}
return result.readByteArray();
}
代码示例来源:origin: square/wire
/** Encode {@code value} as a {@code byte[]}. */
public final byte[] encode(E value) {
checkNotNull(value, "value == null");
Buffer buffer = new Buffer();
try {
encode(buffer, value);
} catch (IOException e) {
throw new AssertionError(e); // No I/O writing to Buffer.
}
return buffer.readByteArray();
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* Returns the concatenation of 8-bit, length prefixed protocol names.
* http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
*/
static byte[] concatLengthPrefixed(List<Protocol> protocols) {
Buffer result = new Buffer();
for (int i = 0, size = protocols.size(); i < size; i++) {
Protocol protocol = protocols.get(i);
if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
result.writeByte(protocol.toString().length());
result.writeUtf8(protocol.toString());
}
return result.readByteArray();
}
代码示例来源:origin: JessYanCoding/MVPArms
/**
* 解析服务器响应的内容
*
* @param responseBody {@link 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);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
/**
* Converts retrofit request to async-http-client request.
*
* @param request retrofit request
* @return async-http-client request.
*/
@SneakyThrows
protected org.asynchttpclient.Request createRequest(@NonNull Request request) {
// create async-http-client request builder
val requestBuilder = new RequestBuilder(request.method());
// request uri
requestBuilder.setUrl(request.url().toString());
// set headers
val headers = request.headers();
headers.names().forEach(name -> requestBuilder.setHeader(name, headers.values(name)));
// set request body
val body = request.body();
if (body != null && body.contentLength() > 0) {
if (body.contentType() != null) {
requestBuilder.setHeader(HttpHeaderNames.CONTENT_TYPE, body.contentType().toString());
}
// write body to buffer
val okioBuffer = new Buffer();
body.writeTo(okioBuffer);
requestBuilder.setBody(okioBuffer.readByteArray());
}
// customize the request builder (external customizer can change the request url for example)
runConsumers(this.requestCustomizers, requestBuilder);
return requestBuilder.build();
}
代码示例来源:origin: line/armeria
body.writeTo(contentBuffer);
return httpClient.execute(headers, contentBuffer.readByteArray());
} catch (IOException e) {
throw new IllegalArgumentException(
代码示例来源:origin: square/okio
@Test public void readFullyByteArray() throws IOException {
Buffer data = new Buffer();
data.writeUtf8("Hello").writeUtf8(repeat('e', SEGMENT_SIZE));
byte[] expected = data.clone().readByteArray();
sink.write(data, data.size());
sink.emit();
byte[] sink = new byte[SEGMENT_SIZE + 5];
source.readFully(sink);
assertByteArraysEquals(expected, sink);
}
代码示例来源:origin: huxq17/tractor
@Override public byte[] readByteArray() {
try {
return readByteArray(size);
} catch (EOFException e) {
throw new AssertionError(e);
}
}
代码示例来源:origin: zalando/logbook
private static byte[] bytes(final RequestBody body) throws IOException {
final Buffer buffer = new Buffer();
body.writeTo(buffer);
return buffer.readByteArray();
}
代码示例来源:origin: zalando/logbook
private static byte[] bytes(final RequestBody body) throws IOException {
final Buffer buffer = new Buffer();
body.writeTo(buffer);
return buffer.readByteArray();
}
代码示例来源:origin: huxq17/tractor
@Override public byte[] readByteArray(long byteCount) throws IOException {
require(byteCount);
return buffer.readByteArray(byteCount);
}
代码示例来源:origin: parse-community/Parse-SDK-Android
assertArrayEquals(requestContent.getBytes(), recordedApacheRequest.getBody().readByteArray());
代码示例来源:origin: com.squareup.wire/wire-runtime
/** Encode {@code value} as a {@code byte[]}. */
public final byte[] encode(E value) {
checkNotNull(value, "value == null");
Buffer buffer = new Buffer();
try {
encode(buffer, value);
} catch (IOException e) {
throw new AssertionError(e); // No I/O writing to Buffer.
}
return buffer.readByteArray();
}
代码示例来源:origin: douban/rexxar-android
private byte[] parseGzipResponseBody(ResponseBody body) throws IOException{
Buffer buffer = new Buffer();
GzipSource gzipSource = new GzipSource(body.source());
while (gzipSource.read(buffer, Integer.MAX_VALUE) != -1) {
}
gzipSource.close();
return buffer.readByteArray();
}
代码示例来源:origin: io.apptik.comm/jus-java
public static NetworkResponse create(MediaType mediaType, String data) {
Utils.checkNotNull(mediaType, "mediaType==null");
return create(mediaType, new Buffer()
.writeString(data, mediaType.charset(Charset.forName(HTTP.UTF_8)))
.readByteArray());
}
代码示例来源:origin: io.apptik.comm/jus-java
public static NetworkRequest create(MediaType mediaType, String data) {
Utils.checkNotNull(mediaType, "mediaType==null");
return create(mediaType, new Buffer()
.writeString(data, mediaType.charset(Charset.forName(HTTP.UTF_8)))
.readByteArray());
}
代码示例来源:origin: scruffyfox/AsyncHttpClient
@Override public void write(Buffer source, long byteCount) throws IOException
{
Buffer copy = new Buffer();
source.copyTo(copy, 0, byteCount);
super.write(source, byteCount);
bytesWritten += byteCount;
listener.onRequestProgress(copy.readByteArray(), byteCount, bytesWritten, contentLength());
}
}
代码示例来源:origin: io.apptik.comm/jus-java
public NetworkRequest.Builder builder() {
return new NetworkRequest.Builder()
.setContentType(CONTENT_TYPE)
.setBody(content.readByteArray());
}
代码示例来源:origin: io.apptik.comm/jus-java
public NetworkRequest build() {
return new NetworkRequest.Builder()
.setContentType(CONTENT_TYPE)
.setBody(content.readByteArray())
.build();
}
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testCborRequests() throws IOException, InterruptedException {
LocalDate date = LocalDate.of(2001, 2, 3);
server.enqueue(new MockResponse());
service.makeCborRequest(date).execute();
RecordedRequest request = server.takeRequest();
assertThat(request.getBody().readByteArray())
.isEqualTo(ObjectMappers.newCborClientObjectMapper().writeValueAsBytes(date));
}
内容来源于网络,如有侵权,请联系作者删除!