diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/domain/internal/DelegatingMutableContentMetadata.java b/apis/atmos/src/main/java/org/jclouds/atmos/domain/internal/DelegatingMutableContentMetadata.java index 71e20e2416..50f763a9b1 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/domain/internal/DelegatingMutableContentMetadata.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/domain/internal/DelegatingMutableContentMetadata.java @@ -23,6 +23,8 @@ import org.jclouds.atmos.domain.MutableContentMetadata; import org.jclouds.io.ContentMetadataBuilder; import org.jclouds.io.payloads.BaseMutableContentMetadata; +import com.google.common.hash.HashCode; + /** * * @author Adrian Cole @@ -50,11 +52,18 @@ public class DelegatingMutableContentMetadata implements MutableContentMetadata return delegate.getContentLength(); } + /** @deprecated use {@link #getContentMD5AsHashCode()} instead. */ + @Deprecated @Override public byte[] getContentMD5() { return delegate.getContentMD5(); } + @Override + public HashCode getContentMD5AsHashCode() { + return delegate.getContentMD5AsHashCode(); + } + @Override public String getContentType() { return delegate.getContentType(); @@ -70,11 +79,18 @@ public class DelegatingMutableContentMetadata implements MutableContentMetadata delegate.setContentLength(contentLength); } + /** @deprecated use {@link #setContentMD5(HashCode)} instead. */ + @Deprecated @Override public void setContentMD5(byte[] contentMD5) { delegate.setContentMD5(contentMD5); } + @Override + public void setContentMD5(HashCode contentMD5) { + delegate.setContentMD5(contentMD5); + } + @Override public void setContentType(String contentType) { delegate.setContentType(contentType); diff --git a/blobstore/src/main/java/org/jclouds/blobstore/domain/BlobBuilder.java b/blobstore/src/main/java/org/jclouds/blobstore/domain/BlobBuilder.java index f0b052c63d..24ee315914 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/domain/BlobBuilder.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/domain/BlobBuilder.java @@ -25,6 +25,7 @@ import java.util.Map; import org.jclouds.blobstore.domain.internal.BlobBuilderImpl; import org.jclouds.io.Payload; +import com.google.common.hash.HashCode; import com.google.common.io.ByteSource; import com.google.inject.ImplementedBy; @@ -117,8 +118,12 @@ public interface BlobBuilder { PayloadBlobBuilder contentLength(long contentLength); + /** @deprecated use {@link #contentMD5(HashCode)} instead. */ + @Deprecated PayloadBlobBuilder contentMD5(byte[] md5); + PayloadBlobBuilder contentMD5(HashCode md5); + PayloadBlobBuilder contentType(String contentType); PayloadBlobBuilder contentDisposition(String contentDisposition); diff --git a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobBuilderImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobBuilderImpl.java index 2d51cdb4ba..2b46de9f4c 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobBuilderImpl.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobBuilderImpl.java @@ -35,6 +35,7 @@ import org.jclouds.io.Payloads; import org.jclouds.io.payloads.PhantomPayload; import com.google.common.collect.Maps; +import com.google.common.hash.HashCode; import com.google.common.io.ByteSource; /** @@ -199,8 +200,15 @@ public class BlobBuilderImpl implements BlobBuilder { return this; } + /** @deprecated use {@link #contentMD5(HashCode)} instead. */ + @Deprecated @Override public PayloadBlobBuilder contentMD5(byte[] md5) { + return contentMD5(md5 == null ? null : HashCode.fromBytes(md5)); + } + + @Override + public PayloadBlobBuilder contentMD5(HashCode md5) { payload.getContentMetadata().setContentMD5(md5); return this; } diff --git a/core/src/main/java/org/jclouds/io/ContentMetadata.java b/core/src/main/java/org/jclouds/io/ContentMetadata.java index 795b3c313b..69bf141fbb 100644 --- a/core/src/main/java/org/jclouds/io/ContentMetadata.java +++ b/core/src/main/java/org/jclouds/io/ContentMetadata.java @@ -28,6 +28,7 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; +import com.google.common.hash.HashCode; import com.google.common.collect.ImmutableSet; /** @@ -82,9 +83,14 @@ public interface ContentMetadata { @Nullable String getContentType(); + /** @deprecated use {@link #getContentMD5AsHashCode()} instead. */ + @Deprecated @Nullable byte[] getContentMD5(); + @Nullable + HashCode getContentMD5AsHashCode(); + /** * Get Content Language of the payload *
diff --git a/core/src/main/java/org/jclouds/io/ContentMetadataBuilder.java b/core/src/main/java/org/jclouds/io/ContentMetadataBuilder.java index 1aa58c432b..e9737fadbd 100644 --- a/core/src/main/java/org/jclouds/io/ContentMetadataBuilder.java +++ b/core/src/main/java/org/jclouds/io/ContentMetadataBuilder.java @@ -16,13 +16,13 @@ */ package org.jclouds.io; -import java.util.Arrays; import java.util.Date; import org.jclouds.io.payloads.BaseImmutableContentMetadata; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; +import com.google.common.hash.HashCode; /** * @author Adrian Cole @@ -35,7 +35,7 @@ public class ContentMetadataBuilder { protected String contentType = "application/unknown"; protected Long contentLength; - protected byte[] contentMD5; + protected HashCode contentMD5; protected String contentDisposition; protected String contentLanguage; protected String contentEncoding; @@ -46,14 +46,17 @@ public class ContentMetadataBuilder { return this; } - public ContentMetadataBuilder contentMD5(byte[] md5) { - if (md5 != null) { - byte[] retval = new byte[md5.length]; - System.arraycopy(md5, 0, retval, 0, md5.length); - this.contentMD5 = md5; + /** @deprecated use {@link #contentMD5(HashCode)} instead. */ + @Deprecated + public ContentMetadataBuilder contentMD5(@Nullable byte[] contentMD5) { + return contentMD5(contentMD5 == null ? null : HashCode.fromBytes(contentMD5)); + } + + public ContentMetadataBuilder contentMD5(@Nullable HashCode contentMD5) { + if (contentMD5 != null) { + this.contentMD5 = contentMD5; } return this; - } public ContentMetadataBuilder contentType(@Nullable String contentType) { @@ -83,7 +86,8 @@ public class ContentMetadataBuilder { } public ContentMetadata build() { - return new BaseImmutableContentMetadata(contentType, contentLength, contentMD5, contentDisposition, + return new BaseImmutableContentMetadata(contentType, contentLength, + contentMD5 == null ? null : contentMD5.asBytes(), contentDisposition, contentLanguage, contentEncoding, expires); } @@ -112,7 +116,7 @@ public class ContentMetadataBuilder { Objects.equal(contentEncoding, other.contentEncoding) && Objects.equal(contentLanguage, other.contentLanguage) && Objects.equal(contentLength, other.contentLength) && - Arrays.equals(contentMD5, other.contentMD5) && + Objects.equal(contentMD5, other.contentMD5) && Objects.equal(contentType, other.contentType) && Objects.equal(expires, other.expires); } @@ -121,6 +125,6 @@ public class ContentMetadataBuilder { public String toString() { return "[contentDisposition=" + contentDisposition + ", contentEncoding=" + contentEncoding + ", contentLanguage=" + contentLanguage + ", contentLength=" + contentLength + ", contentMD5=" - + Arrays.toString(contentMD5) + ", contentType=" + contentType + ", expires=" + expires + "]"; + + contentMD5 + ", contentType=" + contentType + ", expires=" + expires + "]"; } } diff --git a/core/src/main/java/org/jclouds/io/MutableContentMetadata.java b/core/src/main/java/org/jclouds/io/MutableContentMetadata.java index 0eeb3e63e8..4e3518b223 100644 --- a/core/src/main/java/org/jclouds/io/MutableContentMetadata.java +++ b/core/src/main/java/org/jclouds/io/MutableContentMetadata.java @@ -20,6 +20,8 @@ import java.util.Date; import org.jclouds.javax.annotation.Nullable; +import com.google.common.hash.HashCode; + /** * @author Adrian Cole */ @@ -27,8 +29,12 @@ public interface MutableContentMetadata extends ContentMetadata { void setContentLength(@Nullable Long contentLength); + /** @deprecated use {@link #setContentMD5(HashCode)} instead. */ + @Deprecated void setContentMD5(@Nullable byte[] md5); + void setContentMD5(@Nullable HashCode md5); + void setContentType(@Nullable String contentType); /** diff --git a/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java b/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java index 67997c6744..8c181c04a4 100644 --- a/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java +++ b/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java @@ -41,6 +41,7 @@ import org.jclouds.io.payloads.InputStreamPayload; import org.jclouds.io.payloads.InputStreamSupplierPayload; import com.google.common.base.Throwables; +import com.google.common.hash.HashCode; import com.google.common.io.ByteStreams; import com.google.common.io.Files; import com.google.common.io.InputSupplier; @@ -115,7 +116,7 @@ public class BasePayloadSlicer implements PayloadSlicer { if (content.length > 0) { payload = new ByteArrayPayload(content); - ContentMetadata cm = metaData.toBuilder().contentLength((long)content.length).contentMD5(null).build(); + ContentMetadata cm = metaData.toBuilder().contentLength((long)content.length).contentMD5((HashCode) null).build(); payload.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(cm)); } @@ -183,7 +184,7 @@ public class BasePayloadSlicer implements PayloadSlicer { protected Payload copyMetadataAndSetLength(Payload input, Payload returnVal, long length) { returnVal.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(input.getContentMetadata() - .toBuilder().contentLength(length).contentMD5(null).build())); + .toBuilder().contentLength(length).contentMD5((HashCode) null).build())); return returnVal; } @@ -195,7 +196,7 @@ public class BasePayloadSlicer implements PayloadSlicer { ContentMetadata meta = BaseMutableContentMetadata.fromContentMetadata(input.getContentMetadata()) .toBuilder() .contentLength(size) - .contentMD5(null) + .contentMD5((HashCode) null) .build(); Object rawContent = input.getRawContent(); if (rawContent instanceof File) { diff --git a/core/src/main/java/org/jclouds/io/payloads/BaseImmutableContentMetadata.java b/core/src/main/java/org/jclouds/io/payloads/BaseImmutableContentMetadata.java index 7e00eccb91..4ab95aa7e9 100644 --- a/core/src/main/java/org/jclouds/io/payloads/BaseImmutableContentMetadata.java +++ b/core/src/main/java/org/jclouds/io/payloads/BaseImmutableContentMetadata.java @@ -16,13 +16,13 @@ */ package org.jclouds.io.payloads; -import java.util.Arrays; import java.util.Date; import org.jclouds.io.ContentMetadata; import org.jclouds.io.ContentMetadataBuilder; import com.google.common.base.Objects; +import com.google.common.hash.HashCode; /** * @author Adrian Cole @@ -31,7 +31,7 @@ public class BaseImmutableContentMetadata implements ContentMetadata { protected String contentType; protected Long contentLength; - protected byte[] contentMD5; + protected HashCode contentMD5; protected String contentDisposition; protected String contentLanguage; protected String contentEncoding; @@ -41,7 +41,7 @@ public class BaseImmutableContentMetadata implements ContentMetadata { String contentDisposition, String contentLanguage, String contentEncoding, Date expires) { this.contentType = contentType; this.contentLength = contentLength; - this.contentMD5 = contentMD5; + this.contentMD5 = contentMD5 == null ? null : HashCode.fromBytes(contentMD5); this.contentDisposition = contentDisposition; this.contentLanguage = contentLanguage; this.contentEncoding = contentEncoding; @@ -56,18 +56,17 @@ public class BaseImmutableContentMetadata implements ContentMetadata { return contentLength; } - /** - * {@inheritDoc} - */ + /** @deprecated use {@link #getContentMD5AsHashCode()} instead. */ + @Deprecated @Override public byte[] getContentMD5() { - if (contentMD5 != null) { - byte[] retval = new byte[contentMD5.length]; - System.arraycopy(this.contentMD5, 0, retval, 0, contentMD5.length); - return retval; - } else { - return null; - } + HashCode hashCode = getContentMD5AsHashCode(); + return hashCode == null ? null : hashCode.asBytes(); + } + + @Override + public HashCode getContentMD5AsHashCode() { + return contentMD5; } /** @@ -114,7 +113,7 @@ public class BaseImmutableContentMetadata implements ContentMetadata { public String toString() { return "[contentType=" + contentType + ", contentLength=" + contentLength + ", contentDisposition=" + contentDisposition + ", contentEncoding=" + contentEncoding + ", contentLanguage=" + contentLanguage - + ", contentMD5=" + Arrays.toString(contentMD5) + ", expires = " + expires + "]"; + + ", contentMD5=" + contentMD5 + ", expires = " + expires + "]"; } @Override @@ -152,7 +151,7 @@ public class BaseImmutableContentMetadata implements ContentMetadata { return false; } else if (!contentLength.equals(other.contentLength)) return false; - if (!Arrays.equals(contentMD5, other.contentMD5)) + if (!Objects.equal(contentMD5, other.contentMD5)) return false; if (contentType == null) { if (other.contentType != null) diff --git a/core/src/main/java/org/jclouds/io/payloads/BaseMutableContentMetadata.java b/core/src/main/java/org/jclouds/io/payloads/BaseMutableContentMetadata.java index cee2f5b189..c17ad807f4 100644 --- a/core/src/main/java/org/jclouds/io/payloads/BaseMutableContentMetadata.java +++ b/core/src/main/java/org/jclouds/io/payloads/BaseMutableContentMetadata.java @@ -23,6 +23,8 @@ import org.jclouds.io.ContentMetadataBuilder; import org.jclouds.io.MutableContentMetadata; import org.jclouds.javax.annotation.Nullable; +import com.google.common.hash.HashCode; + /** * @author Adrian Cole */ @@ -44,25 +46,28 @@ public class BaseMutableContentMetadata extends ContentMetadataBuilder implement contentLength(contentLength); } - /** - * {@inheritDoc} - */ + /** @deprecated use {@link #getContentMD5AsHashCode()} instead. */ + @Deprecated @Override public byte[] getContentMD5() { - if (contentMD5 != null) { - byte[] retval = new byte[contentMD5.length]; - System.arraycopy(this.contentMD5, 0, retval, 0, contentMD5.length); - return retval; - } else { - return null; - } + HashCode hashCode = getContentMD5AsHashCode(); + return hashCode == null ? null : hashCode.asBytes(); } - /** - * {@inheritDoc} - */ + @Override + public HashCode getContentMD5AsHashCode() { + return contentMD5; + } + + /** @deprecated use {@link #setContentMD5(HashCode)} instead. */ + @Deprecated @Override public void setContentMD5(byte[] md5) { + setContentMD5(md5 == null ? null : HashCode.fromBytes(md5)); + } + + @Override + public void setContentMD5(HashCode md5) { contentMD5(md5); }