/** * Updates the blob's committed block count from the web request. * * @param request * The web request from which to parse the committed block count. */ private void updateCommittedBlockCountFromResponse(HttpURLConnection request) { final String comittedBlockCount = request.getHeaderField(Constants.HeaderConstants.BLOB_COMMITTED_BLOCK_COUNT); if (!Utility.isNullOrEmpty(comittedBlockCount)) { this.getProperties().setAppendBlobCommittedBlockCount(Integer.parseInt(comittedBlockCount)); } }
/** * Updates the blob's committed block count from the web request. * * @param request * The web request from which to parse the committed block count. */ private void updateCommittedBlockCountFromResponse(HttpURLConnection request) { final String comittedBlockCount = request.getHeaderField(Constants.HeaderConstants.BLOB_COMMITTED_BLOCK_COUNT); if (!Utility.isNullOrEmpty(comittedBlockCount)) { this.getProperties().setAppendBlobCommittedBlockCount(Integer.parseInt(comittedBlockCount)); } }
@Override public List<String> readLines() throws IOException { try { if (!gcJournal.exists()) { return Collections.emptyList(); } byte[] data = new byte[(int) gcJournal.getProperties().getLength()]; gcJournal.downloadToByteArray(data, 0); return IOUtils.readLines(new ByteArrayInputStream(data), Charset.defaultCharset()); } catch (StorageException e) { throw new IOException(e); } } }
@Override public List<String> readLines() throws IOException { try { if (!gcJournal.exists()) { return Collections.emptyList(); } byte[] data = new byte[(int) gcJournal.getProperties().getLength()]; gcJournal.downloadToByteArray(data, 0); return IOUtils.readLines(new ByteArrayInputStream(data), Charset.defaultCharset()); } catch (StorageException e) { throw new IOException(e); } } }
public AzureJournalWriter() throws IOException { List<CloudAppendBlob> blobs = getJournalBlobs(); if (blobs.isEmpty()) { try { currentBlob = directory.getAppendBlobReference(getJournalFileName(1)); currentBlob.createOrReplace(); } catch (URISyntaxException | StorageException e) { throw new IOException(e); } } else { currentBlob = blobs.get(0); } Integer bc = currentBlob.getProperties().getAppendBlobCommittedBlockCount(); blockCount = bc == null ? 0 : bc; }
public AzureJournalWriter() throws IOException { List<CloudAppendBlob> blobs = getJournalBlobs(); if (blobs.isEmpty()) { try { currentBlob = directory.getAppendBlobReference(getJournalFileName(1)); currentBlob.createOrReplace(); } catch (URISyntaxException | StorageException e) { throw new IOException(e); } } else { currentBlob = blobs.get(0); } Integer bc = currentBlob.getProperties().getAppendBlobCommittedBlockCount(); blockCount = bc == null ? 0 : bc; }
this.currentBlobOffset = parentBlob.getProperties().getLength();
this.currentBlobOffset = parentBlob.getProperties().getLength();
@Test public void testAppendBlobUploadFromStream() throws StorageException, IOException, URISyntaxException { byte[] buffer = BlobTestHelper.getRandomBuffer(6 * 1024 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); blob.upload(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); blob.upload(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); blob.upload(new ByteArrayInputStream(buffer), buffer.length, null /* accessCondition */, null /* options */, null /* operationContext */); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); }
@Test public void testAppendBlobAppendFromStream() throws StorageException, IOException, URISyntaxException { // Every time append a buffer that is bigger than a single block. byte[] buffer = BlobTestHelper.getRandomBuffer(6 * 1024 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); blob.createOrReplace(); blob.append(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(12 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), buffer.length, null /* accessCondition */, null /* options */, null /* operationContext */); blob.downloadAttributes(); assertEquals(18 * 1024 * 1024, blob.getProperties().getLength()); }
@Test public void testAppendBlobAppendFromStreamWithLength() throws StorageException, IOException, URISyntaxException { // Every time append a buffer that is bigger than a single block. byte[] buffer = BlobTestHelper.getRandomBuffer(6 * 1024 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); blob.createOrReplace(); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024); blob.downloadAttributes(); assertEquals(5 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024); blob.downloadAttributes(); assertEquals(10 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024, null /* accessCondition */, null /* options */, null /* operationContext */); blob.downloadAttributes(); assertEquals(15 * 1024 * 1024, blob.getProperties().getLength()); } }
appendBlobRef1.getProperties().setLength(length); BlobProperties props1 = appendBlobRef1.getProperties(); appendBlobRef1.uploadProperties(); BlobProperties props2 = appendBlobRef1.getProperties(); props1 = appendBlobRef1.getProperties(); appendBlobRef1.getProperties().setLength(length); props2 = appendBlobRef1.getProperties();
@Test public void testAppendBlobUploadNegativeLength() throws URISyntaxException, StorageException, IOException { final int blobLength = 16 * 1024; String blobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testblob"); final CloudAppendBlob blobRef = this.container .getAppendBlobReference(blobName); final byte[] buff = BlobTestHelper.getRandomBuffer(blobLength); ByteArrayInputStream sourceStream = new ByteArrayInputStream(buff); blobRef.upload(sourceStream, -1); assertTrue(blobRef.exists()); assertEquals(blobRef.getProperties().getLength(), blobLength); }
/** * Create a blob and try to download a range of its contents */ @Test public void testAppendBlobDownloadRangeValidationTest() throws StorageException, URISyntaxException, IOException { final int length = 5 * 1024 * 1024; final String appendBlobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testBlockBlob"); final CloudAppendBlob appendBlobRef = this.container .getAppendBlobReference(appendBlobName); appendBlobRef .upload(BlobTestHelper.getRandomDataStream(length), length); // Download full blob appendBlobRef.download(new ByteArrayOutputStream()); assertEquals(length, appendBlobRef.getProperties().getLength()); // Download blob range. byte[] downloadBuffer = new byte[100]; int downloadLength = appendBlobRef.downloadRangeToByteArray(0, (long) 100, downloadBuffer, 0); assertEquals(length, appendBlobRef.getProperties().getLength()); assertEquals(100, downloadLength); }
assertNotNull(copy.getProperties().getEtag()); assertFalse(source.getProperties().getEtag() .equals(copy.getProperties().getEtag())); assertTrue(copy.getProperties().getLastModified() .compareTo(new Date(calendar.get(Calendar.MINUTE) - 1)) > 0); BlobProperties prop1 = copy.getProperties(); BlobProperties prop2 = source.getProperties();
/** * Start copying a blob and then abort */ @Test public void testCopyFromAppendBlobAbortTest() throws StorageException, URISyntaxException, IOException { final int length = 512; CloudAppendBlob originalBlob = (CloudAppendBlob) BlobTestHelper.uploadNewBlob( this.container, BlobType.APPEND_BLOB, "originalBlob", length, null); CloudAppendBlob copyBlob = this.container.getAppendBlobReference(originalBlob.getName() + "copyed"); copyBlob.startCopy(originalBlob); try { copyBlob.abortCopy(copyBlob.getProperties().getCopyState().getCopyId()); } catch (StorageException e) { if (!e.getErrorCode().contains("NoPendingCopyOperation")) { throw e; } } }
@Test public void testAppendBlockFromStream() throws StorageException, IOException, URISyntaxException { int blobSize = 2 * 1024; String blobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testblob"); CloudAppendBlob blob = container.getAppendBlobReference(blobName); blob.createOrReplace(); // Append a block byte[] buffer = BlobTestHelper.getRandomBuffer(blobSize); ByteArrayInputStream sourceStream = new ByteArrayInputStream(buffer); long pos = blob.appendBlock(sourceStream, -1); assertEquals(0, pos); // Download and verify equality byte[] resultBuffer = new byte[blobSize]; blob.downloadToByteArray(resultBuffer, 0); for (int i = 0; i < blob.getProperties().getLength(); i++) { assertEquals(buffer[i], resultBuffer[i]); } // Append another block to check the position is updated correctly sourceStream = new ByteArrayInputStream(buffer); pos = blob.appendBlock(sourceStream, -1); assertEquals(blobSize, pos); }
@Test public void testOpenOutputStreamNoArgs() throws URISyntaxException, StorageException { String blobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testblob"); CloudAppendBlob appendBlob = this.container .getAppendBlobReference(blobName); try { appendBlob.openWriteExisting(); } catch (StorageException ex) { assertEquals("The specified blob does not exist.", ex.getMessage()); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } appendBlob.openWriteNew(); appendBlob.openWriteExisting(); CloudAppendBlob appendBlob2 = this.container .getAppendBlobReference(blobName); appendBlob2.downloadAttributes(); assertEquals(0, appendBlob2.getProperties().getLength()); assertEquals(BlobType.APPEND_BLOB, appendBlob2.getProperties().getBlobType()); }
blob1.createOrReplace(); accessCondition = AccessCondition.generateIfNoneMatchCondition(blob1 .getProperties().getEtag()); try { blob1.upload(srcStream, length, accessCondition, null, null); .getProperties().getEtag()); blob1.upload(srcStream, length, accessCondition, null, null); blob2.createOrReplace(); accessCondition = AccessCondition.generateIfMatchCondition(blob1 .getProperties().getEtag()); try { blob1.upload(srcStream, length, accessCondition, null, null); .getProperties().getEtag()); blob1.upload(srcStream, length, accessCondition, null, null);
@Test public void testBlobUploadWithoutMD5Validation() throws URISyntaxException, StorageException, IOException { final String appendBlobName = BlobTestHelper .generateRandomBlobNameWithPrefix("testAppendBlob"); final CloudAppendBlob appendBlobRef = this.container .getAppendBlobReference(appendBlobName); final int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper .getRandomDataStream(length); BlobRequestOptions options = new BlobRequestOptions(); options.setDisableContentMD5Validation(false); options.setStoreBlobContentMD5(false); appendBlobRef.upload(srcStream, length, null, options, null); appendBlobRef.downloadAttributes(); appendBlobRef.getProperties().setContentMD5("MDAwMDAwMDA="); appendBlobRef.uploadProperties(null, options, null); try { appendBlobRef.download(new ByteArrayOutputStream(), null, options, null); fail(); } catch (StorageException ex) { assertEquals(306, ex.getHttpStatusCode()); assertEquals("InvalidMd5", ex.getErrorCode()); } options.setDisableContentMD5Validation(true); appendBlobRef .download(new ByteArrayOutputStream(), null, options, null); }