import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.MapWritable;
import org.apache.hadoop.io.Text;
import org.junit.Test;
public class TestMapWritable {
@Test
public void test1() throws IOException {
MapWritable map = new MapWritable();
map.put(new IntWritable(100), new Text(“tom”));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(baos);
map.write(dataOut);
dataOut.close();
MapWritable map2 = new MapWritable();
map2.readFields(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/191419.html