]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fix leaked resource warnings from Eclipse (Kepler).
authorGlenn Adams <gadams@apache.org>
Sun, 6 Jul 2014 05:34:16 +0000 (05:34 +0000)
committerGlenn Adams <gadams@apache.org>
Sun, 6 Jul 2014 05:34:16 +0000 (05:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1608162 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/afp/apps/FontPatternExtractor.java
src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java
src/java/org/apache/fop/fonts/type1/PFMFile.java
src/java/org/apache/fop/hyphenation/HyphenationTree.java
src/java/org/apache/fop/image/loader/batik/PreloaderWMF.java
src/java/org/apache/fop/pdf/PDFFactory.java
src/java/org/apache/fop/pdf/PDFOutputIntent.java
src/java/org/apache/fop/render/pcl/PCLGenerator.java
src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
src/java/org/apache/fop/tools/anttasks/FileCompare.java

index 7a2b8ed362159dfc988f40ca14f5956a69f797ec..66150dda3d2b46760ec7c111f5ae234dd9e68f5d 100644 (file)
@@ -63,6 +63,7 @@ public class FontPatternExtractor {
             }
 
             ByteArrayInputStream bin = new ByteArrayInputStream(baout.toByteArray());
+            IOUtils.closeQuietly(baout);
             DataInputStream din = new DataInputStream(bin);
             long len = din.readInt() & 0xFFFFFFFFL;
             println("Length: " + len);
index 7a4575cd344fd55c3116661ff2b934651a20a72e..54826a2ec50e9e9a34d21ed155b9b025ce4845fd 100644 (file)
@@ -21,10 +21,11 @@ package org.apache.fop.afp.goca;
 
 import java.awt.Color;
 import java.awt.color.ColorSpace;
-import java.io.DataOutput;
+import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
 import org.apache.xmlgraphics.java2d.color.CIELabColorSpace;
@@ -105,6 +106,7 @@ public class GraphicsSetProcessColor extends AbstractGraphicsDrawingOrder {
         ColorSpace cs = color.getColorSpace();
         int colSpaceType = cs.getType();
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
+        DataOutputStream dout = null;
         byte[] colsizes;
         if (colSpaceType == ColorSpace.TYPE_CMYK) {
             colspace = CMYK;
@@ -121,7 +123,7 @@ public class GraphicsSetProcessColor extends AbstractGraphicsDrawingOrder {
         } else if (cs instanceof CIELabColorSpace) {
             colspace = CIELAB;
             colsizes = new byte[] {0x08, 0x08, 0x08, 0x00};
-            DataOutput dout = new java.io.DataOutputStream(baout);
+            dout = new DataOutputStream(baout);
             //According to GOCA, I'd expect the multiplicator below to be 255f, not 100f
             //But only IBM AFP Workbench seems to support Lab colors and it requires "c * 100f"
             int l = Math.round(colorComponents[0] * 100f);
@@ -131,6 +133,8 @@ public class GraphicsSetProcessColor extends AbstractGraphicsDrawingOrder {
             dout.writeByte(a);
             dout.writeByte(b);
         } else {
+            IOUtils.closeQuietly(dout);
+            IOUtils.closeQuietly(baout);
             throw new IllegalStateException();
         }
 
@@ -151,6 +155,8 @@ public class GraphicsSetProcessColor extends AbstractGraphicsDrawingOrder {
 
         os.write(data);
         baout.writeTo(os);
+        IOUtils.closeQuietly(dout);
+        IOUtils.closeQuietly(baout);
     }
 
     /** {@inheritDoc} */
index 3b171e85a06b3656fdcc6c069b881306fdbef122..d19c8d478ad2df62f41445a2488c37264c2f9b92 100644 (file)
@@ -85,6 +85,7 @@ public class PFMFile {
         short sh2 = in.readByte();
         if (sh1 == 128 && sh2 == 1) {
             //Found the first section header of a PFB file!
+            IOUtils.closeQuietly(in);
             throw new IOException("Cannot parse PFM file. You probably specified the PFB file"
                     + " of a Type 1 font as parameter instead of the PFM.");
         }
@@ -93,6 +94,7 @@ public class PFMFile {
         bufin.read(b);
         if (new String(b, "US-ASCII").equalsIgnoreCase("StartFontMetrics")) {
             //Found the header of a AFM file!
+            IOUtils.closeQuietly(in);
             throw new IOException("Cannot parse PFM file. You probably specified the AFM file"
                     + " of a Type 1 font as parameter instead of the PFM.");
         }
index 70fc3f05a514f2ac295f05d95ef4fb0174d090b9..60d280f7c9349fb8a05dc0b6558529823e6c3230 100644 (file)
@@ -36,6 +36,8 @@ import java.util.List;
 
 import org.xml.sax.InputSource;
 
+import org.apache.commons.io.IOUtils;
+
 /**
  * <p>This tree structure stores the hyphenation patterns in an efficient
  * way for fast lookup. It provides the provides the method to
@@ -709,9 +711,9 @@ public class HyphenationTree extends TernaryTree
                 token = in.readLine().trim();
                 long starttime = 0;
                 int counter = 0;
+                BufferedReader reader = null;
                 try {
-                    BufferedReader reader
-                        = new BufferedReader(new FileReader(token));
+                    reader = new BufferedReader(new FileReader(token));
                     String line;
 
                     starttime = System.currentTimeMillis();
@@ -731,6 +733,8 @@ public class HyphenationTree extends TernaryTree
                 } catch (Exception ioe) {
                     System.out.println("Exception " + ioe);
                     ioe.printStackTrace();
+                } finally {
+                    IOUtils.closeQuietly(reader);
                 }
                 long endtime = System.currentTimeMillis();
                 long result = endtime - starttime;
index 43341cbe66bbcdc68042daacb91c34434af8968f..582c35a821c4338a080d24dcbd715b146920e305 100644 (file)
@@ -97,6 +97,7 @@ public class PreloaderWMF extends AbstractImagePreloader {
                 int magic = EndianUtils.swapInteger(din.readInt());
                 din.reset();
                 if (magic != WMFConstants.META_ALDUS_APM) {
+                    IOUtils.closeQuietly(din);
                     return null; //Not a WMF file
                 }
 
index eb4f61077dd383e3321b67746b7b8907801fe8fa..e4a9b1b55a7ce9f6501655fd922fae94a3981291 100644 (file)
@@ -1587,6 +1587,8 @@ public class PDFFactory {
             log.error(
                     "Failed to write CIDSet [" + cidFont + "] "
                     + cidFont.getEmbedFontName(), ioe);
+        } finally {
+            IOUtils.closeQuietly(baout);
         }
     }
 
index 1c03739446a93ba61d4223b21396d6b5c3b71079..32a9f01ecaa05825eca3d025e4de2ff26bf82b3f 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
 /**
@@ -167,7 +168,9 @@ public class PDFOutputIntent extends PDFObject {
         } catch (IOException ioe) {
             log.error("Ignored I/O exception", ioe);
         }
-        return bout.toByteArray();
+        byte[] bytes = bout.toByteArray();
+        IOUtils.closeQuietly(bout);
+        return bytes;
     }
 
 
index 0db295a5a36ec4e4c8a1d94345e14655b13b382d..99aa40f229b0a5ba5a39d75a0ca2b2d3c2d2ea68 100644 (file)
@@ -42,6 +42,7 @@ import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.util.Locale;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
 import org.apache.xmlgraphics.image.GraphicsUtil;
@@ -447,6 +448,8 @@ public class PCLGenerator {
         writeCommand("*c" + patternID + "G");
         writeCommand("*c" + baout.size() + "W");
         baout.writeTo(this.out);
+        IOUtils.closeQuietly(data);
+        IOUtils.closeQuietly(baout);
         writeCommand("*c4Q"); //temporary pattern
     }
 
index 471efc56794ece57a27f4508286f9b3d6f704b36..c61ca8cda44267ee7276277ff5e5b5619e2b8035 100644 (file)
@@ -26,6 +26,7 @@ import java.awt.image.Raster;
 import java.io.IOException;
 import java.util.Arrays;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -241,12 +242,12 @@ public abstract class AbstractImageAdapter implements PDFImage {
                     + " The image may not be handled correctly." + " Base color space: "
                     + icm.getColorSpace() + " Image: " + image.getInfo());
         }
-        ByteArrayOutputStream baout = new ByteArrayOutputStream();
         int c = icm.getMapSize();
         int hival = c - 1;
         if (hival > MAX_HIVAL) {
             throw new UnsupportedOperationException("hival must not go beyond " + MAX_HIVAL);
         }
+        ByteArrayOutputStream baout = new ByteArrayOutputStream();
         boolean isDeviceGray = false;
         int[] palette = new int[c];
         icm.getRGBs(palette);
@@ -276,6 +277,7 @@ public abstract class AbstractImageAdapter implements PDFImage {
         indexed.add(hival);
 
         indexed.add(baout.toByteArray());
+        IOUtils.closeQuietly(baout);
 
         dict.put("ColorSpace", indexed);
 
index 4906bdc6c6c653c865974bdb9bccb4c059d5aad5..8591babe281904cd41692ca23e55bce5b684eaab 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.StringTokenizer;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.tools.ant.BuildException;
 
 /**
@@ -98,6 +99,7 @@ public class FileCompare {
      * @return true if files are same byte-by-byte, false otherwise
      */
     private static boolean compareBytes(File file1, File file2) throws IOException {
+        boolean same = true;
         BufferedInputStream file1Input
             = new BufferedInputStream(new java.io.FileInputStream(file1));
         BufferedInputStream file2Input
@@ -111,11 +113,15 @@ public class FileCompare {
                 charact1 = file1Input.read();
                 charact2 = file2Input.read();
             } else {
-                return false;
+                same = false;
+                break;
             }
         }
 
-        return true;
+        IOUtils.closeQuietly(file1Input);
+        IOUtils.closeQuietly(file2Input);
+
+        return same;
     }
 
     /**