如何读出Hadoop SequenceFile里面的图片?

首先我是这样将图片打包进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中读取出来原来的图片呢?谢谢。

阅读 6.4k
1 个回答

最后自己找到了问题的答案。分享一下。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进