這是實現可寫的類..序列化Hadoop中 - 可寫
public class Test implements Writable {
List<AtomicWritable> atoms = new ArrayList<AtomicWritable>();
public void write(DataOutput out) throws IOException {
IntWritable size = new IntWritable(atoms.size());
size.write(out);
for (AtomicWritable atom : atoms)
atom.write(out);
}
public void readFields(DataInput in) throws IOException {
atoms.clear();
IntWritable size = new IntWritable();
size.readFields(in);
int n = size.get();
while(n-- > 0) {
AtomicWritable atom = new AtomicWritable();
atom.readFields(in);
atoms.add(atom);
}
}
}
我會很感激,如果人能幫助我瞭解如何調用寫和閱讀字段的方法。 基本上我沒有理解如何在這種情況下構造Test對象。將對象寫入DataOutput obj後,如何在DataInput對象中將其恢復。這可能聽起來很愚蠢,但是Hadoop的新手並且已經分配了一個使用Hadoop的項目。請幫忙。
謝謝!
你需要考慮它不是線程安全的。 –
小專家提示:如果你打算在這裏問很多[問題](http://stackoverflow.com/users/2503555/rekha-gupta?tab=questions),特別是在像Hadoop這樣不太擁擠的主題上(比C#和Java更加擁擠),請確保你對[你以前問過的]提出的問題進行了讚揚並接受了答案(http://stackoverflow.com/questions/17220884/how-to-serialiaze-list-collection-對象在-hadoop的)。如果你不這樣做,你很快就會失去對社區的同情。 – jason