Example usage for org.apache.hadoop.io ByteWritable readFields

List of usage examples for org.apache.hadoop.io ByteWritable readFields

Introduction

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

Prototype

@Override
    public void readFields(DataInput in) throws IOException 

Source Link

Usage

From source file:org.shaf.core.util.IOUtilsTest.java

License:Apache License

/**
 * Test writing of {@code byte} value./*from  w  w  w  .  ja  v a 2  s.  co m*/
 */
@Test
public void testWriteByte() {
    byte[] buf = null;

    byte value = 123;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(baos);) {
        IOUtils.writeObject(value, out);
        buf = baos.toByteArray();
    } catch (IOException exc) {
        fail(exc.getMessage());
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
            DataInputStream in = new DataInputStream(bais);) {
        ByteWritable probe = new ByteWritable();
        probe.readFields(in);
        assertEquals(value, probe.get());
    } catch (IOException exc) {
        fail(exc.getMessage());
    }
}