diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java index 5383327de3..768f1fe8ff 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java @@ -67,7 +67,7 @@ public class ParseAtmosErrorFromXmlContent implements HttpErrorHandler { AtmosError error = null; if (response.getPayload() != null) { try { - String content = Strings2.toString(response.getPayload()); + String content = Strings2.toStringAndClose(response.getPayload().openStream()); if (content != null && content.indexOf('<') >= 0) { error = utils.parseAtmosErrorFromContent(command, response, Strings2.toInputStream(content)); } else { diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosClientLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosClientLiveTest.java index 99b2b4ec74..0cf4d6cdad 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosClientLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosClientLiveTest.java @@ -261,14 +261,14 @@ public class AtmosClientLiveTest extends BaseBlobStoreIntegrationTest { private static void verifyHeadObject(AtmosClient connection, String path, String metadataValue) throws InterruptedException, ExecutionException, TimeoutException, IOException { AtmosObject getBlob = connection.headFile(path); - assertEquals(Strings2.toString(getBlob.getPayload()), ""); + assertEquals(Strings2.toStringAndClose(getBlob.getPayload().openStream()), ""); verifyMetadata(metadataValue, getBlob); } private static void verifyObject(AtmosClient connection, String path, String compare, String metadataValue) throws InterruptedException, ExecutionException, TimeoutException, IOException { AtmosObject getBlob = connection.readFile(path); - assertEquals(Strings2.toString(getBlob.getPayload()), compare); + assertEquals(Strings2.toStringAndClose(getBlob.getPayload().openStream()), compare); verifyMetadata(metadataValue, getBlob); } diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/handlers/ParseCloudServersErrorFromHttpResponse.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/handlers/ParseCloudServersErrorFromHttpResponse.java index 59734f170f..012e5e5036 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/handlers/ParseCloudServersErrorFromHttpResponse.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/handlers/ParseCloudServersErrorFromHttpResponse.java @@ -80,7 +80,7 @@ public class ParseCloudServersErrorFromHttpResponse implements HttpErrorHandler String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) { if (response.getPayload() != null) { try { - return Strings2.toString(response.getPayload()); + return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { logger.warn(e, "exception reading error from response", response); } diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java index 8be961d3e8..aa9c2bacc7 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java @@ -379,7 +379,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes try { client.connect(); Payload etcPasswd = client.get("/etc/jclouds.txt"); - String etcPasswdContents = Strings2.toString(etcPasswd); + String etcPasswdContents = Strings2.toStringAndClose(etcPasswd.openStream()); assertEquals("rackspace", etcPasswdContents.trim()); } finally { if (client != null) diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java index 3ec4911f8c..56d9aa3606 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/handlers/CloudSigmaErrorHandler.java @@ -88,7 +88,7 @@ public class CloudSigmaErrorHandler implements HttpErrorHandler { if (response.getPayload() == null) return null; try { - return Strings2.toString(response.getPayload()); + return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw new RuntimeException(e); } finally { diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java index 0ba3b45f49..6c6f886ec5 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java @@ -90,7 +90,7 @@ public class CloudStackErrorHandler implements HttpErrorHandler { if (response.getPayload() == null) return null; try { - return Strings2.toString(response.getPayload()); + return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw new RuntimeException(e); } finally { diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java index 6de216446b..36ef425002 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/handlers/ElasticStackErrorHandler.java @@ -91,7 +91,7 @@ public class ElasticStackErrorHandler implements HttpErrorHandler { if (response.getPayload() == null) return null; try { - return Strings2.toString(response.getPayload()); + return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw new RuntimeException(e); } finally { diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackApiLiveTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackApiLiveTest.java index 1253021444..2c1947e4fd 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackApiLiveTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackApiLiveTest.java @@ -328,7 +328,7 @@ public class ElasticStackApiLiveTest extends BaseComputeServiceContextLiveTest { public void testWeCanReadAndWriteToDrive() throws IOException { drive2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build()); client.writeDrive(drive2.getUuid(), Payloads.newStringPayload("foo")); - assertEquals(Strings2.toString(client.readDrive(drive2.getUuid(), 0, 3)), "foo"); + assertEquals(Strings2.toStringAndClose(client.readDrive(drive2.getUuid(), 0, 3).openStream()), "foo"); } @Test(dependsOnMethods = "testWeCanReadAndWriteToDrive") @@ -343,7 +343,7 @@ public class ElasticStackApiLiveTest extends BaseComputeServiceContextLiveTest { assert driveNotClaimed.apply(drive2) : client.getDriveInfo(drive2.getUuid()); System.err.println("after image; drive 2" + client.getDriveInfo(drive2.getUuid())); System.err.println("after image; drive 3" + client.getDriveInfo(drive3.getUuid())); - assertEquals(Strings2.toString(client.readDrive(drive3.getUuid(), 0, 3)), "foo"); + assertEquals(Strings2.toStringAndClose(client.readDrive(drive3.getUuid(), 0, 3).openStream()), "foo"); } finally { client.destroyDrive(drive2.getUuid()); client.destroyDrive(drive3.getUuid()); diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java index 082e13c944..63f808a2aa 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java @@ -703,7 +703,7 @@ public class FilesystemAsyncBlobStoreTest { Blob blobRangeStartAt = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt); payload = blobRangeStartAt.getPayload(); try { - assertEquals(input.substring(1), Strings2.toString(payload)); + assertEquals(input.substring(1), Strings2.toStringAndClose(payload.openStream())); } finally { Closeables2.closeQuietly(payload); } @@ -713,7 +713,7 @@ public class FilesystemAsyncBlobStoreTest { Blob blobRangeTail = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail); payload = blobRangeTail.getPayload(); try { - assertEquals(input.substring(5), Strings2.toString(payload)); + assertEquals(input.substring(5), Strings2.toStringAndClose(payload.openStream())); } finally { Closeables2.closeQuietly(payload); } @@ -723,7 +723,7 @@ public class FilesystemAsyncBlobStoreTest { Blob blobFragment = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment); payload = blobFragment.getPayload(); try { - assertEquals(input.substring(4, 7), Strings2.toString(payload)); + assertEquals(input.substring(4, 7), Strings2.toStringAndClose(payload.openStream())); } finally { Closeables2.closeQuietly(payload); } diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/v1/handlers/ParseCloudLoadBalancersErrorFromHttpResponse.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/v1/handlers/ParseCloudLoadBalancersErrorFromHttpResponse.java index e8f182bc1f..c48e74e4b8 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/v1/handlers/ParseCloudLoadBalancersErrorFromHttpResponse.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/v1/handlers/ParseCloudLoadBalancersErrorFromHttpResponse.java @@ -78,7 +78,7 @@ public class ParseCloudLoadBalancersErrorFromHttpResponse implements HttpErrorHa String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) { if (response.getPayload() != null) { try { - return Strings2.toString(response.getPayload()); + return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { logger.warn(e, "exception reading error from response", response); } diff --git a/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java b/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java index a36881ad6f..d94fda1a0c 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java @@ -278,7 +278,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest { assertConsistencyAwareContainerSize(sourceContainer, 1); S3Object newObject = getApi().getObject(sourceContainer, key); assert newObject != null; - assertEquals(Strings2.toString(newObject.getPayload()), TEST_STRING); + assertEquals(Strings2.toStringAndClose(newObject.getPayload().openStream()), TEST_STRING); return newObject; } diff --git a/apis/sts/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java b/apis/sts/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java index 263a45e93c..b83d31e580 100644 --- a/apis/sts/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java +++ b/apis/sts/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java @@ -78,7 +78,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler { } } else { try { - message = Strings2.toString(response.getPayload()); + message = Strings2.toStringAndClose(response.getPayload().openStream()); exception = new HttpResponseException(command, response, message); } catch (IOException e) { } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java index 1646d0cf98..1fcf0a7f17 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java @@ -244,7 +244,7 @@ public abstract class CommonSwiftClientLiveTest ext assert getApi().getObject(containerName, "non-existent-object") == null; // Test GET of object (including updated metadata) SwiftObject getBlob = getApi().getObject(containerName, object.getInfo().getName()); - assertEquals(Strings2.toString(getBlob.getPayload()), data); + assertEquals(Strings2.toStringAndClose(getBlob.getPayload().openStream()), data); // TODO assertEquals(getBlob.getName(), // object.getMetadata().getName()); assertEquals(getBlob.getInfo().getBytes(), Long.valueOf(data.length())); @@ -289,7 +289,7 @@ public abstract class CommonSwiftClientLiveTest ext GetOptions.Builder.ifETagMatches(newEtag)); assertEquals(getBlob.getInfo().getHash(), base16().lowerCase().decode(newEtag)); getBlob = getApi().getObject(containerName, object.getInfo().getName(), GetOptions.Builder.startAt(8)); - assertEquals(Strings2.toString(getBlob.getPayload()), data.substring(8)); + assertEquals(Strings2.toStringAndClose(getBlob.getPayload().openStream()), data.substring(8)); } finally { returnContainer(containerName); @@ -321,7 +321,7 @@ public abstract class CommonSwiftClientLiveTest ext assertTrue(getApi().objectExists(destinationContainer, destinationObject)); SwiftObject destinationSwiftObject = getApi().getObject(destinationContainer, destinationObject); - assertEquals(Strings2.toString(destinationSwiftObject.getPayload()), data); + assertEquals(Strings2.toStringAndClose(destinationSwiftObject.getPayload().openStream()), data); // test exception thrown on bad destination container try { diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/handlers/ParseVCloudErrorFromHttpResponse.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/handlers/ParseVCloudErrorFromHttpResponse.java index ab322a832e..2c9f96f454 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/handlers/ParseVCloudErrorFromHttpResponse.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/handlers/ParseVCloudErrorFromHttpResponse.java @@ -68,7 +68,7 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler { message = error.getMessage(); exception = new VCloudResponseException(command, response, error); } else { - message = Strings2.toString(response.getPayload()); + message = Strings2.toStringAndClose(response.getPayload().openStream()); exception = message != null ? new HttpResponseException(command, response, message) : exception; } } catch (IOException e) { diff --git a/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java b/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java index c6d721cc00..b1f9245af9 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java @@ -61,7 +61,7 @@ public class BindBlobToMultipartFormTest { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost:8001").build(); binder.bindToRequest(request, TEST_BLOB); - assertEquals(Strings2.toString(request.getPayload()), EXPECTS); + assertEquals(Strings2.toStringAndClose(request.getPayload().openStream()), EXPECTS); assertEquals(request.getPayload().getContentMetadata().getContentLength(), Long.valueOf(113)); assertEquals(request.getPayload().getContentMetadata().getContentType(), "multipart/form-data; boundary=" diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java index dcac38c64f..bed8c35f22 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java @@ -51,7 +51,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name); assertEquals(request.getFilters().size(), 0); - assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text); + assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), text); } finally { returnContainer(container); } @@ -69,7 +69,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1)); assertEquals(request.getFilters().size(), 0); - assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), "fo"); + assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), "fo"); } finally { returnContainer(container); } @@ -89,11 +89,11 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { HttpRequest request = view.getSigner().signGetBlob(container, name, timeout); assertEquals(request.getFilters().size(), 0); - assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text); + assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), text); TimeUnit.SECONDS.sleep(2 * timeout); try { - Strings2.toString(view.utils().http().invoke(request).getPayload()); + Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()); fail("Temporary URL did not expire as expected"); } catch (AuthorizationException expected) { } @@ -114,7 +114,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { try { HttpRequest request = view.getSigner().signPutBlob(container, blob); assertEquals(request.getFilters().size(), 0); - Strings2.toString(view.utils().http().invoke(request).getPayload()); + Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()); assertConsistencyAwareContainerSize(container, 1); } finally { returnContainer(container); @@ -137,7 +137,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { // Java 7+ will throw a ProtocolException instead of setting the response code: // http://www.docjar.com/html/api/sun/net/www/protocol/http/HttpURLConnection.java.html#1021 request = request.toBuilder().removeHeader(EXPECT).build(); - Strings2.toString(view.utils().http().invoke(request).getPayload()); + Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()); assertConsistencyAwareContainerSize(container, 1); view.getBlobStore().removeBlob(container, name); @@ -145,7 +145,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { TimeUnit.SECONDS.sleep(2 * timeout); try { - Strings2.toString(view.utils().http().invoke(request).getPayload()); + Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()); fail("Temporary URL did not expire as expected"); } catch (AuthorizationException expected) { } diff --git a/common/azure/src/main/java/org/jclouds/azure/storage/handlers/ParseAzureStorageErrorFromXmlContent.java b/common/azure/src/main/java/org/jclouds/azure/storage/handlers/ParseAzureStorageErrorFromXmlContent.java index 1685ea9d76..ece8176401 100644 --- a/common/azure/src/main/java/org/jclouds/azure/storage/handlers/ParseAzureStorageErrorFromXmlContent.java +++ b/common/azure/src/main/java/org/jclouds/azure/storage/handlers/ParseAzureStorageErrorFromXmlContent.java @@ -72,14 +72,14 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler { } } catch (RuntimeException e) { try { - message = Strings2.toString(response.getPayload()); + message = Strings2.toStringAndClose(response.getPayload().openStream()); exception = new HttpResponseException(command, response, message); } catch (IOException e1) { } } } else { try { - message = Strings2.toString(response.getPayload()); + message = Strings2.toStringAndClose(response.getPayload().openStream()); exception = new HttpResponseException(command, response, message); } catch (IOException e) { } diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index d8887a8c79..9c9157b73a 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -391,7 +391,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes return actual == null; } try { - String real = Strings2.toString((Payload) actual); + String real = Strings2.toStringAndClose(((Payload) actual).openStream()); assertEquals(real, expected); return true; } catch (IOException e) { diff --git a/core/src/main/java/org/jclouds/http/HttpResponseException.java b/core/src/main/java/org/jclouds/http/HttpResponseException.java index a8723dea7b..eb71002624 100644 --- a/core/src/main/java/org/jclouds/http/HttpResponseException.java +++ b/core/src/main/java/org/jclouds/http/HttpResponseException.java @@ -84,7 +84,7 @@ public class HttpResponseException extends RuntimeException { && request.getPayload().getContentMetadata().getContentLength() < 1024) { try { return String.format(" [%s] ", request.getPayload() instanceof StringPayload ? request.getPayload() - .getRawContent() : Strings2.toString(request.getPayload())); + .getRawContent() : Strings2.toStringAndClose(request.getPayload().openStream())); } catch (IOException e) { } } diff --git a/core/src/main/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20x.java b/core/src/main/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20x.java index 8766f21607..7d3e74689a 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20x.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20x.java @@ -49,7 +49,7 @@ public class ParseURIFromListOrLocationHeaderIf20x implements Function supplier) { - checkNotNull(supplier, "supplier"); + public static ByteSource asByteSource(final Payload payload) { + checkNotNull(payload, "payload"); return new ByteSource() { @Override public InputStream openStream() throws IOException { - return supplier.getInput(); + return payload.openStream(); } }; } 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 632ef82335..198a252c27 100644 --- a/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java +++ b/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java @@ -46,7 +46,6 @@ import com.google.common.hash.HashCode; import com.google.common.io.ByteSource; import com.google.common.io.ByteStreams; import com.google.common.io.Files; -import com.google.common.io.InputSupplier; @Singleton public class BasePayloadSlicer implements PayloadSlicer { @@ -181,12 +180,6 @@ public class BasePayloadSlicer implements PayloadSlicer { return new ByteSourcePayload(content.slice(offset, length)); } - /** @deprecated use doSlice(ByteSource) instead */ - @Deprecated - protected Payload doSlice(InputSupplier content, long offset, long length) { - return doSlice(ByteStreams2.asByteSource(content), offset, length); - } - protected Payload doSlice(byte[] content, long offset, long length) { Payload returnVal; checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array"); diff --git a/core/src/main/java/org/jclouds/util/Strings2.java b/core/src/main/java/org/jclouds/util/Strings2.java index afaac305cd..2081c3d6d4 100644 --- a/core/src/main/java/org/jclouds/util/Strings2.java +++ b/core/src/main/java/org/jclouds/util/Strings2.java @@ -41,7 +41,6 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.Multimap; import com.google.common.io.CharStreams; -import com.google.common.io.InputSupplier; import com.google.common.primitives.Chars; public class Strings2 { @@ -122,13 +121,6 @@ public class Strings2 { } } - /** @deprecated use CharSource.read() instead */ - @Deprecated - public static String toString(InputSupplier supplier) - throws IOException { - return toStringAndClose(supplier.getInput()); - } - public static String toStringAndClose(InputStream input) throws IOException { checkNotNull(input, "input"); try { diff --git a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java index e27ae4ae73..22ab9699b1 100644 --- a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java +++ b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java @@ -145,7 +145,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base try { HttpResponse getStringResponse = client.invoke(HttpRequest.builder().method("GET") .endpoint(server.getUrl("/objects").toString()).build()); - assertEquals(Strings2.toString(getStringResponse.getPayload()).trim(), XML); + assertEquals(Strings2.toStringAndClose(getStringResponse.getPayload().openStream()).trim(), XML); } finally { close(client, true); server.shutdown(); diff --git a/core/src/test/java/org/jclouds/io/payloads/MultipartFormTest.java b/core/src/test/java/org/jclouds/io/payloads/MultipartFormTest.java index aa62ff8a9c..3a673e4712 100644 --- a/core/src/test/java/org/jclouds/io/payloads/MultipartFormTest.java +++ b/core/src/test/java/org/jclouds/io/payloads/MultipartFormTest.java @@ -48,7 +48,7 @@ public class MultipartFormTest { MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello")); - assertEquals(Strings2.toString(multipartForm), expects); + assertEquals(Strings2.toStringAndClose(multipartForm.openStream()), expects); assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(199)); } @@ -108,11 +108,11 @@ public class MultipartFormTest { MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello"), newPart("goodbye")); - assertEquals(Strings2.toString(multipartForm), expects); + assertEquals(Strings2.toStringAndClose(multipartForm.openStream()), expects); // test repeatable assert multipartForm.isRepeatable(); - assertEquals(Strings2.toString(multipartForm), expects); + assertEquals(Strings2.toStringAndClose(multipartForm.openStream()), expects); assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(352)); } diff --git a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiExpectTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiExpectTest.java index dfeca2740d..fe09a0b929 100644 --- a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiExpectTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiExpectTest.java @@ -385,8 +385,8 @@ public abstract class BaseRestApiExpectTest { switch (compareHttpRequestAsType(a)) { case XML: { - Diff diff = XMLUnit.compareXML(Strings2.toString(a.getPayload()), Strings2 - .toString(b.getPayload())); + Diff diff = XMLUnit.compareXML(Strings2.toStringAndClose(a.getPayload().openStream()), + Strings2.toStringAndClose(b.getPayload().openStream())); // Ignoring whitespace in elements that have other children, xsi:schemaLocation and // differences in namespace prefixes @@ -418,8 +418,8 @@ public abstract class BaseRestApiExpectTest { } case JSON: { JsonParser parser = new JsonParser(); - JsonElement payloadA = parser.parse(Strings2.toString(a.getPayload())); - JsonElement payloadB = parser.parse(Strings2.toString(b.getPayload())); + JsonElement payloadA = parser.parse(Strings2.toStringAndClose(a.getPayload().openStream())); + JsonElement payloadB = parser.parse(Strings2.toStringAndClose(b.getPayload().openStream())); return Objects.equal(payloadA, payloadB); } default: { @@ -487,7 +487,7 @@ public abstract class BaseRestApiExpectTest { builder.append(header.getKey()).append(": ").append(header.getValue()).append('\n'); } try { - builder.append('\n').append(Strings2.toString(request.getPayload())); + builder.append('\n').append(Strings2.toStringAndClose(request.getPayload().openStream())); } catch (IOException e) { throw Throwables.propagate(e); } diff --git a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java index f1703b3b9f..114bf5bd9b 100644 --- a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java @@ -112,7 +112,7 @@ public abstract class BaseRestApiTest { } else { String payload = null; try { - payload = Strings2.toString(request.getPayload()); + payload = Strings2.toStringAndClose(request.getPayload().openStream()); } catch (IOException e) { propagate(e); } diff --git a/drivers/gae/src/test/java/org/jclouds/gae/ConvertToJcloudsResponseTest.java b/drivers/gae/src/test/java/org/jclouds/gae/ConvertToJcloudsResponseTest.java index 7022311cb9..b313e1cec3 100644 --- a/drivers/gae/src/test/java/org/jclouds/gae/ConvertToJcloudsResponseTest.java +++ b/drivers/gae/src/test/java/org/jclouds/gae/ConvertToJcloudsResponseTest.java @@ -97,7 +97,7 @@ public class ConvertToJcloudsResponseTest { replay(gaeResponse); HttpResponse response = req.apply(gaeResponse); assertEquals(response.getStatusCode(), 200); - assertEquals(Strings2.toString(response.getPayload()), "hello"); + assertEquals(Strings2.toStringAndClose(response.getPayload().openStream()), "hello"); assertEquals(response.getHeaders().size(), 0); assertEquals(response.getPayload().getContentMetadata().getContentType(), "text/xml"); } diff --git a/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java b/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java index d26514cb48..4045b52ef0 100644 --- a/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java +++ b/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java @@ -162,7 +162,7 @@ public class JschSshClientLiveTest { SshClient client = setupClient(); client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit")); Payload input = setupClient().get(temp.getAbsolutePath()); - String contents = Strings2.toString(input); + String contents = Strings2.toStringAndClose(input.openStream()); assertEquals(contents, "rabbit"); } finally { temp.delete(); @@ -172,7 +172,7 @@ public class JschSshClientLiveTest { @Test public void testGetEtcPassword() throws IOException { Payload input = setupClient().get("/etc/passwd"); - String contents = Strings2.toString(input); + String contents = Strings2.toStringAndClose(input.openStream()); assert contents.indexOf("root") >= 0 : "no root in " + contents; } diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java index 8d89fb09e0..eabe3f01f2 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java @@ -149,7 +149,7 @@ public class SshjSshClientLiveTest { SshClient client = setupClient(); client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit")); Payload input = client.get(temp.getAbsolutePath()); - String contents = Strings2.toString(input); + String contents = Strings2.toStringAndClose(input.openStream()); assertEquals(contents, "rabbit"); } finally { temp.delete(); @@ -158,7 +158,7 @@ public class SshjSshClientLiveTest { public void testGetEtcPassword() throws IOException { Payload input = setupClient().get("/etc/passwd"); - String contents = Strings2.toString(input); + String contents = Strings2.toStringAndClose(input.openStream()); assert contents.indexOf("root") >= 0 : "no root in " + contents; } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java index 351936643a..836d7de199 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java @@ -265,7 +265,7 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest { // Test GET of object (including updated metadata) AzureBlob getBlob = getApi().getBlob(privateContainer, object.getProperties().getName()); - assertEquals(Strings2.toString(getBlob.getPayload()), data); + assertEquals(Strings2.toStringAndClose(getBlob.getPayload().openStream()), data); // TODO assertEquals(getBlob.getName(), object.getProperties().getName()); assertEquals(getBlob.getPayload().getContentMetadata().getContentLength(), Long.valueOf(data.length())); assertEquals(getBlob.getProperties().getContentMetadata().getContentType(), "text/plain"); diff --git a/providers/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java b/providers/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java index d129de6e21..469e6e57a7 100644 --- a/providers/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java +++ b/providers/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java @@ -78,7 +78,7 @@ public class GleSYSErrorHandler implements HttpErrorHandler { if (response.getPayload() == null) return null; try { - return Strings2.toString(response.getPayload()); + return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw new RuntimeException(e); } finally { diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandler.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandler.java index d231bc8d2f..54aa947694 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandler.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandler.java @@ -74,7 +74,7 @@ public class SoftLayerErrorHandler implements HttpErrorHandler { if (response.getPayload() == null) return null; try { - return Strings2.toString(response.getPayload()); + return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw new RuntimeException(e); } finally {