Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
infil00p committed Jun 3, 2013
2 parents bc52345 + c28a313 commit 12d06bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
16 changes: 11 additions & 5 deletions framework/src/org/apache/cordova/FileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ public static InputStream getInputStreamFromUriString(String uriString, CordovaI
if (uriString.startsWith("content:")) {
Uri uri = Uri.parse(uriString);
return cordova.getActivity().getContentResolver().openInputStream(uri);
} else if (uriString.startsWith("file:///android_asset/")) {
Uri uri = Uri.parse(uriString);
String relativePath = uri.getPath().substring(15);
return cordova.getActivity().getAssets().open(relativePath);
} else if (uriString.startsWith("file://")) {
return new FileInputStream(getRealPath(uriString, cordova));
int question = uriString.indexOf("?");
if (question > -1) {
uriString = uriString.substring(0,question);
}
if (uriString.startsWith("file:///android_asset/")) {
Uri uri = Uri.parse(uriString);
String relativePath = uri.getPath().substring(15);
return cordova.getActivity().getAssets().open(relativePath);
} else {
return new FileInputStream(getRealPath(uriString, cordova));
}
} else {
return null;
}
Expand Down
19 changes: 7 additions & 12 deletions framework/src/org/apache/cordova/FileTransfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -855,20 +855,15 @@ public void run() {
* @throws FileNotFoundException
*/
private InputStream getPathFromUri(String path) throws FileNotFoundException {
if (path.startsWith("content:")) {
Uri uri = Uri.parse(path);
return cordova.getActivity().getContentResolver().openInputStream(uri);
}
else if (path.startsWith("file://")) {
int question = path.indexOf("?");
if (question == -1) {
return new FileInputStream(path.substring(7));
try {
InputStream stream = FileHelper.getInputStreamFromUriString(path, cordova);
if (stream == null) {
return new FileInputStream(path);
} else {
return new FileInputStream(path.substring(7, question));
return stream;
}
}
else {
return new FileInputStream(path);
} catch (IOException e) {
throw new FileNotFoundException();
}
}

Expand Down

0 comments on commit 12d06bd

Please sign in to comment.