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);
}
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());
}
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();
}
}
}
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);
}
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());
}
Aggregations