changeset 623:65f09139e9b3

Fixed file handle leak when writing meta data. gnv-artifacts/trunk@694 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 21 Feb 2010 21:05:55 +0000 (2010-02-21)
parents 89aca25642d6
children 6a3a1da5e680
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractHistogram.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/DefaultHistogram.java gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java
diffstat 8 files changed, 84 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Fri Feb 19 13:28:34 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Sun Feb 21 21:05:55 2010 +0000
@@ -1,3 +1,16 @@
+2010-02-21	Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java:
+	  Fixed file handle leak when writing meta data.
+
+	* src/main/java/de/intevation/gnv/state/StateBase.java,
+	  src/main/java/de/intevation/gnv/state/MinMaxState.java,
+	  src/main/java/de/intevation/gnv/utils/MapfileGenerator.java,
+	  src/main/java/de/intevation/gnv/chart/DefaultHistogram.java,
+	  src/main/java/de/intevation/gnv/chart/AbstractHistogram.java,
+	  src/main/java/de/intevation/gnv/exports/ChartExportHelper.java:
+	  Clean up imports.
+
 2010-02-19  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractHistogram.java	Fri Feb 19 13:28:34 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractHistogram.java	Sun Feb 21 21:05:55 2010 +0000
@@ -8,13 +8,10 @@
 import org.jfree.chart.ChartTheme;
 import org.jfree.chart.JFreeChart;
 
-import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.chart.plot.XYPlot;
-import org.jfree.chart.renderer.xy.XYBarRenderer;
 
-import org.jfree.data.statistics.HistogramDataset;
-
+import org.jfree.chart.renderer.xy.XYBarRenderer;
 
 /**
  * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/DefaultHistogram.java	Fri Feb 19 13:28:34 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/DefaultHistogram.java	Sun Feb 21 21:05:55 2010 +0000
@@ -1,19 +1,13 @@
 package de.intevation.gnv.chart;
 
-import java.util.Locale;
-
 import org.apache.log4j.Logger;
 
 import org.jfree.chart.ChartTheme;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.axis.NumberAxis;
+
 import org.jfree.chart.plot.XYPlot;
-import org.jfree.chart.renderer.xy.XYBarRenderer;
 
-import org.jfree.data.general.Dataset;
 import org.jfree.data.statistics.HistogramDataset;
 
-
 /**
  * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
  */
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java	Fri Feb 19 13:28:34 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java	Sun Feb 21 21:05:55 2010 +0000
@@ -4,33 +4,38 @@
 import com.lowagie.text.DocumentException;
 import com.lowagie.text.PageSize;
 import com.lowagie.text.Rectangle;
+
 import com.lowagie.text.pdf.PdfContentByte;
 import com.lowagie.text.pdf.PdfTemplate;
 import com.lowagie.text.pdf.PdfWriter;
 
-import java.awt.Transparency;
-import java.awt.Graphics;
+import de.intevation.artifactdatabase.XMLUtils;
+
+import de.intevation.gnv.chart.Chart;
+
 import java.awt.Graphics2D;
-import java.awt.geom.Point2D;
+import java.awt.Transparency;
+
+import java.awt.geom.Rectangle2D.Double;
+
 import java.awt.geom.Rectangle2D;
-import java.awt.geom.Rectangle2D.Double;
+
 import java.awt.image.BufferedImage;
+
+import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+
 import javax.imageio.ImageIO;
 
 import org.apache.batik.svggen.SVGGraphics2D;
 import org.apache.batik.svggen.SVGGraphics2DIOException;
+
 import org.apache.log4j.Logger;
 
 import org.jfree.chart.JFreeChart;
 
-import de.intevation.artifactdatabase.XMLUtils;
-import de.intevation.gnv.chart.Chart;
-
-
 /**
  * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
  */
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java	Fri Feb 19 13:28:34 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java	Sun Feb 21 21:05:55 2010 +0000
@@ -30,7 +30,6 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 /**
  * @author Tim Englich (tim.englich@intevation.de)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Fri Feb 19 13:28:34 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Sun Feb 21 21:05:55 2010 +0000
@@ -1,49 +1,59 @@
 package de.intevation.gnv.state;
 
+import de.intevation.artifactdatabase.Config;
+import de.intevation.artifactdatabase.XMLUtils;
+
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.gnv.artifacts.GNVArtifactBase;
+
+import de.intevation.gnv.artifacts.cache.CacheFactory;
+
+import de.intevation.gnv.artifacts.ressource.RessourceFactory;
+
+import de.intevation.gnv.geobackend.base.Result;
+
+import de.intevation.gnv.geobackend.base.query.QueryExecutor;
+import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
+
+import de.intevation.gnv.geobackend.base.query.exception.QueryException;
+
+import de.intevation.gnv.geobackend.util.DateUtils;
+
+import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData;
+import de.intevation.gnv.state.describedata.KeyValueDescibeData;
+import de.intevation.gnv.state.describedata.MinMaxDescribeData;
+import de.intevation.gnv.state.describedata.NamedArrayList;
+import de.intevation.gnv.state.describedata.NamedCollection;
+import de.intevation.gnv.state.describedata.SingleValueDescribeData;
+
+import de.intevation.gnv.state.exception.StateException;
+
+import de.intevation.gnv.utils.InputValidator;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import javax.xml.xpath.XPathConstants;
 
 import net.sf.ehcache.Cache;
 
 import org.apache.log4j.Logger;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import de.intevation.artifactdatabase.Config;
-import de.intevation.artifactdatabase.XMLUtils;
-import de.intevation.artifacts.ArtifactNamespaceContext;
-import de.intevation.artifacts.CallContext;
-import de.intevation.artifacts.CallMeta;
-import de.intevation.gnv.artifacts.GNVArtifactBase;
-import de.intevation.gnv.artifacts.cache.CacheFactory;
-import de.intevation.gnv.artifacts.ressource.RessourceFactory;
-import de.intevation.gnv.geobackend.base.Result;
-import de.intevation.gnv.geobackend.base.query.QueryExecutor;
-import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
-import de.intevation.gnv.geobackend.base.query.exception.QueryException;
-import de.intevation.gnv.geobackend.util.DateUtils;
-import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData;
-import de.intevation.gnv.state.describedata.KeyValueDescibeData;
-import de.intevation.gnv.state.describedata.MinMaxDescribeData;
-import de.intevation.gnv.state.describedata.NamedArrayList;
-import de.intevation.gnv.state.describedata.NamedCollection;
-import de.intevation.gnv.state.describedata.SingleValueDescribeData;
-import de.intevation.gnv.state.exception.StateException;
-import de.intevation.gnv.utils.InputValidator;
-
 /**
  * @author Tim Englich         (tim.englich@intevation.de)
  * @author Ingo Weinzierl      (ingo.weinzierl@intevation.de)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Fri Feb 19 13:28:34 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Sun Feb 21 21:05:55 2010 +0000
@@ -383,10 +383,24 @@
                 return null;
             }
 
-            OutputStream out = new FileOutputStream(metaFile);
-            XMLUtils.toStream(meta, out);
+            OutputStream out = null;
+            boolean success = false;
+            try {
+                out = new FileOutputStream(metaFile);
+                success = XMLUtils.toStream(meta, out);
+            }
+            finally {
+                if (out != null) {
+                    try { out.close(); }
+                    catch (IOException ioe) {}
+                }
+            }
 
-            return meta;
+            if (!success && metaFile.exists()) {
+                metaFile.delete();
+            }
+
+            return success ? meta : null;
         }
         catch (FileNotFoundException fnfe) {
             log.error(fnfe);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java	Fri Feb 19 13:28:34 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java	Sun Feb 21 21:05:55 2010 +0000
@@ -2,18 +2,18 @@
 
 import de.intevation.artifactdatabase.Config;
 import de.intevation.artifactdatabase.XMLUtils;
+
 import de.intevation.artifacts.ArtifactNamespaceContext;
-import de.intevation.gnv.artifacts.context.GNVArtifactContext;
+
 import de.intevation.gnv.wms.LayerInfo;
 
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.FileNotFoundException;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
-import java.net.MalformedURLException;
+
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -22,17 +22,16 @@
 import javax.xml.xpath.XPathConstants;
 
 import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
 
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
+
 import org.apache.velocity.app.VelocityEngine;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-
 /**
  * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
  */

http://dive4elements.wald.intevation.org