public BlobURI write( final UUID messageId, final Mailbox mailbox, final String profileName, final InputStream in, final Long size) throws IOException, GeneralSecurityException { Assert.notNull(in, "No data to store"); BlobURI blobUri; InputStream in1; Long updatedSize = size; boolean compressed = false; // compress stream and calculate compressed size if ((compressionHandler != null) && (size > MIN_COMPRESS_SIZE)) { InputStream compressedInputStream = compressionHandler.compress(in); FileBackedOutputStream fbout = new FileBackedOutputStream(MAX_MEMORY_FILE_SIZE, true); updatedSize = ByteStreams.copy(compressedInputStream, fbout); in1 = fbout.getSupplier().getInput(); compressed = true; } else { in1 = in; } if (updatedSize <= Configurator.getDatabaseBlobMaxSize()) { logger.debug( "Storing Blob in the database because size ({}KB) was less than database threshold {}KB", updatedSize, Configurator.getDatabaseBlobMaxSize()); blobUri = dbBlobStorage.write(messageId, mailbox, null, in1, updatedSize); } else { logger.debug( "Storing Blob in the cloud because size ({}KB) was greater than database threshold {}KB", updatedSize, Configurator.getDatabaseBlobMaxSize()); blobUri = cloudBlobStorage.write( messageId, mailbox, Configurator.getBlobStoreWriteProfileName(), in1, updatedSize); } // add compression information to the blob URI if (compressed) { blobUri.setCompression(compressionHandler.getType()); } return blobUri; }
/** * Get quota (maximum) messages for the given mailbox * * @param mailbox * @return */ public Long getQuotaCount(final Mailbox mailbox) { // TODO: add account quota attribute check return Configurator.getDefaultQuotaCount(); }