Revert "Replace uses of ByteArrayPayload"

This reverts commit bd5b6853ee.
This commit is contained in:
Adrian Cole 2014-10-28 15:46:42 -07:00 committed by Adrian Cole
parent ae8b7636df
commit 1702bddffa
11 changed files with 23 additions and 21 deletions

View File

@ -82,7 +82,7 @@ See http://code.google.com/p/jclouds for details."
;; hence separating it from the above
(extend-protocol PayloadSource
(class (make-array Byte/TYPE 0))
(payload [ba] (Payloads/newPayload ba)))
(payload [ba] (Payloads/newByteArrayPayload ba)))
(defn blobstore
"Create a logged in context.

View File

@ -16,6 +16,8 @@
*/
package org.jclouds.blobstore.strategy.internal;
import static org.jclouds.io.Payloads.newByteArrayPayload;
import javax.inject.Named;
import javax.inject.Singleton;
@ -24,7 +26,6 @@ import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.blobstore.strategy.MkdirStrategy;
import com.google.common.io.ByteSource;
import com.google.inject.Inject;
/**
@ -49,8 +50,6 @@ public class MarkerFileMkdirStrategy implements MkdirStrategy {
blobStore.putBlob(
containerName,
blobStore.blobBuilder(directory + directorySuffix).type(StorageType.RELATIVE_PATH)
.payload(ByteSource.empty())
.contentLength(0L)
.contentType("application/directory").build());
.payload(newByteArrayPayload(new byte[] {})).contentType("application/directory").build());
}
}

View File

@ -68,7 +68,7 @@ public class HttpMessage extends PayloadEnclosingImpl {
*/
@Deprecated
public T payload(byte [] payload) {
this.payload = Payloads.newPayload(checkNotNull(payload, "payload"));
this.payload = Payloads.newByteArrayPayload(checkNotNull(payload, "payload"));
return self();
}

View File

@ -45,10 +45,7 @@ public class Payloads {
} else if (data instanceof InputStream) {
return newInputStreamPayload((InputStream) data);
} else if (data instanceof byte[]) {
byte[] array = (byte[]) data;
Payload payload = newByteSourcePayload(ByteSource.wrap(array));
payload.getContentMetadata().setContentLength((long) array.length);
return payload;
return newByteArrayPayload((byte[]) data);
} else if (data instanceof ByteSource) {
return newByteSourcePayload((ByteSource) data);
} else if (data instanceof String) {

View File

@ -33,9 +33,9 @@ import javax.inject.Singleton;
import org.jclouds.io.ContentMetadata;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.io.PayloadSlicer;
import org.jclouds.io.payloads.BaseMutableContentMetadata;
import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.io.payloads.ByteSourcePayload;
import org.jclouds.io.payloads.InputStreamPayload;
@ -119,7 +119,7 @@ public class BasePayloadSlicer implements PayloadSlicer {
Payload payload = null;
if (content.length > 0) {
payload = Payloads.newPayload(content);
payload = new ByteArrayPayload(content);
ContentMetadata cm = metaData.toBuilder().contentLength((long)content.length).contentMD5((HashCode) null).build();
payload.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(cm));
}

View File

@ -23,7 +23,7 @@ import com.google.common.base.Charsets;
/**
* This implementation converts the String to a byte array using UTF-8 encoding. If you wish to use
* a different encoding, please use {@link ByteSourcePayload}.
* a different encoding, please use {@link ByteArrayPayload}.
*
* @deprecated see ByteSourcePayload
*/

View File

@ -300,7 +300,7 @@ public class RestAnnotationProcessor implements Function<Invocation, HttpRequest
payload = Payloads.newUrlEncodedFormPayload(transformValues(formParams, NullableToStringFunction.INSTANCE));
} else if (headers.containsKey(CONTENT_TYPE) && !HttpRequest.NON_PAYLOAD_METHODS.contains(requestMethod)) {
if (payload == null)
payload = Payloads.newPayload(new byte[] {});
payload = Payloads.newByteArrayPayload(new byte[] {});
payload.getContentMetadata().setContentType(get(headers.get(CONTENT_TYPE), 0));
}
if (payload != null) {

View File

@ -36,6 +36,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
@ -47,6 +48,7 @@ import org.jclouds.io.ContentMetadataCodec;
import org.jclouds.io.MutableContentMetadata;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.BasePayload;
import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.io.payloads.DelegatingPayload;
import org.jclouds.io.payloads.FilePayload;
import org.jclouds.io.payloads.StringPayload;
@ -137,6 +139,10 @@ public class ApacheHCUtils {
} else if (payload instanceof FilePayload) {
apacheRequest.setEntity(new FileEntity((File) payload.getRawContent(), payload.getContentMetadata()
.getContentType()));
} else if (payload instanceof ByteArrayPayload) {
ByteArrayEntity Entity = new ByteArrayEntity((byte[]) payload.getRawContent());
Entity.setContentType(payload.getContentMetadata().getContentType());
apacheRequest.setEntity(Entity);
} else {
InputStream inputStream = payload.getInput();
if (payload.getContentMetadata().getContentLength() == null)

View File

@ -43,7 +43,7 @@ public class ConvertToJcloudsResponse implements Function<HTTPResponse, HttpResp
@Override
public HttpResponse apply(HTTPResponse gaeResponse) {
Payload payload = gaeResponse.getContent() != null ? Payloads.newPayload(gaeResponse.getContent())
Payload payload = gaeResponse.getContent() != null ? Payloads.newByteArrayPayload(gaeResponse.getContent())
: null;
Multimap<String, String> headers = LinkedHashMultimap.create();
String message = null;

View File

@ -18,6 +18,7 @@ package org.jclouds.aws.s3;
import static com.google.common.hash.Hashing.md5;
import static org.jclouds.aws.s3.blobstore.options.AWSS3PutOptions.Builder.storageClass;
import static org.jclouds.io.Payloads.newByteArrayPayload;
import static org.jclouds.s3.options.ListBucketOptions.Builder.withPrefix;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@ -40,7 +41,6 @@ import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.domain.Location;
import org.jclouds.io.ByteStreams2;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.s3.S3Client;
import org.jclouds.s3.S3ClientLiveTest;
import org.jclouds.s3.domain.ListBucketResponse;
@ -92,7 +92,7 @@ public class AWSS3ClientLiveTest extends S3ClientLiveTest {
byte[] buffer = oneHundredOneConstitutions.read();
assertEquals(oneHundredOneConstitutions.size(), (long) buffer.length);
Payload part1 = Payloads.newPayload(buffer);
Payload part1 = newByteArrayPayload(buffer);
part1.getContentMetadata().setContentLength((long) buffer.length);
part1.getContentMetadata().setContentMD5(oneHundredOneConstitutionsMD5);

View File

@ -44,7 +44,7 @@ import org.jclouds.blobstore.ContainerNotFoundException;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.options.GetOptions;
import org.jclouds.io.Payloads;
import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.util.Strings2;
import org.jclouds.util.Throwables2;
import org.testng.annotations.Test;
@ -358,9 +358,9 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest {
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.newPayload(A.getBytes()));
getApi().putBlock(blockContainer, blockBlob, blockIdB, Payloads.newPayload(B.getBytes()));
getApi().putBlock(blockContainer, blockBlob, blockIdC, Payloads.newPayload(C.getBytes()));
getApi().putBlock(blockContainer, blockBlob, blockIdA, new ByteArrayPayload(A.getBytes()));
getApi().putBlock(blockContainer, blockBlob, blockIdB, new ByteArrayPayload(B.getBytes()));
getApi().putBlock(blockContainer, blockBlob, blockIdC, new ByteArrayPayload(C.getBytes()));
getApi().putBlockList(blockContainer, blockBlob, Arrays.asList(blockIdA, blockIdB, blockIdC));
ListBlobBlocksResponse blocks = getApi().getBlockList(blockContainer, blockBlob);
assertEquals(3, blocks.getBlocks().size());