use of com.azure.storage.blob.models.BlobStorageException in project beam by apache.
the class AzureBlobStoreFileSystem method toMatchResult.
private MatchResult toMatchResult(AzfsResourceId path) {
BlobClient blobClient = client.get().getBlobContainerClient(path.getContainer()).getBlobClient(path.getBlob());
BlobProperties blobProperties;
try {
blobProperties = blobClient.getProperties();
} catch (BlobStorageException e) {
if (e.getStatusCode() == 404) {
return MatchResult.create(MatchResult.Status.NOT_FOUND, new FileNotFoundException());
}
return MatchResult.create(MatchResult.Status.ERROR, new IOException(e));
}
return MatchResult.create(MatchResult.Status.OK, ImmutableList.of(toMetadata(path.withSize(blobProperties.getBlobSize()).withLastModified(Date.from(blobProperties.getLastModified().toInstant())), blobProperties.getContentEncoding(), blobProperties.getETag())));
}
use of com.azure.storage.blob.models.BlobStorageException in project beam by apache.
the class AzureBlobStoreFileSystem method create.
@Override
protected WritableByteChannel create(AzfsResourceId resourceId, CreateOptions createOptions) throws IOException {
BlobContainerClient blobContainerClient = client.get().getBlobContainerClient(resourceId.getContainer());
if (!blobContainerClient.exists()) {
throw new FileNotFoundException("This container does not exist. Creating containers is not supported.");
}
BlobClient blobClient = blobContainerClient.getBlobClient(resourceId.getBlob());
// so throw an error in this case to prevent data loss
if (blobClient.exists()) {
throw new IOException("This filename is already in use.");
}
OutputStream outputStream;
try {
outputStream = blobClient.getBlockBlobClient().getBlobOutputStream();
} catch (BlobStorageException e) {
throw (IOException) e.getCause();
}
return newChannel(outputStream);
}
Aggregations