@Override public List<MultipartPart> listMultipartUpload(MultipartUpload mpu) { ListBlobBlocksResponse response; try { response = sync.getBlockList(mpu.containerName(), mpu.blobName()); } catch (KeyNotFoundException knfe) { return ImmutableList.<MultipartPart>of(); } ImmutableList.Builder<MultipartPart> parts = ImmutableList.builder(); for (BlobBlockProperties properties : response.getBlocks()) { int partNumber = Ints.fromByteArray(BaseEncoding.base64().decode(properties.getBlockName())); String eTag = ""; // getBlockList does not return ETag Date lastModified = null; // getBlockList does not return LastModified parts.add(MultipartPart.create(partNumber, properties.getContentLength(), eTag, lastModified)); } return parts.build(); }
@Override public List<MultipartPart> listMultipartUpload(MultipartUpload mpu) { ListBlobBlocksResponse response; try { response = sync.getBlockList(mpu.containerName(), mpu.blobName()); } catch (KeyNotFoundException knfe) { return ImmutableList.<MultipartPart>of(); } ImmutableList.Builder<MultipartPart> parts = ImmutableList.builder(); for (BlobBlockProperties properties : response.getBlocks()) { int partNumber = Ints.fromByteArray(BaseEncoding.base64().decode(properties.getBlockName())); String eTag = ""; // getBlockList does not return ETag Date lastModified = null; // getBlockList does not return LastModified parts.add(MultipartPart.create(partNumber, properties.getContentLength(), eTag, lastModified)); } return parts.build(); }
@Test(timeOut = 5 * 60 * 1000) public void testBlockOperations() throws Exception { String blockContainer = CONTAINER_PREFIX + containerIndex.incrementAndGet(); String blockBlob = "myblockblob-" + new SecureRandom().nextInt(); String A = "A"; String B = "B"; String C = "C"; String blockIdA = BaseEncoding.base64().encode((blockBlob + "-" + A).getBytes()); String blockIdB = BaseEncoding.base64().encode((blockBlob + "-" + B).getBytes()); String blockIdC = BaseEncoding.base64().encode((blockBlob + "-" + C).getBytes()); getApi().createContainer(blockContainer); getApi().putBlock(blockContainer, blockBlob, blockIdA, Payloads.newByteArrayPayload(A.getBytes())); getApi().putBlock(blockContainer, blockBlob, blockIdB, Payloads.newByteArrayPayload(B.getBytes())); getApi().putBlock(blockContainer, blockBlob, blockIdC, Payloads.newByteArrayPayload(C.getBytes())); ListBlobsResponse blobs = getApi().listBlobs(blockContainer); assertThat(blobs).isEmpty(); blobs = getApi().listBlobs(blockContainer, new ListBlobsOptions().include(EnumSet.allOf(ListBlobsInclude.class))); assertThat(blobs).hasSize(1); getApi().putBlockList(blockContainer, blockBlob, Arrays.asList(blockIdA, blockIdB, blockIdC)); ListBlobBlocksResponse blocks = getApi().getBlockList(blockContainer, blockBlob); assertEquals(3, blocks.getBlocks().size()); assertEquals(blockIdA, blocks.getBlocks().get(0).getBlockName()); assertEquals(blockIdB, blocks.getBlocks().get(1).getBlockName()); assertEquals(blockIdC, blocks.getBlocks().get(2).getBlockName()); assertEquals(1, blocks.getBlocks().get(0).getContentLength()); assertEquals(1, blocks.getBlocks().get(1).getContentLength()); assertEquals(1, blocks.getBlocks().get(2).getContentLength()); getApi().deleteContainer(blockContainer); }