コード例 #1
0
ファイル: PartDatabase.java プロジェクト: sky921/SMSSecure
  private void getPartValues(PduPart part, Cursor cursor) {

    part.setRowId(cursor.getLong(cursor.getColumnIndexOrThrow(ROW_ID)));
    part.setUniqueId(cursor.getLong(cursor.getColumnIndexOrThrow(UNIQUE_ID)));

    int charsetColumn = cursor.getColumnIndexOrThrow(CHARSET);

    if (!cursor.isNull(charsetColumn)) part.setCharset(cursor.getInt(charsetColumn));

    int contentTypeColumn = cursor.getColumnIndexOrThrow(CONTENT_TYPE);

    if (!cursor.isNull(contentTypeColumn))
      part.setContentType(Util.toIsoBytes(cursor.getString(contentTypeColumn)));

    int nameColumn = cursor.getColumnIndexOrThrow(NAME);

    if (!cursor.isNull(nameColumn)) part.setName(Util.toIsoBytes(cursor.getString(nameColumn)));

    int fileNameColumn = cursor.getColumnIndexOrThrow(FILENAME);

    if (!cursor.isNull(fileNameColumn))
      part.setFilename(Util.toIsoBytes(cursor.getString(fileNameColumn)));

    int contentDispositionColumn = cursor.getColumnIndexOrThrow(CONTENT_DISPOSITION);

    if (!cursor.isNull(contentDispositionColumn))
      part.setContentDisposition(Util.toIsoBytes(cursor.getString(contentDispositionColumn)));

    int contentIdColumn = cursor.getColumnIndexOrThrow(CONTENT_ID);

    if (!cursor.isNull(contentIdColumn))
      part.setContentId(Util.toIsoBytes(cursor.getString(contentIdColumn)));

    int contentLocationColumn = cursor.getColumnIndexOrThrow(CONTENT_LOCATION);

    if (!cursor.isNull(contentLocationColumn))
      part.setContentLocation(Util.toIsoBytes(cursor.getString(contentLocationColumn)));

    int encryptedColumn = cursor.getColumnIndexOrThrow(ENCRYPTED);

    if (!cursor.isNull(encryptedColumn)) part.setEncrypted(cursor.getInt(encryptedColumn) == 1);

    int pendingPushColumn = cursor.getColumnIndexOrThrow(PENDING_PUSH_ATTACHMENT);

    if (!cursor.isNull(pendingPushColumn))
      part.setPendingPush(cursor.getInt(pendingPushColumn) == 1);

    int sizeColumn = cursor.getColumnIndexOrThrow(SIZE);

    if (!cursor.isNull(sizeColumn))
      part.setDataSize(cursor.getLong(cursor.getColumnIndexOrThrow(SIZE)));
  }
コード例 #2
0
ファイル: PartDatabase.java プロジェクト: sky921/SMSSecure
  public void updatePartData(MasterSecret masterSecret, PduPart part, InputStream data)
      throws MmsException {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    Pair<File, Long> partData = writePartData(masterSecret, part, data);

    if (partData == null) throw new MmsException("couldn't update part data");

    Cursor cursor = null;
    try {
      cursor =
          database.query(
              TABLE_NAME,
              new String[] {DATA},
              PART_ID_WHERE,
              part.getPartId().toStrings(),
              null,
              null,
              null);

      if (cursor != null && cursor.moveToFirst()) {
        int dataColumn = cursor.getColumnIndexOrThrow(DATA);
        if (!cursor.isNull(dataColumn) && !new File(cursor.getString(dataColumn)).delete()) {
          Log.w(TAG, "Couldn't delete old part file");
        }
      }
    } finally {
      if (cursor != null) cursor.close();
    }
    ContentValues values = new ContentValues(2);
    values.put(DATA, partData.first.getAbsolutePath());
    values.put(SIZE, partData.second);

    part.setDataSize(partData.second);

    database.update(TABLE_NAME, values, PART_ID_WHERE, part.getPartId().toStrings());
    Log.w(TAG, "updated data for part #" + part.getPartId());
  }