@Override public Properties load() throws IOException { Properties properties = new Properties(); if (exists()) { long length = manifestBlob.getProperties().getLength(); byte[] data = new byte[(int) length]; try { manifestBlob.downloadToByteArray(data, 0); } catch (StorageException e) { throw new IOException(e); } properties.load(new ByteArrayInputStream(data)); } return properties; }
@Override public Properties load() throws IOException { Properties properties = new Properties(); if (exists()) { long length = manifestBlob.getProperties().getLength(); byte[] data = new byte[(int) length]; try { manifestBlob.downloadToByteArray(data, 0); } catch (StorageException e) { throw new IOException(e); } properties.load(new ByteArrayInputStream(data)); } return properties; }
private String[] getStrings(CloudBlockBlob blob) throws StorageException, IOException { HashMap<String, String> md = blob.getMetadata(); byte[] nm = new byte[(int) blob.getProperties().getLength()]; blob.downloadToByteArray(nm, 0, null, null, opContext); if (!md.containsKey("encrypt")) { blob.downloadAttributes(); md = blob.getMetadata(); } boolean encrypt = Boolean.parseBoolean(md.get("encrypt")); if (encrypt) { nm = EncryptUtils.decryptCBC(nm); } boolean compress = Boolean.parseBoolean(md.get("lz4Compress")); if (compress) { int size = Integer.parseInt(md.get("size")); nm = CompressionUtils.decompressLz4(nm, size); } String st = new String(nm); return st.split(","); }
private void doUploadFromByteArrayTest(CloudBlockBlob blob, int bufferSize, int bufferOffset, int count) throws Exception { byte[] buffer = BlobTestHelper.getRandomBuffer(bufferSize); byte[] downloadedBuffer = new byte[bufferSize]; blob.uploadFromByteArray(buffer, bufferOffset, count); blob.downloadToByteArray(downloadedBuffer, 0); int i = 0; for (; i < count; i++) { assertEquals(buffer[i + bufferOffset], downloadedBuffer[i]); } for (; i < downloadedBuffer.length; i++) { assertEquals(0, downloadedBuffer[i]); } }
blockBlob.downloadToByteArray(outBuffer, 0); for (int i = 0; i < length*writes; i ++) { assertEquals(buffer[i], outBuffer[i]);
@Test public void testWithAccessCondition() throws URISyntaxException, StorageException, IOException { int blobLengthToUse = 8 * 512; byte[] buffer = BlobTestHelper.getRandomBuffer(blobLengthToUse); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); AccessCondition accessCondition = AccessCondition.generateIfNotModifiedSinceCondition(new Date()); CloudBlockBlob blockBlob = this.container.getBlockBlobReference(blobName); BlobOutputStream blobOutputStream = blockBlob.openOutputStream(accessCondition, null, null); ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); blobOutputStream.write(inputStream, 512); inputStream = new ByteArrayInputStream(buffer, 512, 3 * 512); blobOutputStream.write(inputStream, 3 * 512); blobOutputStream.close(); byte[] result = new byte[blobLengthToUse]; blockBlob.downloadToByteArray(result, 0); int i = 0; for (; i < 4 * 512; i++) { assertEquals(buffer[i], result[i]); } for (; i < 8 * 512; i++) { assertEquals(0, result[i]); } }
@Test public void testWriteStream() throws URISyntaxException, StorageException, IOException { int blobLengthToUse = 8 * 512; byte[] buffer = BlobTestHelper.getRandomBuffer(blobLengthToUse); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudBlockBlob blockBlob = this.container.getBlockBlobReference(blobName); BlobOutputStream blobOutputStream = blockBlob.openOutputStream(); ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); blobOutputStream.write(inputStream, 512); inputStream = new ByteArrayInputStream(buffer, 512, 3 * 512); blobOutputStream.write(inputStream, 3 * 512); blobOutputStream.close(); byte[] result = new byte[blobLengthToUse]; blockBlob.downloadToByteArray(result, 0); int i = 0; for (; i < 4 * 512; i++) { assertEquals(buffer[i], result[i]); } for (; i < 8 * 512; i++) { assertEquals(0, result[i]); } }
private void smallPutThresholdHelper(int length, int writes, BlobRequestOptions options) throws URISyntaxException, StorageException, IOException { byte[] buffer = BlobTestHelper.getRandomBuffer(length*writes); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("concurrency"); CloudBlockBlob blockBlob = this.container.getBlockBlobReference(blobName); blockBlob.setStreamWriteSizeInBytes(length); BlobOutputStream blobOutputStream = blockBlob.openOutputStream(null, options, null); for (int i = 0; i < writes; i ++) { blobOutputStream.write(buffer, i*length, length); } blobOutputStream.flush(); ArrayList<BlockEntry> blocks = blockBlob.downloadBlockList(BlockListingFilter.UNCOMMITTED, null, null, null); assertEquals(writes, blocks.size()); blobOutputStream.close(); blocks = blockBlob.downloadBlockList(BlockListingFilter.COMMITTED, null, null, null); assertEquals(writes, blocks.size()); byte[] outBuffer = new byte[writes*length]; blockBlob.downloadToByteArray(outBuffer, 0); for (int i = 0; i < length*writes; i ++) { assertEquals(buffer[i], outBuffer[i]); } }
blockBlobRef.downloadToByteArray(downloadBuffer, 0, null, options, opContext); fail("Maximum execution time was reached but request did not fail.");