From e44f7c243a778ec4a899ee4c83b3fd85a6824cc1 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 14 May 2003 21:34:01 +0000 Subject: [PATCH] Close streams immediately after using them. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2575 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/cast/bundle/BundleUtil.java | 10 ++++++++-- .../media/tile/bundle/BundleUtil.java | 19 +++++++++++++------ .../threerings/miso/tile/MisoTileManager.java | 10 ++++++++-- .../miso/tools/xml/SparseMisoSceneParser.java | 11 +++++++++-- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/java/com/threerings/cast/bundle/BundleUtil.java b/src/java/com/threerings/cast/bundle/BundleUtil.java index 66e36a740..3736cf541 100644 --- a/src/java/com/threerings/cast/bundle/BundleUtil.java +++ b/src/java/com/threerings/cast/bundle/BundleUtil.java @@ -1,5 +1,5 @@ // -// $Id: BundleUtil.java,v 1.5 2003/01/14 00:36:14 mdb Exp $ +// $Id: BundleUtil.java,v 1.6 2003/05/14 21:34:01 ray Exp $ package com.threerings.cast.bundle; @@ -9,6 +9,8 @@ import java.io.InputStream; import java.io.InvalidClassException; import java.io.ObjectInputStream; +import com.samskivert.io.StreamUtil; + import com.threerings.cast.Log; import com.threerings.resource.ResourceBundle; @@ -51,8 +53,9 @@ public class BundleUtil public static Object loadObject (ResourceBundle bundle, String path) throws IOException, ClassNotFoundException { + InputStream bin = null; try { - InputStream bin = bundle.getResource(path); + bin = bundle.getResource(path); if (bin == null) { return null; } @@ -64,6 +67,9 @@ public class BundleUtil ", element=" + path + ", error=" + ice.getMessage() + "]."); return null; + + } finally { + StreamUtil.close(bin); } } } diff --git a/src/java/com/threerings/media/tile/bundle/BundleUtil.java b/src/java/com/threerings/media/tile/bundle/BundleUtil.java index 59e8b3ea5..8a80f5eb9 100644 --- a/src/java/com/threerings/media/tile/bundle/BundleUtil.java +++ b/src/java/com/threerings/media/tile/bundle/BundleUtil.java @@ -1,5 +1,5 @@ // -// $Id: BundleUtil.java,v 1.2 2001/11/30 02:34:57 mdb Exp $ +// $Id: BundleUtil.java,v 1.3 2003/05/14 21:34:01 ray Exp $ package com.threerings.media.tile.bundle; @@ -8,6 +8,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; +import com.samskivert.io.StreamUtil; + import com.threerings.resource.ResourceBundle; /** @@ -27,10 +29,15 @@ public class BundleUtil throws IOException, ClassNotFoundException { // unserialize the tileset bundles array - InputStream tbin = bundle.getResource(METADATA_PATH); - ObjectInputStream oin = new ObjectInputStream( - new BufferedInputStream(tbin)); - TileSetBundle tsb = (TileSetBundle)oin.readObject(); - return tsb; + InputStream tbin = null; + try { + tbin = bundle.getResource(METADATA_PATH); + ObjectInputStream oin = new ObjectInputStream( + new BufferedInputStream(tbin)); + TileSetBundle tsb = (TileSetBundle)oin.readObject(); + return tsb; + } finally { + StreamUtil.close(tbin); + } } } diff --git a/src/java/com/threerings/miso/tile/MisoTileManager.java b/src/java/com/threerings/miso/tile/MisoTileManager.java index d45ccb952..ac629cab4 100644 --- a/src/java/com/threerings/miso/tile/MisoTileManager.java +++ b/src/java/com/threerings/miso/tile/MisoTileManager.java @@ -1,11 +1,13 @@ // -// $Id: MisoTileManager.java,v 1.4 2003/01/13 22:55:12 mdb Exp $ +// $Id: MisoTileManager.java,v 1.5 2003/05/14 21:34:01 ray Exp $ package com.threerings.miso.tile; import java.io.IOException; import java.io.InputStream; +import com.samskivert.io.StreamUtil; + import com.threerings.resource.ResourceManager; import com.threerings.util.CompiledConfig; @@ -32,8 +34,9 @@ public class MisoTileManager extends TileManager super(imgr); // look for a fringe configuration in the appropriate place + InputStream in = null; try { - InputStream in = rmgr.getResource(FRINGE_CONFIG_PATH); + in = rmgr.getResource(FRINGE_CONFIG_PATH); FringeConfiguration config = (FringeConfiguration) CompiledConfig.loadConfig(in); @@ -44,6 +47,9 @@ public class MisoTileManager extends TileManager Log.warning("Unable to load fringe configuration " + "[path=" + FRINGE_CONFIG_PATH + ", error=" + ioe + "]."); + + } finally { + StreamUtil.close(in); } } diff --git a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneParser.java b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneParser.java index 89e0bc4c9..a7a37eef7 100644 --- a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneParser.java +++ b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneParser.java @@ -1,5 +1,5 @@ // -// $Id: SparseMisoSceneParser.java,v 1.1 2003/04/19 22:40:34 mdb Exp $ +// $Id: SparseMisoSceneParser.java,v 1.2 2003/05/14 21:34:01 ray Exp $ package com.threerings.miso.tools.xml; @@ -9,6 +9,7 @@ import java.io.FileInputStream; import org.xml.sax.SAXException; import org.apache.commons.digester.Digester; +import com.samskivert.io.StreamUtil; import com.samskivert.util.StringUtil; import com.threerings.tools.xml.NestableRuleSet; @@ -55,7 +56,13 @@ public class SparseMisoSceneParser { _model = null; _digester.push(this); - _digester.parse(new FileInputStream(path)); + FileInputStream stream = null; + try { + stream = new FileInputStream(path); + _digester.parse(stream); + } finally { + StreamUtil.close(stream); + } return _model; }