0

まず、すべての画像を Hadoop 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));

次に、リデューサーで元の画像をシーケンス ファイルから取得したいと考えています。

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 でシーケンス ファイルから元の画像を取得する方法ですか?

4

1 に答える 1

0

問題は、ストリームの読み取りに間違った方法を使用していることです。正しい方法は次のとおりです。

import org.apache.commons.io.IOUtils;
Configuration confHadoop = new Configuration();
FileSystem fs = FileSystem.get(confHadoop);
Path file = new Path(fs.getUri().toString() + "/" + fileName);
in = fs.open(file);
byte[] buffer = IOUtils.toByteArray(in);

次に、バッファを によって sequenceFile に書き込むことができますnew BytesWritable(buffer)。sequenceFile から読み取る場合も同じです。

于 2014-04-22T08:43:43.530 に答える