public interface Writable
DataInput 和 DataOutput 的序列化和反序列化接口.
com.aliyun.odps.Record 列值要求实现 Writable 接口。
com.aliyun.odps.mapreduce.Mapper 输出的 Key/Value 要求实现 Writable 接口。
用户可以实现 Writable 接口,代码示例:
public class MyWritable implements Writable {
// Some data
private int counter;
private long timestamp;
public void write(DataOutput out) throws IOException {
out.writeInt(counter);
out.writeLong(timestamp);
}
public void readFields(DataInput in) throws IOException {
counter = in.readInt();
timestamp = in.readLong();
}
public static MyWritable read(DataInput in) throws IOException {
MyWritable w = new MyWritable();
w.readFields(in);
return w;
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
readFields(DataInput in)
从指定的
DataInput in 反序列化. |
void |
write(DataOutput out)
序列化到指定的
DataOutput out. |
void write(DataOutput out) throws IOException
DataOutput out.out - IOExceptionvoid readFields(DataInput in) throws IOException
DataInput in 反序列化.in - IOExceptionCopyright © 2021 Alibaba Cloud Computing. All rights reserved.