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.accumulo.core.client.mapreduce.RangeInputSplit.java

@Override
public void readFields(DataInput in) throws IOException {
    range.readFields(in);/*  ww  w .j  ava2 s  . c o  m*/
    tableName = in.readUTF();
    tableId = in.readUTF();
    int numLocs = in.readInt();
    locations = new String[numLocs];
    for (int i = 0; i < numLocs; ++i)
        locations[i] = in.readUTF();

    if (in.readBoolean()) {
        isolatedScan = in.readBoolean();
    }

    if (in.readBoolean()) {
        offline = in.readBoolean();
    }

    if (in.readBoolean()) {
        localIterators = in.readBoolean();
    }

    if (in.readBoolean()) {
        mockInstance = in.readBoolean();
    }

    if (in.readBoolean()) {
        int numColumns = in.readInt();
        List<String> columns = new ArrayList<String>(numColumns);
        for (int i = 0; i < numColumns; i++) {
            columns.add(in.readUTF());
        }

        fetchedColumns = InputConfigurator.deserializeFetchedColumns(columns);
    }

    if (in.readBoolean()) {
        String strAuths = in.readUTF();
        auths = new Authorizations(strAuths.getBytes(Constants.UTF8));
    }

    if (in.readBoolean()) {
        principal = in.readUTF();
    }

    if (in.readBoolean()) {
        int ordinal = in.readInt();
        this.tokenSource = TokenSource.values()[ordinal];

        switch (this.tokenSource) {
        case INLINE:
            String tokenClass = in.readUTF();
            byte[] base64TokenBytes = in.readUTF().getBytes(Constants.UTF8);
            byte[] tokenBytes = Base64.decodeBase64(base64TokenBytes);

            this.token = AuthenticationTokenSerializer.deserialize(tokenClass, tokenBytes);
            break;

        case FILE:
            this.tokenFile = in.readUTF();

            break;
        default:
            throw new IOException("Cannot parse unknown TokenSource ordinal");
        }
    }

    if (in.readBoolean()) {
        instanceName = in.readUTF();
    }

    if (in.readBoolean()) {
        zooKeepers = in.readUTF();
    }

    if (in.readBoolean()) {
        level = Level.toLevel(in.readInt());
    }
}

From source file:org.apache.horn.core.AbstractNeuralNetwork.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/*from w w w  .  j a v  a2s. co  m*/
public void readFields(DataInput input) throws IOException {
    // read model type
    this.modelType = WritableUtils.readString(input);
    // read learning rate
    this.learningRate = input.readFloat();
    // read model path
    this.modelPath = WritableUtils.readString(input);

    if (this.modelPath.equals("null")) {
        this.modelPath = null;
    }

    // read feature transformer
    int bytesLen = input.readInt();
    byte[] featureTransformerBytes = new byte[bytesLen];
    for (int i = 0; i < featureTransformerBytes.length; ++i) {
        featureTransformerBytes[i] = input.readByte();
    }

    Class<? extends FloatFeatureTransformer> featureTransformerCls = (Class<? extends FloatFeatureTransformer>) SerializationUtils
            .deserialize(featureTransformerBytes);

    Constructor[] constructors = featureTransformerCls.getDeclaredConstructors();
    Constructor constructor = constructors[0];

    try {
        this.featureTransformer = (FloatFeatureTransformer) constructor.newInstance(new Object[] {});
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}

From source file:ml.shifu.shifu.core.dtrain.dataset.PersistBasicFloatNetwork.java

public BasicFloatNetwork readNetwork(final DataInput in) throws IOException {
    final BasicFloatNetwork result = new BasicFloatNetwork();
    final FlatNetwork flat = new FlatNetwork();

    // read properties
    Map<String, String> properties = new HashMap<String, String>();
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        properties.put(ml.shifu.shifu.core.dtrain.StringUtils.readString(in),
                ml.shifu.shifu.core.dtrain.StringUtils.readString(in));
    }/*from   w  ww  .ja va  2 s  . c  o m*/
    result.getProperties().putAll(properties);

    // read fields
    flat.setBeginTraining(in.readInt());
    flat.setConnectionLimit(in.readDouble());

    flat.setContextTargetOffset(readIntArray(in));
    flat.setContextTargetSize(readIntArray(in));

    flat.setEndTraining(in.readInt());
    flat.setHasContext(in.readBoolean());
    flat.setInputCount(in.readInt());

    flat.setLayerCounts(readIntArray(in));
    flat.setLayerFeedCounts(readIntArray(in));
    flat.setLayerContextCount(readIntArray(in));
    flat.setLayerIndex(readIntArray(in));
    flat.setLayerOutput(readDoubleArray(in));
    flat.setOutputCount(in.readInt());
    flat.setLayerSums(new double[flat.getLayerOutput().length]);
    flat.setWeightIndex(readIntArray(in));
    flat.setWeights(readDoubleArray(in));
    flat.setBiasActivation(readDoubleArray(in));

    // read activations
    flat.setActivationFunctions(new ActivationFunction[flat.getLayerCounts().length]);
    int acSize = in.readInt();
    for (int i = 0; i < acSize; i++) {
        String name = ml.shifu.shifu.core.dtrain.StringUtils.readString(in);
        if (name.equals("ActivationReLU")) {
            name = ActivationReLU.class.getName();
        } else if (name.equals("ActivationLeakyReLU")) {
            name = ActivationLeakyReLU.class.getName();
        } else if (name.equals("ActivationSwish")) {
            name = ActivationSwish.class.getName();
        } else if (name.equals("ActivationPTANH")) {
            name = ActivationPTANH.class.getName();
        } else {
            name = "org.encog.engine.network.activation." + name;
        }
        ActivationFunction af = null;
        try {
            final Class<?> clazz = Class.forName(name);
            af = (ActivationFunction) clazz.newInstance();
        } catch (final ClassNotFoundException e) {
            throw new PersistError(e);
        } catch (final InstantiationException e) {
            throw new PersistError(e);
        } catch (final IllegalAccessException e) {
            throw new PersistError(e);
        }
        double[] params = readDoubleArray(in);
        for (int j = 0; j < params.length; j++) {
            af.setParam(j, params[j]);
        }
        flat.getActivationFunctions()[i] = af;
    }

    // read subset
    int subsetSize = in.readInt();
    Set<Integer> featureList = new HashSet<Integer>();
    for (int i = 0; i < subsetSize; i++) {
        featureList.add(in.readInt());
    }
    result.setFeatureSet(featureList);

    result.getStructure().setFlat(flat);
    return result;
}

From source file:org.apache.hadoop.hbase.io.BatchUpdate.java

public void readFields(final DataInput in) throws IOException {
    // Clear any existing operations; may be hangovers from previous use of
    // this instance.
    if (this.operations.size() != 0) {
        this.operations.clear();
    }// w  w w .j a v a2s  . c o  m
    this.row = Bytes.readByteArray(in);
    timestamp = in.readLong();
    this.size = in.readLong();
    int nOps = in.readInt();
    for (int i = 0; i < nOps; i++) {
        BatchOperation op = new BatchOperation();
        op.readFields(in);
        this.operations.add(op);
    }
    this.rowLock = in.readLong();
}

From source file:org.apache.hama.ml.ann.NeuralNetwork.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//w  w w . ja  va2  s .c o m
public void readFields(DataInput input) throws IOException {
    // read model type
    this.modelType = WritableUtils.readString(input);
    // read learning rate
    this.learningRate = input.readDouble();
    // read model path
    this.modelPath = WritableUtils.readString(input);

    if (this.modelPath.equals("null")) {
        this.modelPath = null;
    }

    // read feature transformer
    int bytesLen = input.readInt();
    byte[] featureTransformerBytes = new byte[bytesLen];
    for (int i = 0; i < featureTransformerBytes.length; ++i) {
        featureTransformerBytes[i] = input.readByte();
    }

    Class<? extends FeatureTransformer> featureTransformerCls = (Class<? extends FeatureTransformer>) SerializationUtils
            .deserialize(featureTransformerBytes);

    Constructor[] constructors = featureTransformerCls.getDeclaredConstructors();
    Constructor constructor = constructors[0];

    try {
        this.featureTransformer = (FeatureTransformer) constructor.newInstance(new Object[] {});
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}

From source file:edu.umn.cs.spatialHadoop.core.RTree.java

/**
 * Reads and skips the header of the tree returning the total number of
 * bytes skipped from the stream. This is used as a preparatory function to
 * read all elements in the tree without the index part.
 * @param in/* w w w.  j ava2 s  .c o m*/
 * @return - Total number of bytes read and skipped
 * @throws IOException
 */
public static int skipHeader(InputStream in) throws IOException {
    DataInput dataIn = in instanceof DataInput ? (DataInput) in : new DataInputStream(in);
    int skippedBytes = 0;
    /*int treeSize = */dataIn.readInt();
    skippedBytes += 4;
    int height = dataIn.readInt();
    skippedBytes += 4;
    if (height == 0) {
        // Empty tree. No results
        return skippedBytes;
    }
    int degree = dataIn.readInt();
    skippedBytes += 4;
    int nodeCount = (int) ((powInt(degree, height) - 1) / (degree - 1));
    /*int elementCount = */dataIn.readInt();
    skippedBytes += 4;
    // Skip all nodes
    dataIn.skipBytes(nodeCount * NodeSize);
    skippedBytes += nodeCount * NodeSize;
    return skippedBytes;
}

From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java

/**
 * Read a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding.//from  ww w  . j  av  a2s. c  o m
 * @param in
 * @param objectWritable
 * @param conf
 * @return the object
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, HbaseObjectWritable objectWritable, Configuration conf)
        throws IOException {
    Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in));
    Object instance;
    if (declaredClass.isPrimitive()) { // primitive types
        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isArray()) { // array
        if (declaredClass.equals(byte[].class)) {
            instance = Bytes.readByteArray(in);
        } else if (declaredClass.equals(Result[].class)) {
            instance = Result.readArray(in);
        } else {
            int length = in.readInt();
            instance = Array.newInstance(declaredClass.getComponentType(), length);
            for (int i = 0; i < length; i++) {
                Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE
        Class<?> componentType = readClass(conf, in);
        int length = in.readInt();
        instance = Array.newInstance(componentType, length);
        for (int i = 0; i < length; i++) {
            Array.set(instance, i, readObject(in, conf));
        }
    } else if (List.class.isAssignableFrom(declaredClass)) { // List
        int length = in.readInt();
        instance = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            ((ArrayList) instance).add(readObject(in, conf));
        }
    } else if (declaredClass == String.class) { // String
        instance = Text.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in));
    } else if (declaredClass == Message.class) {
        String className = Text.readString(in);
        try {
            declaredClass = getClassByName(conf, className);
            instance = tryInstantiateProtobuf(declaredClass, in);
        } catch (ClassNotFoundException e) {
            LOG.error("Can't find class " + className, e);
            throw new IOException("Can't find class " + className, e);
        }
    } else { // Writable or Serializable
        Class instanceClass = null;
        int b = (byte) WritableUtils.readVInt(in);
        if (b == NOT_ENCODED) {
            String className = Text.readString(in);
            try {
                instanceClass = getClassByName(conf, className);
            } catch (ClassNotFoundException e) {
                LOG.error("Can't find class " + className, e);
                throw new IOException("Can't find class " + className, e);
            }
        } else {
            instanceClass = CODE_TO_CLASS.get(b);
        }
        if (Writable.class.isAssignableFrom(instanceClass)) {
            Writable writable = WritableFactories.newInstance(instanceClass, conf);
            try {
                writable.readFields(in);
            } catch (Exception e) {
                LOG.error("Error in readFields", e);
                throw new IOException("Error in readFields", e);
            }
            instance = writable;
            if (instanceClass == NullInstance.class) { // null
                declaredClass = ((NullInstance) instance).declaredClass;
                instance = null;
            }
        } else {
            int length = in.readInt();
            byte[] objectBytes = new byte[length];
            in.readFully(objectBytes);
            ByteArrayInputStream bis = null;
            ObjectInputStream ois = null;
            try {
                bis = new ByteArrayInputStream(objectBytes);
                ois = new ObjectInputStream(bis);
                instance = ois.readObject();
            } catch (ClassNotFoundException e) {
                LOG.error("Class not found when attempting to deserialize object", e);
                throw new IOException("Class not found when attempting to " + "deserialize object", e);
            } finally {
                if (bis != null)
                    bis.close();
                if (ois != null)
                    ois.close();
            }
        }
    }
    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }
    return instance;
}

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

/**
 * Read a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding.// w w  w  .j av a  2s. c o m
 * @param in
 * @param objectWritable
 * @param conf
 * @return the object
 * @throws IOException
 */
@SuppressWarnings("unchecked")
static Object readObject(DataInput in, HbaseObjectWritableFor96Migration objectWritable, Configuration conf)
        throws IOException {
    Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in));
    Object instance;
    if (declaredClass.isPrimitive()) { // primitive types
        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isArray()) { // array
        if (declaredClass.equals(byte[].class)) {
            instance = Bytes.readByteArray(in);
        } else {
            int length = in.readInt();
            instance = Array.newInstance(declaredClass.getComponentType(), length);
            for (int i = 0; i < length; i++) {
                Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE
        Class<?> componentType = readClass(conf, in);
        int length = in.readInt();
        instance = Array.newInstance(componentType, length);
        for (int i = 0; i < length; i++) {
            Array.set(instance, i, readObject(in, conf));
        }
    } else if (List.class.isAssignableFrom(declaredClass)) { // List
        int length = in.readInt();
        instance = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            ((ArrayList) instance).add(readObject(in, conf));
        }
    } else if (declaredClass == String.class) { // String
        instance = Text.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in));
    } else if (declaredClass == Message.class) {
        String className = Text.readString(in);
        try {
            declaredClass = getClassByName(conf, className);
            instance = tryInstantiateProtobuf(declaredClass, in);
        } catch (ClassNotFoundException e) {
            LOG.error("Can't find class " + className, e);
            throw new IOException("Can't find class " + className, e);
        }
    } else if (Scan.class.isAssignableFrom(declaredClass)) {
        int length = in.readInt();
        byte[] scanBytes = new byte[length];
        in.readFully(scanBytes);
        ClientProtos.Scan.Builder scanProto = ClientProtos.Scan.newBuilder();
        instance = ProtobufUtil.toScan(scanProto.mergeFrom(scanBytes).build());
    } else { // Writable or Serializable
        Class instanceClass = null;
        int b = (byte) WritableUtils.readVInt(in);
        if (b == NOT_ENCODED) {
            String className = Text.readString(in);
            try {
                instanceClass = getClassByName(conf, className);
            } catch (ClassNotFoundException e) {
                LOG.error("Can't find class " + className, e);
                throw new IOException("Can't find class " + className, e);
            }
        } else {
            instanceClass = CODE_TO_CLASS.get(b);
        }
        if (Writable.class.isAssignableFrom(instanceClass)) {
            Writable writable = WritableFactories.newInstance(instanceClass, conf);
            try {
                writable.readFields(in);
            } catch (Exception e) {
                LOG.error("Error in readFields", e);
                throw new IOException("Error in readFields", e);
            }
            instance = writable;
            if (instanceClass == NullInstance.class) { // null
                declaredClass = ((NullInstance) instance).declaredClass;
                instance = null;
            }
        } else {
            int length = in.readInt();
            byte[] objectBytes = new byte[length];
            in.readFully(objectBytes);
            ByteArrayInputStream bis = null;
            ObjectInputStream ois = null;
            try {
                bis = new ByteArrayInputStream(objectBytes);
                ois = new ObjectInputStream(bis);
                instance = ois.readObject();
            } catch (ClassNotFoundException e) {
                LOG.error("Class not found when attempting to deserialize object", e);
                throw new IOException("Class not found when attempting to " + "deserialize object", e);
            } finally {
                if (bis != null)
                    bis.close();
                if (ois != null)
                    ois.close();
            }
        }
    }
    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }
    return instance;
}

From source file:FormatStorage1.IRecord.java

@Override
public void readFields(DataInput in) throws IOException {
    this.oldformat = in.readBoolean();
    this.fieldnum = in.readInt();
    HashMap<Integer, IFType> fts = new HashMap<Integer, IFType>(fieldnum);
    for (int i = 0; i < fieldnum; i++) {
        IFType ift = new IFType();
        ift.readFields(in);//from  ww  w . jav a2 s .  co m
        fts.put(ift.idx, ift);
    }
    this.setFieldTypes(fts);
    this.readfieldTypes = this.fieldTypes;

    this.unpersistent(in);
}

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

/**
 *  This is called to read this object <code>InPortInst</code> from the
 *  specified object of input stream.//from www .  j  ava2 s  .co m
 *
 * @param is DataInput object
 * @param versionNo Description of the Parameter
 * @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_strPortName = readUTF(is);
    m_strDscription = readUTF(is);
    m_strXSD = readUTF(is);
    m_strJavaClass = readUTF(is);
    m_bIsSyncRequestType = is.readBoolean();
    m_bisDisabled = is.readBoolean();

    int size = is.readInt();

    for (int i = 0; i < size; ++i) {
        Param param = new Param();

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