Пример #1
0
  public long getSize() throws MessagingException {

    final StorageManager storageManager = StorageManager.getInstance(context);

    final File attachmentDirectory =
        storageManager.getAttachmentDirectory(uUid, database.getStorageProviderId());

    return database.execute(
        false,
        new DbCallback<Long>() {
          @Override
          public Long doDbWork(final SQLiteDatabase db) {
            final File[] files = attachmentDirectory.listFiles();
            long attachmentLength = 0;
            if (files != null) {
              for (File file : files) {
                if (file.exists()) {
                  attachmentLength += file.length();
                }
              }
            }

            final File dbFile = storageManager.getDatabase(uUid, database.getStorageProviderId());
            return dbFile.length() + attachmentLength;
          }
        });
  }
Пример #2
0
  private void deleteAllMessagePartsDataFromDisk() {
    final StorageManager storageManager = StorageManager.getInstance(context);
    File attachmentDirectory =
        storageManager.getAttachmentDirectory(uUid, database.getStorageProviderId());
    File[] files = attachmentDirectory.listFiles();
    if (files == null) {
      return;
    }

    for (File file : files) {
      if (file.exists() && !file.delete()) {
        file.deleteOnExit();
      }
    }
  }
Пример #3
0
 File getAttachmentFile(String attachmentId) {
   final StorageManager storageManager = StorageManager.getInstance(context);
   final File attachmentDirectory =
       storageManager.getAttachmentDirectory(uUid, database.getStorageProviderId());
   return new File(attachmentDirectory, attachmentId);
 }