I am reading blobs with size between 100kb and 1000kb from SQlite in my Android App using the following code :
public Object getCachefromDb(String sIdentifier){
String sSQL = " Select cache from cachtable where identifier='" + sIdentifier + "'";
Cursor c = null;
try {
c = connection_chronica.rawQuery(sSQL, null);
} catch (SQLiteException e) {
Log.v("SQLite Excetion", e.getMessage());
}
c.moveToFirst();
Log.v("DEBUG load Cache","sIdentifier : " + sIdentifier);
byte[] bData=null;
try{
bData = c.getBlob(0);
}catch(Exception e){
e.printStackTrace();
}
Object o = null;
if (bData!=null){
ByteArrayInputStream bos = new ByteArrayInputStream(bData);
ObjectInputStream ois;
try {
ois = new ObjectInputStream(bos);
o=ois.readObject();
} catch (StreamCorruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
c.close();
return o;
}
I would like to optimize the speed of reading and I found articles mentoining simpleQueryForBlobFileDescriptor.
My question : Does this help me reading BLOBS faster ? and if so how can I use it ?
Example from other posts:
SQLiteStatement get = mDb.compileStatement(
"SELECT blobColumn" +
" FROM tableName" +
" WHERE _id = 1" +
" LIMIT 1"
);
ParcelFileDescriptor result = get.simpleQueryForBlobFileDescriptor();
FileInputStream fis = new FileInputStream(result.getFileDescriptor()); // read like any other