You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/12/13 17:18:11 UTC
[15/15] git commit: Android: Clean up unclosed file objects
Android: Clean up unclosed file objects
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/5df7f190
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/5df7f190
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/5df7f190
Branch: refs/heads/android-file
Commit: 5df7f190fab683f7629ba01840731e92e338f8ea
Parents: 9125371
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Dec 2 15:53:43 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Dec 11 10:00:11 2013 -0500
----------------------------------------------------------------------
src/android/LocalFilesystem.java | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5df7f190/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index adb3ef6..be1d2d1 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -537,19 +537,20 @@ public class LocalFilesystem implements Filesystem {
String contentType;
File file = new File(this.filesystemPathForURL(inputURL));
- InputStream inputStream = new FileInputStream(file);
-
contentType = FileHelper.getMimeTypeForExtension(file.getAbsolutePath());
+
+ InputStream inputStream = new FileInputStream(file);
int numBytesRead = 0;
-
- if (start > 0) {
- inputStream.skip(start);
- }
-
- while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
- numBytesToRead -= numBytesRead;
+ try {
+ if (start > 0) {
+ inputStream.skip(start);
+ }
+ while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
+ numBytesToRead -= numBytesRead;
+ }
+ } finally {
+ inputStream.close();
}
- inputStream.close();
readFileCallback.handleData(bytes, contentType);
}
@@ -572,12 +573,16 @@ public class LocalFilesystem implements Filesystem {
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
try
{
+ byte buff[] = new byte[rawData.length];
FileOutputStream out = new FileOutputStream(this.filesystemPathForURL(inputURL), append);
- byte buff[] = new byte[rawData.length];
- in.read(buff, 0, buff.length);
- out.write(buff, 0, rawData.length);
- out.flush();
- out.close();
+ try {
+ in.read(buff, 0, buff.length);
+ out.write(buff, 0, rawData.length);
+ out.flush();
+ } finally {
+ // Always close the output
+ out.close();
+ }
}
catch (NullPointerException e)
{