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:com.ibm.bi.dml.runtime.matrix.data.MatrixBlock.java

/**
 * /*from   w  w w  . ja  v a  2 s  . com*/
 * @param in
 * @throws IOException
 */
private void readSparseBlock(DataInput in) throws IOException {
    allocateSparseRowsBlock(false);
    resetSparse(); //reset all sparse rows

    if (in instanceof MatrixBlockDataInput) //fast deserialize
    {
        MatrixBlockDataInput mbin = (MatrixBlockDataInput) in;
        nonZeros = mbin.readSparseRows(rlen, sparseRows);
    } else if (in instanceof DataInputBuffer && MRJobConfiguration.USE_BINARYBLOCK_SERIALIZATION) {
        //workaround because sequencefile.reader.next(key, value) does not yet support serialization framework
        DataInputBuffer din = (DataInputBuffer) in;
        MatrixBlockDataInput mbin = new FastBufferedDataInputStream(din);
        nonZeros = mbin.readSparseRows(rlen, sparseRows);
        ((FastBufferedDataInputStream) mbin).close();
    } else //default deserialize
    {
        for (int r = 0; r < rlen; r++) {
            int nr = in.readInt();
            if (nr == 0) {
                if (sparseRows[r] != null)
                    sparseRows[r].reset(estimatedNNzsPerRow, clen);
                continue;
            }
            if (sparseRows[r] == null)
                sparseRows[r] = new SparseRow(nr);
            else
                sparseRows[r].reset(nr, clen);
            for (int j = 0; j < nr; j++)
                sparseRows[r].append(in.readInt(), in.readDouble());
        }
    }
}