Java 类io.grpc.internal.IoUtils 实例源码

项目:grift    文件:ThriftUtilsTest.java   
@Test
public void testDrainTo_all() throws Exception {
  Message m = new Message();
  byte[] bytes = IoUtils.toByteArray(marshaller.stream(m));
  InputStream is = marshaller.stream(m);
  Drainable d = (Drainable) is;
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  int drained = d.drainTo(baos);
  assertEquals(baos.size(), drained);
  assertArrayEquals(bytes, baos.toByteArray());
  assertEquals(0, is.available());
}
项目:grift    文件:ThriftUtilsTest.java   
@Test
public void testDrainTo_none() throws Exception {
  Message m = new Message();
  byte[] bytes = IoUtils.toByteArray(marshaller.stream(m));
  InputStream is = marshaller.stream(m);
  byte[] unused = IoUtils.toByteArray(is);
  Drainable d = (Drainable) is;
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  assertEquals(0, d.drainTo(baos));
  assertArrayEquals(new byte[0], baos.toByteArray());
  assertEquals(0, is.available());
}
项目:grpc-java    文件:AbstractTransportTest.java   
@Override
public String parse(InputStream stream) {
  try {
    return new String(IoUtils.toByteArray(stream), UTF_8);
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}