aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-08-21 17:09:37 +0000
committerJeremias Maerki <jeremias@apache.org>2005-08-21 17:09:37 +0000
commitb243af2bc77269287d267f122c96c87b9cea165a (patch)
tree249d93bbd4c61cb6e0a93093965e2cc63c217899
parentf53181fd9465de68db0b07d72c73b37c4b6e0c0c (diff)
downloadxmlgraphics-fop-b243af2bc77269287d267f122c96c87b9cea165a.tar.gz
xmlgraphics-fop-b243af2bc77269287d267f122c96c87b9cea165a.zip
Code simplification.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@234273 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java-1.4/org/apache/fop/image/ImageIOImage.java5
-rw-r--r--src/java/org/apache/fop/image/BatikImage.java25
-rw-r--r--src/java/org/apache/fop/image/BmpImage.java14
-rw-r--r--src/java/org/apache/fop/image/GifImage.java8
-rw-r--r--src/java/org/apache/fop/image/JAIImage.java14
-rw-r--r--src/java/org/apache/fop/image/JimiImage.java8
-rw-r--r--src/java/org/apache/fop/image/JpegImage.java7
-rw-r--r--src/java/org/apache/fop/image/TIFFImage.java13
-rw-r--r--src/java/org/apache/fop/image/analyser/EPSReader.java3
-rw-r--r--src/java/org/apache/fop/image/analyser/SVGReader.java7
-rw-r--r--src/java/org/apache/fop/image/analyser/XMLReader.java9
11 files changed, 36 insertions, 77 deletions
diff --git a/src/java-1.4/org/apache/fop/image/ImageIOImage.java b/src/java-1.4/org/apache/fop/image/ImageIOImage.java
index 882f36d92..56bb863b7 100644
--- a/src/java-1.4/org/apache/fop/image/ImageIOImage.java
+++ b/src/java-1.4/org/apache/fop/image/ImageIOImage.java
@@ -27,6 +27,8 @@ import java.awt.image.BufferedImage;
// ImageIO
import javax.imageio.ImageIO;
+import org.apache.commons.io.IOUtils;
+
/**
* FopImage object using ImageIO.
* @see AbstractFopImage
@@ -145,6 +147,9 @@ public class ImageIOImage extends AbstractFopImage {
} catch (Exception ex) {
log.error("Error while loading image: " + ex.getMessage(), ex);
return false;
+ } finally {
+ IOUtils.closeQuietly(inputStream);
+ inputStream = null;
}
return true;
}
diff --git a/src/java/org/apache/fop/image/BatikImage.java b/src/java/org/apache/fop/image/BatikImage.java
index 9c99eb465..380b21ab6 100644
--- a/src/java/org/apache/fop/image/BatikImage.java
+++ b/src/java/org/apache/fop/image/BatikImage.java
@@ -31,6 +31,7 @@ import org.apache.batik.ext.awt.image.codec.MemoryCacheSeekableStream;
import org.apache.batik.ext.awt.image.codec.FileCacheSeekableStream;
import org.apache.batik.ext.awt.image.rendered.Any2sRGBRed;
import org.apache.batik.ext.awt.image.rendered.CachableRed;
+import org.apache.commons.io.IOUtils;
/**
* FopImage object using TIFF
@@ -114,16 +115,8 @@ public abstract class BatikImage extends AbstractFopImage {
}
} catch (IOException ioe) {
log.error("Error while loading image (Batik): " + ioe.getMessage(), ioe);
- try {
- seekableInput.close();
- } catch (IOException ioex) {
- // ignore
- }
- try {
- inputStream.close();
- } catch (IOException ioex) {
- // ignore
- }
+ IOUtils.closeQuietly(seekableInput);
+ IOUtils.closeQuietly(inputStream);
seekableInput = null;
inputStream = null;
return false;
@@ -219,16 +212,8 @@ public abstract class BatikImage extends AbstractFopImage {
log.error("Error while loading image (Batik): " + ex.getMessage(), ex);
} finally {
// Make sure we clean up
- try {
- seekableInput.close();
- } catch (IOException ioex) {
- // ignore
- }
- try {
- inputStream.close();
- } catch (IOException ioex) {
- // ignore
- }
+ IOUtils.closeQuietly(seekableInput);
+ IOUtils.closeQuietly(inputStream);
seekableInput = null;
inputStream = null;
cr = null;
diff --git a/src/java/org/apache/fop/image/BmpImage.java b/src/java/org/apache/fop/image/BmpImage.java
index 3cffc4642..3e256cf77 100644
--- a/src/java/org/apache/fop/image/BmpImage.java
+++ b/src/java/org/apache/fop/image/BmpImage.java
@@ -22,6 +22,8 @@ package org.apache.fop.image;
import java.io.IOException;
import java.awt.color.ColorSpace;
+import org.apache.commons.io.IOUtils;
+
/**
* Bitmap image.
* This supports loading a bitmap image into bitmap data.
@@ -84,11 +86,7 @@ public class BmpImage extends AbstractFopImage {
}
} catch (IOException ex) {
log.error("Error while loading image (Bmp): " + ex.getMessage(), ex);
- try {
- inputStream.close();
- } catch (java.io.IOException ioe) {
- // Ignore
- }
+ IOUtils.closeQuietly(inputStream);
inputStream = null;
return false;
}
@@ -147,11 +145,7 @@ public class BmpImage extends AbstractFopImage {
log.error("Error while loading image (Bmp): " + ex.getMessage(), ex);
return false;
} finally {
- try {
- inputStream.close();
- } catch (java.io.IOException ioe) {
- // Ignore
- }
+ IOUtils.closeQuietly(inputStream);
inputStream = null;
}
diff --git a/src/java/org/apache/fop/image/GifImage.java b/src/java/org/apache/fop/image/GifImage.java
index 3cafef559..20c24525b 100644
--- a/src/java/org/apache/fop/image/GifImage.java
+++ b/src/java/org/apache/fop/image/GifImage.java
@@ -28,6 +28,8 @@ import java.io.InputStream;
import java.io.IOException;
import java.net.URLConnection;
+import org.apache.commons.io.IOUtils;
+
/**
* FopImage object for GIF images, using Java native classes.
* @author Eric SCHAEFFER
@@ -143,11 +145,7 @@ public class GifImage extends AbstractFopImage {
log.error("Error while loading image (Gif): " + ex.getMessage(), ex);
return false;
} finally {
- try {
- inputStream.close();
- } catch (java.io.IOException ioe) {
- // Ignore
- }
+ IOUtils.closeQuietly(inputStream);
inputStream = null;
}
diff --git a/src/java/org/apache/fop/image/JAIImage.java b/src/java/org/apache/fop/image/JAIImage.java
index 8daaa9fc1..624dbfcbc 100644
--- a/src/java/org/apache/fop/image/JAIImage.java
+++ b/src/java/org/apache/fop/image/JAIImage.java
@@ -28,6 +28,8 @@ import java.awt.Color;
// JAI
import javax.media.jai.JAI;
import javax.media.jai.RenderedOp;
+
+import org.apache.commons.io.IOUtils;
// Sun codec
import com.sun.media.jai.codec.FileCacheSeekableStream;
@@ -154,18 +156,10 @@ public class JAIImage extends AbstractFopImage {
} catch (Exception ex) {
log.error("Error while loading image (JAI): " + ex.getMessage(), ex);
} finally {
- try {
- inputStream.close();
- } catch (java.io.IOException ioe) {
- // Ignore
- }
+ IOUtils.closeQuietly(inputStream);
inputStream = null;
if (seekableInput != null) {
- try {
- seekableInput.close();
- } catch (java.io.IOException ioe) {
- // Ignore
- }
+ IOUtils.closeQuietly(seekableInput);
}
}
}
diff --git a/src/java/org/apache/fop/image/JimiImage.java b/src/java/org/apache/fop/image/JimiImage.java
index e10024bea..103a067c4 100644
--- a/src/java/org/apache/fop/image/JimiImage.java
+++ b/src/java/org/apache/fop/image/JimiImage.java
@@ -25,6 +25,8 @@ import java.awt.image.IndexColorModel;
import java.awt.color.ColorSpace;
import java.awt.Color;
+import org.apache.commons.io.IOUtils;
+
// Jimi
import com.sun.jimi.core.Jimi;
@@ -155,11 +157,7 @@ public class JimiImage extends AbstractFopImage {
log.error("Error while loading image (Jimi): " + ex.getMessage(), ex);
return;
} finally {
- try {
- inputStream.close();
- } catch (java.io.IOException ioe) {
- // Ignore
- }
+ IOUtils.closeQuietly(inputStream);
inputStream = null;
}
diff --git a/src/java/org/apache/fop/image/JpegImage.java b/src/java/org/apache/fop/image/JpegImage.java
index b3c8cb0bd..6a40e4495 100644
--- a/src/java/org/apache/fop/image/JpegImage.java
+++ b/src/java/org/apache/fop/image/JpegImage.java
@@ -24,6 +24,7 @@ import java.awt.color.ColorSpace;
import java.awt.color.ICC_Profile;
// FOP
+import org.apache.commons.io.IOUtils;
import org.apache.fop.util.CMYKColorSpace;
/**
@@ -69,11 +70,7 @@ public class JpegImage extends AbstractFopImage {
log.error("Error while loading image (Jpeg): " + ex.getMessage(), ex);
return false;
} finally {
- try {
- inputStream.close();
- } catch (java.io.IOException ioe) {
- // Ignore
- }
+ IOUtils.closeQuietly(inputStream);
inputStream = null;
}
diff --git a/src/java/org/apache/fop/image/TIFFImage.java b/src/java/org/apache/fop/image/TIFFImage.java
index 0f959c6f2..6be59663b 100644
--- a/src/java/org/apache/fop/image/TIFFImage.java
+++ b/src/java/org/apache/fop/image/TIFFImage.java
@@ -26,6 +26,7 @@ import org.apache.batik.ext.awt.image.codec.tiff.TIFFDirectory;
import org.apache.batik.ext.awt.image.codec.tiff.TIFFField;
import org.apache.batik.ext.awt.image.codec.tiff.TIFFImageDecoder;
import org.apache.batik.ext.awt.image.rendered.CachableRed;
+import org.apache.commons.io.IOUtils;
/**
* TIFF implementation using the Batik codecs.
@@ -140,16 +141,8 @@ public class TIFFImage extends BatikImage {
log.error("Error while loading image strip 1 (TIFF): ", ioe);
return false;
} finally {
- try {
- this.seekableInput.close();
- } catch (IOException ioex) {
- // ignore
- }
- try {
- this.inputStream.close();
- } catch (IOException ioex) {
- // ignore
- }
+ IOUtils.closeQuietly(seekableInput);
+ IOUtils.closeQuietly(inputStream);
this.seekableInput = null;
this.inputStream = null;
this.cr = null;
diff --git a/src/java/org/apache/fop/image/analyser/EPSReader.java b/src/java/org/apache/fop/image/analyser/EPSReader.java
index 712050ba5..1d34d702b 100644
--- a/src/java/org/apache/fop/image/analyser/EPSReader.java
+++ b/src/java/org/apache/fop/image/analyser/EPSReader.java
@@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
// FOP
+import org.apache.commons.io.IOUtils;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.EPSImage;
import org.apache.fop.apps.FOUserAgent;
@@ -89,7 +90,7 @@ public class EPSReader implements ImageReader {
info.height = (int) (data.bbox[3] - data.bbox[1]);
// image data read
- bis.close();
+ IOUtils.closeQuietly(bis);
info.inputStream = null;
return info;
diff --git a/src/java/org/apache/fop/image/analyser/SVGReader.java b/src/java/org/apache/fop/image/analyser/SVGReader.java
index 656c84cf9..f5328d04e 100644
--- a/src/java/org/apache/fop/image/analyser/SVGReader.java
+++ b/src/java/org/apache/fop/image/analyser/SVGReader.java
@@ -33,6 +33,7 @@ import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.UnitProcessor;
import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -60,11 +61,7 @@ public class SVGReader implements ImageReader {
FOUserAgent ua) throws IOException {
FopImage.ImageInfo info = loadImage(uri, fis, ua);
if (info != null) {
- try {
- fis.close();
- } catch (Exception e) {
- //ignore
- }
+ IOUtils.closeQuietly(fis);
}
return info;
}
diff --git a/src/java/org/apache/fop/image/analyser/XMLReader.java b/src/java/org/apache/fop/image/analyser/XMLReader.java
index bb85980c6..55ebc5dfd 100644
--- a/src/java/org/apache/fop/image/analyser/XMLReader.java
+++ b/src/java/org/apache/fop/image/analyser/XMLReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import org.apache.fop.image.FopImage;
import org.apache.fop.apps.FOUserAgent;
// Commons-Logging
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -62,11 +63,7 @@ public class XMLReader implements ImageReader {
throws IOException {
FopImage.ImageInfo info = loadImage(uri, fis, ua);
if (info != null) {
- try {
- fis.close();
- } catch (Exception e) {
- //ignore
- }
+ IOUtils.closeQuietly(fis);
}
return info;
}