Example usage for java.io DataOutput writeInt

List of usage examples for java.io DataOutput writeInt

Introduction

In this page you can find the example usage for java.io DataOutput writeInt.

Prototype

void writeInt(int v) throws IOException;

Source Link

Document

Writes an int value, which is comprised of four bytes, to the output stream.

Usage

From source file:org.apache.bigtop.bigpetstore.generator.PetStoreTransactionInputSplit.java

public void write(DataOutput dataOutputStream) throws IOException {
    dataOutputStream.writeInt(records);
    dataOutputStream.writeUTF(state.name());
    dataOutputStream.writeLong(customerIdRange.getMinimum());
    dataOutputStream.writeLong(customerIdRange.getMaximum());
}

From source file:org.apache.drill.exec.cache.CachedVectorContainer.java

@Override
public void write(DataOutput output) throws IOException {
    output.writeInt(data.length);
    output.write(data);
}

From source file:edu.nyu.vida.data_polygamy.scalar_function.Median.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeInt(count);
    out.writeInt(floatValues.size());//  w  w  w .j  a  v  a 2 s  . co  m
    for (int i = 0; i < floatValues.size(); i++)
        out.writeFloat(floatValues.get(i));
}

From source file:org.apache.hadoop.raid.protocol.PolicyList.java

public void write(DataOutput out) throws IOException {
    out.writeInt(category.size());
    for (PolicyInfo p : category) {
        p.write(out);/*from   ww  w. j  ava 2 s .  c om*/
    }
}

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

@SuppressWarnings("unchecked")
public static void writeDatum(DataOutput out, Object val) throws IOException {
    // Read the data type
    byte type = DataType.findType(val);
    switch (type) {
    case DataType.TUPLE:
        // Because tuples are written directly by hadoop, the
        // tuple's write method needs to write the indicator byte.
        // So don't write the indicator byte here as it is for
        // everyone else.
        ((Tuple) val).write(out);
        break;/*from   www. j  av a  2s. co  m*/

    case DataType.BAG:
        out.writeByte(DataType.BAG);
        ((DataBag) val).write(out);
        break;

    case DataType.MAP: {
        out.writeByte(DataType.MAP);
        Map<String, Object> m = (Map<String, Object>) val;
        out.writeInt(m.size());
        Iterator<Map.Entry<String, Object>> i = m.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<String, Object> entry = i.next();
            writeDatum(out, entry.getKey());
            writeDatum(out, entry.getValue());
        }
        break;
    }

    case DataType.INTERNALMAP: {
        out.writeByte(DataType.INTERNALMAP);
        Map<Object, Object> m = (Map<Object, Object>) val;
        out.writeInt(m.size());
        Iterator<Map.Entry<Object, Object>> i = m.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<Object, Object> entry = i.next();
            writeDatum(out, entry.getKey());
            writeDatum(out, entry.getValue());
        }
        break;
    }

    case DataType.INTEGER:
        out.writeByte(DataType.INTEGER);
        out.writeInt((Integer) val);
        break;

    case DataType.LONG:
        out.writeByte(DataType.LONG);
        out.writeLong((Long) val);
        break;

    case DataType.FLOAT:
        out.writeByte(DataType.FLOAT);
        out.writeFloat((Float) val);
        break;

    case DataType.DOUBLE:
        out.writeByte(DataType.DOUBLE);
        out.writeDouble((Double) val);
        break;

    case DataType.BOOLEAN:
        out.writeByte(DataType.BOOLEAN);
        out.writeBoolean((Boolean) val);
        break;

    case DataType.BYTE:
        out.writeByte(DataType.BYTE);
        out.writeByte((Byte) val);
        break;

    case DataType.BYTEARRAY: {
        out.writeByte(DataType.BYTEARRAY);
        DataByteArray bytes = (DataByteArray) val;
        out.writeInt(bytes.size());
        out.write(bytes.mData);
        break;
    }

    case DataType.CHARARRAY: {
        String s = (String) val;
        byte[] utfBytes = s.getBytes(DataReaderWriter.UTF8);
        int length = utfBytes.length;

        if (length < DataReaderWriter.UNSIGNED_SHORT_MAX) {
            out.writeByte(DataType.CHARARRAY);
            out.writeShort(length);
            out.write(utfBytes);
        } else {
            out.writeByte(DataType.BIGCHARARRAY);
            out.writeInt(length);
            out.write(utfBytes);
        }
        break;
    }
    case DataType.GENERIC_WRITABLECOMPARABLE:
        out.writeByte(DataType.GENERIC_WRITABLECOMPARABLE);
        //store the class name, so we know the class to create on read
        writeDatum(out, val.getClass().getName());
        Writable writable = (Writable) val;
        writable.write(out);
        break;

    case DataType.NULL:
        out.writeByte(DataType.NULL);
        break;

    default:
        throw new RuntimeException("Unexpected data type " + type + " found in stream.");
    }
}

From source file:org.apache.hama.bsp.BSPMessageBundle.java

@SuppressWarnings("unchecked")
@Override/* w  w  w  . j a v a2  s  .  c om*/
public void write(DataOutput out) throws IOException {
    out.writeInt(messages.size());

    if (messages.size() > 0) {
        Class<M> clazz = (Class<M>) messages.get(0).getClass();
        out.writeUTF(clazz.getName());

        for (M m : messages) {
            m.write(out);
        }
    }
}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Write a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *///  www .j a v a  2  s. c o  m
public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf,
        boolean arrayComponent) throws IOException {

    if (instance == null) { // null
        instance = new NullInstance(declaredClass, conf);
        declaredClass = CWritable.class;
        arrayComponent = false;
    }

    if (!arrayComponent) {
        CUTF8.writeString(out, declaredClass.getName()); // always write declared
        //System.out.println("Write:declaredClass.getName():" + declaredClass.getName());
    }

    if (declaredClass.isArray()) { // array
        int length = Array.getLength(instance);
        out.writeInt(length);
        //System.out.println("Write:length:" + length);

        if (declaredClass.getComponentType() == Byte.TYPE) {
            out.write((byte[]) instance);
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            //ColumnValue?  Deserialize? ?? ?   ?? ?  .
            writeColumnValue(out, instance, declaredClass, conf, length);
        } else {
            for (int i = 0; i < length; i++) {
                writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf,
                        !declaredClass.getComponentType().isArray());
            }
        }
    } else if (declaredClass == String.class) { // String
        CUTF8.writeString(out, (String) instance);

    } else if (declaredClass.isPrimitive()) { // primitive type

        if (declaredClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instance).booleanValue());
        } else if (declaredClass == Character.TYPE) { // char
            out.writeChar(((Character) instance).charValue());
        } else if (declaredClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instance).byteValue());
        } else if (declaredClass == Short.TYPE) { // short
            out.writeShort(((Short) instance).shortValue());
        } else if (declaredClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instance).intValue());
        } else if (declaredClass == Long.TYPE) { // long
            out.writeLong(((Long) instance).longValue());
        } else if (declaredClass == Float.TYPE) { // float
            out.writeFloat(((Float) instance).floatValue());
        } else if (declaredClass == Double.TYPE) { // double
            out.writeDouble(((Double) instance).doubleValue());
        } else if (declaredClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isEnum()) { // enum
        CUTF8.writeString(out, ((Enum) instance).name());
    } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable
        if (instance.getClass() == declaredClass) {
            out.writeShort(TYPE_SAME); // ? ?? ? ?? 
            //System.out.println("Write:TYPE_SAME:" + TYPE_SAME);

        } else {
            out.writeShort(TYPE_DIFF);
            //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF);
            CUTF8.writeString(out, instance.getClass().getName());
            //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName());
        }
        ((CWritable) instance).write(out);
        //System.out.println("Write:instance value");

    } else {
        throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
}

From source file:com.vmware.demo.sgf.tests.domain.PersonKey.java

@Override
public void toData(DataOutput out) throws IOException {
    out.writeInt(id);
    out.writeUTF(surname);
}

From source file:org.apache.hadoop.hbase.index.TableIndices.java

/**
 * @param out Data output stream// w  w w . j a va 2  s.  co  m
 */
public void write(DataOutput out) throws IOException {
    out.writeInt(this.indices.size());
    for (IndexSpecification index : indices) {
        index.write(out);
    }
}

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

@Override
public void serialize(Object value, DataOutput dataOutput) throws IOException {
    byte[] bytes = SerializationUtils.serialize((Serializable) value);
    dataOutput.writeInt(bytes.length);
    dataOutput.write(bytes);/*from w w  w . java 2s. c om*/
}