Hadooopシーケンス化フレームワークの使用
1527 ワード
: Writable (TestGenericWritable.java)
public static class Baz extends Bar {
@Override
public void readFields(DataInput in) throws IOException {
super.readFields(in);
//needs a configuration parameter
assertEquals("Configuration is not set for the wrapped object",
CONF_TEST_VALUE, getConf().get(CONF_TEST_KEY));
}
@Override
public void write(DataOutput out) throws IOException {
super.write(out);
}
}
/////////////////////////////////////////////////////////////
Text before = new Text("test writable");
: / JavaSerialization/WritableSerialization/AvroSerialization/AvroReflectSerialization/AvroSpecificSerialization
SerializationFactory factory = new SerializationFactory(conf);
Serializer<K> serializer
= factory.getSerializer(GenericsUtil.getClass(before));
Deserializer<K> deserializer
= factory.getDeserializer(GenericsUtil.getClass(before));
: /
DataOutputBuffer out = new DataOutputBuffer();
serializer.open(out);
serializer.serialize(before);
serializer.close();
DataInputBuffer in = new DataInputBuffer();
in.reset(out.getData(), out.getLength());
deserializer.open(in);
K after = deserializer.deserialize(null);
deserializer.close();