@Test
public void testJAIReadType() throws IOException {
// Definition of the reader
ImageReader reader = new TIFFImageReaderSpi().createReaderInstance();
FileImageInputStream in = new FileImageInputStream(DataUtilities.urlToFile(granuleUrl));
try {
reader.setInput(in);
// Definition of the read type
ReadType jaiImageRead = ReadType.JAI_IMAGEREAD;
// Check if the default read type is JAI
ReadType defaultRead = ReadType.getDefault();
assertEquals(jaiImageRead, defaultRead);
// Test 1 = wrong region
RenderedImage output = jaiImageRead.read(readParameters, IMAGE_INDEX, granuleUrl,
rasterDimensionsWrong, reader, hints, CLOSE_ELEMENTS);
assertNull(output);
// Test 2 = null URL
output = jaiImageRead.read(readParameters, IMAGE_INDEX, null, rasterDimensions, reader,
hints, CLOSE_ELEMENTS);
assertNull(output);
// Test 3 = null Reader
output = jaiImageRead.read(readParameters, IMAGE_INDEX, granuleUrl, rasterDimensions,
null, hints, CLOSE_ELEMENTS);
assertNull(output);
// Test 4 = correct
output = jaiImageRead.read(readParameters, IMAGE_INDEX, granuleUrl, rasterDimensions,
reader, hints, CLOSE_ELEMENTS);
assertNotNull(output);
Rectangle sourceRegion = readParameters.getSourceRegion();
// Calculate the intersection between the raster dimension and the read parameters
Rectangle.intersect(sourceRegion, rasterDimensions, sourceRegion);
// Check dimensions
assertEquals(output.getMinX(), sourceRegion.x);
assertEquals(output.getMinY(), sourceRegion.y);
assertEquals(output.getWidth(), sourceRegion.width);
assertEquals(output.getHeight(), sourceRegion.height);
} finally {
if (in != null) {
in.close();
}
if(reader != null){
reader.dispose();
}
}