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; } }); }
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(); } } }
File getAttachmentFile(String attachmentId) { final StorageManager storageManager = StorageManager.getInstance(context); final File attachmentDirectory = storageManager.getAttachmentDirectory(uUid, database.getStorageProviderId()); return new File(attachmentDirectory, attachmentId); }