Example usage for org.apache.hadoop.io UTF8 writeString

List of usage examples for org.apache.hadoop.io UTF8 writeString

Introduction

In this page you can find the example usage for org.apache.hadoop.io UTF8 writeString.

Prototype

public static int writeString(DataOutput out, String s) throws IOException 

Source Link

Document

Write a UTF-8 encoded string.

Usage

From source file:co.cask.hydrator.plugin.batchSource.KafkaKey.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    UTF8.writeString(out, this.leaderId);
    out.writeInt(this.partition);
    out.writeLong(this.beginOffset);
    out.writeLong(this.offset);
    out.writeLong(this.checksum);
    out.writeUTF(this.topic);
    this.partitionMap.write(out);
}

From source file:com.chinamobile.bcbsp.comm.BSPMessage.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    out.writeInt(dstPartition);/* w  w  w .  j a  va2s .  com*/
    out.writeInt(data.length);
    out.write(data);
    UTF8.writeString(out, dstVertex);
}

From source file:com.cloudera.recordbreaker.learnstructure.InferredType.java

License:Open Source License

public void write(DataOutput out) throws IOException {
    out.write(BASE_TYPE);/*from  ww  w  .  j a  va2  s.c  om*/
    out.writeUTF(name);
    out.writeInt(sampleStrs.size());
    for (int i = 0; i < sampleStrs.size(); i++) {
        UTF8.writeString(out, sampleStrs.get(i));
    }
    out.writeInt(tokenClassIdentifier);
    out.writeBoolean(tokenParameter != null);
    if (tokenParameter != null) {
        UTF8.writeString(out, tokenParameter);
    }
}

From source file:com.nebulousnews.io.ObjectSerializableWritable.java

License:Apache License

/** Write a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding. *///from w  w  w .ja  v  a  2 s.  com
@SuppressWarnings("unchecked")
public static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf)
        throws IOException {

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

    UTF8.writeString(out, declaredClass.getName()); // always write declared

    if (declaredClass.isArray()) { // array
        int length = Array.getLength(instance);
        out.writeInt(length);
        for (int i = 0; i < length; i++) {
            writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf);
        }

    } else if (declaredClass == String.class) { // String
        UTF8.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
        UTF8.writeString(out, ((Enum) instance).name());
    } else if (Writable.class.isAssignableFrom(declaredClass)) { // Writable
        UTF8.writeString(out, instance.getClass().getName());
        ((Writable) instance).write(out);
        //write serializable classes
    } else if (Serializable.class.isAssignableFrom(declaredClass)) {
        ObjectOutputStream output = new ObjectOutputStream((OutputStream) out);
        output.writeObject(instance);
    } else {
        throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
}

From source file:utils.ArrayPrimitiveWritable.java

License:Apache License

@Override
@SuppressWarnings("deprecation")
public void write(DataOutput out) throws IOException {
    // write componentType 
    UTF8.writeString(out, componentType.getName());
    // write length
    out.writeInt(length);/*from   ww  w .ja v a2s  . c  o m*/

    // do the inner loop.  Walk the decision tree only once.
    if (componentType == Boolean.TYPE) { // boolean
        writeBooleanArray(out);
    } else if (componentType == Character.TYPE) { // char
        writeCharArray(out);
    } else if (componentType == Byte.TYPE) { // byte
        writeByteArray(out);
    } else if (componentType == Short.TYPE) { // short
        writeShortArray(out);
    } else if (componentType == Integer.TYPE) { // int
        writeIntArray(out);
    } else if (componentType == Long.TYPE) { // long
        writeLongArray(out);
    } else if (componentType == Float.TYPE) { // float
        writeFloatArray(out);
    } else if (componentType == Double.TYPE) { // double
        writeDoubleArray(out);
    } else {
        throw new IOException("Component type " + componentType.toString()
                + " is set as the output type, but no encoding is implemented for this type.");
    }
}