Example usage for java.io DataInput readInt

List of usage examples for java.io DataInput readInt

Introduction

In this page you can find the example usage for java.io DataInput readInt.

Prototype

int readInt() throws IOException;

Source Link

Document

Reads four input bytes and returns an int value.

Usage

From source file:Main.java

/**
 * Reads an int[] from a DataInput/*from w w  w. ja v  a2  s . c  om*/
 * @throws java.io.IOException
 */
public static int[] readIntArray(DataInput in) throws IOException {
    int length = in.readInt();
    int[] array = new int[length];
    for (int index = 0; index < length; index++) {
        array[index] = in.readInt();
    }

    return array;
}

From source file:Main.java

/**
 * Reads a double[] from a DataInput//ww w.  j a v a2s. c o m
 * @throws java.io.IOException
 */
public static double[] readDoubleArray(DataInput in) throws IOException {
    int length = in.readInt();
    double[] array = new double[length];
    for (int index = 0; index < length; index++) {
        array[index] = in.readDouble();
    }

    return array;
}

From source file:Main.java

public static byte[] readByteBuffer(DataInput in) throws Exception {
    int b = in.readByte();
    if (b == 1) {
        b = in.readInt();
        byte[] buf = new byte[b];
        in.readFully(buf, 0, buf.length);
        return buf;
    }/*w  w w  . j a  va2 s . co m*/
    return null;
}

From source file:com.cloud.utils.crypt.RSAHelper.java

private static byte[] readElement(DataInput dis) throws IOException {
    int len = dis.readInt();
    byte[] buf = new byte[len];
    dis.readFully(buf);/*from w  w  w  . ja v a2 s.  c om*/
    return buf;
}

From source file:org.jactr.io.antlr3.serialization.Serializer.java

static public CommonTree read(DataInput input) throws IOException {
    int nodeType = input.readInt();
    String nodeText = input.readUTF();

    int tokenType = input.readInt();
    String tokenText = input.readUTF();
    int tokenStart = input.readInt();
    int tokenStop = input.readInt();
    int tokenLine = input.readInt();
    int tokenLineOffset = input.readInt();

    CommonToken token = new CommonToken(tokenType, tokenText);
    token.setStartIndex(tokenStart);//w  w w.  java  2 s. c  o m
    token.setStopIndex(tokenStop);
    token.setLine(tokenLine);
    token.setCharPositionInLine(tokenLineOffset);

    DetailedCommonTree node = (DetailedCommonTree) _adaptor.create(nodeType, token, nodeText);
    node.setTokenStartIndex(input.readInt());
    node.setTokenStopIndex(input.readInt());

    node.setStartOffset(input.readInt());
    node.setEndOffset(input.readInt());

    String url = input.readUTF();
    if (url.length() != 0)
        try {
            node.setSource(new URL(url));
        } catch (Exception e) {

        }

    int children = input.readInt();
    for (int i = 0; i < children; i++)
        node.addChild(read(input));
    return node;
}

From source file:org.mrgeo.utils.StringUtils.java

public static String read(DataInput in) throws IOException {
    int len = in.readInt();
    if (len == -1) {
        return null;
    } else {//from   w  w w .  j av  a  2s. com
        byte[] data = new byte[len];
        in.readFully(data);

        return new String(data, "UTF-8");
    }
}

From source file:com.ebay.erl.mobius.util.SerializableUtil.java

public static CaseInsensitiveTreeMap deseralizeTreeMap(DataInput in) throws IOException {
    CaseInsensitiveTreeMap map = new CaseInsensitiveTreeMap();
    int keys_nbr = in.readInt();
    for (int i = 0; i < keys_nbr; i++) {
        map.put(in.readUTF(), in.readUTF());
    }//from   w  ww .  j  a  v a  2s.c o  m
    return map;
}

From source file:com.chinamobile.bcbsp.ml.VectorWritable.java

public static DoubleVector readVector(DataInput in) throws IOException {
    int length = in.readInt();
    DoubleVector vector;/*from   ww  w  .j a  v a 2s.  c o m*/
    vector = new DenseDoubleVector(length);
    for (int i = 0; i < length; i++) {
        vector.set(i, in.readDouble());
    }

    if (in.readBoolean()) {
        vector = new NamedDoubleVector(in.readUTF(), vector);
    }
    return vector;
}

From source file:org.apache.mahout.classifier.df.node.Node.java

public static Node read(DataInput in) throws IOException {
    Type type = Type.values()[in.readInt()];
    Node node;/*from  w w w.  jav  a  2  s .c o m*/

    switch (type) {
    case LEAF:
        node = new Leaf();
        break;
    case NUMERICAL:
        node = new NumericalNode();
        break;
    case CATEGORICAL:
        node = new CategoricalNode();
        break;
    default:
        throw new IllegalStateException("This implementation is not currently supported");
    }

    node.readFields(in);

    return node;
}

From source file:org.apache.mahout.classifier.df.DFUtils.java

/**
 * Reads a Node[] from a DataInput//from   w w w.j  a  v a 2  s. co m
 * @throws java.io.IOException
 */
public static Node[] readNodeArray(DataInput in) throws IOException {
    int length = in.readInt();
    Node[] nodes = new Node[length];
    for (int index = 0; index < length; index++) {
        nodes[index] = Node.read(in);
    }

    return nodes;
}