@Override public long writeAll(Source source) throws IOException {
    if (source == null) throw new IllegalArgumentException("source == null");
    long totalBytesRead = 0;
    for (long readCount; (readCount = source.read(buffer, Segment.SIZE)) != -1; ) {
      totalBytesRead += readCount;
      emitCompleteSegments();
    }
    return totalBytesRead;
  }
@Test public void writeAll() throws IOException {
    MockSink mockSink = new MockSink();
    BufferedSink bufferedSink = Okio.buffer(mockSink);

    bufferedSink.buffer().writeUtf8("abc");
    assertEquals(3, bufferedSink.writeAll(new Buffer().writeUtf8("def")));

    assertEquals(6, bufferedSink.buffer().size());
    assertEquals("abcdef", bufferedSink.buffer().readUtf8(6));
    mockSink.assertLog(); // No writes.
 }