com.google.common.io.ByteProcessor Java Examples

The following examples show how to use com.google.common.io.ByteProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrayByteSourceTest.java    From Strata with Apache License 2.0 6 votes vote down vote up
@Test
public void test_read_processor() throws IOException {
  ArrayByteSource test = ArrayByteSource.copyOf(new byte[] {1, 2, 3});
  ByteProcessor<Integer> processor = new ByteProcessor<Integer>() {

    @Override
    public boolean processBytes(byte[] buf, int off, int len) throws IOException {
      assertThat(off).isEqualTo(0);
      assertThat(len).isEqualTo(3);
      assertThat(buf[0]).isEqualTo((byte) 1);
      assertThat(buf[1]).isEqualTo((byte) 2);
      assertThat(buf[2]).isEqualTo((byte) 3);
      return false;
    }

    @Override
    public Integer getResult() {
      return 123;
    }
  };
  assertThat(test.read(processor)).isEqualTo(123);
}
 
Example #2
Source File: ArrayByteSource.java    From Strata with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T read(ByteProcessor<T> processor) throws IOException {
  processor.processBytes(array, 0, array.length);
  return processor.getResult();
}