GroupDocsGists
10/24/2017 - 1:10 PM

Examples-src-main-java-com-groupdocs-signature-examples-SampleAzureOutputDataHandler-SampleAzureOutputDataHandler.java

// For complete examples and data files, please go to https://github.com/groupdocs-signature/GroupDocs.Signature-for-Java
public class AzureOutputDataHandler extends AzureDataHandler implements IOutputDataHandler {
	public AzureOutputDataHandler(String endpoint, String accountName, String accountKey, String containerName)
			throws URISyntaxException, StorageException {
		super(endpoint, accountName, accountKey, containerName);
	}

	@Override
	public OutputStream createFile(FileDescription fileDescription, SignOptions signOptions, SaveOptions saveOptions) {
		try {
			CloudBlobContainer container = getContainerReference();
			String name = fileDescription.getGUID().toLowerCase();
			CloudBlockBlob blob = container.getBlockBlobReference(name);
			try {
				CloudAppendBlob appendBlob = container.getAppendBlobReference(name);
				appendBlob.createOrReplace();
				return appendBlob.openWriteNew()/* OpenWrite(true) */;
			} catch (Exception exception) {
				// Azure Storage Emulator does not support append BLOBs,
				// so we emulate appending
				return new CountingOutputStream(blob.openOutputStream());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public OutputStream createStream(FileDescription fileDescription, SignOptions signOptions,
			SaveOptions saveOptions) {
		throw new NotImplementedException(_containerName);
	}

	public CloudBlobContainer getContainerReference() throws URISyntaxException, StorageException {
		CloudBlobContainer container = _remoteStorage.getContainerReference(_containerName);
		return container;
	}
}