mirror of https://github.com/apache/jclouds.git
Merge pull request #902 from andrewgaul/input-suppliers-of-byte-array
Remove InputSuppliers.of(byte[])
This commit is contained in:
commit
53fcdbb790
|
@ -50,7 +50,6 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
import org.jclouds.io.ContentMetadata;
|
import org.jclouds.io.ContentMetadata;
|
||||||
import org.jclouds.io.InputSuppliers;
|
|
||||||
import org.jclouds.io.MutableContentMetadata;
|
import org.jclouds.io.MutableContentMetadata;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.PayloadEnclosing;
|
import org.jclouds.io.PayloadEnclosing;
|
||||||
|
@ -304,17 +303,9 @@ public class HttpUtils {
|
||||||
if (message.getPayload().getContentMetadata().getContentLength() != null)
|
if (message.getPayload().getContentMetadata().getContentLength() != null)
|
||||||
logger.debug("%s %s: %s", prefix, CONTENT_LENGTH, message.getPayload().getContentMetadata()
|
logger.debug("%s %s: %s", prefix, CONTENT_LENGTH, message.getPayload().getContentMetadata()
|
||||||
.getContentLength());
|
.getContentLength());
|
||||||
if (message.getPayload().getContentMetadata().getContentMD5() != null)
|
byte[] md5 = message.getPayload().getContentMetadata().getContentMD5();
|
||||||
try {
|
if (md5 != null)
|
||||||
logger.debug(
|
logger.debug("%s %s: %s", prefix, "Content-MD5", CryptoStreams.base64(md5));
|
||||||
"%s %s: %s",
|
|
||||||
prefix,
|
|
||||||
"Content-MD5",
|
|
||||||
CryptoStreams.base64Encode(InputSuppliers.of(message.getPayload().getContentMetadata()
|
|
||||||
.getContentMD5())));
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.warn(e, " error getting md5 for %s", message);
|
|
||||||
}
|
|
||||||
if (message.getPayload().getContentMetadata().getContentDisposition() != null)
|
if (message.getPayload().getContentMetadata().getContentDisposition() != null)
|
||||||
logger.debug("%s %s: %s", prefix, "Content-Disposition", message.getPayload().getContentMetadata()
|
logger.debug("%s %s: %s", prefix, "Content-Disposition", message.getPayload().getContentMetadata()
|
||||||
.getContentDisposition());
|
.getContentDisposition());
|
||||||
|
|
|
@ -82,11 +82,8 @@ public class InputSuppliers {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputSupplier<? extends InputStream> of(byte[] in) {
|
|
||||||
return ByteStreams.newInputStreamSupplier(checkNotNull(in, "in"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InputSupplier<? extends InputStream> of(String in) {
|
public static InputSupplier<? extends InputStream> of(String in) {
|
||||||
return of(checkNotNull(in, "in").getBytes(Charsets.UTF_8));
|
byte[] bytes = checkNotNull(in, "in").getBytes(Charsets.UTF_8);
|
||||||
|
return ByteStreams.newInputStreamSupplier(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
payload.getContentMetadata().setContentMD5(digest);
|
payload.getContentMetadata().setContentMD5(digest);
|
||||||
Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
|
Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
|
||||||
assertEquals(headers.get("x-Content-MD5"),
|
assertEquals(headers.get("x-Content-MD5"),
|
||||||
Collections.singleton(CryptoStreams.base64Encode(InputSuppliers.of(digest))));
|
Collections.singleton(CryptoStreams.base64(digest)));
|
||||||
payload.release();
|
payload.release();
|
||||||
} finally {
|
} finally {
|
||||||
if (os != null)
|
if (os != null)
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.vcloud.director.v1_5.handlers;
|
||||||
|
|
||||||
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
|
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
|
|
||||||
|
@ -27,7 +28,6 @@ import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpErrorHandler;
|
import org.jclouds.http.HttpErrorHandler;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.io.InputSuppliers;
|
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
|
@ -58,7 +58,7 @@ public class VCloudDirectorErrorHandler implements HttpErrorHandler {
|
||||||
// Try to create a VCloudDirectorException from XML payload, if it exists
|
// Try to create a VCloudDirectorException from XML payload, if it exists
|
||||||
if (response.getPayload() != null && response.getPayload().getContentMetadata().getContentType().startsWith(VCloudDirectorMediaType.ERROR)) {
|
if (response.getPayload() != null && response.getPayload().getContentMetadata().getContentType().startsWith(VCloudDirectorMediaType.ERROR)) {
|
||||||
try {
|
try {
|
||||||
Error error = JAXB.unmarshal(InputSuppliers.of(data).getInput(), Error.class);
|
Error error = JAXB.unmarshal(new ByteArrayInputStream(data), Error.class);
|
||||||
exception = new VCloudDirectorException(error);
|
exception = new VCloudDirectorException(error);
|
||||||
message = error.getMessage();
|
message = error.getMessage();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue