画像を読み書きするためのmapreduceコードを作成しようとしていますが、 ArrayIndexOutOfBoundsException
ImageIO.writeを使用して画像を保存すると、画像に変更を加えていません。コードは次のとおりです。
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import java.io.BufferedInputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.Writable;
public class mrimage implements Writable {
private static final Log log = LogFactory.getLog(mrimage.class);
BufferedImage reader = null;
String FileName;
public mrimage(){
}
public mrimage(BufferedImage buff,String fileName){
this.reader = buff;
this.FileName = fileName;
}
public BufferedImage getImage(int i){
return this.reader;
}
//reading generated image files
@Override
public void readFields(DataInput in) throws IOException {
try{
reader = ImageIO.read(new BufferedInputStream((InputStream)in));
}
catch(Exception e){
log.info(e);
}
}
//writing the image files
@Override
public void write(DataOutput out) throws IOException {
try{
ImageIO.write(reader, "jpg", (OutputStream)out);
}
catch(Exception e){
}
}
}
誰か助けてもらえますか?
これは私が受け取っている完全なエラーメッセージです:
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at java.io.ByteArrayInputStream.read(ByteArrayInputStream.java:174)
at java.io.DataInputStream.read(DataInputStream.java:132)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at javax.imageio.stream.FileCacheImageInputStream.readUntil(FileCacheImageInputStream.java:121)
at javax.imageio.stream.FileCacheImageInputStream.read(FileCacheImageInputStream.java:167)
at javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:337)
at javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:347)
at com.sun.imageio.plugins.bmp.BMPImageReaderSpi.canDecodeInput(BMPImageReaderSpi.java:66)
at javax.imageio.ImageIO$CanDecodeInputFilter.filter(ImageIO.java:541)
at javax.imageio.spi.FilterIterator.advance(ServiceRegistry.java:793)
at javax.imageio.spi.FilterIterator.<init>(ServiceRegistry.java:787)
at javax.imageio.spi.ServiceRegistry.getServiceProviders(ServiceRegistry.java:491)
at javax.imageio.ImageIO.getImageReaders(ImageIO.java:620)
at javax.imageio.ImageIO.read(ImageIO.java:1412)
at javax.imageio.ImageIO.read(ImageIO.java:1326)
at imagetojpeg.KUImage.readFields(KUImage.java:33)
at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:67)
at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:40)
at org.apache.hadoop.mapreduce.ReduceContext.nextKeyValue(ReduceContext.java:116)
at org.apache.hadoop.mapreduce.ReduceContext.nextKey(ReduceContext.java:92)
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:175)
at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:649)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:417)
at org.apache.hadoop.mapred.Child$4.run(Child.java:261)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1059)
at org.apache.hadoop.mapred.Child.main(Child.java:255)