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:org.apache.geode.internal.InternalDataSerializer.java

public static int readArrayLength(DataInput in) throws IOException {
    byte code = in.readByte();
    if (code == NULL_ARRAY) {
        return -1;
    } else {/*from  www.  jav a 2 s  .c o m*/
        int result = ubyteToInt(code);
        if (result > MAX_BYTE_ARRAY_LEN) {
            if (code == SHORT_ARRAY_LEN) {
                result = in.readUnsignedShort();
            } else if (code == INT_ARRAY_LEN) {
                result = in.readInt();
            } else {
                throw new IllegalStateException("unexpected array length code=" + code);
            }
        }
        return result;
    }
}

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

/**
 *  This method reads this object <code>Routes</code> from the specified
 *  input stream object./* w w  w . j  a  v a  2  s  .  co  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.
 * @see #toStream(DataOutput, int)
 * @since Tifosi2.0
 */
public void fromStream(DataInput is, int versionNo) throws IOException {
    super.fromStream(is, versionNo);

    m_isP2PRoute = is.readBoolean();

    m_isPersitant = is.readBoolean();

    m_isDurable = is.readBoolean();

    m_applyTransformationAtSrc = is.readBoolean();

    String temp = UTFReaderWriter.readUTF(is);

    if (temp.equals("")) {
        m_routeName = null;
    } else {
        m_routeName = temp;
    }

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals("")) {
        m_routeGUID = null;
    } else {
        m_routeGUID = temp;
    }

    m_iTimeToLive = is.readLong();

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals("")) {
        m_srcServInst = null;
    } else {
        m_srcServInst = temp;
    }

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals("")) {
        m_trgtServInst = null;
    } else {
        m_trgtServInst = temp;
    }

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals("")) {
        m_srcPortName = null;
    } else {
        m_srcPortName = temp;
    }

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals("")) {
        m_trgtPortName = null;
    } else {
        m_trgtPortName = temp;
    }

    temp = UTFReaderWriter.readUTF(is);
    if (temp.equals("")) {
        m_transformationXSL = null;
    } else {
        m_transformationXSL = temp;
    }

    int size = is.readInt();

    if (size > 0) {
        _readSelectorFromOldDmi(is, versionNo, size);
    } else if (size < 0) {
        _readSelector(is, versionNo);
    }

    int tempInt = 0;

    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_shortDescription = null;
    } else {
        m_shortDescription = temp;
    }

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

    if (is.readInt() == 1) {
        m_altDestination = new AlternateDestination();
        m_altDestination.fromStream(is, versionNo);
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static int readDSFIDHeader(final DataInput in) throws IOException {
    checkIn(in);/* w ww .j  a  va  2s .c  o m*/
    byte header = in.readByte();
    if (header == DS_FIXED_ID_BYTE) {
        return in.readByte();
    } else if (header == DS_FIXED_ID_SHORT) {
        return in.readShort();
    } else if (header == DS_NO_FIXED_ID) {
        // is that correct??
        return Integer.MAX_VALUE;
    } else if (header == DS_FIXED_ID_INT) {
        return in.readInt();
    } else {
        throw new IllegalStateException("unexpected byte: " + header + " while reading dsfid");
    }
}

From source file:bobs.is.compress.sevenzip.SevenZFile.java

private void readSubStreamsInfo(final DataInput header, final Archive archive) throws IOException {
    for (final Folder folder : archive.folders) {
        folder.numUnpackSubStreams = 1;//w  w w  . j  a va 2  s.  co m
    }
    int totalUnpackStreams = archive.folders.length;

    int nid = header.readUnsignedByte();
    if (nid == NID.kNumUnpackStream) {
        totalUnpackStreams = 0;
        for (final Folder folder : archive.folders) {
            final long numStreams = readUint64(header);
            folder.numUnpackSubStreams = (int) numStreams;
            totalUnpackStreams += numStreams;
        }
        nid = header.readUnsignedByte();
    }

    final SubStreamsInfo subStreamsInfo = new SubStreamsInfo();
    subStreamsInfo.unpackSizes = new long[totalUnpackStreams];
    subStreamsInfo.hasCrc = new BitSet(totalUnpackStreams);
    subStreamsInfo.crcs = new long[totalUnpackStreams];

    int nextUnpackStream = 0;
    for (final Folder folder : archive.folders) {
        if (folder.numUnpackSubStreams == 0) {
            continue;
        }
        long sum = 0;
        if (nid == NID.kSize) {
            for (int i = 0; i < folder.numUnpackSubStreams - 1; i++) {
                final long size = readUint64(header);
                subStreamsInfo.unpackSizes[nextUnpackStream++] = size;
                sum += size;
            }
        }
        subStreamsInfo.unpackSizes[nextUnpackStream++] = folder.getUnpackSize() - sum;
    }
    if (nid == NID.kSize) {
        nid = header.readUnsignedByte();
    }

    int numDigests = 0;
    for (final Folder folder : archive.folders) {
        if (folder.numUnpackSubStreams != 1 || !folder.hasCrc) {
            numDigests += folder.numUnpackSubStreams;
        }
    }

    if (nid == NID.kCRC) {
        final BitSet hasMissingCrc = readAllOrBits(header, numDigests);
        final long[] missingCrcs = new long[numDigests];
        for (int i = 0; i < numDigests; i++) {
            if (hasMissingCrc.get(i)) {
                missingCrcs[i] = 0xffffFFFFL & Integer.reverseBytes(header.readInt());
            }
        }
        int nextCrc = 0;
        int nextMissingCrc = 0;
        for (final Folder folder : archive.folders) {
            if (folder.numUnpackSubStreams == 1 && folder.hasCrc) {
                subStreamsInfo.hasCrc.set(nextCrc, true);
                subStreamsInfo.crcs[nextCrc] = folder.crc;
                ++nextCrc;
            } else {
                for (int i = 0; i < folder.numUnpackSubStreams; i++) {
                    subStreamsInfo.hasCrc.set(nextCrc, hasMissingCrc.get(nextMissingCrc));
                    subStreamsInfo.crcs[nextCrc] = missingCrcs[nextMissingCrc];
                    ++nextCrc;
                    ++nextMissingCrc;
                }
            }
        }

        nid = header.readUnsignedByte();
    }

    if (nid != NID.kEnd) {
        throw new IOException("Badly terminated SubStreamsInfo");
    }

    archive.subStreamsInfo = subStreamsInfo;
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static Object readDSFID(final DataInput in) throws IOException, ClassNotFoundException {
    checkIn(in);/*w w w  .j  a v a 2 s.c om*/
    byte header = in.readByte();
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "readDSFID: header={}", header);
    }
    if (header == DS_FIXED_ID_BYTE) {
        return DSFIDFactory.create(in.readByte(), in);
    } else if (header == DS_FIXED_ID_SHORT) {
        return DSFIDFactory.create(in.readShort(), in);
    } else if (header == DS_NO_FIXED_ID) {
        return readDataSerializableFixedID(in);
    } else if (header == DS_FIXED_ID_INT) {
        return DSFIDFactory.create(in.readInt(), in);
    } else {
        throw new IllegalStateException("unexpected byte: " + header + " while reading dsfid");
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

public static Object basicReadObject(final DataInput in) throws IOException, ClassNotFoundException {
    checkIn(in);// ww w .ja  v  a  2s . c  o  m

    // Read the header byte
    byte header = in.readByte();
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "basicReadObject: header={}", header);
    }
    switch (header) {
    case DS_FIXED_ID_BYTE:
        return DSFIDFactory.create(in.readByte(), in);
    case DS_FIXED_ID_SHORT:
        return DSFIDFactory.create(in.readShort(), in);
    case DS_FIXED_ID_INT:
        return DSFIDFactory.create(in.readInt(), in);
    case DS_NO_FIXED_ID:
        return readDataSerializableFixedID(in);
    case NULL:
        return null;
    case NULL_STRING:
    case STRING:
    case HUGE_STRING:
    case STRING_BYTES:
    case HUGE_STRING_BYTES:
        return readString(in, header);
    case CLASS:
        return readClass(in);
    case DATE:
        return readDate(in);
    case FILE:
        return readFile(in);
    case INET_ADDRESS:
        return readInetAddress(in);
    case BOOLEAN:
        return readBoolean(in);
    case CHARACTER:
        return readCharacter(in);
    case BYTE:
        return readByte(in);
    case SHORT:
        return readShort(in);
    case INTEGER:
        return readInteger(in);
    case LONG:
        return readLong(in);
    case FLOAT:
        return readFloat(in);
    case DOUBLE:
        return readDouble(in);
    case BYTE_ARRAY:
        return readByteArray(in);
    case ARRAY_OF_BYTE_ARRAYS:
        return readArrayOfByteArrays(in);
    case SHORT_ARRAY:
        return readShortArray(in);
    case STRING_ARRAY:
        return readStringArray(in);
    case INT_ARRAY:
        return readIntArray(in);
    case LONG_ARRAY:
        return readLongArray(in);
    case FLOAT_ARRAY:
        return readFloatArray(in);
    case DOUBLE_ARRAY:
        return readDoubleArray(in);
    case BOOLEAN_ARRAY:
        return readBooleanArray(in);
    case CHAR_ARRAY:
        return readCharArray(in);
    case OBJECT_ARRAY:
        return readObjectArray(in);
    case ARRAY_LIST:
        return readArrayList(in);
    case LINKED_LIST:
        return readLinkedList(in);
    case HASH_SET:
        return readHashSet(in);
    case LINKED_HASH_SET:
        return readLinkedHashSet(in);
    case HASH_MAP:
        return readHashMap(in);
    case IDENTITY_HASH_MAP:
        return readIdentityHashMap(in);
    case HASH_TABLE:
        return readHashtable(in);
    case CONCURRENT_HASH_MAP:
        return readConcurrentHashMap(in);
    case PROPERTIES:
        return readProperties(in);
    case TIME_UNIT:
        return readTimeUnit(in);
    case USER_CLASS:
        return readUserObject(in, in.readByte());
    case USER_CLASS_2:
        return readUserObject(in, in.readShort());
    case USER_CLASS_4:
        return readUserObject(in, in.readInt());
    case VECTOR:
        return readVector(in);
    case STACK:
        return readStack(in);
    case TREE_MAP:
        return readTreeMap(in);
    case TREE_SET:
        return readTreeSet(in);
    case BOOLEAN_TYPE:
        return Boolean.TYPE;
    case CHARACTER_TYPE:
        return Character.TYPE;
    case BYTE_TYPE:
        return Byte.TYPE;
    case SHORT_TYPE:
        return Short.TYPE;
    case INTEGER_TYPE:
        return Integer.TYPE;
    case LONG_TYPE:
        return Long.TYPE;
    case FLOAT_TYPE:
        return Float.TYPE;
    case DOUBLE_TYPE:
        return Double.TYPE;
    case VOID_TYPE:
        return Void.TYPE;

    case USER_DATA_SERIALIZABLE:
        return readUserDataSerializable(in, in.readByte());
    case USER_DATA_SERIALIZABLE_2:
        return readUserDataSerializable(in, in.readShort());
    case USER_DATA_SERIALIZABLE_4:
        return readUserDataSerializable(in, in.readInt());

    case DATA_SERIALIZABLE:
        return readDataSerializable(in);

    case SERIALIZABLE: {
        final boolean isDebugEnabled_SERIALIZER = logger.isTraceEnabled(LogMarker.SERIALIZER);
        Object serializableResult;
        if (in instanceof DSObjectInputStream) {
            serializableResult = ((DSObjectInputStream) in).readObject();
        } else {
            InputStream stream;
            if (in instanceof InputStream) {
                stream = (InputStream) in;
            } else {
                stream = new InputStream() {
                    @Override
                    public int read() throws IOException {
                        try {
                            return in.readUnsignedByte(); // fix for bug 47249
                        } catch (EOFException ignored) {
                            return -1;
                        }
                    }

                };
            }

            ObjectInput ois = new DSObjectInputStream(stream);
            if (stream instanceof VersionedDataStream) {
                Version v = ((VersionedDataStream) stream).getVersion();
                if (v != null && v != Version.CURRENT) {
                    ois = new VersionedObjectInput(ois, v);
                }
            }

            serializableResult = ois.readObject();

            if (isDebugEnabled_SERIALIZER) {
                logger.trace(LogMarker.SERIALIZER, "Read Serializable object: {}", serializableResult);
            }
        }
        if (isDebugEnabled_SERIALIZER) {
            logger.trace(LogMarker.SERIALIZER, "deserialized instanceof {}", serializableResult.getClass());
        }
        return serializableResult;
    }
    case PDX:
        return readPdxSerializable(in);
    case PDX_ENUM:
        return readPdxEnum(in);
    case GEMFIRE_ENUM:
        return readGemFireEnum(in);
    case PDX_INLINE_ENUM:
        return readPdxInlineEnum(in);
    case BIG_INTEGER:
        return readBigInteger(in);
    case BIG_DECIMAL:
        return readBigDecimal(in);
    case UUID:
        return readUUID(in);
    case TIMESTAMP:
        return readTimestamp(in);
    default:
        String s = "Unknown header byte: " + header;
        throw new IOException(s);
    }
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

/**
 * Reads an instance of {@code String} from a {@code DataInput} given the header byte already
 * being read. The return value may be {@code null}.
 *
 * @throws IOException A problem occurs while reading from {@code in}
 *
 * @since GemFire 5.7/*  w w w .java 2  s .  com*/
 */
public static String readString(DataInput in, byte header) throws IOException {
    if (header == DSCODE.STRING_BYTES) {
        int len = in.readUnsignedShort();
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading STRING_BYTES of len={}", len);
        }
        byte[] buf = new byte[len];
        in.readFully(buf, 0, len);
        return new String(buf, 0); // intentionally using deprecated constructor
    } else if (header == DSCODE.STRING) {
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading utf STRING");
        }
        return in.readUTF();
    } else if (header == DSCODE.NULL_STRING) {
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading NULL_STRING");
        }
        return null;
    } else if (header == DSCODE.HUGE_STRING_BYTES) {
        int len = in.readInt();
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading HUGE_STRING_BYTES of len={}", len);
        }
        byte[] buf = new byte[len];
        in.readFully(buf, 0, len);
        return new String(buf, 0); // intentionally using deprecated constructor
    } else if (header == DSCODE.HUGE_STRING) {
        int len = in.readInt();
        if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
            logger.trace(LogMarker.SERIALIZER, "Reading HUGE_STRING of len={}", len);
        }
        char[] buf = new char[len];
        for (int i = 0; i < len; i++) {
            buf[i] = in.readChar();
        }
        return new String(buf);
    } else {
        String s = "Unknown String header " + header;
        throw new IOException(s);
    }
}

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

/**
 *  This method reads this object <code>ServiceInstance</code> from the
 *  specified object of input stream.//ww  w  . jav a 2  s . co 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_isManualLaunch = is.readBoolean();

    m_isStateful = is.readBoolean();

    m_isDelayedLaunch = is.readBoolean();

    String temp = UTFReaderWriter.readUTF(is);

    if (temp == null)
        m_delayedPortName = "";
    else
        m_delayedPortName = temp;

    m_isTransacted = is.readBoolean();

    m_isErrorHandlingEnabled = is.readBoolean();

    m_isVersionLocked = is.readBoolean();

    m_isEndOfWorkflow = is.readBoolean();

    m_isInMemoryLaunch = is.readBoolean();

    m_isTransportLPC = is.readBoolean();

    m_bPreferLaunchOnHigherLevelNode = is.readBoolean();

    m_bIsDurableSubscription = is.readBoolean();

    m_bIsDurableConnection = is.readBoolean();

    m_bKillPrimaryOnSecondaryLaunch = is.readBoolean();

    m_bIsDebugMode = is.readBoolean();

    m_iDebugPort = is.readInt();

    m_maxRetries = is.readInt();

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

    m_dBufferSizePerPort = is.readLong();

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

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

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

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

    // Service Dependency
    int tempInt = is.readInt();

    for (int i = 0; i < tempInt; ++i) {
        RuntimeDependency serv = new RuntimeDependency();

        serv.fromStream(is, versionNo);
        m_runtimeDependencies.addElement(serv);
    }

    tempInt = is.readInt();

    if (tempInt != 0) {
        m_runtimeArgs = new RuntimeArgs();
        m_runtimeArgs.fromStream(is, versionNo);
    }

    tempInt = is.readInt();
    if (tempInt != 0) {
        m_portInstDescriptor = new PortInstDescriptor();
        m_portInstDescriptor.fromStream(is, versionNo);
    }

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

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

    tempInt = is.readInt();
    if (tempInt != 0) {
        m_statusTracking = new StatusTracking();
        m_statusTracking.fromStream(is, versionNo);
    }

    tempInt = is.readInt();

    if (tempInt != 0) {
        m_vecEndStates = new Vector();
        for (int i = 0; i < tempInt; i++) {
            EndState endState = new EndState();

            endState.fromStream(is, versionNo);
            m_vecEndStates.add(endState);

        }
    }

    tempInt = is.readInt();
    if (tempInt != 0)
        for (int i = 0; i < tempInt; i++)
            m_nodes.put(UTFReaderWriter.readUTF(is), UTFReaderWriter.readUTF(is));

    tempInt = is.readInt();
    if (tempInt != 0) {
        m_monitor = new Monitor();
        m_monitor.fromStream(is, versionNo);
    }

    tempInt = is.readInt();
    if (tempInt != 0) {
        m_logModules = new LogModules();
        m_logModules.fromStream(is, versionNo);
    }

    // Log Manager and log params
    m_logManager = readUTF(is);
    m_profile = readUTF(is);

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

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

    //  Event Parameters.
    m_eventDeliveryMode = readUTF(is);
    m_eventExpiryTime = is.readLong();
    m_eventHandler = is.readInt();
}

From source file:org.apache.hawq.pxf.service.io.GPDBWritable.java

@Override
public void readFields(DataInput in) throws IOException {
    /*/*from   ww w .  j  a v  a2  s  . c o m*/
     * extract pkt len.
    *
    * GPSQL-1107:
    * The DataInput might already be empty (EOF), but we can't check it beforehand.
    * If that's the case, pktlen is updated to -1, to mark that the object is still empty.
    * (can be checked with isEmpty()).
    */
    pktlen = readPktLen(in);
    if (isEmpty()) {
        return;
    }

    /* extract the version and col cnt */
    int version = in.readShort();
    int curOffset = 4 + 2;
    int colCnt;

    /* !!! Check VERSION !!! */
    if (version != GPDBWritable.VERSION && version != GPDBWritable.PREV_VERSION) {
        throw new IOException("Current GPDBWritable version(" + GPDBWritable.VERSION
                + ") does not match input version(" + version + ")");
    }

    if (version == GPDBWritable.VERSION) {
        errorFlag = in.readByte();
        curOffset += 1;
    }

    colCnt = in.readShort();
    curOffset += 2;

    /* Extract Column Type */
    colType = new int[colCnt];
    DBType[] coldbtype = new DBType[colCnt];
    for (int i = 0; i < colCnt; i++) {
        int enumType = (in.readByte());
        curOffset += 1;
        if (enumType == DBType.BIGINT.ordinal()) {
            colType[i] = BIGINT.getOID();
            coldbtype[i] = DBType.BIGINT;
        } else if (enumType == DBType.BOOLEAN.ordinal()) {
            colType[i] = BOOLEAN.getOID();
            coldbtype[i] = DBType.BOOLEAN;
        } else if (enumType == DBType.FLOAT8.ordinal()) {
            colType[i] = FLOAT8.getOID();
            coldbtype[i] = DBType.FLOAT8;
        } else if (enumType == DBType.INTEGER.ordinal()) {
            colType[i] = INTEGER.getOID();
            coldbtype[i] = DBType.INTEGER;
        } else if (enumType == DBType.REAL.ordinal()) {
            colType[i] = REAL.getOID();
            coldbtype[i] = DBType.REAL;
        } else if (enumType == DBType.SMALLINT.ordinal()) {
            colType[i] = SMALLINT.getOID();
            coldbtype[i] = DBType.SMALLINT;
        } else if (enumType == DBType.BYTEA.ordinal()) {
            colType[i] = BYTEA.getOID();
            coldbtype[i] = DBType.BYTEA;
        } else if (enumType == DBType.TEXT.ordinal()) {
            colType[i] = TEXT.getOID();
            coldbtype[i] = DBType.TEXT;
        } else {
            throw new IOException("Unknown GPDBWritable.DBType ordinal value");
        }
    }

    /* Extract null bit array */
    byte[] nullbytes = new byte[getNullByteArraySize(colCnt)];
    in.readFully(nullbytes);
    curOffset += nullbytes.length;
    boolean[] colIsNull = byteArrayToBooleanArray(nullbytes, colCnt);

    /* extract column value */
    colValue = new Object[colCnt];
    for (int i = 0; i < colCnt; i++) {
        if (!colIsNull[i]) {
            /* Skip the alignment padding */
            int skipbytes = roundUpAlignment(curOffset, coldbtype[i].getAlignment()) - curOffset;
            for (int j = 0; j < skipbytes; j++) {
                in.readByte();
            }
            curOffset += skipbytes;

            /* For fixed length type, increment the offset according to type type length here.
                 * For var length type (BYTEA, TEXT), we'll read 4 byte length header and the
             * actual payload.
             */
            int varcollen = -1;
            if (coldbtype[i].isVarLength()) {
                varcollen = in.readInt();
                curOffset += 4 + varcollen;
            } else {
                curOffset += coldbtype[i].getTypeLength();
            }

            switch (DataType.get(colType[i])) {
            case BIGINT: {
                colValue[i] = in.readLong();
                break;
            }
            case BOOLEAN: {
                colValue[i] = in.readBoolean();
                break;
            }
            case FLOAT8: {
                colValue[i] = in.readDouble();
                break;
            }
            case INTEGER: {
                colValue[i] = in.readInt();
                break;
            }
            case REAL: {
                colValue[i] = in.readFloat();
                break;
            }
            case SMALLINT: {
                colValue[i] = in.readShort();
                break;
            }

            /* For BYTEA column, it has a 4 byte var length header. */
            case BYTEA: {
                colValue[i] = new byte[varcollen];
                in.readFully((byte[]) colValue[i]);
                break;
            }
            /* For text formatted column, it has a 4 byte var length header
             * and it's always null terminated string.
            * So, we can remove the last "\0" when constructing the string.
            */
            case TEXT: {
                byte[] data = new byte[varcollen];
                in.readFully(data, 0, varcollen);
                colValue[i] = new String(data, 0, varcollen - 1, CHARSET);
                break;
            }

            default:
                throw new IOException("Unknown GPDBWritable ColType");
            }
        }
    }

    /* Skip the ending alignment padding */
    int skipbytes = roundUpAlignment(curOffset, 8) - curOffset;
    for (int j = 0; j < skipbytes; j++) {
        in.readByte();
    }
    curOffset += skipbytes;

    if (errorFlag != 0) {
        throw new IOException("Received error value " + errorFlag + " from format");
    }
}

From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java

private void readSparseToDense(DataInput in) throws IOException, DMLRuntimeException {
    allocateDenseBlock(false); //allocate block
    Arrays.fill(denseBlock, 0);/*from   ww w  .  ja va2s . c om*/

    for (int r = 0; r < rlen; r++) {
        int nr = in.readInt();
        for (int j = 0; j < nr; j++) {
            int c = in.readInt();
            double val = in.readDouble();
            denseBlock[r * clen + c] = val;
        }
    }
}