@Test public void testDisposeReader() { AtomicBoolean readerDisposed = new AtomicBoolean(false); AtomicBoolean streamDisposed = new AtomicBoolean(false); byte[] bytes = Base64.getDecoder().decode("R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="); MemoryCacheImageInputStream is = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)) { @Override public void close() { streamDisposed.set(true); } }; final ImageReader nativeReader = ImageIO.getImageReadersByFormatName("GIF").next(); nativeReader.setInput(is); ImageReader reader = new ImageReader(null) { @Override public int getNumImages(boolean allowSearch) throws IOException { return nativeReader.getNumImages(allowSearch); } @Override public int getWidth(int imageIndex) throws IOException { return nativeReader.getWidth(imageIndex); } @Override public int getHeight(int imageIndex) throws IOException { return nativeReader.getHeight(imageIndex); } @Override public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException { return nativeReader.getImageTypes(imageIndex); } @Override public IIOMetadata getStreamMetadata() throws IOException { return nativeReader.getStreamMetadata(); } @Override public IIOMetadata getImageMetadata(int imageIndex) throws IOException { return nativeReader.getImageMetadata(imageIndex); } @Override public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException { return nativeReader.read(imageIndex, param); } @Override public void dispose() { nativeReader.dispose(); readerDisposed.set(true); } }; RenderedOp image = ImageReadDescriptor.create( is, 0, false, false, false, null, null, null, reader, null); ImageUtilities.disposePlanarImageChain(image); assertTrue(streamDisposed.get()); assertTrue(readerDisposed.get()); }
public static void disposePlanarImageChain(PlanarImage pi) { Utilities.ensureNonNull("PlanarImage", pi); disposePlanarImageChain(pi, new HashSet<PlanarImage>()); }
ImageUtilities { public static void disposePlanarImageChain(PlanarImage pi) { Utilities.ensureNonNull("PlanarImage", pi); disposePlanarImageChain(pi, new HashSet<PlanarImage>()); } }
ImageUtilities { public static void disposePlanarImageChain(PlanarImage pi) { Utilities.ensureNonNull("PlanarImage", pi); disposePlanarImageChain(pi, new HashSet<PlanarImage>()); } private  ImageUtilities(); }
ImageUtilities { public static void disposePlanarImageChain(PlanarImage pi) { Utilities.ensureNonNull("PlanarImage", pi); disposePlanarImageChain(pi, new HashSet<PlanarImage>()); } private  ImageUtilities(); static ImageLayout getImageLayout(final RenderedImage image); static RenderingHints getRenderingHints(final RenderedImage image); static Dimension toTileSize(final Dimension size); static ImageLayout createIntersection(
            final ImageLayout layout, final List<RenderedImage> sources); static Interpolation toInterpolation(final Object type); static String getInterpolationName(Interpolation interp); static RenderedOp tileImage(final RenderedOp image); static void fill(final WritableRenderedImage image, final Number value); static boolean isMediaLibAvailable(); static void disposePlanarImageChain(PlanarImage pi); static RenderedImage maskColor(final Color transparentColor, final RenderedImage image); static ImageReadParam cloneImageReadParam(ImageReadParam param); static Rectangle2D layoutHelper(
            RenderedImage source,
            float scaleX,
            float scaleY,
            float transX,
            float transY,
            Interpolation interp); static ReferencedEnvelope getReferencedEnvelopeFromGeographicBoundingBox(
            final GeographicBoundingBox geographicBBox); static ReferencedEnvelope getWGS84ReferencedEnvelope(
            final GeneralEnvelope coverageEnvelope); static Rectangle getDimension(
            final int imageIndex, final ImageInputStream inStream, final ImageReader reader); static final boolean checkEmptySourceRegion(
            final ImageReadParam readParameters, final Rectangle dimensions); static Number[] getBackgroundValues(
            final SampleModel sampleModel, final double[] backgroundValues); static void disposeImage(RenderedImage inputImage); static void disposeSinglePlanarImage(PlanarImage planarImage); static String getDatabufferTypeName(int dataType); static RenderedImage applyRescaling(
            Double[] scales, Double[] offsets, RenderedImage image, Hints hints); }
ImageUtilities { public static void disposePlanarImageChain(PlanarImage pi) { Utilities.ensureNonNull("PlanarImage", pi); disposePlanarImageChain(pi, new HashSet<PlanarImage>()); } private  ImageUtilities(); static ImageLayout getImageLayout(final RenderedImage image); static RenderingHints getRenderingHints(final RenderedImage image); static Dimension toTileSize(final Dimension size); static ImageLayout createIntersection(
            final ImageLayout layout, final List<RenderedImage> sources); static Interpolation toInterpolation(final Object type); static String getInterpolationName(Interpolation interp); static RenderedOp tileImage(final RenderedOp image); static void fill(final WritableRenderedImage image, final Number value); static boolean isMediaLibAvailable(); static void disposePlanarImageChain(PlanarImage pi); static RenderedImage maskColor(final Color transparentColor, final RenderedImage image); static ImageReadParam cloneImageReadParam(ImageReadParam param); static Rectangle2D layoutHelper(
            RenderedImage source,
            float scaleX,
            float scaleY,
            float transX,
            float transY,
            Interpolation interp); static ReferencedEnvelope getReferencedEnvelopeFromGeographicBoundingBox(
            final GeographicBoundingBox geographicBBox); static ReferencedEnvelope getWGS84ReferencedEnvelope(
            final GeneralEnvelope coverageEnvelope); static Rectangle getDimension(
            final int imageIndex, final ImageInputStream inStream, final ImageReader reader); static final boolean checkEmptySourceRegion(
            final ImageReadParam readParameters, final Rectangle dimensions); static Number[] getBackgroundValues(
            final SampleModel sampleModel, final double[] backgroundValues); static void disposeImage(RenderedImage inputImage); static void disposeSinglePlanarImage(PlanarImage planarImage); static String getDatabufferTypeName(int dataType); static RenderedImage applyRescaling(
            Double[] scales, Double[] offsets, RenderedImage image, Hints hints); static final double[][] RGB_TO_GRAY_MATRIX; static final double[][] RGBA_TO_GRAY_MATRIX; static final RenderingHints DONT_REPLACE_INDEX_COLOR_MODEL; static final RenderingHints REPLACE_INDEX_COLOR_MODEL; static final RenderingHints NN_INTERPOLATION_HINT; static final RenderingHints NOCACHE_HINT; static final RenderingHints EXTEND_BORDER_BY_COPYING; static final RenderingHints EXTEND_BORDER_BY_REFLECT; static final String[] INTERPOLATION_NAMES; static final int[] INTERPOLATION_TYPES; static final BorderExtender DEFAULT_BORDER_EXTENDER; static final RenderingHints BORDER_EXTENDER_HINTS; static final String DIRECT_KAKADU_PLUGIN; static final float RATIONAL_TOLERANCE; }