private IIOImage read(File jpeg) throws IOException{
initReader();
IIOImage image = null;
/* Read the input image including stream and image meta-data */
do{
ImageInputStream iis =
ImageIO.createImageInputStream(
new BufferedInputStream(new FileInputStream(jpeg)));
try{
reader.setInput(iis);
IIOException iiox = null;
try{
image = reader.readAll(0, null);
} catch (IIOException ex){
iiox = ex;
}
if (iiox != null){
if (iiox.getMessage() != null &&
iiox.getMessage().endsWith("without prior JFIF!") ) {
//We have run into Java bug 4924909
//We try patching the input
System.err.println("Trying workaround for java bug");
System.err.println("http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4924909");
System.err.println("Please vote for this bug!");
iis.close();
iis = patch(jpeg);
reader.setInput(iis);
image = reader.readAll(0, null);
} else {
throw iiox;
}
}
} finally {
iis.close();
}
} while(image == null);
return image;
}