aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2011-10-13 18:47:02 -0700
committerRaphael <raphael@google.com>2011-10-13 18:47:02 -0700
commit796b6c0491833587ba096a33bd0d34329f6213c5 (patch)
tree714a82b04d421e61f18947d919e6f539b78596b4 /ddms/libs
parent694eb6d79041e6ce66cd3830456826b6015d375a (diff)
downloadsdk-796b6c0491833587ba096a33bd0d34329f6213c5.zip
sdk-796b6c0491833587ba096a33bd0d34329f6213c5.tar.gz
sdk-796b6c0491833587ba096a33bd0d34329f6213c5.tar.bz2
Code cleanup: make sure FileInputStreams are closed.
Various places of the code construct a new FileInputStream on the fly and give it to another method. One many occasions the stream is never properly closed, which can lock files on Windows. 2 specific cases: - Properties.load() doesn't seem to close its input (when looking at the source bundled with the JRE). - The doc of InputSource (used by various XML parsers like the pull parser) indicates the caller should in general not close the stream and the parser itself should do it. Change-Id: I622b54a22f97ed2c9c8fdc56ccde331207d9d212
Diffstat (limited to 'ddms/libs')
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/BugReportImporter.java23
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogImporter.java13
2 files changed, 28 insertions, 8 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/BugReportImporter.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/BugReportImporter.java
index 9de1ac7..da41e70 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/BugReportImporter.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/BugReportImporter.java
@@ -24,14 +24,14 @@ import java.io.InputStreamReader;
import java.util.ArrayList;
public class BugReportImporter {
-
+
private final static String TAG_HEADER = "------ EVENT LOG TAGS ------";
private final static String LOG_HEADER = "------ EVENT LOG ------";
private final static String HEADER_TAG = "------";
-
+
private String[] mTags;
private String[] mLog;
-
+
public BugReportImporter(String filePath) throws FileNotFoundException {
BufferedReader reader = new BufferedReader(
new InputStreamReader(new FileInputStream(filePath)));
@@ -45,20 +45,27 @@ public class BugReportImporter {
}
}
} catch (IOException e) {
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException ignore) {
+ }
+ }
}
}
-
+
public String[] getTags() {
return mTags;
}
-
+
public String[] getLog() {
return mLog;
}
private void readTags(BufferedReader reader) throws IOException {
String line;
-
+
ArrayList<String> content = new ArrayList<String>();
while ((line = reader.readLine()) != null) {
if (LOG_HEADER.equals(line)) {
@@ -82,8 +89,8 @@ public class BugReportImporter {
break;
}
}
-
+
mLog = content.toArray(new String[content.size()]);
}
-
+
}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogImporter.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogImporter.java
index a1303f6..011bcf1 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogImporter.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogImporter.java
@@ -47,6 +47,19 @@ public class EventLogImporter {
readTags(tagReader);
readLog(eventReader);
} catch (IOException e) {
+ } finally {
+ if (tagReader != null) {
+ try {
+ tagReader.close();
+ } catch (IOException ignore) {
+ }
+ }
+ if (eventReader != null) {
+ try {
+ eventReader.close();
+ } catch (IOException ignore) {
+ }
+ }
}
}