2017-05-28 54 views
1

我想從我得到的三星S健康SDK的BLOB文件中獲取數據。 我實際上做的是:從BLOB文件恢復數據S健康

Cursor c = null; 
int i = 0; 
c = result.getResultCursor(); 

if (c != null) { 
    while (c.moveToNext()) { 
     byte[] live_data = c.getBlob(c.getColumnIndex(HealthConstants.Exercise.LIVE_DATA)); 
     if (live_data != null) { 

      // Do something with data. 


     } else { 
      Log.d(APP_TAG, "there is no live data."); 
     } 
    } 
} else { 
    Log.d(APP_TAG, "There is no result."); 
} 

「live_data」是包含了所有數據的JSON一個壓縮文件。 我試圖用ZipInputStream解壓縮它沒有成功。 我該怎麼辦?

回答

0

最後,我在幾次嘗試後找到了解決方案。 問題在於blob文件是gzip文件。 下面是一個簡單的代碼來解壓縮字節數組(在我的情況live_data):

ByteArrayInputStream inputStream = new ByteArrayInputStream(live_data); 
GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream); 
BufferedReader bf = new BufferedReader(new 
InputStreamReader(gzipInputStream, "UTF-8")); 
String outStr = ""; 
String line; 
while ((line=bf.readLine())!=null) { 
    outStr += line; 
} 

哪裏outStr是我想要檢索和live_data是塊字節數組文件的內容。 我希望這可以幫助別人。