public MutableBlobProperties apply(BlobMetadata from) { if (from == null) return null; MutableBlobProperties to = new MutableBlobPropertiesImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setETag(from.getETag()); to.setName(from.getName()); to.setUrl(from.getUri()); to.setLastModified(from.getLastModified()); if (from.getUserMetadata() != null) { for (Entry<String, String> entry : from.getUserMetadata().entrySet()) to.getMetadata().put(entry.getKey().toLowerCase(), entry.getValue()); } return to; }
public MutableBlobProperties apply(BlobMetadata from) { if (from == null) return null; MutableBlobProperties to = new MutableBlobPropertiesImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setETag(from.getETag()); to.setName(from.getName()); to.setUrl(from.getUri()); to.setLastModified(from.getLastModified()); if (from.getUserMetadata() != null) { for (Entry<String, String> entry : from.getUserMetadata().entrySet()) to.getMetadata().put(entry.getKey().toLowerCase(), entry.getValue()); } return to; }
public MutableBlobProperties apply(BlobMetadata from) { if (from == null) return null; MutableBlobProperties to = new MutableBlobPropertiesImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setETag(from.getETag()); to.setName(from.getName()); to.setUrl(from.getUri()); to.setLastModified(from.getLastModified()); if (from.getUserMetadata() != null) { for (Entry<String, String> entry : from.getUserMetadata().entrySet()) to.getMetadata().put(entry.getKey().toLowerCase(), entry.getValue()); } return to; }
public MutableBlobProperties apply(BlobMetadata from) { if (from == null) return null; MutableBlobProperties to = new MutableBlobPropertiesImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setETag(from.getETag()); to.setName(from.getName()); to.setUrl(from.getUri()); to.setLastModified(from.getLastModified()); if (from.getUserMetadata() != null) { for (Entry<String, String> entry : from.getUserMetadata().entrySet()) to.getMetadata().put(entry.getKey().toLowerCase(), entry.getValue()); } return to; }
public MutableBlobProperties apply(BlobMetadata from) { if (from == null) return null; MutableBlobProperties to = new MutableBlobPropertiesImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setETag(from.getETag()); to.setName(from.getName()); to.setUrl(from.getUri()); to.setLastModified(from.getLastModified()); if (from.getUserMetadata() != null) { for (Entry<String, String> entry : from.getUserMetadata().entrySet()) to.getMetadata().put(entry.getKey().toLowerCase(), entry.getValue()); } return to; }
object.getProperties().getContentMetadata().setContentMD5(Hashing.md5().hashString(data, Charsets.UTF_8).asBytes()); object.getProperties().getContentMetadata().setContentType("text/plain"); object.getProperties().getMetadata().put("mykey", "metadata-value"); byte[] md5 = object.getProperties().getContentMetadata().getContentMD5(); String newEtag = getApi().putBlob(privateContainer, object); assertEquals(base16().lowerCase().encode(md5), base16().lowerCase().encode(getBlob.getProperties().getContentMetadata().getContentMD5())); assertEquals(getBlob.getProperties().getMetadata().size(), 2); assertEquals(getBlob.getProperties().getMetadata().get("new_metadata_1"), "value-1"); assertEquals(getBlob.getProperties().getMetadata().get("new_metadata_2"), "value-2"); assertEquals(metadata.getMetadata().entrySet().size(), 1); assertEquals(metadata.getMetadata().get("mykey"), "metadata-value");
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer" }) public void testCopyBlob() throws Exception { ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024); // create blob AzureBlob object = getApi().newBlob(); object.getProperties().setName("from"); object.setPayload(byteSource.read()); getApi().putBlob(privateContainer, object); // copy blob URI copySource = view.getSigner().signGetBlob(privateContainer, "from").getEndpoint(); getApi().copyBlob(copySource, privateContainer, "to", CopyBlobOptions.NONE); // ensure copied blob matches original AzureBlob getBlob = getApi().getBlob(privateContainer, "to"); assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read()); assertThat(getBlob.getProperties().getMetadata().isEmpty()); }
Payloads.calculateMD5(object); object.getProperties().getContentMetadata().setContentType("text/plain"); object.getProperties().getMetadata().put("mykey", "metadata-value"); byte[] md5 = object.getProperties().getContentMetadata().getContentMD5(); String newEtag = getApi().putBlob(privateContainer, object);
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer" }) public void testCopyBlobReplaceMetadata() throws Exception { ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024); // create blob AzureBlob object = getApi().newBlob(); object.getProperties().setName("from"); object.setPayload(byteSource.read()); getApi().putBlob(privateContainer, object); // copy blob URI copySource = view.getSigner().signGetBlob(privateContainer, "from").getEndpoint(); Map<String, String> newMetadata = ImmutableMap.of("foo", "bar"); getApi().copyBlob(copySource, privateContainer, "to", CopyBlobOptions.builder().overrideUserMetadata(newMetadata).build()); // ensure copied blob matches original AzureBlob getBlob = getApi().getBlob(privateContainer, "to"); assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read()); assertThat(getBlob.getProperties().getMetadata()).isEqualTo(newMetadata); }