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

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

Introduction

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

Prototype

@Override
public void readFields(DataInput in) throws IOException 

Source Link

Document

read the short value

Usage

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

License:Apache License

/**
 * Test writing of {@code short} value.//  w w w. ja  v a2  s . com
 */
@Test
public void testWriteShort() {
    byte[] buf = null;

    short 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);) {
        ShortWritable probe = new ShortWritable();
        probe.readFields(in);
        assertEquals(value, probe.get());
    } catch (IOException exc) {
        fail(exc.getMessage());
    }
}