Example usage for org.apache.hadoop.io InputBuffer InputBuffer

List of usage examples for org.apache.hadoop.io InputBuffer InputBuffer

Introduction

In this page you can find the example usage for org.apache.hadoop.io InputBuffer InputBuffer.

Prototype

public InputBuffer() 

Source Link

Document

Constructs a new empty buffer.

Usage

From source file:com.asakusafw.runtime.directio.util.DelimiterRangeInputStreamTest.java

License:Apache License

/**
 * all patterns for read byte./*  w ww .  j ava 2  s. co  m*/
 * @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.// ww  w.  j a  v a 2 s.com
 * @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"));
    }
}

From source file:com.asakusafw.runtime.value.StringOptionUtil.java

License:Apache License

/**
 * Returns a {@link Reader} to read the text contents in the {@link StringOption}.
 * @param option the target {@link StringOption}
 * @return the created reader//  w w w .j  a va  2s.c  om
 * @throws NullPointerException if the {@link StringOption} is/represents {@code null}
 */
public static Reader asReader(StringOption option) {
    Text text = option.get();
    InputBuffer buffer = new InputBuffer();
    buffer.reset(text.getBytes(), 0, text.getLength());
    return new InputStreamReader(buffer, ENCODING);
}