Time for action – using the Writable wrapper classes

Let's write a class to show some of these wrapper classes in action:

  1. Create the following as WritablesTest.java:
    import org.apache.hadoop.io.* ; import java.util.* ; public class WritablesTest { public static class IntArrayWritable extends ArrayWritable { public IntArrayWritable() { super(IntWritable.class) ; } } public static void main(String[] args) { System.out.println("*** Primitive Writables ***") ; BooleanWritable bool1 = new BooleanWritable(true) ; ByteWritable byte1 = new ByteWritable( (byte)3) ; System.out.printf("Boolean:%s Byte:%d\n", bool1, byte1.get()) ; IntWritable i1 = new IntWritable(5) ; IntWritable i2 = new IntWritable( 17) ;
 System.out.printf("I1:%d I2:%d\n", i1.get(), i2.get()) ...

Get Hadoop Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.