【发布时间】:2014-03-21 20:28:43
【问题描述】:
我正在使用以下代码从我的 Android 应用程序中的 SQlite 读取大小在 100kb 和 1000kb 之间的 blob:
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;
}
我想优化阅读速度,发现有文章提到 simpleQueryForBlobFileDescriptor。
我的问题:这有助于我更快地阅读 BLOBS 吗?如果是这样,我该如何使用它?
来自其他帖子的示例:
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
【问题讨论】: