List of usage examples for org.apache.hadoop.io InputBuffer reset
public void reset(byte[] input, int length)
From source file:com.asakusafw.runtime.directio.util.DelimiterRangeInputStreamTest.java
License:Apache License
/** * all patterns for read byte.// w ww .j a v a 2 s . com * @throws Exception if failed */ @Test public void readByte_random() throws Exception { byte[] bytes = "ABC|D|EF".getBytes(StandardCharsets.US_ASCII); InputBuffer buffer = new InputBuffer(); buffer.reset(bytes, bytes.length); Random random = new Random(12345); for (int i = 0; i < 100000; i++) { int[] bounds = new int[5]; for (int j = 0; j < bounds.length; j++) { bounds[j] = random.nextInt(bytes.length + 1); } Arrays.sort(bounds); StringBuilder buf = new StringBuilder(); int start = 0; for (int j = 0; j < bounds.length; j++) { int end = bounds[j]; copy(buffer, buf, start, end); start = end; } copy(buffer, buf, start, bytes.length); assertThat(Arrays.toString(bounds), buf.toString(), is("ABC|D|EF")); } }
From source file:com.asakusafw.runtime.directio.util.DelimiterRangeInputStreamTest.java
License:Apache License
/** * all patterns for read byte.//from www . ja v a 2s. c o m * @throws Exception if failed */ @Test public void readArray_random() throws Exception { byte[] bytes = "ABC|D|EF".getBytes(StandardCharsets.US_ASCII); InputBuffer buffer = new InputBuffer(); buffer.reset(bytes, bytes.length); Random random = new Random(12345); for (int i = 0; i < 100000; i++) { int[] bounds = new int[5]; for (int j = 0; j < bounds.length; j++) { bounds[j] = random.nextInt(bytes.length + 1); } Arrays.sort(bounds); StringBuilder buf = new StringBuilder(); int start = 0; for (int j = 0; j < bounds.length; j++) { int end = bounds[j]; copy(buffer, buf, start, end, 4); start = end; } copy(buffer, buf, start, bytes.length, 4); assertThat(Arrays.toString(bounds), buf.toString(), is("ABC|D|EF")); } }