0%

序列化

序列化

Hadoop使用自己的序列化格式Writable

Writable接口

1
2
3
4
5
6
public interface Writable {

void write(DataOutput out) throws IOException;

void readFields(DataInput in) throws IOException;
}

以IntWritable为例

1
2
IntWritable writable = new IntWritable();
writable.set(100);

其在进行读取和写入时

1
2
3
4
5
6
7
8
9
@Override
public void readFields(DataInput in) throws IOException {
value = in.readInt();
}

@Override
public void write(DataOutput out) throws IOException {
out.writeInt(value);
}

欢迎关注我的其它发布渠道