自定义Writable兑现类

自定义Writable实现类
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;
	}


}