diff options
| author | Bananeweizen <Bananeweizen@gmx.de> | 2011-08-11 10:43:17 -0700 |
|---|---|---|
| committer | Bananeweizen <Bananeweizen@gmx.de> | 2011-08-11 10:43:17 -0700 |
| commit | 4830d6db4c93597f212e281b3a965333a4d2dd01 (patch) | |
| tree | 7ae820f7c60a5e84539314590001ad75aca5a51e | |
| parent | 44ee89c26a160030a6f3d3b884374b97d4f35468 (diff) | |
| parent | baea41a31978e39fde87085cd3a17cfd3965b9ce (diff) | |
| download | cgeo-4830d6db4c93597f212e281b3a965333a4d2dd01.zip cgeo-4830d6db4c93597f212e281b3a965333a4d2dd01.tar.gz cgeo-4830d6db4c93597f212e281b3a965333a4d2dd01.tar.bz2 | |
Merge pull request #151 from deebug/master
Some more resource leaks
| -rw-r--r-- | src/cgeo/geocaching/cgDirectionImg.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgGPXParser.java | 30 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgHtmlImg.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgMapImg.java | 2 |
4 files changed, 25 insertions, 11 deletions
diff --git a/src/cgeo/geocaching/cgDirectionImg.java b/src/cgeo/geocaching/cgDirectionImg.java index 52ff7f3..f9227b2 100644 --- a/src/cgeo/geocaching/cgDirectionImg.java +++ b/src/cgeo/geocaching/cgDirectionImg.java @@ -73,11 +73,11 @@ public class cgDirectionImg { fos.write(buffer, 0, l); } ok = true; + fos.flush(); } catch (IOException e) { Log.e(cgSettings.tag, "cgDirectionImg.getDrawable (saving to cache): " + e.toString()); } finally { is.close(); - fos.flush(); fos.close(); } } diff --git a/src/cgeo/geocaching/cgGPXParser.java b/src/cgeo/geocaching/cgGPXParser.java index ab76226..fcb0c95 100644 --- a/src/cgeo/geocaching/cgGPXParser.java +++ b/src/cgeo/geocaching/cgGPXParser.java @@ -2,12 +2,15 @@ package cgeo.geocaching; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.xml.sax.Attributes; +import org.xml.sax.SAXException; import android.os.Handler; import android.os.Message; @@ -537,15 +540,26 @@ public class cgGPXParser { } }); } - + FileInputStream fis = null; + boolean parsed = false; try { - Xml.parse(new FileInputStream(file), Xml.Encoding.UTF_8, root.getContentHandler()); - - return search.getCurrentId(); - } catch (Exception e) { - Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": " + e.toString()); + fis = new FileInputStream(file); + } catch (FileNotFoundException e) { + Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": file not found!"); } - - return 0l; + try { + Xml.parse(fis, Xml.Encoding.UTF_8, root.getContentHandler()); + parsed = true; + } catch (IOException e) { + Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": could not read file!"); + } catch (SAXException e) { + Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": could not parse XML - " + e.toString()); + } + try { + fis.close(); + } catch (IOException e) { + Log.e(cgSettings.tag, "Error after parsing .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": could not close file!"); + } + return parsed ? search.getCurrentId() : 0l; } } diff --git a/src/cgeo/geocaching/cgHtmlImg.java b/src/cgeo/geocaching/cgHtmlImg.java index 36fc1fc..f3e9f20 100644 --- a/src/cgeo/geocaching/cgHtmlImg.java +++ b/src/cgeo/geocaching/cgHtmlImg.java @@ -230,11 +230,11 @@ public class cgHtmlImg implements Html.ImageGetter { while ((l = is.read(buffer)) != -1) { fos.write(buffer, 0, l); } + fos.flush(); } catch (IOException e) { Log.e(cgSettings.tag, "cgHtmlImg.getDrawable (saving to cache): " + e.toString()); } finally { is.close(); - fos.flush(); fos.close(); } } diff --git a/src/cgeo/geocaching/cgMapImg.java b/src/cgeo/geocaching/cgMapImg.java index 207971a..1ab8cdb 100644 --- a/src/cgeo/geocaching/cgMapImg.java +++ b/src/cgeo/geocaching/cgMapImg.java @@ -86,12 +86,12 @@ public class cgMapImg { fos.write(buffer, 0, bytesRead); fileSize += bytesRead; } + fos.flush(); ok = true; } catch (IOException e) { Log.e(cgSettings.tag, "cgMapImg.getDrawable (saving to cache): " + e.toString()); } finally { is.close(); - fos.flush(); fos.close(); } |
