public class ContentWritable implements Writable{
private Text before;
private IntWritable num;
//默认的构造函数必须写,不然会出NullPointException异常,而且必须默认初始化成员变量,不知道为何,看底层是反射实例化的,估计跟这个有关。
public ContentWritable(){
this.before = new Text();
this.num = new IntWritable();
}
public ContentWritable(Text before,IntWritable num){
this.before = before;
this.num = num;
}
@Override
public void readFields(DataInput in) throws IOException {
before.readFields(in);
num.readFields(in);
}
@Override
public void write(DataOutput out) throws IOException {
before.write(out);
num.write(out);
}
public Text getBefore() {
return before;
}
public IntWritable getNum() {
return num;
}
public void setBefore(Text before) {
this.before = before;
}
public void setNum(IntWritable num) {
this.num = num;
}
}
自定义Writable实现类
最新推荐文章于 2022-09-29 19:10:53 发布