我首先将所有图像打包到 Hadoop 序列文件中:
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
我的问题是如何从 hadoop 中的序列文件中获取原始图像?