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.ricemap.spateDB.core.RTree.java

@Override
public void readFields(DataInput in) throws IOException {
    // Tree size (Header + structure + data)
    treeSize = in.readInt();
    if (treeSize == 0) {
        height = elementCount = 0;//from w  w w  . jav a  2 s.  c  om
        return;
    }

    // Read only the tree structure in memory while actual records remain on
    // disk and loaded when necessary
    height = in.readInt();
    if (height == 0)
        return;
    degree = in.readInt();
    elementCount = in.readInt();
    columnar = in.readInt() == 1;

    // Keep only tree structure in memory
    nodeCount = (int) ((powInt(degree, height) - 1) / (degree - 1));
    int structureSize = nodeCount * NodeSize;
    byte[] treeStructure = new byte[structureSize];
    in.readFully(treeStructure, 0, structureSize);
    structure = new FSDataInputStream(new MemoryInputStream(treeStructure));
    if (in instanceof FSDataInputStream) {
        this.treeStartOffset = ((FSDataInputStream) in).getPos() - structureSize - TreeHeaderSize;
        this.data = (FSDataInputStream) in;
    } else {
        // Load all tree data in memory
        this.treeStartOffset = 0 - structureSize - TreeHeaderSize;
        int treeDataSize = treeSize - TreeHeaderSize - structureSize;
        byte[] treeData = new byte[treeDataSize];
        in.readFully(treeData, 0, treeDataSize);
        this.data = new FSDataInputStream(new MemoryInputStream(treeData));
    }
    nodeCount = (int) ((Math.pow(degree, height) - 1) / (degree - 1));
    leafNodeCount = (int) Math.pow(degree, height - 1);
    nonLeafNodeCount = nodeCount - leafNodeCount;
}

From source file:com.mobicage.rogerthat.plugins.messaging.BrandingMgr.java

@SuppressWarnings("unchecked")
private void readLegacyStashedLockRequests(DataInput in) throws IOException, PickleException {
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        String key = in.readUTF();
        BrandedItem item = getMessageFromQueue(key);
        item.calls.add(createRpcCall("com.mobicage.capi.messaging.messageLocked",
                (Map<String, Object>) JSONValue.parse(in.readUTF())));
    }//from   w  w w .jav a2  s . co m
}

From source file:com.mobicage.rogerthat.plugins.messaging.BrandingMgr.java

@SuppressWarnings("unchecked")
private void readLegacyStashedMemberStatusUpdates(DataInput in) throws IOException, PickleException {
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        String key = in.readUTF();
        BrandedItem item = getMessageFromQueue(key);
        int updatesCount = in.readInt();
        for (int j = 0; j < updatesCount; j++) {
            item.calls.add(createRpcCall("com.mobicage.capi.messaging.updateMessageMemberStatus",
                    (Map<String, Object>) JSONValue.parse(in.readUTF())));
        }/*w  ww .j  a v a 2 s  . c  om*/
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.BrandingMgr.java

@SuppressWarnings("unchecked")
private void deserializeStashedLegacyManager(int version, DataInput in) throws IOException, PickleException {
    int msgQueueSize = in.readInt();
    for (int i = 0; i < msgQueueSize; i++) {
        try {/*w  w w  .  j  a  v a  2  s  .  c o m*/
            Message message = new Message((Map<String, Object>) JSONValue.parse(in.readUTF()));
            mQueue.add(new BrandedItem(message));
        } catch (IncompleteMessageException e) {
            L.bug(e);
        }
    }

    if (version == 3) {
        readLegacyStashedMemberStatusUpdates(in);
    }

    if (version >= 2) {
        int friendQueueSize = in.readInt();
        for (int i = 0; i < friendQueueSize; i++) {
            try {
                FriendTO friend = new FriendTO((Map<String, Object>) JSONValue.parse(in.readUTF()));
                mQueue.add(new BrandedItem(BrandedItem.TYPE_FRIEND, friend, friend.descriptionBranding));
            } catch (IncompleteMessageException e) {
                L.bug(e);
            }
        }
    }
}

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

/**
 * Deserialize the tuple from the input/*from  w  ww .  j  ava 2  s. com*/
 * <code>in</code>.
 */
@Override
public void readFields(DataInput in) throws IOException {
    if (this.values == null) {
        this.values = new ArrayList<Object>();
    } else
        this.values.clear();

    int columns_nbrs = in.readInt();

    ReadFieldImpl read_impl = new ReadFieldImpl(this.values, in, this.conf);

    for (int i = 0; i < columns_nbrs; i++) {
        byte type = in.readByte();
        read_impl.handle(type);
    }
}

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

public int getTupleSize(DataInput in, byte type) throws IOException {
    int sz;/*from   ww  w . j  a v a2  s.c  o m*/
    switch (type) {
    case TUPLE_0:
        return 0;
    case TUPLE_1:
        return 1;
    case TUPLE_2:
        return 2;
    case TUPLE_3:
        return 3;
    case TUPLE_4:
        return 4;
    case TUPLE_5:
        return 5;
    case TUPLE_6:
        return 6;
    case TUPLE_7:
        return 7;
    case TUPLE_8:
        return 8;
    case TUPLE_9:
        return 9;
    case TINYTUPLE:
        sz = in.readUnsignedByte();
        break;
    case SMALLTUPLE:
        sz = in.readUnsignedShort();
        break;
    case TUPLE:
        sz = in.readInt();
        break;
    default: {
        int errCode = 2112;
        String msg = "Unexpected datatype " + type + " while reading tuple" + "from binary file.";
        throw new ExecException(msg, errCode, PigException.BUG);
    }
    }
    // if sz == 0, we construct an "empty" tuple - presumably the writer wrote an empty tuple!
    if (sz < 0) {
        throw new IOException("Invalid size " + sz + " for a tuple");
    }
    return sz;
}

From source file:org.apache.sysml.runtime.compress.CompressedMatrixBlock.java

@Override
public void readFields(DataInput in) throws IOException {
    boolean compressed = in.readBoolean();

    //deserialize uncompressed block
    if (!compressed) {
        super.readFields(in);
        return;//from   w  w  w.j  ava 2  s . c  om
    }

    //deserialize compressed block
    rlen = in.readInt();
    clen = in.readInt();
    nonZeros = in.readLong();
    int ncolGroups = in.readInt();

    _colGroups = new ArrayList<ColGroup>(ncolGroups);
    for (int i = 0; i < ncolGroups; i++) {
        CompressionType ctype = CompressionType.values()[in.readByte()];
        ColGroup grp = null;

        //create instance of column group
        switch (ctype) {
        case UNCOMPRESSED:
            grp = new ColGroupUncompressed();
            break;
        case OLE_BITMAP:
            grp = new ColGroupOLE();
            break;
        case RLE_BITMAP:
            grp = new ColGroupRLE();
            break;
        }

        //deserialize and add column group
        grp.readFields(in);
        _colGroups.add(grp);
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.BrandingMgr.java

@Override
public void readFromPickle(int version, DataInput in) throws IOException, PickleException {
    T.dontCare();/*from w  ww.  j  av a  2 s .  co m*/
    if (version < 4) {
        deserializeStashedLegacyManager(version, in);
    } else {
        // Read branding queue
        int queueSize = in.readInt();
        for (int i = 0; i < queueSize; i++) {
            @SuppressWarnings("unchecked")
            Map<String, Object> jsonMap = (Map<String, Object>) JSONValue.parse(in.readUTF());
            try {
                mQueue.add(new BrandedItem(jsonMap));
            } catch (IncompleteMessageException e) {
                L.bug(e);
            }
        }

        if (version < 6) {
            readLegacyStashedMemberStatusUpdates(in);
            if (version >= 5) {
                readLegacyStashedLockRequests(in);
            }
        }

        if (version >= 7) {
            int downloadQueueSize = in.readInt();
            for (int i = 0; i < downloadQueueSize; i++) {
                @SuppressWarnings("unchecked")
                Map<String, Object> jsonMap = (Map<String, Object>) JSONValue.parse(in.readUTF());
                try {
                    final BrandedItem item = new BrandedItem(jsonMap);
                    mDownloadMgrQueue.put(item.downloadId, item);
                } catch (IncompleteMessageException e) {
                    L.bug(e);
                }
            }
        }
    }
}

From source file:org.apache.hadoop.hbase.HRegionInfo.java

/**
 * @deprecated Use protobuf deserialization instead.
 * @see #parseFrom(byte[])/*from  w  w w . j av a  2s .  c  om*/
 */
@Deprecated
public void readFields(DataInput in) throws IOException {
    // Read the single version byte.  We don't ask the super class do it
    // because freaks out if its not the current classes' version.  This method
    // can deserialize version 0 and version 1 of HRI.
    byte version = in.readByte();
    if (version == 0) {
        // This is the old HRI that carried an HTD.  Migrate it.  The below
        // was copied from the old 0.90 HRI readFields.
        this.endKey = Bytes.readByteArray(in);
        this.offLine = in.readBoolean();
        this.regionId = in.readLong();
        this.regionName = Bytes.readByteArray(in);
        this.split = in.readBoolean();
        this.startKey = Bytes.readByteArray(in);
        try {
            HTableDescriptor htd = new HTableDescriptor();
            htd.readFields(in);
            this.tableName = htd.getTableName();
        } catch (EOFException eofe) {
            throw new IOException("HTD not found in input buffer", eofe);
        }
        this.hashCode = in.readInt();
    } else if (getVersion() == version) {
        this.endKey = Bytes.readByteArray(in);
        this.offLine = in.readBoolean();
        this.regionId = in.readLong();
        this.regionName = Bytes.readByteArray(in);
        this.split = in.readBoolean();
        this.startKey = Bytes.readByteArray(in);
        this.tableName = TableName.valueOf(Bytes.readByteArray(in));
        this.hashCode = in.readInt();
    } else {
        throw new IOException("Non-migratable/unknown version=" + getVersion());
    }
}

From source file:com.fiorano.openesb.application.aps.ApplicationHeader.java

/**
 *  This method reads this <code>ApplicationHeaders</code> object from the
 *  specified input stream object./* w  ww . java2 s . c  o m*/
 *
 * @param is DataInput object
 * @param versionNo
 * @exception IOException if an error occurs while reading bytes or while
 *      converting them into specified Java primitive type.
 * @since Tifosi2.0
 */
public void fromStream(DataInput is, int versionNo) throws IOException {
    super.fromStream(is, versionNo);

    m_canBeSubGraphed = is.readBoolean();

    String temp = UTFReaderWriter.readUTF(is);

    if (temp.equals(""))
        m_scope = null;

    else
        m_scope = temp;

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals(""))
        m_appName = null;

    else
        m_appName = temp;

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals(""))
        m_appGUID = null;

    else
        setApplicationGUID(temp);

    temp = UTFReaderWriter.readUTF(is);

    if (temp == null || temp.trim().equals(""))
        formatStringAsDate("");
    else
        formatStringAsDate(temp);

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals(""))
        m_category = null;

    else
        m_category = temp;

    int tempInt;

    if ((tempInt = is.readInt()) != 0)
        for (int i = 0; i < tempInt; i++) {
            String name = UTFReaderWriter.readUTF(is);

            m_authorNames.add(name);
        }

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals(""))
        m_iconName = null;

    else
        m_iconName = temp;

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals(""))
        m_shortDescription = null;

    else
        m_shortDescription = temp;

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals(""))
        m_longDescription = null;

    else
        m_longDescription = temp;

    if ((tempInt = is.readInt()) != 0)
        for (int i = 0; i < tempInt; i++) {
            String name = UTFReaderWriter.readUTF(is);

            m_compatibleWith.add(name);
        }

    m_maxInstLimit = is.readInt();

    if ((tempInt = is.readInt()) != 0)
        for (int i = 0; i < tempInt; i++) {
            Param param = new Param();

            param.fromStream(is, versionNo);
            m_params.add(param);
        }

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals(""))
        m_version = null;

    else
        m_version = temp;

    m_isVersionLocked = is.readBoolean();

    m_strProfile = UTFReaderWriter.readUTF(is);

    int result = is.readInt();

    if (result == 1) {
        m_appContext = new ApplicationContext();
        m_appContext.fromStream(is, versionNo);
    }
}