Example usage for org.apache.hadoop.io WritableFactories newInstance

List of usage examples for org.apache.hadoop.io WritableFactories newInstance

Introduction

In this page you can find the example usage for org.apache.hadoop.io WritableFactories newInstance.

Prototype

public static Writable newInstance(Class<? extends Writable> c) 

Source Link

Document

Create a new instance of a class with a defined factory.

Usage

From source file:org.apache.flink.hadoopcompatibility.mapreduce.wrapper.HadoopInputSplit.java

License:Apache License

@Override
public void read(DataInputView in) throws IOException {
    this.splitNumber = in.readInt();
    String className = in.readUTF();

    if (this.mapreduceInputSplit == null) {
        try {//from   ww w . jav  a2s . c  o  m
            Class<? extends org.apache.hadoop.io.Writable> inputSplit = Class.forName(className)
                    .asSubclass(org.apache.hadoop.io.Writable.class);
            this.mapreduceInputSplit = (org.apache.hadoop.mapreduce.InputSplit) WritableFactories
                    .newInstance(inputSplit);
        } catch (Exception e) {
            throw new RuntimeException("Unable to create InputSplit", e);
        }
    }
    ((Writable) this.mapreduceInputSplit).readFields(in);
}

From source file:org.apache.giraph.utils.ArrayWritable.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    valueClass = WritableUtils.readClass(in);
    values = (T[]) Array.newInstance(valueClass, in.readInt());

    for (int i = 0; i < values.length; i++) {
        T value = (T) WritableFactories.newInstance(valueClass);
        value.readFields(in); // read a value
        values[i] = value; // store it in values
    }/*  w w  w  .j  av a 2  s. c o m*/
}

From source file:org.kiji.hive.io.KijiRowDataWritable.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    EntityIdWritable entityIdWritable = (EntityIdWritable) WritableFactories
            .newInstance(EntityIdWritable.class);
    entityIdWritable.readFields(in);/*from  w  w  w .  j  ava  2 s  . co m*/
    mEntityId = entityIdWritable;

    int numDecodedData = WritableUtils.readVInt(in);

    // We need to dirty the decoded data so that these objects can be reused.
    mDecodedData = null;

    mWritableData = Maps.newHashMap();
    for (int c = 0; c < numDecodedData; c++) {
        String columnText = WritableUtils.readString(in);
        KijiColumnName column = new KijiColumnName(columnText);

        NavigableMap<Long, KijiCellWritable> data = Maps.newTreeMap();
        int numCells = WritableUtils.readVInt(in);
        for (int d = 0; d < numCells; d++) {
            long ts = WritableUtils.readVLong(in);
            KijiCellWritable cellWritable = (KijiCellWritable) WritableFactories
                    .newInstance(KijiCellWritable.class);
            cellWritable.readFields(in);
            data.put(ts, cellWritable);
        }

        mWritableData.put(column, data);
    }

    mSchemas = Maps.newHashMap();
    int numSchemas = WritableUtils.readVInt(in);
    for (int c = 0; c < numSchemas; c++) {
        String columnText = WritableUtils.readString(in);
        KijiColumnName column = new KijiColumnName(columnText);
        String schemaString = WritableUtils.readString(in);
        Schema schema = new Schema.Parser().parse(schemaString);
        mSchemas.put(column, schema);
    }
}

From source file:org.megalon.MArrayWritable.java

License:Apache License

public void readFields(DataInput in) throws IOException {
    // values = new Writable[in.readInt()]; // construct values
    values = (Writable[]) Array.newInstance(valueClass, in.readInt());
    for (int i = 0; i < values.length; i++) {
        Writable value = WritableFactories.newInstance(valueClass);
        value.readFields(in); // read a value
        values[i] = value; // store it in values
    }//  w w  w  .  j  av a 2s .  c o  m
}

From source file:org.zuinnote.hadoop.office.format.common.dao.SpreadSheetCellDAO.java

License:Apache License

@Override
public void readFields(DataInput dataInput) throws IOException {
    Text formattedValueText = (Text) WritableFactories.newInstance(Text.class);
    formattedValueText.readFields(dataInput);
    this.formattedValue = formattedValueText.toString();
    Text commentText = (Text) WritableFactories.newInstance(Text.class);
    commentText.readFields(dataInput);//from   w w w. j  a v  a2  s.co m
    this.comment = commentText.toString();
    Text formulaText = (Text) WritableFactories.newInstance(Text.class);
    formulaText.readFields(dataInput);
    this.formula = formulaText.toString();
    Text addressText = (Text) WritableFactories.newInstance(Text.class);
    addressText.readFields(dataInput);
    this.address = addressText.toString();
    Text sheetNameText = (Text) WritableFactories.newInstance(Text.class);
    sheetNameText.readFields(dataInput);
    this.sheetName = sheetNameText.toString();
}