okio.Buffer.readFrom()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(2.5k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中okio.Buffer.readFrom()方法的一些代码示例,展示了Buffer.readFrom()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.readFrom()方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:readFrom

Buffer.readFrom介绍

[英]Read and exhaust bytes from in to this.
[中]从中读取并耗尽字节到此。

代码示例

代码示例来源:origin: square/okio

@Test public void readFromStream() throws Exception {
 InputStream in = new ByteArrayInputStream("hello, world!".getBytes(UTF_8));
 Buffer buffer = new Buffer();
 buffer.readFrom(in);
 String out = buffer.readUtf8();
 assertEquals("hello, world!", out);
}

代码示例来源:origin: square/okio

@Test public void readFromStreamWithCount() throws Exception {
 InputStream in = new ByteArrayInputStream("hello, world!".getBytes(UTF_8));
 Buffer buffer = new Buffer();
 buffer.readFrom(in, 10);
 String out = buffer.readUtf8();
 assertEquals("hello, wor", out);
}

代码示例来源:origin: square/okio

@Test public void readFromSpanningSegments() throws Exception {
 InputStream in = new ByteArrayInputStream("hello, world!".getBytes(UTF_8));
 Buffer buffer = new Buffer().writeUtf8(repeat('a', SEGMENT_SIZE - 10));
 buffer.readFrom(in);
 String out = buffer.readUtf8();
 assertEquals(repeat('a', SEGMENT_SIZE - 10) + "hello, world!", out);
}

代码示例来源:origin: huxq17/tractor

/** Read and exhaust bytes from {@code in} to this. */
public Buffer readFrom(InputStream in) throws IOException {
 readFrom(in, Long.MAX_VALUE, true);
 return this;
}

代码示例来源:origin: huxq17/tractor

/** Read {@code byteCount} bytes from {@code in} to this. */
public Buffer readFrom(InputStream in, long byteCount) throws IOException {
 if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
 readFrom(in, byteCount, false);
 return this;
}

代码示例来源:origin: gmazzo/okhttp-client-mock

public Response.Builder respond(long contentLength, @NonNull InputStream body, @NonNull MediaType mediaType) {
  try {
    return respond(ResponseBody.create(mediaType, contentLength, new Buffer().readFrom(body)));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate

@NonNull
public static Response success(@NonNull Request request, @NonNull InputStream stream) throws IOException {
  Buffer buffer = new Buffer().readFrom(stream);
  return new Response.Builder()
      .request(request)
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("OK")
      .body(ResponseBody.create(APPLICATION_JSON, buffer.size(), buffer))
      .build();
}

代码示例来源:origin: Gitteroid/GitterJavaSDK

public static MockResponse createMockedResponse(String fileName) throws IOException {
  Buffer buffer = new Buffer().readFrom(ClassLoader.getSystemClassLoader().getResourceAsStream(fileName));
  return new MockResponse().setBody(buffer);
}

相关文章