练习2增加一个分区类
1.对象
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Set;
import org.apache.hadoop.io.Writable;
/**
* Bean对象要需要实现Writable接口
*
*/
public class FlowBean implements Writable{
private long upFlow; //上行流量
private long downFlow; //下行流量
private long sumFlow; //总流量
//必须要有空参构造,为了后续反射用
public FlowBean() {
super();
}
public FlowBean(long upFlow, long downFlow) {
super();
this.upFlow = upFlow;
this.downFlow = downFlow;
this.sumFlow = upFlow+downFlow;//总流量
}
//负责累加上行流量和下行流量
public void set(long upFlow, long downFlow) {
this.upFlow = upFlow;
this.downFlow = downFlow;
this.sumFlow = upFlow+downFlow;//总流量
}
//改造toString方法,方便后续处理数据
@Override
public String toString() {
return upFlow+"\t"+ downFlow+ "\t" + sumFlow;
}
//反序列化方法
@Override
public void readFields(DataInput in) throws IOException {
//顺序一致
this.upFlow = in.readLong();
this.downFlow = in.readLong();
this.sumFlow = in.readLong();
}
//序列化方法
@Override
public void write(DataOutput out) throws IOException {
//顺序一致
out.wr