List of usage examples for android.database Cursor getBlob
byte[] getBlob(int columnIndex);
From source file:mobisocial.socialkit.musubi.Musubi.java
public DbObj objForId(long localId) { Cursor cursor = mContext.getContentResolver().query(DbObj.OBJ_URI, new String[] { DbObj.COL_APP_ID, DbObj.COL_TYPE, DbObj.COL_STRING_KEY, DbObj.COL_JSON, DbObj.COL_RAW, DbObj.COL_IDENTITY_ID, DbObj.COL_UNIVERSAL_HASH, DbObj.COL_FEED_ID, DbObj.COL_INT_KEY, DbObj.COL_TIMESTAMP, DbObj.COL_PARENT_ID }, DbObj.COL_ID + " = ?", new String[] { String.valueOf(localId) }, null); try {/*w w w . j a v a 2s.c o m*/ if (cursor == null || !cursor.moveToFirst()) { Log.w(TAG, "Obj " + localId + " not found."); return null; } final String appId = cursor.getString(0); final String type = cursor.getString(1); final String name = cursor.getString(2); final JSONObject json = new JSONObject(cursor.getString(3)); final byte[] raw = cursor.isNull(4) ? null : cursor.getBlob(4); final long senderId = cursor.getLong(5); final byte[] hash = cursor.getBlob(6); final long feedId = cursor.getLong(7); final Integer intKey = cursor.isNull(8) ? null : cursor.getInt(8); final long timestamp = cursor.getLong(9); Long parentId = cursor.isNull(10) ? null : cursor.getLong(10); return new DbObj(this, appId, feedId, parentId, senderId, localId, type, json, raw, intKey, name, timestamp, hash); } catch (JSONException e) { Log.e(TAG, "Couldn't parse obj.", e); return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:ru.gkpromtech.exhibition.db.Table.java
private void fillFieldValue(int type, Field field, Object entity, Cursor cursor, int i) throws IllegalAccessException { if (cursor.isNull(i)) { field.set(entity, null);/*ww w . j a va2 s. c o m*/ return; } switch (type) { case INTEGER: field.set(entity, cursor.getInt(i)); break; case SHORT: field.set(entity, cursor.getShort(i)); break; case LONG: field.set(entity, cursor.getLong(i)); break; case FLOAT: field.set(entity, cursor.getFloat(i)); break; case DOUBLE: field.set(entity, cursor.getDouble(i)); break; case STRING: field.set(entity, cursor.getString(i)); break; case BYTE_ARRAY: field.set(entity, cursor.getBlob(i)); break; case DATE: field.set(entity, new Date(cursor.getLong(i))); break; case BOOLEAN: field.set(entity, cursor.getInt(i) != 0); break; } }
From source file:org.jumpmind.symmetric.android.AndroidSqlTemplate.java
@SuppressWarnings("unchecked") protected <T> T get(Cursor cursor, Class<T> clazz, int columnIndex) { Object result = null;/* w w w . ja v a 2 s . c om*/ if (clazz.equals(String.class)) { result = (String) cursor.getString(columnIndex); } else if (clazz.equals(Integer.class)) { result = (Integer) cursor.getInt(columnIndex); } else if (clazz.equals(Integer.class)) { result = (Double) cursor.getDouble(columnIndex); } else if (clazz.equals(Float.class)) { result = (Float) cursor.getFloat(columnIndex); } else if (clazz.equals(Long.class)) { result = (Long) cursor.getLong(columnIndex); } else if (clazz.equals(Date.class) || clazz.equals(Timestamp.class)) { String dateString = cursor.getString(columnIndex); if (dateString.contains("-")) { result = Timestamp.valueOf(dateString); } else { result = new Timestamp(Long.parseLong(dateString)); } } else if (clazz.equals(Short.class)) { result = (Short) cursor.getShort(columnIndex); } else if (clazz.equals(byte[].class)) { result = (byte[]) cursor.getBlob(columnIndex); } else { throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); } return (T) result; }
From source file:com.android.mtkex.chips.BaseRecipientAdapter.java
/** * M: For updating PhotoCacheMap// w ww .j av a2 s . c om * @param photoThumbnailUri Uri for photo Thumbnail * @hide */ public void updatePhotoCacheByUri(final Uri photoThumbnailUri) { if (photoThumbnailUri == null) { return; } final Cursor photoCursor = mContentResolver.query(photoThumbnailUri, PhotoQuery.PROJECTION, null, null, null); if (photoCursor != null) { try { if (photoCursor.moveToFirst()) { byte[] photoBytes = photoCursor.getBlob(PhotoQuery.PHOTO); mPhotoCacheMap.put(photoThumbnailUri, photoBytes); } } finally { photoCursor.close(); } } }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public byte[] firstBlob(SQLiteDatabase db, String table, String column, String orderBy) { Cursor cursor = null; byte[] value = null; try {//from w ww.j av a2 s. co m cursor = query(db, table, new String[] { column }, orderBy); if (cursor.moveToFirst()) { value = cursor.getBlob(0); } } finally { Closeables.closeSilently(cursor); } return value; }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public byte[] firstBlob(Uri uri, String column, String orderBy) { Cursor cursor = null; byte[] value = null; try {/*from w w w .ja va 2 s . c o m*/ cursor = select(uri, new String[] { column }, orderBy, false); if (cursor.moveToFirst()) { value = cursor.getBlob(0); } } finally { Closeables.closeSilently(cursor); } return value; }
From source file:com.dileepindia.cordova.sms.SMSPlugin.java
private JSONObject getJsonFromCursor(Cursor cur) { JSONObject json = new JSONObject(); int nCol = cur.getColumnCount(); String[] keys = cur.getColumnNames(); try {/*from w ww .j av a2 s. c om*/ for (int j = 0; j < nCol; j++) { switch (cur.getType(j)) { /*case 0: json.put(keys[j], null); break; case 1: json.put(keys[j], cur.getInt(j)); break; case 2: json.put(keys[j], cur.getLong(j)); break; case 3: json.put(keys[j], cur.getFloat(j)); break; case 4: json.put(keys[j], cur.getString(j)); break; case 5: json.put(keys[j], cur.getBlob(j)); */ case Cursor.FIELD_TYPE_BLOB: json.put(keys[j], cur.getBlob(j).toString()); break; case Cursor.FIELD_TYPE_FLOAT: json.put(keys[j], cur.getDouble(j)); break; case Cursor.FIELD_TYPE_INTEGER: json.put(keys[j], cur.getLong(j)); break; case Cursor.FIELD_TYPE_NULL: json.put(keys[j], cur); break; case Cursor.FIELD_TYPE_STRING: json.put(keys[j], cur.getString(j)); break; } } } catch (Exception e) { e.printStackTrace(); return null; } return json; }
From source file:io.github.mkjung.ivi.media.MediaDatabase.java
public synchronized Bitmap getPicture(Uri uri) { /* Used for the lazy loading */ Cursor cursor; Bitmap picture = null;//from www . j a v a 2 s . com byte[] blob; cursor = mDb.query(MEDIA_TABLE_NAME, new String[] { MEDIA_PICTURE }, MEDIA_LOCATION + "=?", new String[] { uri.toString() }, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { blob = cursor.getBlob(0); if (blob != null && blob.length > 1 && blob.length < 500000) { try { picture = BitmapFactory.decodeByteArray(blob, 0, blob.length); } catch (OutOfMemoryError e) { picture = null; } finally { blob = null; } } } cursor.close(); } return picture; }
From source file:org.sufficientlysecure.keychain.provider.ProviderHelper.java
public HashMap<String, Object> getGenericData(Uri uri, String[] proj, int[] types) throws NotFoundException { Cursor cursor = mContentResolver.query(uri, proj, null, null, null); try {/* w w w. j av a 2 s . c om*/ HashMap<String, Object> result = new HashMap<String, Object>(proj.length); if (cursor != null && cursor.moveToFirst()) { int pos = 0; for (String p : proj) { switch (types[pos]) { case FIELD_TYPE_NULL: result.put(p, cursor.isNull(pos)); break; case FIELD_TYPE_INTEGER: result.put(p, cursor.getLong(pos)); break; case FIELD_TYPE_FLOAT: result.put(p, cursor.getFloat(pos)); break; case FIELD_TYPE_STRING: result.put(p, cursor.getString(pos)); break; case FIELD_TYPE_BLOB: result.put(p, cursor.getBlob(pos)); break; } pos += 1; } } return result; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public byte[][] selectBlobArray(Uri uri, String column, String orderBy) { Cursor cursor = null; try {/*from www . j a v a 2 s .c o m*/ cursor = select(uri, new String[] { column }, orderBy, false); byte[][] array = new byte[cursor.getCount()][]; for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToNext(); array[i] = cursor.getBlob(0); } return array; } finally { Closeables.closeSilently(cursor); } }