]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Changed image loading to use Commons IO.
authorJeremias Maerki <jeremias@apache.org>
Sat, 8 Nov 2003 14:19:45 +0000 (14:19 +0000)
committerJeremias Maerki <jeremias@apache.org>
Sat, 8 Nov 2003 14:19:45 +0000 (14:19 +0000)
Properly close InputStream.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196995 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java

index 6af9e4ce9eeb1ddfb9e8ecff7547b3619c19278b..d4ac4d9faedad092a15307d346d7f135f80bd96a 100644 (file)
 
 package org.apache.fop.render.rtf.rtflib.rtfdoc;
 
+import org.apache.commons.io.IOUtil;
 import org.apache.fop.render.rtf.rtflib.tools.ImageConstants;
 import org.apache.fop.render.rtf.rtflib.tools.ImageUtil;
 //import org.apache.fop.render.rtf.rtflib.tools.jpeg.Encoder;
 //import org.apache.fop.render.rtf.rtflib.tools.jpeg.JPEGException;
 
-import java.io.BufferedInputStream;
-
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Writer;
 
 import java.io.File;
@@ -247,18 +246,12 @@ public class RtfExternalGraphic extends RtfElement {
 
         data = null;
         try {
-            // image reading patch provided by Michael Krause <michakurt@web.de>
-            final BufferedInputStream bin = new BufferedInputStream(url.openStream());
-            final ByteArrayOutputStream bout = new ByteArrayOutputStream();
-            while (true) {
-                final int datum = bin.read();
-                if (datum == -1) {
-                   break;
-                }
-                bout.write(datum);
-             }
-             bout.flush();
-             data = bout.toByteArray();
+            final InputStream in = url.openStream();
+            try {
+                data = IOUtil.toByteArray(url.openStream());
+            } finally {
+                IOUtil.shutdownStream(in);
+            }
         } catch (Exception e) {
             throw new ExternalGraphicException("The attribute 'src' of "
                     + "<fo:external-graphic> has a invalid value: '"