8000 fixed return so that is AssetFileDescriptor not MemoryFile using Refl… · Sjith/android-database-sqlcipher@b5ecbd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5ecbd0

Browse files
committed
fixed return so that is AssetFileDescriptor not MemoryFile using Reflection
1 parent 91b270b commit b5ecbd0

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/info/guardianproject/database/sqlcipher/SQLiteContentHelper.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,29 @@ public class SQLiteContentHelper {
4545
* value of column 0 is NULL, or if there is an error creating the
4646
* asset file descriptor.
4747
*/
48-
public static MemoryFile getBlobColumnAsAssetFile(SQLiteDatabase db, String sql,
49-
String[] selectionArgs) throws FileNotFoundException {
50-
try {
51-
MemoryFile file = simpleQueryForBlobMemoryFile(db, sql, selectionArgs);
52-
if (file == null) {
53-
throw new FileNotFoundException("No results.");
54-
}
55-
return file;
56-
} catch (IOException ex) {
57-
throw new FileNotFoundException(ex.toString());
58-
}
59-
}
48+
public static AssetFileDescriptor getBlobColumnAsAssetFile(SQLiteDatabase db, String sql,
49+
String[] selectionArgs) throws FileNotFoundException {
50+
android.os.ParcelFileDescriptor fd = null;
51+
52+
try {
53+
MemoryFile file = simpleQueryForBlobMemoryFile(db, sql, selectionArgs);
54+
if (file == null) {
55+
throw new FileNotFoundException("No results.");
56+
}
57+
Class c = file.getClass();
58+
try {
59+
java.lang.reflect.Method m = c.getDeclaredMethod("getParcelFileDescriptor");
60+
m.setAccessible(true);
61+
fd = (android.os.ParcelFileDescriptor)m.invoke(file);
62+
} catch (Exception e) {
63+
android.util.Log.i("SQLiteContentHelper", "SQLiteCursor.java: " + e);
64+
}
65+
AssetFileDescriptor afd = new AssetFileDescriptor(fd, 0, file.length());
66+
return afd;
67+
} catch (IOException ex) {
68+
throw new FileNotFoundException(ex.toString());
69+
}
70+
}
6071

6172
/**
6273
* Runs an SQLite query and returns a MemoryFile for the
@@ -84,6 +95,7 @@ private static MemoryFile simpleQueryForBlobMemoryFile(SQLiteDatabase db, String
8495
}
8596
MemoryFile file = new MemoryFile(null, bytes.length);
8697
file.writeBytes(bytes, 0, 0, bytes.length);
98+
8799
// file.deactivate();
88100
return file;
89101
} finally {

0 commit comments

Comments
 (0)
0