xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maxber...@apache.org
Subject svn commit: r735989 - in /xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader: ImageSource.java impl/AbstractImageSessionContext.java util/ImageInputStreamAdapter.java
Date Tue, 20 Jan 2009 10:44:26 GMT
Author: maxberger
Date: Tue Jan 20 02:44:25 2009
New Revision: 735989

URL: http://svn.apache.org/viewvc?rev=735989&view=rev
Log:
Make sure that ImageStreams are only opened on existing files and not on directories

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSource.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageInputStreamAdapter.java

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSource.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSource.java?rev=735989&r1=735988&r2=735989&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSource.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSource.java
Tue Jan 20 02:44:25 2009
@@ -42,6 +42,7 @@
      * @param fastSource true if it's a fast source (accessing local files)
      */
     public ImageSource(ImageInputStream in, String systemId, boolean fastSource) {
+        assert in != null : "InputStream is null";
         this.iin = in;
         this.systemId = systemId;
         this.fastSource = fastSource;

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java?rev=735989&r1=735988&r2=735989&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java
Tue Jan 20 02:44:25 2009
@@ -126,10 +126,20 @@
                 //Close as the file is reopened in a more optimal way
                 IOUtils.closeQuietly(in);
                 try {
-                    //We let the OS' file system cache do the caching for us
-                    //--> lower Java memory consumption, probably no speed loss
-                    imageSource = new ImageSource(ImageIO.createImageInputStream(f),
-                            resolvedURI, true);
+                    // We let the OS' file system cache do the caching for us
+                    // --> lower Java memory consumption, probably no speed loss
+                    final ImageInputStream newInputStream = ImageIO
+                            .createImageInputStream(f);
+                    if (newInputStream == null) {
+                        log.error("Unable to create ImageInputStream for local file "
+                                        + f
+                                        + " from system identifier '"
+                                        + source.getSystemId() + "'");
+                        return null;
+                    } else {
+                        imageSource = new ImageSource(newInputStream,
+                                resolvedURI, true);
+                    }
                 } catch (IOException ioe) {
                     log.error("Unable to create ImageInputStream for local file"
                             + " from system identifier '"
@@ -207,7 +217,11 @@
                     filename = filename.substring(0, pos) + ch + filename.substring(pos +
3);
                 }
             }
-            return new File(filename);
+            final File f = new File(filename);
+            if (!f.isFile()) {
+                return null;
+            }
+            return f;
         }
     }
     

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageInputStreamAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageInputStreamAdapter.java?rev=735989&r1=735988&r2=735989&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageInputStreamAdapter.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageInputStreamAdapter.java
Tue Jan 20 02:44:25 2009
@@ -40,6 +40,7 @@
      * @param iin the underlying ImageInputStream
      */
     public ImageInputStreamAdapter(ImageInputStream iin) {
+        assert iin != null : "InputStream is null";
         this.iin = iin;
     }
     



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message