.forEach(k -> newMetadata.put(k, originalMetadata.get(k))); CopyOptions options = CopyOptions.builder().userMetadata(newMetadata).build(); String etag = serverCopyBlob(blobStore, container, objectName, container, objectName, options); if (etag == null) {
options.ifMatch(ifMatch); options.ifNoneMatch(ifNoneMatch); options.ifModifiedSince(new Date(ifModifiedSince)); options.ifUnmodifiedSince(new Date(ifUnmodifiedSince)); options.contentMetadata(contentMetadata.build()); options.userMetadata(userMetadata.build()); eTag = blobStore.copyBlob( sourceContainerName, sourceBlobName, destContainerName, destBlobName, options.build()); } catch (KeyNotFoundException knfe) { throw new S3Exception(S3ErrorCode.NO_SUCH_KEY, knfe);
builder.contentMetadata(contentMetadata.build()); builder.userMetadata(additionalUserMeta); } else { if (!additionalUserMeta.isEmpty()) { newMetadata.putAll(meta.getUserMetadata()); newMetadata.putAll(additionalUserMeta); builder.userMetadata(newMetadata); builder.ifMatch(ifMatch); builder.ifModifiedSince(ifModifiedSince); builder.ifUnmodifiedSince(ifUnmodifiedSince); CopyOptions options = builder.build(); validateUserMetadata(options.userMetadata());
options.ifMatch(ifMatch); options.ifNoneMatch(ifNoneMatch); options.ifModifiedSince(new Date(ifModifiedSince)); options.ifUnmodifiedSince(new Date(ifUnmodifiedSince)); options.contentMetadata(contentMetadata.build()); options.userMetadata(userMetadata.build()); eTag = blobStore.copyBlob( sourceContainerName, sourceBlobName, destContainerName, destBlobName, options.build()); } catch (KeyNotFoundException knfe) { throw new S3Exception(S3ErrorCode.NO_SUCH_KEY, knfe);
options.ifMatch(ifMatch); options.ifNoneMatch(ifNoneMatch); options.ifModifiedSince(new Date(ifModifiedSince)); options.ifUnmodifiedSince(new Date(ifUnmodifiedSince)); options.contentMetadata(contentMetadata.build()); options.userMetadata(userMetadata.build()); eTag = blobStore.copyBlob( sourceContainerName, sourceBlobName, destContainerName, destBlobName, options.build()); } catch (KeyNotFoundException knfe) { throw new S3Exception(S3ErrorCode.NO_SUCH_KEY, knfe);
Map<String, String> userMetadata = ImmutableMap.of("key3", "value3", "key4", "value4"); blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder() .contentMetadata(ContentMetadataBuilder.create() .cacheControl("max-age=3600") .contentType("text/csv") .contentLanguage("en") .build()) .userMetadata(userMetadata) .build()); Blob toBlob = blobStore.getBlob(toContainer, toName); InputStream is = null;
ContentMetadata dmd = blobStore.blobMetadata(this.name, id).getContentMetadata(); blobStore.copyBlob(this.name, id, this.name, id, CopyOptions.builder().contentMetadata(dmd).userMetadata(md).build()); } catch (Exception e) { ContentMetadata dmd = blobStore.blobMetadata(this.name, id).getContentMetadata(); blobStore.copyBlob(this.name, id, this.name, id + ".ck", CopyOptions.builder().contentMetadata(dmd).userMetadata(md).build()); blobStore.removeBlob(name, id); blobStore.copyBlob(this.name, id + ".ck", this.name, id, CopyOptions.builder().contentMetadata(dmd).userMetadata(md).build()); blobStore.removeBlob(name, id + ".ck");
@Test(groups = { "integration", "live" }) public void testCopyIfModifiedSince() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { blobStore.putBlob(fromContainer, blob); Date before = new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1)); blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifModifiedSince(before).build()); Blob toBlob = blobStore.getBlob(toContainer, toName); InputStream is = null; try { is = toBlob.getPayload().openStream(); assertEquals(ByteStreams.toByteArray(is), payload.read()); } finally { Closeables2.closeQuietly(is); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
@Test(groups = { "integration", "live" }) public void testCopyIfMatch() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { String eTag = blobStore.putBlob(fromContainer, blob); blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifMatch(eTag).build()); Blob toBlob = blobStore.getBlob(toContainer, toName); InputStream is = null; try { is = toBlob.getPayload().openStream(); assertEquals(ByteStreams.toByteArray(is), payload.read()); } finally { Closeables2.closeQuietly(is); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
@Test(groups = { "integration", "live" }) public void testCopyIfModifiedSinceNegative() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { blobStore.putBlob(fromContainer, blob); // TODO: some problem with S3 and times in the future? Date after = new Date(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1)); try { blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifModifiedSince(after).build()); Fail.failBecauseExceptionWasNotThrown(HttpResponseException.class); } catch (HttpResponseException hre) { // most object stores return 412 but swift returns 304 assertThat(hre.getResponse().getStatusCode()).isIn(304, 412); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
@Test(groups = { "integration", "live" }) public void testCopyIfNoneMatch() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { blobStore.putBlob(fromContainer, blob); blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifNoneMatch("fake-etag").build()); Blob toBlob = blobStore.getBlob(toContainer, toName); InputStream is = null; try { is = toBlob.getPayload().openStream(); assertEquals(ByteStreams.toByteArray(is), payload.read()); } finally { Closeables2.closeQuietly(is); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
@Test(groups = { "integration", "live" }) public void testCopyIfUnmodifiedSinceNegative() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { blobStore.putBlob(fromContainer, blob); Date before = new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1)); try { blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifUnmodifiedSince(before).build()); Fail.failBecauseExceptionWasNotThrown(HttpResponseException.class); } catch (HttpResponseException hre) { assertThat(hre.getResponse().getStatusCode()).isEqualTo(412); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
@Test(groups = { "integration", "live" }) public void testCopyIfMatchNegative() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { blobStore.putBlob(fromContainer, blob); try { blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifMatch("fake-etag").build()); Fail.failBecauseExceptionWasNotThrown(HttpResponseException.class); } catch (HttpResponseException hre) { assertThat(hre.getResponse().getStatusCode()).isEqualTo(412); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
@Test(groups = { "integration", "live" }) public void testCopyIfUnmodifiedSince() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { blobStore.putBlob(fromContainer, blob); Date after = new Date(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1)); blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifUnmodifiedSince(after).build()); Blob toBlob = blobStore.getBlob(toContainer, toName); InputStream is = null; try { is = toBlob.getPayload().openStream(); assertEquals(ByteStreams.toByteArray(is), payload.read()); } finally { Closeables2.closeQuietly(is); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
@Test(groups = { "integration", "live" }) public void testCopyIfNoneMatchNegative() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { String eTag = blobStore.putBlob(fromContainer, blob); try { blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifNoneMatch(eTag).build()); Fail.failBecauseExceptionWasNotThrown(HttpResponseException.class); } catch (HttpResponseException hre) { assertThat(hre.getResponse().getStatusCode()).isEqualTo(412); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
CopyOptions.builder().userMetadata(ImmutableMap.of("B", "b", "a", "a")).build() );
@Override public void renameFile(String from, String to, String pp) throws IOException { while (from.startsWith(File.separator)) from = from.substring(1); while (to.startsWith(File.separator)) to = to.substring(1); String fn = EncyptUtils.encString(from, Main.chunkStoreEncryptionEnabled); String tn = EncyptUtils.encString(to, Main.chunkStoreEncryptionEnabled); try { blobStore.copyBlob(this.name, fn, this.name, tn, CopyOptions.builder().userMetadata(this.getUserMetaData(fn)).build()); } catch (Exception e) { throw new IOException(e); } }
public CopyOptions build() { Map<String, String> userMetadata = userMetadata(); if (userMetadata != null) { userMetadata(ImmutableMap.copyOf(userMetadata)); } return autoBuild(); } }
public CopyOptions build() { Map<String, String> userMetadata = userMetadata(); if (userMetadata != null) { userMetadata(ImmutableMap.copyOf(userMetadata)); } return autoBuild(); } }
public CopyOptions build() { Map<String, String> userMetadata = userMetadata(); if (userMetadata != null) { userMetadata(ImmutableMap.copyOf(userMetadata)); } return autoBuild(); } }