}
OpImage image = null;
try {
// Attempt to create an OpImage from the decoder image.
image = new DisposableNullOpImage(dec.decodeAsRenderedImage(page),
layout,
renderHints,
bound);
} catch(OutOfMemoryError memoryError) {
// Ran out of memory - may be due to the decoder being
// obliged to read the entire image when it creates the
// RenderedImage it returns.
if(canAttemptRecovery) {
// First flush the cache if one is defined.
TileCache cache = image != null ?
image.getTileCache() :
RIFUtil.getTileCacheHint(renderHints);
if(cache != null) {
cache.flush();
}
// Force garbage collection.
System.gc(); //slow
// Reposition the stream before the previous decoding.
source.seek(streamPosition);
// Retry image decoding.
image = new DisposableNullOpImage(dec.decodeAsRenderedImage(page),
layout,
renderHints,
bound);
} else {
// Re-throw the error.