&& blobDS.isCompressed()) .ok(blobDS.getInputStream(), MediaType.TEXT_PLAIN) .header(HttpHeaders.CONTENT_ENCODING, "deflate").build(); } else { response = Response.ok(blobDS.getUncompressedInputStream(), MediaType.TEXT_PLAIN).build();
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; } }
@Override public InputStream getMessage(String uid) throws IOException { UUID uuid = Base64UUIDUtils.decode(uid); logger.debug("POP3: Get message {}/{} [{}]", mailbox, uuid, uid); try { InputStream is = dao.getRaw(mailbox, uuid).getUncompressedInputStream(); return new CRLFInputStream(is); } catch (Exception e) { logger.error("Error occured while retreiving POP3 message " + mailbox + "/" + uuid + " :", e); throw new IOException("Unable to read message"); } }
/** * Returns Blob data and ensures that content is always uncompressed. * If not compressed, original Blob will be returned. * <p> * Use this method if you want to ensure that data is always uncompressed. * * @return * @throws IOException */ public InputStream getUncompressedInputStream() throws IOException { if (this.isCompressed()) { return this.compressionHandler.uncompress(in); } else { return in; } }
@Override public BlobDataSource read(final URI uri) throws IOException { logger.debug("Reading blob {} from Cassandra", uri); BlobURI blobUri = new BlobURI().fromURI(uri); Assert.isTrue(blobUri.getProfile().equals(DATABASE_PROFILE), "Blob store profile does not match database."); UUID messageId = UUID.fromString(blobUri.getName()); byte[] messageBlock = BlobPersistence.readBlock(messageId, DATABASE_DEFAULT_BLOCK_ID); InputStream in = ByteStreams.newInputStreamSupplier(messageBlock).getInput(); return new BlobDataSource(uri, in); }
rawIn = messageDAO.getRaw(mailbox, messageId).getUncompressedInputStream(); MimeParser mimeParser = new MimeParser(); mimeParser.parse(rawIn);
@Override public BlobDataSource read(final URI uri) throws IOException { InputStream in; BlobURI blobUri = new BlobURI().fromURI(uri); String keyAlias = blobUri.getEncryptionKey(); if (keyAlias != null) { // currently we only support AES encryption, use by default EncryptionHandler eh = new AESEncryptionHandler(); try { logger.debug("Decrypting object {} with key {}", uri, keyAlias); byte[] iv = getCipherIVFromBlobName(BlobUtils.relativize(uri.getPath())); in = eh.decrypt(CloudStoreProxy.read(uri), Configurator.getEncryptionKey(keyAlias), iv); } catch (GeneralSecurityException gse) { throw new IOException("Unable to decrypt message blob: ", gse); } } else { in = CloudStoreProxy.read(uri); } return new BlobDataSource(uri, in); }
rawIn = messageDAO.getRaw(mailbox, messageId).getUncompressedInputStream(); MimeParser mimeParser = new MimeParser(); mimeParser.parse(rawIn);