From a06eddcd954f070386a4ccc0f4cbdc5997f8b07a Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Thu, 13 Dec 2007 00:48:34 +0000 Subject: [PATCH] Super-sweet. Java 1.4.2 apparently has some kind of awesome bug in its MemoryCacheImageStream. Let's work around that by falling back to the Image IO reading that's gonna bork in sandbox land. Guess anything in a sandbox is gonna require Java 1.5 unless we find a different way around this. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@376 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../threerings/resource/ResourceManager.java | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/java/com/threerings/resource/ResourceManager.java b/src/java/com/threerings/resource/ResourceManager.java index 301529be..abb305f4 100644 --- a/src/java/com/threerings/resource/ResourceManager.java +++ b/src/java/com/threerings/resource/ResourceManager.java @@ -44,6 +44,7 @@ import java.util.StringTokenizer; import java.security.AccessController; import java.security.PrivilegedAction; +import javax.imageio.IIOException; import javax.imageio.ImageIO; import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.MemoryCacheImageInputStream; @@ -743,22 +744,29 @@ public class ResourceManager image = ImageIO.read(iis); } else { - // if we don't already have an image input stream, create a memory cache image input - // stream to avoid causing freakout if we're used in a sandbox because ImageIO - // otherwise use FileCacheImageInputStream which tries to create a temp file - MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream(iis); - image = ImageIO.read(mciis); try { - // this doesn't close the underlying stream - mciis.close(); - } catch (IOException ioe) { - // ImageInputStreamImpl.close() throws an IOException if it's already closed; - // there's no way to find out if it's already closed or not, so we have to check - // the exception message to determine if this is actually warning worthy - if (!"closed".equals(ioe.getMessage())) { - Log.warning("Failure closing image input '" + iis + "'."); - Log.logStackTrace(ioe); + // if we don't already have an image input stream, create a memory cache image input + // stream to avoid causing freakout if we're used in a sandbox because ImageIO + // otherwise use FileCacheImageInputStream which tries to create a temp file + MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream(iis); + image = ImageIO.read(mciis); + try { + // this doesn't close the underlying stream + mciis.close(); + } catch (IOException ioe) { + // ImageInputStreamImpl.close() throws an IOException if it's already closed; + // there's no way to find out if it's already closed or not, so we have to check + // the exception message to determine if this is actually warning worthy + if (!"closed".equals(ioe.getMessage())) { + Log.warning("Failure closing image input '" + iis + "'."); + Log.logStackTrace(ioe); + } } + } catch (IIOException iioe) { + // Fall back to the old way of doing things. + // It would appear that Java 1.4.2 explodes trying to use the + // MemoryCacheImageInputStream to load its images. + image = ImageIO.read(iis); } }