Save This Page
Home » hadoop-0.14.4 » org.apache » hadoop » io » [javadoc | source]
org.apache.hadoop.io
abstract public class: GenericWritable [javadoc | source]
java.lang.Object
   org.apache.hadoop.io.GenericWritable

All Implemented Interfaces:
    Writable

A wrapper for Writable instances.

When two sequence files, which have same Key type but different Value types, are mapped out to reduce, multiple Value types is not allowed. In this case, this class can help you wrap instances with different types.

Compared with ObjectWritable, this class is much more effective, because ObjectWritable will append the class declaration as a String into the output file in every Key-Value pair.

how to use it:
1. Write your own class, such as GenericObject, which extends GenericWritable.
2. Implements the abstract method getTypes(), defines the classes which will be wrapped in GenericObject in application. Attention: this classes defined in getTypes() method, must implement Writable interface.

The code looks like this:
public class GenericObject extends GenericWritable {

private static Class[] CLASSES = {
ClassType1.class,
ClassType2.class,
ClassType3.class,
};

protected Class[] getTypes() {
return CLASSES;
}

}
Method from org.apache.hadoop.io.GenericWritable Summary:
get,   getTypes,   readFields,   set,   write
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.hadoop.io.GenericWritable Detail:
 public Writable get() 
    Return the wrapped instance.
 abstract protected Class[] getTypes()
    Return all classes that may be wrapped. Subclasses should implement this to return a constant array of classes.
 public  void readFields(DataInput in) throws IOException 
 public  void set(Writable obj) 
    Set the instance that is wrapped.
 public  void write(DataOutput out) throws IOException