private static IOException badStartRangeException(CloudPageBlobWrapper blob, PageRange startRange) { return fileCorruptException(blob, String.format( "Page blobs for ASV should always use a page range starting at byte 0. " + "This starts at byte %d.", startRange.getStartOffset())); }
/** * Returns the content of the page range as a string. * * @return A <code>String</code> which represents the contents of the page range. */ @Override public String toString() { return String.format("bytes=%d-%d", this.getStartOffset(), this.getEndOffset()); } }
/** * Returns the content of the page range as a string. * * @return A <code>String</code> which represents the contents of the page range. */ @Override public String toString() { return String.format("bytes=%d-%d", this.getStartOffset(), this.getEndOffset()); } }
if (allRanges.get(0).getStartOffset() != 0) { throw badStartRangeException(blob, allRanges.get(0));
private void doUpdatePageBlob(CloudPageBlob client, InputStream is, BlobServiceRequestOptions opts, Exchange exchange) throws Exception { Long blobOffset = getConfiguration().getBlobOffset(); Long blobDataLength = getConfiguration().getDataLength(); PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class); if (range != null) { blobOffset = range.getStartOffset(); blobDataLength = range.getEndOffset() - range.getStartOffset(); } if (blobDataLength == null) { blobDataLength = (long)is.available(); } try { client.uploadPages(is, blobOffset, blobDataLength, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); } finally { closeInputStreamIfNeeded(is); } }
return 0; if (pageRanges.get(0).getStartOffset() != 0) {
@Test public void testDownloadPageRangesWithOffsetAndLength() throws StorageException, URISyntaxException, IOException { final CloudPageBlob blobRef = setUpPageRanges(); List<PageRange> actualPageRanges = blobRef.downloadPageRanges((long)1*512, (long)5*512); List<PageRange> expectedPageRanges = new ArrayList<PageRange>(); expectedPageRanges.add(new PageRange(2 * 512, 5 * 512 - 1)); assertEquals(expectedPageRanges.size(), actualPageRanges.size()); for (int i = 0; i < expectedPageRanges.size(); i++) { assertEquals(expectedPageRanges.get(i).getStartOffset(), actualPageRanges.get(i).getStartOffset()); assertEquals(expectedPageRanges.get(i).getEndOffset(), actualPageRanges.get(i).getEndOffset()); } }
PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class); if (range != null) { blobOffset = range.getStartOffset(); blobDataLength = range.getEndOffset() - range.getStartOffset();
@Test public void testDownloadPageRangesWithOffset() throws StorageException, URISyntaxException, IOException { final CloudPageBlob blobRef = setUpPageRanges(); List<PageRange> actualPageRanges = blobRef.downloadPageRanges((long)1*512, null); List<PageRange> expectedPageRanges = new ArrayList<PageRange>(); expectedPageRanges.add(new PageRange(2 * 512, 5 * 512 - 1)); expectedPageRanges.add(new PageRange(6 * 512, 7 * 512 - 1)); assertEquals(expectedPageRanges.size(), actualPageRanges.size()); for (int i = 0; i < expectedPageRanges.size(); i++) { assertEquals(expectedPageRanges.get(i).getStartOffset(), actualPageRanges.get(i).getStartOffset()); assertEquals(expectedPageRanges.get(i).getEndOffset(), actualPageRanges.get(i).getEndOffset()); } }
private void clearPageBlob(Exchange exchange) throws Exception { LOG.trace("Clearing a page blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration()); BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange); Long blobOffset = getConfiguration().getBlobOffset(); Long blobDataLength = getConfiguration().getDataLength(); PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class); if (range != null) { blobOffset = range.getStartOffset(); blobDataLength = range.getEndOffset() - range.getStartOffset(); } if (blobDataLength == null) { blobDataLength = blobOffset == 0 ? getPageBlobSize(exchange) : 512L; } client.clearPages(blobOffset, blobDataLength, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); }
@Test public void testDownloadPages() throws StorageException, URISyntaxException, IOException { final CloudPageBlob blobRef = setUpPageRanges(); ArrayList<PageRange> actualPageRanges = blobRef.downloadPageRanges(); ArrayList<PageRange> expectedPageRanges = new ArrayList<PageRange>(); expectedPageRanges.add(new PageRange(0, 512 - 1)); expectedPageRanges.add(new PageRange(2 * 512, 5 * 512 - 1)); expectedPageRanges.add(new PageRange(6 * 512, 7 * 512 - 1)); assertEquals(expectedPageRanges.size(), actualPageRanges.size()); for (int i = 0; i < expectedPageRanges.size(); i++) { assertEquals(expectedPageRanges.get(i).getStartOffset(), actualPageRanges.get(i).getStartOffset()); assertEquals(expectedPageRanges.get(i).getEndOffset(), actualPageRanges.get(i).getEndOffset()); } }
@Test public void testEightTBBlob() throws StorageException, URISyntaxException, IOException { CloudPageBlob blob = this.container.getPageBlobReference("blob1"); CloudPageBlob blob2 = this.container.getPageBlobReference("blob1"); long eightTb = 8L * 1024L * 1024L * 1024L * 1024L; blob.create(eightTb); assertEquals(eightTb, blob.getProperties().getLength()); blob2.downloadAttributes(); assertEquals(eightTb, blob2.getProperties().getLength()); for (ListBlobItem listBlob : this.container.listBlobs()) { CloudPageBlob listPageBlob = (CloudPageBlob)listBlob; assertEquals(eightTb, listPageBlob.getProperties().getLength()); } CloudPageBlob blob3 = this.container.getPageBlobReference("blob3"); blob3.create(1024); blob3.resize(eightTb); final Random randGenerator = new Random(); final byte[] buffer = new byte[1024]; randGenerator.nextBytes(buffer); blob.uploadPages(new ByteArrayInputStream(buffer), eightTb - 512L, 512L); ArrayList<PageRange> ranges = blob.downloadPageRanges(); assertEquals(1, ranges.size()); assertEquals(eightTb - 512L, ranges.get(0).getStartOffset()); assertEquals(eightTb - 1L, ranges.get(0).getEndOffset()); }