本文整理汇总了Java中org.apache.hadoop.util.GenericsUtil.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java GenericsUtil.getClass方法的具体用法?Java GenericsUtil.getClass怎么用?Java GenericsUtil.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.util.GenericsUtil
的用法示例。
在下文中一共展示了GenericsUtil.getClass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: storeArray
import org.apache.hadoop.util.GenericsUtil; //导入方法依赖的package包/类
/**
* Stores the array of items in the configuration with the given keyName.
*
* @param <K> the class of the item
* @param conf the configuration to use
* @param items the objects to be stored
* @param keyName the name of the key to use
* @throws IndexOutOfBoundsException if the items array is empty
* @throws IOException : forwards Exceptions from the underlying
* {@link Serialization} classes.
*/
public static <K> void storeArray(Configuration conf, K[] items,
String keyName) throws IOException {
DefaultStringifier<K> stringifier = new DefaultStringifier<K>(conf,
GenericsUtil.getClass(items[0]));
try {
StringBuilder builder = new StringBuilder();
for (K item : items) {
builder.append(stringifier.toString(item)).append(SEPARATOR);
}
conf.set(keyName, builder.toString());
}
finally {
stringifier.close();
}
}
示例2: toString
import org.apache.hadoop.util.GenericsUtil; //导入方法依赖的package包/类
@Override
public String toString() {
Configuration conf = new Configuration();
conf.set("io.serializations",
"org.apache.hadoop.io.serializer.JavaSerialization,"
+ "org.apache.hadoop.io.serializer.WritableSerialization");
DefaultStringifier<Map<String,String>> mapStringifier = new DefaultStringifier<Map<String,String>>(conf,
GenericsUtil.getClass(params));
try {
return mapStringifier.toString(params);
} catch (IOException e) {
log.info("Encountered IOException while deserializing returning empty string", e);
return "";
}
}
示例3: parseParams
import org.apache.hadoop.util.GenericsUtil; //导入方法依赖的package包/类
public static Map<String,String> parseParams(String serializedString) throws IOException {
Configuration conf = new Configuration();
conf.set("io.serializations",
"org.apache.hadoop.io.serializer.JavaSerialization,"
+ "org.apache.hadoop.io.serializer.WritableSerialization");
Map<String,String> params = Maps.newHashMap();
DefaultStringifier<Map<String,String>> mapStringifier = new DefaultStringifier<Map<String,String>>(conf,
GenericsUtil.getClass(params));
return mapStringifier.fromString(serializedString);
}
示例4: store
import org.apache.hadoop.util.GenericsUtil; //导入方法依赖的package包/类
/**
* Stores the item in the configuration with the given keyName.
*
* @param <K> the class of the item
* @param conf the configuration to store
* @param item the object to be stored
* @param keyName the name of the key to use
* @throws IOException : forwards Exceptions from the underlying
* {@link Serialization} classes.
*/
public static <K> void store(Configuration conf, K item, String keyName)
throws IOException {
DefaultStringifier<K> stringifier = new DefaultStringifier<K>(conf,
GenericsUtil.getClass(item));
conf.set(keyName, stringifier.toString(item));
stringifier.close();
}