Search in sources :

Example 1 with DownloadResponse

use of com.microsoft.azure.storage.blob.DownloadResponse in project geowebcache by GeoWebCache.

the class AzureClient method getBytes.

@Nullable
public byte[] getBytes(String key) throws StorageException {
    BlockBlobURL blob = getBlockBlobURL(key);
    try {
        DownloadResponse response = blob.download().blockingGet();
        ByteBuffer buffer = FlowableUtil.collectBytesInBuffer(response.body(null)).blockingGet();
        byte[] result = new byte[buffer.remaining()];
        buffer.get(result);
        return result;
    } catch (RestException e) {
        if (e.response().statusCode() == 404) {
            return null;
        }
        throw new StorageException("Failed to retreive bytes for " + key, e);
    }
}
Also used : BlockBlobURL(com.microsoft.azure.storage.blob.BlockBlobURL) RestException(com.microsoft.rest.v2.RestException) DownloadResponse(com.microsoft.azure.storage.blob.DownloadResponse) ByteBuffer(java.nio.ByteBuffer) StorageException(org.geowebcache.storage.StorageException) Nullable(javax.annotation.Nullable)

Example 2 with DownloadResponse

use of com.microsoft.azure.storage.blob.DownloadResponse in project geowebcache by GeoWebCache.

the class AzureBlobStore method get.

@Override
public boolean get(TileObject obj) throws StorageException {
    final String key = keyBuilder.forTile(obj);
    final BlockBlobURL blob = client.getBlockBlobURL(key);
    try {
        DownloadResponse response = blob.download().blockingGet();
        ByteBuffer buffer = FlowableUtil.collectBytesInBuffer(response.body(null)).blockingGet();
        byte[] bytes = new byte[buffer.remaining()];
        buffer.get(bytes);
        obj.setBlobSize(bytes.length);
        obj.setBlob(new ByteArrayResource(bytes));
        obj.setCreated(response.headers().lastModified().toEpochSecond() * 1000l);
    } catch (RestException e) {
        if (e.response().statusCode() == 404) {
            return false;
        }
        throw new StorageException("Error getting " + key, e);
    }
    return true;
}
Also used : BlockBlobURL(com.microsoft.azure.storage.blob.BlockBlobURL) RestException(com.microsoft.rest.v2.RestException) DownloadResponse(com.microsoft.azure.storage.blob.DownloadResponse) ByteArrayResource(org.geowebcache.io.ByteArrayResource) ByteBuffer(java.nio.ByteBuffer) StorageException(org.geowebcache.storage.StorageException)

Aggregations

BlockBlobURL (com.microsoft.azure.storage.blob.BlockBlobURL)2 DownloadResponse (com.microsoft.azure.storage.blob.DownloadResponse)2 RestException (com.microsoft.rest.v2.RestException)2 ByteBuffer (java.nio.ByteBuffer)2 StorageException (org.geowebcache.storage.StorageException)2 Nullable (javax.annotation.Nullable)1 ByteArrayResource (org.geowebcache.io.ByteArrayResource)1