DisposeStopper implements RenderedImage { public Raster getData() { return adaptee.getData(); } DisposeStopper(RenderedImage adaptee); Vector<RenderedImage> getSources(); Object getProperty(String name); String[] getPropertyNames(); ColorModel getColorModel(); SampleModel getSampleModel(); int getWidth(); int getHeight(); int getMinX(); int getMinY(); int getNumXTiles(); int getNumYTiles(); int getMinTileX(); int getMinTileY(); int getTileWidth(); int getTileHeight(); int getTileGridXOffset(); int getTileGridYOffset(); Raster getTile(int tileX, int tileY); Raster getData(); Raster getData(Rectangle rect); WritableRaster copyData(WritableRaster raster);  }
@Test public void testDispose() throws FileNotFoundException, IOException { final File tiff = TestData.file(MosaicTest.class, "sample0.tif"); final TIFFImageReader reader = (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader) new TIFFImageReaderSpi() .createReaderInstance(); final ImageInputStream stream = ImageIO.createImageInputStream(tiff); reader.setInput(stream); RenderedImage image = ImageReadDescriptor.create(stream, 0, false, false, false, null, null, null, reader, null); DisposeStopper stopper = new DisposeStopper(image); boolean readSuccess = true; try { ImageUtilities.disposeImage(stopper); assertNotNull(image); assertEquals(187, image.getData().getSample(1, 5, 0)); ImageUtilities.disposeImage(image); image.getData().getSample(1, 5, 0); } catch (RuntimeException ioe) { readSuccess = false; } finally { if (stream != null) { try { stream.close(); } catch (Throwable t) { } } if (reader != null) { try { reader.dispose(); } catch (Throwable t) { } } } assertFalse(readSuccess); }