mirror of https://github.com/apache/jclouds.git
JCLOUDS-622: Remove most vestiges of InputSupplier
Guava 16 deprecated InputSupplier and a future release will remove it.
This commit is contained in:
parent
1a3ad75efd
commit
fb60d76704
|
@ -67,7 +67,7 @@ public class ParseAtmosErrorFromXmlContent implements HttpErrorHandler {
|
||||||
AtmosError error = null;
|
AtmosError error = null;
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
String content = Strings2.toString(response.getPayload());
|
String content = Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
if (content != null && content.indexOf('<') >= 0) {
|
if (content != null && content.indexOf('<') >= 0) {
|
||||||
error = utils.parseAtmosErrorFromContent(command, response, Strings2.toInputStream(content));
|
error = utils.parseAtmosErrorFromContent(command, response, Strings2.toInputStream(content));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -261,14 +261,14 @@ public class AtmosClientLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
private static void verifyHeadObject(AtmosClient connection, String path, String metadataValue)
|
private static void verifyHeadObject(AtmosClient connection, String path, String metadataValue)
|
||||||
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
AtmosObject getBlob = connection.headFile(path);
|
AtmosObject getBlob = connection.headFile(path);
|
||||||
assertEquals(Strings2.toString(getBlob.getPayload()), "");
|
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().openStream()), "");
|
||||||
verifyMetadata(metadataValue, getBlob);
|
verifyMetadata(metadataValue, getBlob);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyObject(AtmosClient connection, String path, String compare, String metadataValue)
|
private static void verifyObject(AtmosClient connection, String path, String compare, String metadataValue)
|
||||||
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
AtmosObject getBlob = connection.readFile(path);
|
AtmosObject getBlob = connection.readFile(path);
|
||||||
assertEquals(Strings2.toString(getBlob.getPayload()), compare);
|
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().openStream()), compare);
|
||||||
verifyMetadata(metadataValue, getBlob);
|
verifyMetadata(metadataValue, getBlob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class ParseCloudServersErrorFromHttpResponse implements HttpErrorHandler
|
||||||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
return Strings2.toString(response.getPayload());
|
return Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn(e, "exception reading error from response", response);
|
logger.warn(e, "exception reading error from response", response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -379,7 +379,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
try {
|
try {
|
||||||
client.connect();
|
client.connect();
|
||||||
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
||||||
String etcPasswdContents = Strings2.toString(etcPasswd);
|
String etcPasswdContents = Strings2.toStringAndClose(etcPasswd.openStream());
|
||||||
assertEquals("rackspace", etcPasswdContents.trim());
|
assertEquals("rackspace", etcPasswdContents.trim());
|
||||||
} finally {
|
} finally {
|
||||||
if (client != null)
|
if (client != null)
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class CloudSigmaErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toString(response.getPayload());
|
return Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class CloudStackErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toString(response.getPayload());
|
return Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class ElasticStackErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toString(response.getPayload());
|
return Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -328,7 +328,7 @@ public class ElasticStackApiLiveTest extends BaseComputeServiceContextLiveTest {
|
||||||
public void testWeCanReadAndWriteToDrive() throws IOException {
|
public void testWeCanReadAndWriteToDrive() throws IOException {
|
||||||
drive2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build());
|
drive2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build());
|
||||||
client.writeDrive(drive2.getUuid(), Payloads.newStringPayload("foo"));
|
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")
|
@Test(dependsOnMethods = "testWeCanReadAndWriteToDrive")
|
||||||
|
@ -343,7 +343,7 @@ public class ElasticStackApiLiveTest extends BaseComputeServiceContextLiveTest {
|
||||||
assert driveNotClaimed.apply(drive2) : client.getDriveInfo(drive2.getUuid());
|
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 2" + client.getDriveInfo(drive2.getUuid()));
|
||||||
System.err.println("after image; drive 3" + client.getDriveInfo(drive3.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 {
|
} finally {
|
||||||
client.destroyDrive(drive2.getUuid());
|
client.destroyDrive(drive2.getUuid());
|
||||||
client.destroyDrive(drive3.getUuid());
|
client.destroyDrive(drive3.getUuid());
|
||||||
|
|
|
@ -703,7 +703,7 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
Blob blobRangeStartAt = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
|
Blob blobRangeStartAt = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
|
||||||
payload = blobRangeStartAt.getPayload();
|
payload = blobRangeStartAt.getPayload();
|
||||||
try {
|
try {
|
||||||
assertEquals(input.substring(1), Strings2.toString(payload));
|
assertEquals(input.substring(1), Strings2.toStringAndClose(payload.openStream()));
|
||||||
} finally {
|
} finally {
|
||||||
Closeables2.closeQuietly(payload);
|
Closeables2.closeQuietly(payload);
|
||||||
}
|
}
|
||||||
|
@ -713,7 +713,7 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
Blob blobRangeTail = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
|
Blob blobRangeTail = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
|
||||||
payload = blobRangeTail.getPayload();
|
payload = blobRangeTail.getPayload();
|
||||||
try {
|
try {
|
||||||
assertEquals(input.substring(5), Strings2.toString(payload));
|
assertEquals(input.substring(5), Strings2.toStringAndClose(payload.openStream()));
|
||||||
} finally {
|
} finally {
|
||||||
Closeables2.closeQuietly(payload);
|
Closeables2.closeQuietly(payload);
|
||||||
}
|
}
|
||||||
|
@ -723,7 +723,7 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
Blob blobFragment = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
|
Blob blobFragment = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
|
||||||
payload = blobFragment.getPayload();
|
payload = blobFragment.getPayload();
|
||||||
try {
|
try {
|
||||||
assertEquals(input.substring(4, 7), Strings2.toString(payload));
|
assertEquals(input.substring(4, 7), Strings2.toStringAndClose(payload.openStream()));
|
||||||
} finally {
|
} finally {
|
||||||
Closeables2.closeQuietly(payload);
|
Closeables2.closeQuietly(payload);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class ParseCloudLoadBalancersErrorFromHttpResponse implements HttpErrorHa
|
||||||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
return Strings2.toString(response.getPayload());
|
return Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn(e, "exception reading error from response", response);
|
logger.warn(e, "exception reading error from response", response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
assertConsistencyAwareContainerSize(sourceContainer, 1);
|
assertConsistencyAwareContainerSize(sourceContainer, 1);
|
||||||
S3Object newObject = getApi().getObject(sourceContainer, key);
|
S3Object newObject = getApi().getObject(sourceContainer, key);
|
||||||
assert newObject != null;
|
assert newObject != null;
|
||||||
assertEquals(Strings2.toString(newObject.getPayload()), TEST_STRING);
|
assertEquals(Strings2.toStringAndClose(newObject.getPayload().openStream()), TEST_STRING);
|
||||||
return newObject;
|
return newObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
message = Strings2.toString(response.getPayload());
|
message = Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
exception = new HttpResponseException(command, response, message);
|
exception = new HttpResponseException(command, response, message);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ public abstract class CommonSwiftClientLiveTest<C extends CommonSwiftClient> ext
|
||||||
assert getApi().getObject(containerName, "non-existent-object") == null;
|
assert getApi().getObject(containerName, "non-existent-object") == null;
|
||||||
// Test GET of object (including updated metadata)
|
// Test GET of object (including updated metadata)
|
||||||
SwiftObject getBlob = getApi().getObject(containerName, object.getInfo().getName());
|
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(),
|
// TODO assertEquals(getBlob.getName(),
|
||||||
// object.getMetadata().getName());
|
// object.getMetadata().getName());
|
||||||
assertEquals(getBlob.getInfo().getBytes(), Long.valueOf(data.length()));
|
assertEquals(getBlob.getInfo().getBytes(), Long.valueOf(data.length()));
|
||||||
|
@ -289,7 +289,7 @@ public abstract class CommonSwiftClientLiveTest<C extends CommonSwiftClient> ext
|
||||||
GetOptions.Builder.ifETagMatches(newEtag));
|
GetOptions.Builder.ifETagMatches(newEtag));
|
||||||
assertEquals(getBlob.getInfo().getHash(), base16().lowerCase().decode(newEtag));
|
assertEquals(getBlob.getInfo().getHash(), base16().lowerCase().decode(newEtag));
|
||||||
getBlob = getApi().getObject(containerName, object.getInfo().getName(), GetOptions.Builder.startAt(8));
|
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 {
|
} finally {
|
||||||
returnContainer(containerName);
|
returnContainer(containerName);
|
||||||
|
@ -321,7 +321,7 @@ public abstract class CommonSwiftClientLiveTest<C extends CommonSwiftClient> ext
|
||||||
assertTrue(getApi().objectExists(destinationContainer, destinationObject));
|
assertTrue(getApi().objectExists(destinationContainer, destinationObject));
|
||||||
|
|
||||||
SwiftObject destinationSwiftObject = getApi().getObject(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
|
// test exception thrown on bad destination container
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler {
|
||||||
message = error.getMessage();
|
message = error.getMessage();
|
||||||
exception = new VCloudResponseException(command, response, error);
|
exception = new VCloudResponseException(command, response, error);
|
||||||
} else {
|
} else {
|
||||||
message = Strings2.toString(response.getPayload());
|
message = Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
exception = message != null ? new HttpResponseException(command, response, message) : exception;
|
exception = message != null ? new HttpResponseException(command, response, message) : exception;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class BindBlobToMultipartFormTest {
|
||||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost:8001").build();
|
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost:8001").build();
|
||||||
binder.bindToRequest(request, TEST_BLOB);
|
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().getContentLength(), Long.valueOf(113));
|
||||||
|
|
||||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), "multipart/form-data; boundary="
|
assertEquals(request.getPayload().getContentMetadata().getContentType(), "multipart/form-data; boundary="
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
assertConsistencyAwareContainerSize(container, 1);
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
HttpRequest request = view.getSigner().signGetBlob(container, name);
|
HttpRequest request = view.getSigner().signGetBlob(container, name);
|
||||||
assertEquals(request.getFilters().size(), 0);
|
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 {
|
} finally {
|
||||||
returnContainer(container);
|
returnContainer(container);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
assertConsistencyAwareContainerSize(container, 1);
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1));
|
HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1));
|
||||||
assertEquals(request.getFilters().size(), 0);
|
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 {
|
} finally {
|
||||||
returnContainer(container);
|
returnContainer(container);
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,11 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
HttpRequest request = view.getSigner().signGetBlob(container, name, timeout);
|
HttpRequest request = view.getSigner().signGetBlob(container, name, timeout);
|
||||||
|
|
||||||
assertEquals(request.getFilters().size(), 0);
|
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);
|
TimeUnit.SECONDS.sleep(2 * timeout);
|
||||||
try {
|
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");
|
fail("Temporary URL did not expire as expected");
|
||||||
} catch (AuthorizationException expected) {
|
} catch (AuthorizationException expected) {
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
try {
|
try {
|
||||||
HttpRequest request = view.getSigner().signPutBlob(container, blob);
|
HttpRequest request = view.getSigner().signPutBlob(container, blob);
|
||||||
assertEquals(request.getFilters().size(), 0);
|
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);
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(container);
|
returnContainer(container);
|
||||||
|
@ -137,7 +137,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
// Java 7+ will throw a ProtocolException instead of setting the response code:
|
// 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
|
// http://www.docjar.com/html/api/sun/net/www/protocol/http/HttpURLConnection.java.html#1021
|
||||||
request = request.toBuilder().removeHeader(EXPECT).build();
|
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);
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
|
|
||||||
view.getBlobStore().removeBlob(container, name);
|
view.getBlobStore().removeBlob(container, name);
|
||||||
|
@ -145,7 +145,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
TimeUnit.SECONDS.sleep(2 * timeout);
|
TimeUnit.SECONDS.sleep(2 * timeout);
|
||||||
try {
|
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");
|
fail("Temporary URL did not expire as expected");
|
||||||
} catch (AuthorizationException expected) {
|
} catch (AuthorizationException expected) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,14 +72,14 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler {
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
try {
|
try {
|
||||||
message = Strings2.toString(response.getPayload());
|
message = Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
exception = new HttpResponseException(command, response, message);
|
exception = new HttpResponseException(command, response, message);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
message = Strings2.toString(response.getPayload());
|
message = Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
exception = new HttpResponseException(command, response, message);
|
exception = new HttpResponseException(command, response, message);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,7 +391,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
|
||||||
return actual == null;
|
return actual == null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String real = Strings2.toString((Payload) actual);
|
String real = Strings2.toStringAndClose(((Payload) actual).openStream());
|
||||||
assertEquals(real, expected);
|
assertEquals(real, expected);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class HttpResponseException extends RuntimeException {
|
||||||
&& request.getPayload().getContentMetadata().getContentLength() < 1024) {
|
&& request.getPayload().getContentMetadata().getContentLength() < 1024) {
|
||||||
try {
|
try {
|
||||||
return String.format(" [%s] ", request.getPayload() instanceof StringPayload ? request.getPayload()
|
return String.format(" [%s] ", request.getPayload() instanceof StringPayload ? request.getPayload()
|
||||||
.getRawContent() : Strings2.toString(request.getPayload()));
|
.getRawContent() : Strings2.toStringAndClose(request.getPayload().openStream()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class ParseURIFromListOrLocationHeaderIf20x implements Function<HttpRespo
|
||||||
try {
|
try {
|
||||||
if (from.getPayload().getInput() == null)
|
if (from.getPayload().getInput() == null)
|
||||||
throw new HttpResponseException("no content", null, from);
|
throw new HttpResponseException("no content", null, from);
|
||||||
String toParse = Strings2.toString(from.getPayload());
|
String toParse = Strings2.toStringAndClose(from.getPayload().getInput());
|
||||||
return URI.create(toParse.trim());
|
return URI.create(toParse.trim());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpResponseException("couldn't parse uri from content", null, from, e);
|
throw new HttpResponseException("couldn't parse uri from content", null, from, e);
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class CloseContentAndSetExceptionErrorHandler implements HttpErrorHandler
|
||||||
public void handleError(HttpCommand command, HttpResponse from) {
|
public void handleError(HttpCommand command, HttpResponse from) {
|
||||||
String content;
|
String content;
|
||||||
try {
|
try {
|
||||||
content = from.getPayload() != null ? Strings2.toString(from.getPayload()) : null;
|
content = from.getPayload() != null ? Strings2.toStringAndClose(from.getPayload().openStream()) : null;
|
||||||
command.setException(new HttpResponseException(command, from, content));
|
command.setException(new HttpResponseException(command, from, content));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
command.setException(new HttpResponseException(command, from));
|
command.setException(new HttpResponseException(command, from));
|
||||||
|
|
|
@ -28,7 +28,6 @@ import com.google.common.hash.HashingInputStream;
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
import com.google.common.io.InputSupplier;
|
|
||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
public class ByteStreams2 {
|
public class ByteStreams2 {
|
||||||
|
@ -54,12 +53,12 @@ public class ByteStreams2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static ByteSource asByteSource(final InputSupplier<? extends InputStream> supplier) {
|
public static ByteSource asByteSource(final Payload payload) {
|
||||||
checkNotNull(supplier, "supplier");
|
checkNotNull(payload, "payload");
|
||||||
return new ByteSource() {
|
return new ByteSource() {
|
||||||
@Override
|
@Override
|
||||||
public InputStream openStream() throws IOException {
|
public InputStream openStream() throws IOException {
|
||||||
return supplier.getInput();
|
return payload.openStream();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ import com.google.common.hash.HashCode;
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.common.io.InputSupplier;
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class BasePayloadSlicer implements PayloadSlicer {
|
public class BasePayloadSlicer implements PayloadSlicer {
|
||||||
|
@ -181,12 +180,6 @@ public class BasePayloadSlicer implements PayloadSlicer {
|
||||||
return new ByteSourcePayload(content.slice(offset, length));
|
return new ByteSourcePayload(content.slice(offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated use doSlice(ByteSource) instead */
|
|
||||||
@Deprecated
|
|
||||||
protected Payload doSlice(InputSupplier<? extends InputStream> content, long offset, long length) {
|
|
||||||
return doSlice(ByteStreams2.asByteSource(content), offset, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Payload doSlice(byte[] content, long offset, long length) {
|
protected Payload doSlice(byte[] content, long offset, long length) {
|
||||||
Payload returnVal;
|
Payload returnVal;
|
||||||
checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array");
|
checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array");
|
||||||
|
|
|
@ -41,7 +41,6 @@ import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
import com.google.common.io.InputSupplier;
|
|
||||||
import com.google.common.primitives.Chars;
|
import com.google.common.primitives.Chars;
|
||||||
|
|
||||||
public class Strings2 {
|
public class Strings2 {
|
||||||
|
@ -122,13 +121,6 @@ public class Strings2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated use CharSource.read() instead */
|
|
||||||
@Deprecated
|
|
||||||
public static String toString(InputSupplier<? extends InputStream> supplier)
|
|
||||||
throws IOException {
|
|
||||||
return toStringAndClose(supplier.getInput());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toStringAndClose(InputStream input) throws IOException {
|
public static String toStringAndClose(InputStream input) throws IOException {
|
||||||
checkNotNull(input, "input");
|
checkNotNull(input, "input");
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -145,7 +145,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
try {
|
try {
|
||||||
HttpResponse getStringResponse = client.invoke(HttpRequest.builder().method("GET")
|
HttpResponse getStringResponse = client.invoke(HttpRequest.builder().method("GET")
|
||||||
.endpoint(server.getUrl("/objects").toString()).build());
|
.endpoint(server.getUrl("/objects").toString()).build());
|
||||||
assertEquals(Strings2.toString(getStringResponse.getPayload()).trim(), XML);
|
assertEquals(Strings2.toStringAndClose(getStringResponse.getPayload().openStream()).trim(), XML);
|
||||||
} finally {
|
} finally {
|
||||||
close(client, true);
|
close(client, true);
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class MultipartFormTest {
|
||||||
|
|
||||||
MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello"));
|
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));
|
assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(199));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,11 +108,11 @@ public class MultipartFormTest {
|
||||||
|
|
||||||
MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello"), newPart("goodbye"));
|
MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello"), newPart("goodbye"));
|
||||||
|
|
||||||
assertEquals(Strings2.toString(multipartForm), expects);
|
assertEquals(Strings2.toStringAndClose(multipartForm.openStream()), expects);
|
||||||
|
|
||||||
// test repeatable
|
// test repeatable
|
||||||
assert multipartForm.isRepeatable();
|
assert multipartForm.isRepeatable();
|
||||||
assertEquals(Strings2.toString(multipartForm), expects);
|
assertEquals(Strings2.toStringAndClose(multipartForm.openStream()), expects);
|
||||||
assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(352));
|
assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(352));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -385,8 +385,8 @@ public abstract class BaseRestApiExpectTest<S> {
|
||||||
|
|
||||||
switch (compareHttpRequestAsType(a)) {
|
switch (compareHttpRequestAsType(a)) {
|
||||||
case XML: {
|
case XML: {
|
||||||
Diff diff = XMLUnit.compareXML(Strings2.toString(a.getPayload()), Strings2
|
Diff diff = XMLUnit.compareXML(Strings2.toStringAndClose(a.getPayload().openStream()),
|
||||||
.toString(b.getPayload()));
|
Strings2.toStringAndClose(b.getPayload().openStream()));
|
||||||
|
|
||||||
// Ignoring whitespace in elements that have other children, xsi:schemaLocation and
|
// Ignoring whitespace in elements that have other children, xsi:schemaLocation and
|
||||||
// differences in namespace prefixes
|
// differences in namespace prefixes
|
||||||
|
@ -418,8 +418,8 @@ public abstract class BaseRestApiExpectTest<S> {
|
||||||
}
|
}
|
||||||
case JSON: {
|
case JSON: {
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
JsonElement payloadA = parser.parse(Strings2.toString(a.getPayload()));
|
JsonElement payloadA = parser.parse(Strings2.toStringAndClose(a.getPayload().openStream()));
|
||||||
JsonElement payloadB = parser.parse(Strings2.toString(b.getPayload()));
|
JsonElement payloadB = parser.parse(Strings2.toStringAndClose(b.getPayload().openStream()));
|
||||||
return Objects.equal(payloadA, payloadB);
|
return Objects.equal(payloadA, payloadB);
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -487,7 +487,7 @@ public abstract class BaseRestApiExpectTest<S> {
|
||||||
builder.append(header.getKey()).append(": ").append(header.getValue()).append('\n');
|
builder.append(header.getKey()).append(": ").append(header.getValue()).append('\n');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
builder.append('\n').append(Strings2.toString(request.getPayload()));
|
builder.append('\n').append(Strings2.toStringAndClose(request.getPayload().openStream()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ public abstract class BaseRestApiTest {
|
||||||
} else {
|
} else {
|
||||||
String payload = null;
|
String payload = null;
|
||||||
try {
|
try {
|
||||||
payload = Strings2.toString(request.getPayload());
|
payload = Strings2.toStringAndClose(request.getPayload().openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
propagate(e);
|
propagate(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class ConvertToJcloudsResponseTest {
|
||||||
replay(gaeResponse);
|
replay(gaeResponse);
|
||||||
HttpResponse response = req.apply(gaeResponse);
|
HttpResponse response = req.apply(gaeResponse);
|
||||||
assertEquals(response.getStatusCode(), 200);
|
assertEquals(response.getStatusCode(), 200);
|
||||||
assertEquals(Strings2.toString(response.getPayload()), "hello");
|
assertEquals(Strings2.toStringAndClose(response.getPayload().openStream()), "hello");
|
||||||
assertEquals(response.getHeaders().size(), 0);
|
assertEquals(response.getHeaders().size(), 0);
|
||||||
assertEquals(response.getPayload().getContentMetadata().getContentType(), "text/xml");
|
assertEquals(response.getPayload().getContentMetadata().getContentType(), "text/xml");
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class JschSshClientLiveTest {
|
||||||
SshClient client = setupClient();
|
SshClient client = setupClient();
|
||||||
client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit"));
|
client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit"));
|
||||||
Payload input = setupClient().get(temp.getAbsolutePath());
|
Payload input = setupClient().get(temp.getAbsolutePath());
|
||||||
String contents = Strings2.toString(input);
|
String contents = Strings2.toStringAndClose(input.openStream());
|
||||||
assertEquals(contents, "rabbit");
|
assertEquals(contents, "rabbit");
|
||||||
} finally {
|
} finally {
|
||||||
temp.delete();
|
temp.delete();
|
||||||
|
@ -172,7 +172,7 @@ public class JschSshClientLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetEtcPassword() throws IOException {
|
public void testGetEtcPassword() throws IOException {
|
||||||
Payload input = setupClient().get("/etc/passwd");
|
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;
|
assert contents.indexOf("root") >= 0 : "no root in " + contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ public class SshjSshClientLiveTest {
|
||||||
SshClient client = setupClient();
|
SshClient client = setupClient();
|
||||||
client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit"));
|
client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit"));
|
||||||
Payload input = client.get(temp.getAbsolutePath());
|
Payload input = client.get(temp.getAbsolutePath());
|
||||||
String contents = Strings2.toString(input);
|
String contents = Strings2.toStringAndClose(input.openStream());
|
||||||
assertEquals(contents, "rabbit");
|
assertEquals(contents, "rabbit");
|
||||||
} finally {
|
} finally {
|
||||||
temp.delete();
|
temp.delete();
|
||||||
|
@ -158,7 +158,7 @@ public class SshjSshClientLiveTest {
|
||||||
|
|
||||||
public void testGetEtcPassword() throws IOException {
|
public void testGetEtcPassword() throws IOException {
|
||||||
Payload input = setupClient().get("/etc/passwd");
|
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;
|
assert contents.indexOf("root") >= 0 : "no root in " + contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,7 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
// Test GET of object (including updated metadata)
|
// Test GET of object (including updated metadata)
|
||||||
AzureBlob getBlob = getApi().getBlob(privateContainer, object.getProperties().getName());
|
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());
|
// TODO assertEquals(getBlob.getName(), object.getProperties().getName());
|
||||||
assertEquals(getBlob.getPayload().getContentMetadata().getContentLength(), Long.valueOf(data.length()));
|
assertEquals(getBlob.getPayload().getContentMetadata().getContentLength(), Long.valueOf(data.length()));
|
||||||
assertEquals(getBlob.getProperties().getContentMetadata().getContentType(), "text/plain");
|
assertEquals(getBlob.getProperties().getContentMetadata().getContentType(), "text/plain");
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class GleSYSErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toString(response.getPayload());
|
return Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class SoftLayerErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toString(response.getPayload());
|
return Strings2.toStringAndClose(response.getPayload().openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue