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.fiorano.openesb.application.DmiObject.java

/**
 * Utility method to read a list from input stream
 * @param list list/*from  ww  w .  j  a  va  2  s .c om*/
 * @param dmiType type of dmi object
 * @param in input stream
 * @param versionNo version
 * @throws IOException IOException
 */
public static void fromStream(List list, int dmiType, DataInput in, int versionNo) throws IOException {
    try {
        int size = in.readInt();
        for (int i = 0; i < size; i++) {
            DmiObject dmi = DmiObject.getDatamodelObject(dmiType);
            dmi.fromStream(in, versionNo);
            list.add(dmi);
        }
    } catch (FioranoException ex) {
        throw (IOException) new IOException().initCause(ex);
    }
}

From source file:org.apache.marmotta.kiwi.io.KiWiIO.java

/**
 * Read a potentially compressed string from the data input.
 *
 * @param in//from ww  w . ja  v a2s . co  m
 * @return
 * @throws IOException
 */
private static String readContent(DataInput in) throws IOException {
    int mode = in.readByte();

    if (mode == MODE_COMPRESSED) {
        try {
            int strlen = in.readInt();
            int buflen = in.readInt();

            byte[] buffer = new byte[buflen];
            in.readFully(buffer);

            Inflater decompressor = new Inflater(true);
            decompressor.setInput(buffer);

            byte[] data = new byte[strlen];
            decompressor.inflate(data);
            decompressor.end();

            return new String(data, "UTF-8");
        } catch (DataFormatException ex) {
            throw new IllegalStateException("input data is not valid", ex);
        }
    } else {
        return DataIO.readString(in);
    }
}

From source file:org.apache.hadoop.hbase.security.access.PermissionStorage.java

public static ListMultimap<String, Permission> readPermissions(byte[] data, Configuration conf)
        throws DeserializationException {
    if (ProtobufUtil.isPBMagicPrefix(data)) {
        int pblen = ProtobufUtil.lengthOfPBMagic();
        try {// w  w w  . j ava 2s  . co  m
            AccessControlProtos.UsersAndPermissions.Builder builder = AccessControlProtos.UsersAndPermissions
                    .newBuilder();
            ProtobufUtil.mergeFrom(builder, data, pblen, data.length - pblen);
            return AccessControlUtil.toPermission(builder.build());
        } catch (IOException e) {
            throw new DeserializationException(e);
        }
    } else {
        // TODO: We have to re-write non-PB data as PB encoded. Otherwise we will carry old Writables
        // forever (here and a couple of other places).
        ListMultimap<String, Permission> perms = ArrayListMultimap.create();
        try {
            DataInput in = new DataInputStream(new ByteArrayInputStream(data));
            int length = in.readInt();
            for (int i = 0; i < length; i++) {
                String user = Text.readString(in);
                perms.putAll(user, readWritableUserPermission(in, conf));
            }
        } catch (IOException | ClassNotFoundException e) {
            throw new DeserializationException(e);
        }
        return perms;
    }
}

From source file:org.apache.hadoop.hbase.security.access.PermissionStorage.java

@VisibleForTesting
public static ListMultimap<String, UserPermission> readUserPermission(byte[] data, Configuration conf)
        throws DeserializationException {
    if (ProtobufUtil.isPBMagicPrefix(data)) {
        int pblen = ProtobufUtil.lengthOfPBMagic();
        try {//from w  w  w .j  a v  a 2  s  . c  o m
            AccessControlProtos.UsersAndPermissions.Builder builder = AccessControlProtos.UsersAndPermissions
                    .newBuilder();
            ProtobufUtil.mergeFrom(builder, data, pblen, data.length - pblen);
            return AccessControlUtil.toUserPermission(builder.build());
        } catch (IOException e) {
            throw new DeserializationException(e);
        }
    } else {
        // TODO: We have to re-write non-PB data as PB encoded. Otherwise we will carry old Writables
        // forever (here and a couple of other places).
        ListMultimap<String, UserPermission> userPermission = ArrayListMultimap.create();
        try {
            DataInput in = new DataInputStream(new ByteArrayInputStream(data));
            int length = in.readInt();
            for (int i = 0; i < length; i++) {
                String user = Text.readString(in);
                List<Permission> perms = readWritableUserPermission(in, conf);
                for (Permission p : perms) {
                    userPermission.put(user, new UserPermission(user, p));
                }
            }
        } catch (IOException | ClassNotFoundException e) {
            throw new DeserializationException(e);
        }
        return userPermission;
    }
}

From source file:org.apache.hadoop.hbase.security.access.PermissionStorage.java

private static List<Permission> readWritableUserPermission(DataInput in, Configuration conf)
        throws IOException, ClassNotFoundException {
    assert WritableUtils.readVInt(in) == LIST_CODE;
    int length = in.readInt();
    List<Permission> list = new ArrayList<>(length);
    for (int i = 0; i < length; i++) {
        assert WritableUtils.readVInt(in) == WRITABLE_CODE;
        assert WritableUtils.readVInt(in) == WRITABLE_NOT_ENCODED;
        String className = Text.readString(in);
        Class<? extends Writable> clazz = conf.getClassByName(className).asSubclass(Writable.class);
        Writable instance = WritableFactories.newInstance(clazz, conf);
        instance.readFields(in);//from  w  ww  .j  av a 2s  .  com
        list.add((Permission) instance);
    }
    return list;
}

From source file:org.apache.marmotta.kiwi.io.KiWiIO.java

/**
 * Read a KiWiDateLiteral serialized with writeDateLiteral from a DataInput source
 *
 * @param input the source//from  w  w w  .ja  v a  2  s .  com
 * @return the de-serialized KiWiDateLiteral
 * @throws IOException
 */
public static KiWiDateLiteral readDateLiteral(DataInput input) throws IOException {
    long id = input.readLong();

    if (id == -1) {
        return null;
    } else {
        DateTime content = new DateTime(input.readLong(), DateTimeZone.forOffsetMillis(input.readInt()));

        KiWiUriResource dtype = readURI(input);

        Date created = new Date(input.readLong());

        KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
        r.setId(id);

        return r;
    }
}

From source file:org.apache.eagle.alert.engine.serialization.impl.JavaObjectSerializer.java

@Override
public Object deserialize(DataInput dataInput) throws IOException {
    int len = dataInput.readInt();
    byte[] bytes = new byte[len];
    dataInput.readFully(bytes);/* w w w  .  ja v  a2  s .c  o m*/
    return SerializationUtils.deserialize(bytes);
}

From source file:edu.iu.lda.TopicCountList.java

@Override
public void read(DataInput in) throws IOException {
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        topicCount.add(in.readLong());//from w w  w.  j ava2s.  com
    }
    topicCount.trim();
}

From source file:org.apache.sqoop.mapreduce.netezza.NetezzaExternalTableInputSplit.java

@Override
public void readFields(DataInput input) throws IOException {
    dataSliceId = input.readInt();
}

From source file:edu.iu.lda.TopicCount.java

@Override
public void read(DataInput in) throws IOException {
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        topicCount.put(in.readInt(), in.readInt());
    }/*from   ww w . j  av a  2  s .  c  o  m*/
    topicCount.trim();
}