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

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

Introduction

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

Prototype

void readFields(DataInput in) throws IOException;

Source Link

Document

Deserialize the fields of this object from in.

Usage

From source file:com.ebay.erl.mobius.core.datajoin.DataJoinKey.java

License:Apache License

private WritableComparable getKey(byte type, DataInputBuffer input) throws IOException {
    if (type == Tuple.NULL_WRITABLE_TYPE)
        return NullWritable.get();
    else if (type == Tuple.TUPLE_TYPE) {
        Tuple newTuple = new Tuple();
        newTuple.readFields(input);/*w w w  .j av a 2 s.  com*/
        return newTuple;
    } else {
        WritableComparable w = (WritableComparable) ReflectionUtils.newInstance(Util.getClass(input.readUTF()),
                conf);
        w.readFields(input);
        return w;
    }
}

From source file:com.ebay.erl.mobius.core.model.ReadFieldImpl.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//  w  w  w.  j a  v  a  2 s  . c  o m
protected Void on_writable() throws IOException {
    WritableComparable writable = (WritableComparable) ReflectionUtils.newInstance(Util.getClass(in.readUTF()),
            this.conf);
    writable.readFields(in);
    this.values.add(writable);

    return null;
}

From source file:org.apache.nutch.searcher.Hits.java

License:Apache License

public void readFields(DataInput in) throws IOException {
    total = in.readLong(); // read total hits
    top = new Hit[in.readInt()]; // read hits returned
    Class sortClass = null;//from w  w w  .j  a v  a  2  s.  co m
    if (top.length > 0) { // read sort value class
        try {
            sortClass = Class.forName(Text.readString(in));
        } catch (ClassNotFoundException e) {
            throw new IOException(e.toString());
        }
    }

    for (int i = 0; i < top.length; i++) {
        int indexDocNo = in.readInt(); // read indexDocNo

        WritableComparable sortValue = null;
        try {
            sortValue = (WritableComparable) sortClass.newInstance();
        } catch (Exception e) {
            throw new IOException(e.toString());
        }
        sortValue.readFields(in); // read sortValue
        String dedupValue = Text.readString(in); // read dedupValue

        top[i] = new Hit(indexDocNo, sortValue, dedupValue);
    }
}

From source file:org.apache.pig.data.BinInterSedes.java

License:Apache License

private WritableComparable readWritable(DataInput in) throws IOException {
    String className = (String) readDatum(in);
    // create the writeable class . It needs to have a default constructor
    Class<?> objClass = null;
    try {/*ww w  .ja va2 s.  c o m*/
        objClass = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new IOException("Could not find class " + className + ", while attempting to de-serialize it ",
                e);
    }
    WritableComparable writable = null;
    try {
        writable = (WritableComparable) objClass.newInstance();
    } catch (Exception e) {
        String msg = "Could create instance of class " + className
                + ", while attempting to de-serialize it. (no default constructor ?)";
        throw new IOException(msg, e);
    }

    // read the fields of the object from DataInput
    writable.readFields(in);
    return writable;
}