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

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

Introduction

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

Prototype

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

Source Link

Document

Write a UTF8 encoded string to out

Usage

From source file:org.apache.hama.commons.io.PipesKeyValueWritable.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    // LOG.debug("write: '" + this.toString() + "'");
    Text.writeString(out, this.toString());
}

From source file:org.apache.hama.commons.io.PipesVectorWritable.java

License:Apache License

public static void writeVector(DoubleVector vector, DataOutput out) throws IOException {
    String str = "";
    for (int i = 0; i < vector.getLength(); i++) {
        str += (i < vector.getLength() - 1) ? vector.get(i) + ", " : vector.get(i);
    }/*  w  w  w  .j a  va 2 s  . c  o  m*/

    // LOG.debug("writeVector: '" + str + "'");
    Text.writeString(out, str);
}

From source file:org.apache.hama.ipc.ConnectionHeader.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    Text.writeString(out, (protocol == null) ? "" : protocol);
    if (ugi != null) {
        if (authMethod == AuthMethod.KERBEROS) {
            // Send effective user for Kerberos auth
            out.writeBoolean(true);/*w  ww  . ja  v a2 s.  c  o  m*/
            out.writeUTF(ugi.getUserName());
            out.writeBoolean(false);
        } else if (authMethod == AuthMethod.DIGEST) {
            // Don't send user for token auth
            out.writeBoolean(false);
        } else {
            //Send both effective user and real user for simple auth
            out.writeBoolean(true);
            out.writeUTF(ugi.getUserName());
            if (ugi.getRealUser() != null) {
                out.writeBoolean(true);
                out.writeUTF(ugi.getRealUser().getUserName());
            } else {
                out.writeBoolean(false);
            }
        }
    } else {
        out.writeBoolean(false);
    }
}

From source file:org.apache.hama.pipes.BinaryProtocol.java

License:Apache License

public void setBSPJob(Configuration conf) throws IOException {
    WritableUtils.writeVInt(stream, MessageType.SET_BSPJOB_CONF.code);
    List<String> list = new ArrayList<String>();
    for (Map.Entry<String, String> itm : conf) {
        list.add(itm.getKey());/*from   w w w.  j  a  v  a2s  .  co m*/
        list.add(itm.getValue());
    }
    WritableUtils.writeVInt(stream, list.size());
    for (String entry : list) {
        Text.writeString(stream, entry);
    }
    flush();
    LOG.debug("Sent MessageType.SET_BSPJOB_CONF");
}

From source file:org.apache.hama.pipes.BinaryProtocol.java

License:Apache License

@Override
public void setInputTypes(String keyType, String valueType) throws IOException {
    WritableUtils.writeVInt(stream, MessageType.SET_INPUT_TYPES.code);
    Text.writeString(stream, keyType);
    Text.writeString(stream, valueType);
    flush();/*from   w w w.  j  ava 2  s  .c om*/
    LOG.debug("Sent MessageType.SET_INPUT_TYPES");
}

From source file:org.apache.hama.pipes.protocol.BinaryProtocol.java

License:Apache License

@Override
public void setBSPJobConf(Configuration conf) throws IOException {
    WritableUtils.writeVInt(this.outStream, MessageType.SET_BSPJOB_CONF.code);
    List<Entry<String, String>> list = new ArrayList<Entry<String, String>>();
    for (Entry<String, String> entry : conf) {
        list.add(entry);/*from  ww w.j a  v a2  s.c  om*/
    }
    WritableUtils.writeVInt(this.outStream, list.size());
    for (Entry<String, String> entry : list) {
        Text.writeString(this.outStream, entry.getKey());
        Text.writeString(this.outStream, entry.getValue());
    }
    flush();
    LOG.debug("Sent MessageType.SET_BSPJOB_CONF including " + list.size() + " entries.");
}

From source file:org.apache.hama.pipes.protocol.BinaryProtocol.java

License:Apache License

@Override
public void setInputTypes(String keyType, String valueType) throws IOException {
    WritableUtils.writeVInt(this.outStream, MessageType.SET_INPUT_TYPES.code);
    Text.writeString(this.outStream, keyType);
    Text.writeString(this.outStream, valueType);
    flush();//from w  ww .  ja v  a2  s.c om
    LOG.debug("Sent MessageType.SET_INPUT_TYPES");
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void getPeerName() throws IOException {
    int id = WritableUtils.readVInt(this.inStream);
    LOG.debug("Got MessageType.GET_PEERNAME id: " + id);

    WritableUtils.writeVInt(this.outStream, MessageType.GET_PEERNAME.code);
    if (id == -1) { // -1 indicates get own PeerName
        Text.writeString(this.outStream, peer.getPeerName());
        LOG.debug("Responded MessageType.GET_PEERNAME - Get Own PeerName: " + peer.getPeerName());

    } else if ((id < -1) || (id >= peer.getNumPeers())) {
        // if no PeerName for this index is found write emptyString
        Text.writeString(this.outStream, "");
        LOG.debug("Responded MessageType.GET_PEERNAME - Empty PeerName!");

    } else {/*from  w  ww.  j a  va 2s. c  om*/
        Text.writeString(this.outStream, peer.getPeerName(id));
        LOG.debug("Responded MessageType.GET_PEERNAME - PeerName: " + peer.getPeerName(id));
    }
    binProtocol.flush();
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

License:Apache License

public void getAllPeerNames() throws IOException {
    LOG.debug("Got MessageType.GET_ALL_PEERNAME");
    String[] peerNames = peer.getAllPeerNames();
    WritableUtils.writeVInt(this.outStream, MessageType.GET_ALL_PEERNAME.code);
    WritableUtils.writeVInt(this.outStream, peerNames.length);
    for (String s : peerNames) {
        Text.writeString(this.outStream, s);
    }//from w w w  .  j ava  2 s  .  c  o  m
    binProtocol.flush();
    LOG.debug("Responded MessageType.GET_ALL_PEERNAME - peerNamesCount: " + peerNames.length);
}

From source file:org.apache.kylin.source.kafka.hadoop.KafkaInputSplit.java

License:Apache License

public void write(DataOutput out) throws IOException {
    Text.writeString(out, brokers);
    Text.writeString(out, topic);
    out.writeInt(partition);//from w  ww .  j a  va2s.c  o  m
    out.writeLong(offsetStart);
    out.writeLong(offsetEnd);
}