Example usage for org.apache.hadoop.io Stringifier fromString

List of usage examples for org.apache.hadoop.io Stringifier fromString

Introduction

In this page you can find the example usage for org.apache.hadoop.io Stringifier fromString.

Prototype

public T fromString(String str) throws IOException;

Source Link

Document

Restores the object from its string representation.

Usage

From source file:org.warcbase.mapreduce.lib.Chain.java

License:Apache License

/**
 * Creates a {@link Configuration} for the Map or Reduce in the chain.
 *
 * <p>// w  ww .j a  v  a  2  s.c  om
 * It creates a new Configuration using the chain job's Configuration as base
 * and adds to it the configuration properties for the chain element. The keys
 * of the chain element Configuration have precedence over the given
 * Configuration.
 * </p>
 *
 * @param jobConf
 *          the chain job's Configuration.
 * @param confKey
 *          the key for chain element configuration serialized in the chain
 *          job's Configuration.
 * @return a new Configuration aggregating the chain job's Configuration with
 *         the chain element configuration properties.
 */
protected static Configuration getChainElementConf(Configuration jobConf, String confKey) {
    Configuration conf = null;
    try {
        Stringifier<Configuration> stringifier = new DefaultStringifier<Configuration>(jobConf,
                Configuration.class);
        String confString = jobConf.get(confKey, null);
        if (confString != null) {
            conf = stringifier.fromString(jobConf.get(confKey, null));
        }
    } catch (IOException ioex) {
        throw new RuntimeException(ioex);
    }
    // we have to do this because the Writable desearialization clears all
    // values set in the conf making not possible do a
    // new Configuration(jobConf) in the creation of the conf above
    jobConf = new Configuration(jobConf);

    if (conf != null) {
        for (Map.Entry<String, String> entry : conf) {
            jobConf.set(entry.getKey(), entry.getValue());
        }
    }
    return jobConf;
}