Search in sources :

Example 1 with CloudPageBlob

use of com.microsoft.azure.storage.blob.CloudPageBlob in project camel by apache.

the class BlobServiceProducer method uploadPageBlob.

private void uploadPageBlob(Exchange exchange) throws Exception {
    LOG.trace("Updating a page blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange);
    CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration());
    configureCloudBlobForWrite(client);
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    if (opts.getAccessCond() == null) {
        // Default: do not reset the blob content if the blob already exists
        opts.setAccessCond(AccessCondition.generateIfNotExistsCondition());
    }
    Boolean pageBlobCreated = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOCK_CREATED, Boolean.class);
    if (Boolean.TRUE != pageBlobCreated) {
        doCreatePageBlob(client, opts, exchange);
    }
    InputStream inputStream = getInputStreamFromExchange(exchange);
    doUpdatePageBlob(client, inputStream, opts, exchange);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Example 2 with CloudPageBlob

use of com.microsoft.azure.storage.blob.CloudPageBlob in project camel by apache.

the class BlobServiceProducer method resizePageBlob.

private void resizePageBlob(Exchange exchange) throws Exception {
    LOG.trace("Resizing a page blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange);
    CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration());
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    Long pageSize = getPageBlobSize(exchange);
    client.resize(pageSize, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
}
Also used : CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Example 3 with CloudPageBlob

use of com.microsoft.azure.storage.blob.CloudPageBlob in project camel by apache.

the class BlobServiceUtil method doGetBlob.

private static void doGetBlob(CloudBlob client, Exchange exchange, BlobServiceConfiguration cfg) throws Exception {
    BlobServiceUtil.configureCloudBlobForRead(client, cfg);
    BlobServiceRequestOptions opts = getRequestOptions(exchange);
    LOG.trace("Getting a blob [{}] from exchange [{}]...", cfg.getBlobName(), exchange);
    OutputStream os = exchange.getIn().getBody(OutputStream.class);
    if (os == null) {
        String fileDir = cfg.getFileDir();
        if (fileDir != null) {
            File file = new File(fileDir, getBlobFileName(cfg));
            ExchangeUtil.getMessageForResponse(exchange).setBody(file);
            os = new FileOutputStream(file);
        }
    }
    try {
        if (os == null) {
            // Let the producers like file: deal with it
            InputStream blobStream = client.openInputStream(opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
            exchange.getIn().setBody(blobStream);
            exchange.getIn().setHeader(Exchange.FILE_NAME, getBlobFileName(cfg));
        } else {
            Long blobOffset = cfg.getBlobOffset();
            Long blobDataLength = cfg.getDataLength();
            if (client instanceof CloudPageBlob) {
                PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class);
                if (range != null) {
                    blobOffset = range.getStartOffset();
                    blobDataLength = range.getEndOffset() - range.getStartOffset();
                }
            }
            client.downloadRange(blobOffset, blobDataLength, os, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
        }
    } finally {
        if (os != null && cfg.isCloseStreamAfterRead()) {
            os.close();
        }
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) PageRange(com.microsoft.azure.storage.blob.PageRange)

Example 4 with CloudPageBlob

use of com.microsoft.azure.storage.blob.CloudPageBlob in project camel by apache.

the class BlobServiceUtil method getPageBlob.

private static void getPageBlob(Exchange exchange, BlobServiceConfiguration cfg) throws Exception {
    CloudPageBlob client = createPageBlobClient(cfg);
    doGetBlob(client, exchange, cfg);
}
Also used : CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Example 5 with CloudPageBlob

use of com.microsoft.azure.storage.blob.CloudPageBlob in project camel by apache.

the class BlobServiceProducer method clearPageBlob.

private void clearPageBlob(Exchange exchange) throws Exception {
    LOG.trace("Clearing a page blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange);
    CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration());
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    Long blobOffset = getConfiguration().getBlobOffset();
    Long blobDataLength = getConfiguration().getDataLength();
    PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class);
    if (range != null) {
        blobOffset = range.getStartOffset();
        blobDataLength = range.getEndOffset() - range.getStartOffset();
    }
    if (blobDataLength == null) {
        blobDataLength = blobOffset == 0 ? getPageBlobSize(exchange) : 512L;
    }
    client.clearPages(blobOffset, blobDataLength, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
}
Also used : CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) PageRange(com.microsoft.azure.storage.blob.PageRange)

Aggregations

CloudPageBlob (com.microsoft.azure.storage.blob.CloudPageBlob)10 PageRange (com.microsoft.azure.storage.blob.PageRange)3 InputStream (java.io.InputStream)2 StorageCredentials (com.microsoft.azure.storage.StorageCredentials)1 StorageException (com.microsoft.azure.storage.StorageException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1