首先我是这样将图片打包进SequenceFile的:
FSDataInputStream in = null;
in = fs.open(new Path(uri)); //uri is the image location in HDFS
byte buffer[] = new byte[in.available()];
in.read(buffer);
context.write(imageID, new BytesWritable(buffer));
然后在reducer中我这样试图取出我的图片
BufferedImage imag;
imag = ImageIO.read(new ByteArrayInputStream(value.getBytes()));
但是没有成功,原因是:
Error: javax.imageio.IIOException: Error reading PNG image data
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
所以应该如何从Sequence File中读取出来原来的图片呢?谢谢。
最后自己找到了问题的答案。分享一下。