コード例 #1
0
  public BlobDataSource read(final URI uri) throws IOException {
    // check if blob was stored for the message
    Assert.notNull(uri, "URI cannot be null");

    BlobDataSource blobDS;
    BlobURI blobUri = new BlobURI().fromURI(uri);

    if (blobUri.getProfile().equals(DatabaseConstants.DATABASE_PROFILE)) {
      blobDS = dbBlobStorage.read(uri);
    } else {
      blobDS = cloudBlobStorage.read(uri);
    }

    // if compressed, add compression handler to data source
    if ((blobUri.getCompression() != null
            && blobUri.getCompression().equals(DeflateCompressionHandler.COMPRESSION_TYPE_DEFLATE))
        ||
        // TODO: deprecated suffix based compression detection
        // kept for backward compatibility with 0.3
        blobUri.getName().endsWith(BlobStoreConstants.COMPRESS_SUFFIX)) {
      CompressionHandler ch = new DeflateCompressionHandler();
      return new BlobDataSource(uri, blobDS.getInputStream(), ch);
    } else {
      return blobDS;
    }
  }
コード例 #2
0
  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;
  }