如何为自定义对象的映射或列表实现自定义可写的write和readFields?

时间:2018-08-28 00:02:32

标签: java hadoop mapreduce

我有一个包含以下内容的包装器类

class myWrapperClass {
    Map<Long, myInnerClass> myMap;
    int myInt1;
    int myInt2;
}

class myInnerClass {
    int myInnerInt;
    long myInnerLong;
}

到目前为止,我想拥有一个customWritable

@Override
public void write(DataOutput out) throws IOException {
    out.writeInt(this.myInt1);
    out.writeInt(this.myInt2);
    // What do I do here
}

@Override
public void readFields(DataInput in) throws IOException {
    myInt1 = in.readInt();
    myInt2 = in.readShort();
    // What do I do here
}

如果我有一个自定义对象,我不确定如何写DataOutput和从中读取。

有人可以给我指明方向吗?

0 个答案:

没有答案