예제 #1
0
파일: OkioTest.java 프로젝트: happysir/okio
  @Test
  public void sinkFromOutputStream() throws Exception {
    Buffer data = new Buffer();
    data.writeUtf8("a");
    data.writeUtf8(repeat('b', 9998));
    data.writeUtf8("c");

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Sink sink = Okio.sink(out);
    sink.write(data, 3);
    assertEquals("abb", out.toString("UTF-8"));
    sink.write(data, data.size());
    assertEquals("a" + repeat('b', 9998) + "c", out.toString("UTF-8"));
  }
예제 #2
0
 @Test
 public void readExhaustedSource() throws Exception {
   Buffer sink = new Buffer();
   sink.writeUtf8(repeat('a', 10));
   assertEquals(-1, source.read(sink, 10));
   assertEquals(10, sink.size());
   assertTrue(source.exhausted());
 }
예제 #3
0
  @Test
  public void readZeroBytesFromSource() throws Exception {
    Buffer sink = new Buffer();
    sink.writeUtf8(repeat('a', 10));

    // Either 0 or -1 is reasonable here. For consistency with Android's
    // ByteArrayInputStream we return 0.
    assertEquals(-1, source.read(sink, 0));
    assertEquals(10, sink.size());
    assertTrue(source.exhausted());
  }
예제 #4
0
  @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());

    byte[] sink = new byte[Segment.SIZE + 5];
    source.readFully(sink);
    assertByteArraysEquals(expected, sink);
  }