com.microsoft.azure.storage.blob.CloudAppendBlob Java Examples
The following examples show how to use
com.microsoft.azure.storage.blob.CloudAppendBlob.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoStorageAzure.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public VideoStorageSession create(UUID recordingId, UUID cameraId, UUID accountId, UUID placeId, @Nullable UUID personId, long ttlInSeconds) throws Exception { long startTime = System.nanoTime(); try { CloudBlobContainer container = getRandomContainer(recordingId, cameraId, placeId); CloudBlobDirectory dir = container.getDirectoryReference(placeId.toString()); CloudAppendBlob blob = dir.getAppendBlobReference(recordingId.toString()); blob.getProperties().setCacheControl("no-cache"); blob.getProperties().setContentType("video/mp2t"); blob.setStreamWriteSizeInBytes(4*1024*1024); VideoStorageSession result = new AzureStorageSession(recordingId, cameraId, accountId, placeId, ttlInSeconds, personId, blob); VIDEO_STORAGE_AZURE_CREATE_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); return result; } catch (Exception ex) { VIDEO_STORAGE_AZURE_CREATE_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); throw ex; } }
Example #2
Source File: VideoStorageAzure.java From arcusplatform with Apache License 2.0 | 4 votes |
@Override public VideoStorageSession create(VideoRecording recording) throws Exception { long startTime = System.nanoTime(); try { if (recording == null || recording.storage == null) { VIDEO_STORAGE_AZURE_NO_LOCATION.inc(); throw new Exception("no storage location"); } CloudBlobContainer foundContainer = null; for (CloudBlobContainer container : containers) { URI uri = container.getUri(); String uriString = uri.toString(); if (recording.storage.startsWith(uriString)) { foundContainer = container; break; } } if (foundContainer == null) { VIDEO_STORAGE_AZURE_NO_CONTAINER.inc(); throw new Exception("no azure container for storage location"); } CloudBlobDirectory dir = foundContainer.getDirectoryReference(recording.placeId.toString()); CloudAppendBlob blob = dir.getAppendBlobReference(recording.recordingId.toString()); blob.getProperties().setCacheControl("no-cache"); blob.getProperties().setContentType("video/mp2t"); long expiration = recording.expiration; long ttlInSeconds = VideoV2Util.createActualTTL(recording.recordingId, expiration); VideoStorageSession result = new AzureStorageSession(recording.recordingId, recording.cameraId, recording.accountId, recording.placeId, ttlInSeconds, recording.personId, blob); VIDEO_STORAGE_AZURE_EXISTING_CREATE_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); return result; } catch (Exception ex) { VIDEO_STORAGE_AZURE_EXISTING_CREATE_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); throw ex; } }
Example #3
Source File: VideoStorageAzure.java From arcusplatform with Apache License 2.0 | 4 votes |
public AzureStorageSession(UUID recordingId, UUID cameraId, UUID accountId, UUID placeId, long ttlInSeconds, @Nullable UUID personId, CloudAppendBlob blob) { super(recordingId, cameraId, accountId, placeId, personId, ttlInSeconds); this.blob = blob; }
Example #4
Source File: BlobBasics.java From storage-blob-java-getting-started with MIT License | 4 votes |
/** * Demonstrates the basic operations with a append blob. * * @param container The CloudBlobContainer object to work with * * @throws StorageException * @throws IOException * @throws IllegalArgumentException * @throws URISyntaxException */ private static void basicAppendBlobOperations(CloudBlobContainer container) throws StorageException, IOException, IllegalArgumentException, URISyntaxException { // Create sample files for use Random random = new Random(); System.out.println("\tCreating sample files between 128KB-256KB in size for upload demonstration."); File tempFile1 = DataGenerator.createTempLocalFile("appendblob-", ".tmp", (128 * 1024) + random.nextInt(128 * 1024)); System.out.println(String.format("\t\tSuccessfully created the file \"%s\".", tempFile1.getAbsolutePath())); File tempFile2 = DataGenerator.createTempLocalFile("appendblob-", ".tmp", (128 * 1024) + random.nextInt(128 * 1024)); System.out.println(String.format("\t\tSuccessfully created the file \"%s\".", tempFile2.getAbsolutePath())); // Create an append blob and append data to it from the sample file System.out.println("\n\tCreate an empty append blob and append data to it from the sample files."); CloudAppendBlob appendBlob = container.getAppendBlobReference("appendblob.tmp"); appendBlob.createOrReplace(); appendBlob.appendFromFile(tempFile1.getAbsolutePath()); appendBlob.appendFromFile(tempFile2.getAbsolutePath()); System.out.println("\t\tSuccessfully created the append blob and appended data to it."); // Write random data blocks to the end of the append blob byte[] randomBytes = new byte[4096]; for (int i = 0; i < 8; i++) { random.nextBytes(randomBytes); appendBlob.appendFromByteArray(randomBytes, 0, 4096); } // Download the blob if (appendBlob != null) { System.out.println("\n\tDownload the blob."); String downloadedAppendBlobPath = String.format("%scopyof-%s", System.getProperty("java.io.tmpdir"), appendBlob.getName()); System.out.println(String.format("\t\tDownload the blob from \"%s\" to \"%s\".", appendBlob.getUri().toURL(), downloadedAppendBlobPath)); appendBlob.downloadToFile(downloadedAppendBlobPath); new File(downloadedAppendBlobPath).deleteOnExit(); System.out.println("\t\t\tSuccessfully downloaded the blob."); } }
Example #5
Source File: AzureIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testAppendBlob() throws Exception { StorageCredentials creds = getStorageCredentials("camelblob", System.getenv(AZURE_STORAGE_BLOB)); Assume.assumeNotNull("Credentials not null", creds); CamelContext camelctx = createCamelContext(creds); camelctx.addRoutes(new RouteBuilder() { public void configure() throws Exception { from("direct:start") .to("azure-blob://camelblob/container1/blobAppend?credentials=#creds&operation=updateAppendBlob"); from("azure-blob://camelblob/container1/blobAppend?credentials=#creds&blobType=appendblob") .to("mock:read"); from("direct:list") .to("azure-blob://camelblob/container1?credentials=#creds&operation=listBlobs"); } }); camelctx.start(); try { MockEndpoint mockRead = camelctx.getEndpoint("mock:read", MockEndpoint.class); mockRead.expectedBodiesReceived("Append Blob"); mockRead.expectedMessageCount(1); ProducerTemplate producer = camelctx.createProducerTemplate(); Iterator<?> it = producer.requestBody("direct:list", null, Iterable.class).iterator(); Assert.assertFalse("No Blob exists", it.hasNext()); // append to blob producer.sendBody("direct:start", "Append Blob"); mockRead.assertIsSatisfied(); it = producer.requestBody("direct:list", null, Iterable.class).iterator(); Assert.assertTrue("Blob exists", it.hasNext()); CloudBlob blob = (CloudAppendBlob) it.next(); blob.delete(); it = producer.requestBody("direct:list", null, Iterable.class).iterator(); Assert.assertFalse("No Blob exists", it.hasNext()); } finally { camelctx.close(); } }