Example usage for java.io DataInputStream readInt

List of usage examples for java.io DataInputStream readInt

Introduction

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

Prototype

public final int readInt() throws IOException 

Source Link

Document

See the general contract of the readInt method of DataInput.

Usage

From source file:org.apache.hadoop.hbase.io.hfile.TestChecksum.java

private void validateData(DataInputStream in) throws IOException {
    // validate data
    for (int i = 0; i < 1234; i++) {
        int val = in.readInt();
        if (val != i) {
            String msg = "testChecksumCorruption: data mismatch at index " + i + " expected " + i + " found "
                    + val;
            LOG.warn(msg);/*from   ww w . j  av a  2 s .co m*/
            assertEquals(i, val);
        }
    }
}

From source file:org.gitools.matrix.format.CmatrixMatrixFormat.java

@Override
protected CompressMatrix readResource(IResourceLocator resourceLocator, IProgressMonitor progressMonitor)
        throws PersistenceException {

    try {//w w  w  . j a  v  a2 s  . co m
        DataInputStream in = new DataInputStream(resourceLocator.openInputStream(progressMonitor));

        // Format version
        int formatVersion = in.readInt();

        // Dictionary
        byte[] dictionary = readBuffer(in);

        // Columns
        String[] columns = splitBuffer(readBuffer(in));

        // Rows
        String[] rows = splitBuffer(readBuffer(in));

        // Headers
        String[] headers = splitBuffer(readBuffer(in));

        // Values
        Map<Integer, CompressRow> values = new HashMap<>(rows.length);

        for (int i = 0; i < rows.length; i++) {
            int row = in.readInt();
            int uncompressLength = in.readInt();
            values.put(row, new CompressRow(uncompressLength, readBuffer(in)));
        }

        in.close();

        CompressDimension rowDim = new CompressDimension(MatrixDimensionKey.ROWS, rows);
        CompressDimension colDim = new CompressDimension(MatrixDimensionKey.COLUMNS, columns);
        return new CompressMatrix(rowDim, colDim, dictionary, headers, values);

    } catch (IOException e) {
        throw new PersistenceException(e);
    }

}

From source file:org.structr.core.graph.SyncCommand.java

private static Object readObject(final DataInputStream inputStream, final byte type) throws IOException {

    switch (type) {

    case 0://from  w  w w.j  a  va 2s.c om
    case 1:
        return inputStream.readByte();

    case 2:
    case 3:
        return inputStream.readShort();

    case 4:
    case 5:
        return inputStream.readInt();

    case 6:
    case 7:
        return inputStream.readLong();

    case 8:
    case 9:
        return inputStream.readFloat();

    case 10:
    case 11:
        return inputStream.readDouble();

    case 12:
    case 13:
        return inputStream.readChar();

    case 14:
    case 15:
        return new String(deserializeData(inputStream), "UTF-8");

    // this doesn't work with very long strings
    //return inputStream.readUTF();

    case 16:
    case 17:
        return inputStream.readBoolean();
    }

    return null;
}

From source file:mitm.common.security.password.PBEncryptionParameters.java

private void fromByteArray(byte[] encoded) throws IOException {
    ByteArrayInputStream bis = new ByteArrayInputStream(encoded);

    DataInputStream in = new DataInputStream(bis);

    long version = in.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }//from w w w.  j a v a 2s  .c om

    int saltSize = in.readInt();

    this.salt = new byte[saltSize];

    in.readFully(salt);

    this.iterationCount = in.readInt();

    int encryptedSize = in.readInt();

    this.encryptedData = new byte[encryptedSize];

    in.readFully(encryptedData);
}

From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java

protected String readElementLabel(DataInputStream stream) throws IOException {
    int val = stream.readInt();
    if (val == -1) {
        return null;
    } else {//  w  ww  .j av  a 2 s. com
        byte[] label = new byte[val];
        stream.readFully(label);
        return new String(label);
    }
}

From source file:RealFunctionValidation.java

public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out,
        final Class<?> type) throws IOException {

    if (!type.isPrimitive()) {
        throw new IllegalArgumentException("type must be primitive");
    }/*w w w.  ja v  a 2s  .  c o m*/
    if (type.equals(Boolean.TYPE)) {
        final boolean x = in.readBoolean();
        out.writeBoolean(x);
        return Boolean.valueOf(x);
    } else if (type.equals(Byte.TYPE)) {
        final byte x = in.readByte();
        out.writeByte(x);
        return Byte.valueOf(x);
    } else if (type.equals(Character.TYPE)) {
        final char x = in.readChar();
        out.writeChar(x);
        return Character.valueOf(x);
    } else if (type.equals(Double.TYPE)) {
        final double x = in.readDouble();
        out.writeDouble(x);
        return Double.valueOf(x);
    } else if (type.equals(Float.TYPE)) {
        final float x = in.readFloat();
        out.writeFloat(x);
        return Float.valueOf(x);
    } else if (type.equals(Integer.TYPE)) {
        final int x = in.readInt();
        out.writeInt(x);
        return Integer.valueOf(x);
    } else if (type.equals(Long.TYPE)) {
        final long x = in.readLong();
        out.writeLong(x);
        return Long.valueOf(x);
    } else if (type.equals(Short.TYPE)) {
        final short x = in.readShort();
        out.writeShort(x);
        return Short.valueOf(x);
    } else {
        // This should never occur.
        throw new IllegalStateException();
    }
}

From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java

/**
 * Skip bloom bytes if not needed to re-read bloom filter
 * @param stream// w w w . j av  a2 s.c o m
 * @throws IOException
 */
protected void skipBloom(DataInputStream stream) throws IOException {
    int bytesToSkip = stream.readInt();
    stream.skip(bytesToSkip);
}

From source file:org.mule.transport.comm.protocols.LengthProtocol.java

public Object read(InputStream is) throws IOException {
    // original comments indicated that we need to use read(byte[]) rather than readInt()
    // to avoid socket timeouts - don't understand, but don't want to risk change.

    // first read the data necessary to know the length of the payload
    DataInputStream dis = new DataInputStream(is);
    dis.mark(SIZE_INT);//w ww  . j av  a  2  s. c  om
    // this pulls through SIZE_INT bytes
    if (null == super.read(dis, SIZE_INT)) {
        return null; // eof
    }

    // reset and read the integer
    dis.reset();
    int length = dis.readInt();
    if (logger.isDebugEnabled()) {
        logger.debug("length: " + length);
    }

    if (length < 0 || (getMaxMessageLength() > 0 && length > getMaxMessageLength())) {
        //            throw new IOException("Length " + length + " exceeds limit: " + getMaxMessageLength());
        System.out.println("Length " + length + " exceeds limit: " + getMaxMessageLength());
    }

    // finally read the rest of the data
    if (length > 0) {
        byte[] buffer = new byte[0];
        dis.readFully(buffer);
        if (logger.isDebugEnabled()) {
            logger.debug("length read: " + buffer.length);
        }

        return buffer;
    } else {
        byte[] buffer = new byte[0];
        return buffer;
    }
}

From source file:org.mule.transport.tcp.protocols.LengthProtocol.java

public Object read(InputStream is) throws IOException {
    // original comments indicated that we need to use read(byte[]) rather than readInt()
    // to avoid socket timeouts - don't understand, but don't want to risk change.

    // first read the data necessary to know the length of the payload
    DataInputStream dis = new DataInputStream(is);
    dis.mark(SIZE_INT);//from  w  w w  .j a  v a  2 s.  c o  m
    // this pulls through SIZE_INT bytes
    if (null == super.read(dis, SIZE_INT)) {
        return null; // eof
    }

    // reset and read the integer
    dis.reset();
    int length = dis.readInt();
    if (logger.isDebugEnabled()) {
        logger.debug("length: " + length);
    }

    if (length < 0 || (getMaxMessageLength() > 0 && length > getMaxMessageLength())) {
        throw new IOException("Length " + length + " exceeds limit: " + getMaxMessageLength());
    }

    // finally read the rest of the data
    byte[] buffer = new byte[length];
    dis.readFully(buffer);
    if (logger.isDebugEnabled()) {
        logger.debug("length read: " + buffer.length);
    }

    return buffer;
}

From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java

protected byte[] readGraphBloom(DataInputStream stream) throws IOException {
    byte[] bloom = new byte[stream.readInt()];
    stream.readFully(bloom);/*  w  ww .ja  va 2s.  c  om*/
    return bloom;
}