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.giraph.io.GiraphInputFormat.java

License:Apache License

/**
 * Write input split info to DataOutput.
 *
 * @param inputSplit InputSplit//ww w .  ja v  a2  s .co  m
 * @param dataOutput DataOutput
 */
public void writeInputSplit(InputSplit inputSplit, DataOutput dataOutput) throws IOException {
    Text.writeString(dataOutput, inputSplit.getClass().getName());
    ((Writable) inputSplit).write(dataOutput);
}

From source file:org.apache.giraph.TestBspBasic.java

License:Apache License

/**
 * Run a test to see if the InputSplitPathOrganizer can correctly sort
 * locality information from a mocked znode of data.
 * @throws IOException//from w w  w.  jav  a 2s  .  c o  m
 * @throws KeeperException
 * @throws InterruptedException
 */
@Test
public void testInputSplitPathOrganizer() throws IOException, KeeperException, InterruptedException {
    final List<String> testList = new ArrayList<String>();
    Collections.addAll(testList, "remote2", "local", "remote1");
    final String localHost = "node.LOCAL.com";
    final String testListName = "test_list_parent_znode";
    // build output just as we do to store hostlists in ZNODES
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    String last = "node.test4.com\tnode.test5.com\tnode.test6.com";
    Text.writeString(dos, last);
    byte[] remote1 = baos.toByteArray();
    baos = new ByteArrayOutputStream();
    dos = new DataOutputStream(baos);
    String middle = "node.test1.com\tnode.test2.com\tnode.test3.com";
    Text.writeString(dos, middle);
    byte[] remote2 = baos.toByteArray();
    baos = new ByteArrayOutputStream();
    dos = new DataOutputStream(baos);
    String first = "node.testx.com\tnode.LOCAL.com\tnode.testy.com";
    Text.writeString(dos, first);
    byte[] local = baos.toByteArray();
    ZooKeeperExt zk = mock(ZooKeeperExt.class);
    when(zk.getChildrenExt(testListName, false, false, true)).thenReturn(testList);
    when(zk.getData("remote1", false, null)).thenReturn(remote1);
    when(zk.getData("remote2", false, null)).thenReturn(remote2);
    when(zk.getData("local", false, null)).thenReturn(local);
    InputSplitPathOrganizer lis = new InputSplitPathOrganizer(zk, testListName, localHost, true);
    final List<String> resultList = Lists.newArrayList(lis.getPathList());
    assertEquals("local", resultList.get(0));
}

From source file:org.apache.gora.filter.FilterList.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    out.writeByte(operator.ordinal());/*from www.ja  v a2s .  c om*/
    out.writeInt(filters.size());
    for (Filter<K, T> filter : filters) {
        Text.writeString(out, filter.getClass().getName());
        filter.write(out);
    }
}

From source file:org.apache.gora.filter.MapFieldValueFilter.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    Text.writeString(out, fieldName);
    Text.writeString(out, mapKey.toString());
    WritableUtils.writeEnum(out, filterOp);
    WritableUtils.writeVInt(out, operands.size());
    for (int i = 0; i < operands.size(); i++) {
        Object operand = operands.get(i);
        if (operand instanceof String) {
            throw new IllegalStateException("Use Utf8 instead of String for operands");
        }//from w  w  w .ja  v  a  2s  .  c  om
        if (operand instanceof Utf8) {
            operand = operand.toString();
        }
        if (operand instanceof Boolean) {
            ObjectWritable.writeObject(out, operand, Boolean.TYPE, conf);
        } else if (operand instanceof Character) {
            ObjectWritable.writeObject(out, operand, Character.TYPE, conf);
        } else if (operand instanceof Byte) {
            ObjectWritable.writeObject(out, operand, Byte.TYPE, conf);
        } else if (operand instanceof Short) {
            ObjectWritable.writeObject(out, operand, Short.TYPE, conf);
        } else if (operand instanceof Integer) {
            ObjectWritable.writeObject(out, operand, Integer.TYPE, conf);
        } else if (operand instanceof Long) {
            ObjectWritable.writeObject(out, operand, Long.TYPE, conf);
        } else if (operand instanceof Float) {
            ObjectWritable.writeObject(out, operand, Float.TYPE, conf);
        } else if (operand instanceof Double) {
            ObjectWritable.writeObject(out, operand, Double.TYPE, conf);
        } else if (operand instanceof Void) {
            ObjectWritable.writeObject(out, operand, Void.TYPE, conf);
        } else {
            ObjectWritable.writeObject(out, operand, operand.getClass(), conf);
        }
    }
    out.writeBoolean(filterIfMissing);
}

From source file:org.apache.gora.filter.SingleFieldValueFilter.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    Text.writeString(out, fieldName);
    WritableUtils.writeEnum(out, filterOp);
    WritableUtils.writeVInt(out, operands.size());
    for (int i = 0; i < operands.size(); i++) {
        Object operand = operands.get(i);
        if (operand instanceof String) {
            throw new IllegalStateException("Use Utf8 instead of String for operands");
        }//from w w  w.j  av  a  2s . com
        if (operand instanceof Utf8) {
            operand = operand.toString();
        }
        if (operand instanceof Boolean) {
            ObjectWritable.writeObject(out, operand, Boolean.TYPE, conf);
        } else if (operand instanceof Character) {
            ObjectWritable.writeObject(out, operand, Character.TYPE, conf);
        } else if (operand instanceof Byte) {
            ObjectWritable.writeObject(out, operand, Byte.TYPE, conf);
        } else if (operand instanceof Short) {
            ObjectWritable.writeObject(out, operand, Short.TYPE, conf);
        } else if (operand instanceof Integer) {
            ObjectWritable.writeObject(out, operand, Integer.TYPE, conf);
        } else if (operand instanceof Long) {
            ObjectWritable.writeObject(out, operand, Long.TYPE, conf);
        } else if (operand instanceof Float) {
            ObjectWritable.writeObject(out, operand, Float.TYPE, conf);
        } else if (operand instanceof Double) {
            ObjectWritable.writeObject(out, operand, Double.TYPE, conf);
        } else if (operand instanceof Void) {
            ObjectWritable.writeObject(out, operand, Void.TYPE, conf);
        } else {
            ObjectWritable.writeObject(out, operand, operand.getClass(), conf);
        }
    }
    out.writeBoolean(filterIfMissing);
}

From source file:org.apache.gora.mapreduce.StringSerialization.java

License:Apache License

@Override
public Serializer<String> getSerializer(Class<String> c) {
    return new Serializer<String>() {

        private DataOutputStream out;

        @Override//from   w  ww . ja v a 2  s.c  om
        public void close() throws IOException {
            this.out.close();
        }

        @Override
        public void open(OutputStream out) throws IOException {
            this.out = new DataOutputStream(out);
        }

        @Override
        public void serialize(String str) throws IOException {
            Text.writeString(out, str);
        }
    };
}

From source file:org.apache.gora.query.impl.QueryBase.java

License:Apache License

public void write(DataOutput out) throws IOException {
    //write datastore
    Text.writeString(out, dataStore.getClass().getCanonicalName());
    dataStore.write(out);/*from ww w .java 2 s .  c om*/

    IOUtils.writeNullFieldsInfo(out, queryString, (fields), startKey, endKey, filter);

    if (queryString != null)
        Text.writeString(out, queryString);
    if (fields != null)
        IOUtils.writeStringArray(out, fields);
    if (startKey != null)
        IOUtils.serialize(getConf(), out, startKey, dataStore.getKeyClass());
    if (endKey != null)
        IOUtils.serialize(getConf(), out, endKey, dataStore.getKeyClass());
    if (filter != null) {
        Text.writeString(out, filter.getClass().getCanonicalName());
        filter.write(out);
    }

    WritableUtils.writeVLong(out, getStartTime());
    WritableUtils.writeVLong(out, getEndTime());
    WritableUtils.writeVLong(out, getLimit());
    out.writeBoolean(localFilterEnabled);
}

From source file:org.apache.gora.store.impl.DataStoreBase.java

License:Apache License

public void write(DataOutput out) {
    try {/*from   w  w w . ja va2 s  .  c  o  m*/
        Text.writeString(out, getKeyClass().getCanonicalName());
        Text.writeString(out, getPersistentClass().getCanonicalName());
        WritableUtils.writeProperties(out, properties);
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:org.apache.gora.store.impl.FileBackedDataStoreBase.java

License:Apache License

@Override
public void write(DataOutput out) {
    try {//from w  w  w  .  jav a2  s. c  o m
        super.write(out);
        org.apache.gora.util.IOUtils.writeNullFieldsInfo(out, inputPath, outputPath);
        if (inputPath != null)
            Text.writeString(out, inputPath);
        if (outputPath != null)
            Text.writeString(out, outputPath);
    } catch (IOException ex) {
        LOG.error(ex.getMessage(), ex);
    }
}

From source file:org.apache.gora.util.IOUtils.java

License:Apache License

/** Serializes the object to the given dataoutput using
 * available Hadoop serializations//from   w  ww. java2  s.  c  o m
 * @throws IOException */
@SuppressWarnings("unchecked")
public static <T> void serialize(Configuration conf, DataOutput out, T obj) throws IOException {
    Text.writeString(out, obj.getClass().getName());
    serialize(conf, out, obj, (Class<T>) obj.getClass());
}