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

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

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

Buffer.writeAll介绍

暂无

代码示例

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

private Buffer fileToBytes(File file) throws IOException {
 Buffer result = new Buffer();
 result.writeAll(Okio.source(file));
 return result;
}

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

public Buffer readBuffer(File file) throws IOException {
 try (Source source = Okio.source(file)) {
  Buffer buffer = new Buffer();
  buffer.writeAll(source);
  return buffer;
 }
}

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

/**
 * Marks the current position in the stream as one to potentially return back to. Returns the
 * offset of this position. Call {@link #reset(long)} with this position to return to it later. It
 * is an error to call {@link #reset(long)} after consuming more than {@code readLimit} bytes from
 * {@linkplain #source() the source}.
 */
public long mark(long readLimit) throws IOException {
 if (readLimit < 0L) {
  throw new IllegalArgumentException("readLimit < 0: " + readLimit);
 }
 if (closed) {
  throw new IllegalStateException("closed");
 }
 // Mark the current position in the buffered source.
 long userOffset = offset - userBuffer.size();
 // If this is a new mark promote userBuffer data into the markBuffer.
 if (mark == -1L) {
  markBuffer.writeAll(userBuffer);
  mark = userOffset;
  offset = userOffset;
 }
 // Grow the limit if necessary.
 long newMarkBufferLimit = userOffset + readLimit;
 if (newMarkBufferLimit < 0) newMarkBufferLimit = Long.MAX_VALUE; // Long overflow!
 limit = Math.max(limit, newMarkBufferLimit);
 return userOffset;
}

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

readBuffer.writeAll(receiveBuffer);
if (wasEmpty) {
 Http2Stream.this.notifyAll();

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

private List<Integer> moveBytesBetweenBuffers(String... contents) throws IOException {
 StringBuilder expected = new StringBuilder();
 Buffer buffer = new Buffer();
 for (String s : contents) {
  Buffer source = new Buffer();
  source.writeUtf8(s);
  buffer.writeAll(source);
  expected.append(s);
 }
 List<Integer> segmentSizes = segmentSizes(buffer);
 assertEquals(expected.toString(), buffer.readUtf8(expected.length()));
 return segmentSizes;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

readBuffer.writeAll(receiveBuffer);
if (wasEmpty) {
 Http2Stream.this.notifyAll();

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

try (GzipSource gzippedResponseBody = new GzipSource(buffer.clone())) {
 buffer = new Buffer();
 buffer.writeAll(gzippedResponseBody);

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

@Test public void writeAllMultipleSegments() throws Exception {
 Buffer source = new Buffer().writeUtf8(TestUtil.repeat('a', SEGMENT_SIZE * 3));
 Buffer sink = new Buffer();
 assertEquals(SEGMENT_SIZE * 3, sink.writeAll(source));
 assertEquals(0, source.size());
 assertEquals(TestUtil.repeat('a', SEGMENT_SIZE * 3), sink.readUtf8());
}

代码示例来源:origin: com.squareup.okhttp3/logging-interceptor

try (GzipSource gzippedResponseBody = new GzipSource(buffer.clone())) {
 buffer = new Buffer();
 buffer.writeAll(gzippedResponseBody);

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

@Override public String readString(Charset charset) throws IOException {
 if (charset == null) throw new IllegalArgumentException("charset == null");
 buffer.writeAll(source);
 return buffer.readString(charset);
}

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

@Override public String readUtf8() throws IOException {
 buffer.writeAll(source);
 return buffer.readUtf8();
}

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

@Override public ByteString readByteString() throws IOException {
 buffer.writeAll(source);
 return buffer.readByteString();
}

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

@Override public byte[] readByteArray() throws IOException {
 buffer.writeAll(source);
 return buffer.readByteArray();
}

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

@Override public void readFully(Buffer sink, long byteCount) throws IOException {
 try {
  require(byteCount);
 } catch (EOFException e) {
  // The underlying source is exhausted. Copy the bytes we got before rethrowing.
  sink.writeAll(buffer);
  throw e;
 }
 buffer.readFully(sink, byteCount);
}

代码示例来源:origin: NightlyNexus/logging-retrofit

/**
 * Reads a {@link ResponseBody} as a string. This is useful for logging error bodies. Does not
 * consume the {@code errorBody}.
 * <p>Warning: Error bodies can be very large because they can come from unexpected sources.
 * Only call this method if you are sure you can buffer the entire body into memory.
 */
public static String errorMessage(ResponseBody errorBody) throws IOException {
 if (errorBody.contentLength() == 0) {
  return "";
 }
 Buffer buffer = new Buffer();
 buffer.writeAll(errorBody.source().peek());
 if (!isPlaintext(buffer)) {
  return "Error body is not plain text.";
 }
 return ResponseBody.create(errorBody.contentType(), buffer.size(), buffer).string();
}

代码示例来源:origin: mapbox/mapbox-java

@Override
 public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
  okio.Buffer buffer = new okio.Buffer();
  try {
   buffer.writeAll(Okio.source(new File("src/test/resources/test_response.mp3")));
  } catch (IOException ioException) {
   throw new RuntimeException(ioException);
  }
  return new MockResponse().setBody(buffer);
 }
});

代码示例来源:origin: mapbox/mapbox-java

@Override
 public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
  okio.Buffer buffer = new okio.Buffer();
  try {
   buffer.writeAll(Okio.source(new File("src/test/resources/2018-10-31T15_28_22.155Z.tar")));
  } catch (IOException ioException) {
   throw new RuntimeException(ioException);
  }
  return new MockResponse().setBody(buffer);
 }
});

代码示例来源:origin: com.github.ljun20160606/okhttp

readBuffer.writeAll(receiveBuffer);
if (wasEmpty) {
 Http2Stream.this.notifyAll();

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

readBuffer.writeAll(receiveBuffer);
if (wasEmpty) {
 FramedStream.this.notifyAll();

代码示例来源:origin: com.squareup.okhttp/mockwebserver

body.writeAll(stream.getSource());
body.close();

相关文章