コード例 #1
0
ファイル: IoUtilTest.java プロジェクト: nikss/modeshape
  @Test
  public void readBytesShouldReadInputStreamCorrectlyAndShouldCloseStream() throws Exception {
    // Read content shorter than buffer size ...
    String content = "This is the way to grandma's house.";
    InputStream stream = new ByteArrayInputStream(content.getBytes());
    InputStreamWrapper wrapper = new InputStreamWrapper(stream);
    assertThat(wrapper.isClosed(), is(false));
    byte[] bytes = IoUtil.readBytes(wrapper);
    String output = new String(bytes);
    assertThat(output, is(content));
    assertThat(wrapper.isClosed(), is(true));

    // Read content longer than buffer size ...
    for (int i = 0; i != 10; ++i) {
      content += content; // note this doubles each time!
    }
    stream = new ByteArrayInputStream(content.getBytes());
    wrapper = new InputStreamWrapper(stream);
    assertThat(wrapper.isClosed(), is(false));
    bytes = IoUtil.readBytes(wrapper);
    output = new String(bytes);
    assertThat(output, is(content));
    assertThat(wrapper.isClosed(), is(true));
  }
コード例 #2
0
ファイル: IoUtilTest.java プロジェクト: nikss/modeshape
 @Test
 public void readBytesShouldReturnEmptyByteArrayForNullInputStream() throws Exception {
   assertThat(IoUtil.readBytes((InputStream) null), is(new byte[] {}));
 }