Prefer ImmutableCollection over mutable array

Also static.
This commit is contained in:
Andrew Gaul 2012-03-19 18:51:21 -07:00
parent f2ce700ec1
commit 74862d7321
2 changed files with 8 additions and 5 deletions

View File

@ -62,6 +62,7 @@ import org.jclouds.s3.Bucket;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
@ -85,9 +86,9 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
} }
}; };
private final String[] firstHeadersToSign = new String[] { HttpHeaders.DATE }; private static final Collection<String> FIRST_HEADERS_TO_SIGN = ImmutableList.of(HttpHeaders.DATE);
public static Set<String> SIGNED_PARAMETERS = ImmutableSet.of("acl", "torrent", "logging", "location", "policy", private static final Set<String> SIGNED_PARAMETERS = ImmutableSet.of("acl", "torrent", "logging", "location", "policy",
"requestPayment", "versioning", "versions", "versionId", "notification", "uploadId", "uploads", "requestPayment", "versioning", "versions", "versionId", "notification", "uploadId", "uploads",
"partNumber", "website", "response-content-type", "response-content-language", "response-expires", "partNumber", "website", "response-content-type", "response-content-language", "response-expires",
"response-cache-control", "response-content-disposition", "response-content-encoding"); "response-cache-control", "response-content-disposition", "response-content-encoding");
@ -209,7 +210,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
buffer.append( buffer.append(
utils.valueOrEmpty(request.getPayload() == null ? request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE) utils.valueOrEmpty(request.getPayload() == null ? request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)
: request.getPayload().getContentMetadata().getContentType())).append("\n"); : request.getPayload().getContentMetadata().getContentType())).append("\n");
for (String header : firstHeadersToSign) for (String header : FIRST_HEADERS_TO_SIGN)
buffer.append(valueOrEmpty(request.getHeaders().get(header))).append("\n"); buffer.append(valueOrEmpty(request.getHeaders().get(header))).append("\n");
} }

View File

@ -20,6 +20,7 @@ package org.jclouds.azure.storage.filters;
import static org.jclouds.util.Patterns.NEWLINE_PATTERN; import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
import java.util.Collection;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -45,6 +46,7 @@ import org.jclouds.logging.Logger;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
@ -58,7 +60,7 @@ import com.google.common.collect.Multimaps;
*/ */
@Singleton @Singleton
public class SharedKeyLiteAuthentication implements HttpRequestFilter { public class SharedKeyLiteAuthentication implements HttpRequestFilter {
private final String[] firstHeadersToSign = new String[] { HttpHeaders.DATE }; private static final Collection<String> FIRST_HEADERS_TO_SIGN = ImmutableList.of(HttpHeaders.DATE);
private final SignatureWire signatureWire; private final SignatureWire signatureWire;
private final String identity; private final String identity;
@ -163,7 +165,7 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
} }
private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) { private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
for (String header : firstHeadersToSign) for (String header : FIRST_HEADERS_TO_SIGN)
toSign.append(utils.valueOrEmpty(request.getHeaders().get(header))).append("\n"); toSign.append(utils.valueOrEmpty(request.getHeaders().get(header))).append("\n");
} }