protected PlanarImage readRaster(final File input, final boolean useJAI,
final ImageReadParam imageReadParam, final boolean useMultithreading)
throws IOException {
PlanarImage raster;
final ImageReader reader;
FileImageInputStreamExtImpl fiis = null;
if (useJAI) {
fiis = new FileImageInputStreamExtImpl(input);
reader = readerSpi.createReaderInstance();
final ParameterBlock pbjImageRead = new ParameterBlock();
pbjImageRead.add(fiis);
pbjImageRead.add(0);
pbjImageRead.add(Boolean.FALSE);
pbjImageRead.add(Boolean.FALSE);
pbjImageRead.add(Boolean.FALSE);
pbjImageRead.add(null);
pbjImageRead.add(null);
pbjImageRead.add(imageReadParam);
pbjImageRead.add(reader);
// Check if to use a simple JAI ImageRead operation or a
// multithreaded one
final String jaiOperation = useMultithreading ? GridCoverageUtilities.IMAGEREADMT: GridCoverageUtilities.IMAGEREAD;
raster = JAI.create(jaiOperation, pbjImageRead, hints);
} else {
reader = readerSpi.createReaderInstance();
fiis = new FileImageInputStreamExtImpl(input);
try {
reader.setInput(fiis, true, true);
raster = PlanarImage.wrapRenderedImage(reader.read(0,imageReadParam));
}
finally {
if (fiis != null) {
try {
fiis.close();
} catch (Exception e) {
if (LOGGER.isLoggable(Level.FINE)){
LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
}
}