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

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

Introduction

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

Prototype

void readFields(DataInput in) throws IOException;

Source Link

Document

Deserialize the fields of this object from in.

Usage

From source file:org.sf.xrime.model.vertex.AdjBiSetVertex.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*  w  ww . j  av  a2 s .  com*/
public void readFields(DataInput in) throws IOException {
    // Call super first.
    super.readFields(in);
    // Clean containers.
    _forward_vertexes.clear();
    _backward_vertexes.clear();
    // Deal with forward vertex set.
    int size = in.readInt();
    if (size > 0) {
        // Determine the type of elements.
        String className = Text.readString(in);
        try {
            Class instanceClass = Class.forName(className);
            for (int ii = 0; ii < size; ii++) {
                Writable writable = WritableFactories.newInstance(instanceClass, null);
                writable.readFields(in);
                if (writable instanceof AdjVertexEdge) {
                    addForwardVertex((AdjVertexEdge) writable);
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    // Deal with backward vertex set.
    size = in.readInt();
    if (size > 0) {
        // Determine the type of elements.
        String className = Text.readString(in);
        Class instanceClass;
        try {
            instanceClass = Class.forName(className);
            for (int i = 0; i < size; i++) {
                Writable writable = WritableFactories.newInstance(instanceClass, null);
                writable.readFields(in);
                if (writable instanceof AdjVertexEdge) {
                    addBackwardVertex((AdjVertexEdge) writable);
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.sf.xrime.model.vertex.AdjSetVertex.java

License:Apache License

@SuppressWarnings("unchecked")
public void readFields(DataInput in) throws IOException {
    // super./*from   w  w w.  j av  a  2  s .  c o m*/
    super.readFields(in);
    // Clear the container.
    opposites.clear();
    // Determine container size.
    int size = in.readInt();

    if (size > 0) {
        // Determine the element type.
        String className = Text.readString(in);
        try {
            for (int ii = 0; ii < size; ii++) {
                Class instanceClass = Class.forName(className);
                Writable writable = WritableFactories.newInstance(instanceClass, null);
                writable.readFields(in);
                if (writable instanceof AdjVertexEdge) {
                    addOpposite((AdjVertexEdge) writable);
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.sf.xrime.model.vertex.AdjSetVertexWithTwoHopLabel.java

License:Apache License

@SuppressWarnings("unchecked")
public void readFields(DataInput in) throws IOException {
    // super.//www  .  j  a  va2 s.  com
    super.readFields(in);
    //System.out.println("Invoking readFields() for De-serialization, node = "+this.id);
    // Clear the container.
    neighbors.clear();
    allTwoHopNeighbors.clear();
    if (this.id.equals("")) {
        this.id = null;
    } else {
        // Determine container size.
        int size = in.readInt();
        //System.out.println("neighbors.size() = "+size);
        if (size > 0) {
            //Determine the element type, read neighbors
            String className = Text.readString(in);
            //System.out.println("ClassName = "+className);
            try {
                for (int ii = 0; ii < size; ii++) {
                    Class instanceClass = Class.forName(className);
                    Writable writable = WritableFactories.newInstance(instanceClass, null);
                    writable.readFields(in);
                    if (writable instanceof AdjVertexEdgeWithLabel) {
                        this.addNeighbor((AdjVertexEdgeWithLabel) writable);
                        //System.out.println("addNeighbor(): "+((AdjVertexEdgeWithLabel) writable).getOpposite());
                    }
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }

            // read two hop neighbors
            int mapSize = in.readInt();
            //System.out.println("twoHopNeihgbor map size = " + mapSize);
            while (mapSize > 0) {
                String currentKey = Text.readString(in);
                int neighborSize = in.readInt();
                if (neighborSize > 0) {
                    String currentClassName = Text.readString(in);
                    Set<AdjVertexEdgeWithLabel> currentTwoHopNeighbors = new TreeSet<AdjVertexEdgeWithLabel>(
                            new AdjVertexEdgeWithLabelComparator());
                    try {
                        for (int jj = 0; jj < neighborSize; jj++) {
                            Class currentInstanceClass = Class.forName(currentClassName);
                            Writable currentWritable = WritableFactories.newInstance(currentInstanceClass,
                                    null);
                            currentWritable.readFields(in);
                            if (currentWritable instanceof AdjVertexEdgeWithLabel) {
                                currentTwoHopNeighbors.add((AdjVertexEdgeWithLabel) currentWritable);
                            }
                        }
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                    allTwoHopNeighbors.put(currentKey, currentTwoHopNeighbors);
                    mapSize--;
                }
            }
        }
    }
}

From source file:org.sf.xrime.model.vertex.AdjVertex.java

License:Apache License

@SuppressWarnings("unchecked")
public void readFields(DataInput in) throws IOException {
    super.readFields(in);
    // Clear the container.
    edges.clear();//from ww w . j  av a2  s  .  c  o  m
    // Determine the size.
    int size = in.readInt();

    if (size > 0) {
        // Determine the element type.
        String className = Text.readString(in);
        try {
            for (int ii = 0; ii < size; ii++) {
                Class instanceClass = Class.forName(className);
                Writable writable = WritableFactories.newInstance(instanceClass, null);
                writable.readFields(in);
                if (writable instanceof Edge) {
                    addEdge((Edge) writable);
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.sf.xrime.model.vertex.SetOfVertexSets.java

License:Apache License

@SuppressWarnings("unchecked")
@Override// ww  w .j av  a  2  s. c  om
public void readFields(DataInput in) throws IOException {
    // Clear the container.
    _the_set.clear();
    // Determine the size.
    int size = in.readInt();
    if (size > 0) {
        // All vertex sets in the set should have the same type.
        String className = Text.readString(in);
        try {
            Class instanceClass;
            instanceClass = Class.forName(className);
            for (int i = 0; i < size; i++) {
                Writable writable = WritableFactories.newInstance(instanceClass, null);
                writable.readFields(in);
                if (writable instanceof VertexSet) {
                    addVertexSet((VertexSet) writable);
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.shaf.core.io.emulator.SequenceReader.java

License:Apache License

/**
 * Reads a {@link Record record} from the sequence file.
 *//* w w  w . ja v a  2  s.  c  o m*/
@Override
public Record<Writable, Writable> readRecord() throws IOException {
    try {
        Writable key = (Writable) this.keyClass.newInstance();
        key.readFields(super.in);

        Writable value = (Writable) this.valueClass.newInstance();
        value.readFields(super.in);

        return new Record<>(key, value);
    } catch (InstantiationException | IllegalAccessException exc) {
        throw new IOException("Invalid sequence file format.", exc);
    } catch (EOFException exc) {
        LOG.trace("The file reader reached the end of file.", exc);
        return null;
    }
}

From source file:utils.SerializationUtils.java

License:Apache License

private static Writable deserializeWritable(Writable writable, byte[] bytes) {
    try {//w w w.  ja  va2  s. com
        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
        DataInputStream dataIn = new DataInputStream(in);
        writable.readFields(dataIn);
        dataIn.close();
        return writable;
    } catch (Exception ex) {
        throw Throwables.propagate(ex);
    }

}