From d0bd30cc15f877248ee2ab457855c3fda6f78edd Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Fri, 11 Apr 2014 22:25:16 -0700 Subject: [PATCH] Address several Guava InputSupplier deprecations Many remain due to Payload implementing InputSupplier. Guava 18 will remove InputSupplier. --- .../internal/FilesystemStorageStrategyImplTest.java | 5 ++--- .../test/java/org/jclouds/filesystem/utils/TestUtils.java | 4 ++-- .../integration/SwiftBlobIntegrationLiveTest.java | 2 +- .../integration/internal/BaseBlobIntegrationTest.java | 8 ++++---- core/src/main/java/org/jclouds/logging/internal/Wire.java | 2 +- .../BaseHttpCommandExecutorServiceIntegrationTest.java | 2 +- core/src/test/java/org/jclouds/http/BaseJettyTest.java | 3 +-- .../test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java | 2 +- .../integration/AzureBlobIntegrationLiveTest.java | 4 ++-- .../functionloader/filters/LicenseHeaderFilter.java | 5 ++--- 10 files changed, 17 insertions(+), 20 deletions(-) diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java index 96a2181cba..f7eab9b04c 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java @@ -48,7 +48,6 @@ import org.testng.annotations.Test; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.io.ByteSource; -import com.google.common.io.ByteStreams; import com.google.common.io.Files; /** @@ -356,7 +355,7 @@ public class FilesystemStorageStrategyImplTest { File blobFullPath = new File(TARGET_CONTAINER_NAME, blobKey); ByteSource expectedInput = Files.asByteSource(sourceFile); ByteSource actualInput = Files.asByteSource(blobFullPath); - assertTrue(ByteStreams.equal(expectedInput, actualInput), + assertTrue(expectedInput.contentEquals(actualInput), "Files are not equal"); } @@ -375,7 +374,7 @@ public class FilesystemStorageStrategyImplTest { File blobFullPath = new File(TARGET_CONTAINER_NAME, blobKey); ByteSource expectedInput = Files.asByteSource(sourceFile); ByteSource actualInput = Files.asByteSource(blobFullPath); - assertTrue(ByteStreams.equal(expectedInput, actualInput), + assertTrue(expectedInput.contentEquals(actualInput), "Files are not equal"); } diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java index 3b9159ffbc..c27f895dc3 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java @@ -31,7 +31,7 @@ import org.jclouds.filesystem.util.Utils; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterators; import com.google.common.collect.Sets; -import com.google.common.io.ByteStreams; +import com.google.common.io.ByteSource; import com.google.common.io.Files; /** @@ -218,7 +218,7 @@ public class TestUtils { for (File file : IMAGE_RESOURCES) { byte[] buffer = new byte[random.nextInt(2 * 1024 * 1024)]; random.nextBytes(buffer); - Files.copy(ByteStreams.newInputStreamSupplier(buffer), file); + ByteSource.wrap(buffer).copyTo(Files.asByteSink(file)); } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java index 64b828a6eb..e05d792aee 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java @@ -183,7 +183,7 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest { } File fileToUpload = new File("target/lots-of-const.txt"); - Files.copy(temp, fileToUpload); + temp.copyTo(Files.asByteSink(fileToUpload)); assertTrue(fileToUpload.length() > partSize); return fileToUpload; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java index dfedeeb72a..c454cd264c 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java @@ -135,7 +135,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest { public void testPutFileParallel() throws InterruptedException, IOException, TimeoutException { File payloadFile = File.createTempFile("testPutFileParallel", "png"); - Files.copy(createTestInput(32 * 1024), payloadFile); + createTestInput(32 * 1024).copyTo(Files.asByteSink(payloadFile)); final Payload testPayload = Payloads.newFilePayload(payloadFile); final byte[] md5 = md5Supplier(testPayload); @@ -225,7 +225,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest { .payload(new InputStreamSupplierPayload(supplier)) .contentType("text/plain") .contentMD5(supplier.hash(md5()).asBytes()) - .contentLength(ByteStreams.length(supplier)) + .contentLength(supplier.size()) .contentDisposition(contentDisposition) .build()); } @@ -297,14 +297,14 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest { @Test(groups = { "integration", "live" }) public void testPutCorrectContentMD5() throws InterruptedException, IOException { - byte[] payload = ByteStreams.toByteArray(createTestInput(1024)); + byte[] payload = createTestInput(1024).read(); HashCode contentMD5 = md5().hashBytes(payload); putBlobWithMd5(payload, contentMD5); } @Test(groups = { "integration", "live" }) public void testPutIncorrectContentMD5() throws InterruptedException, IOException { - byte[] payload = ByteStreams.toByteArray(createTestInput(1024)); + byte[] payload = createTestInput(1024).read(); HashCode contentMD5 = md5().hashBytes(new byte[0]); try { putBlobWithMd5(payload, contentMD5); diff --git a/core/src/main/java/org/jclouds/logging/internal/Wire.java b/core/src/main/java/org/jclouds/logging/internal/Wire.java index fbc0b84b0b..893fa077c3 100644 --- a/core/src/main/java/org/jclouds/logging/internal/Wire.java +++ b/core/src/main/java/org/jclouds/logging/internal/Wire.java @@ -100,7 +100,7 @@ public abstract class Wire { is.close(); } // we must call FileBackedOutputStream.reset to remove temporary file - return new FilterInputStream(out.asByteSource().getInput()) { + return new FilterInputStream(out.asByteSource().openStream()) { @Override public void close() throws IOException { super.close(); diff --git a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java index 0de5181961..7c6e7fe924 100644 --- a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java +++ b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java @@ -227,7 +227,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base public void testGetBigFile() throws Exception { MockResponse response = new MockResponse().addHeader("Content-MD5", constitutionsMd5) .addHeader("Content-type", "text/plain") - .setBody(oneHundredOneConstitutions.getInput(), constitutionsLength); + .setBody(oneHundredOneConstitutions.openStream(), constitutionsLength); MockWebServer server = mockWebServer(response, response); InputStream input = server.getUrl("/101constitutions").openStream(); diff --git a/core/src/test/java/org/jclouds/http/BaseJettyTest.java b/core/src/test/java/org/jclouds/http/BaseJettyTest.java index 056a134635..2541412f32 100644 --- a/core/src/test/java/org/jclouds/http/BaseJettyTest.java +++ b/core/src/test/java/org/jclouds/http/BaseJettyTest.java @@ -19,7 +19,6 @@ package org.jclouds.http; import static com.google.common.base.Throwables.getStackTraceAsString; import static com.google.common.hash.Hashing.md5; import static com.google.common.io.BaseEncoding.base64; -import static com.google.common.io.ByteStreams.copy; import static com.google.common.io.ByteStreams.toByteArray; import static com.google.common.net.HttpHeaders.CONTENT_DISPOSITION; import static com.google.common.net.HttpHeaders.CONTENT_ENCODING; @@ -114,7 +113,7 @@ public abstract class BaseJettyTest { response.setContentType("text/plain"); response.setHeader("Content-MD5", md5); response.setStatus(SC_OK); - copy(oneHundredOneConstitutions, response.getOutputStream()); + oneHundredOneConstitutions.copyTo(response.getOutputStream()); } else if (request.getMethod().equals("PUT")) { if (request.getContentLength() > 0) { response.setStatus(SC_OK); diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java index 3af30fda01..49d301030f 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java @@ -149,7 +149,7 @@ public class AWSS3ClientLiveTest extends S3ClientLiveTest { public void testMultipartChunkedFileStream() throws IOException, InterruptedException { File file = new File("target/const.txt"); - Files.copy(oneHundredOneConstitutions, file); + oneHundredOneConstitutions.copyTo(Files.asByteSink(file)); String containerName = getContainerName(); try { diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java index ba64e8f130..2c4060ff9d 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java @@ -81,7 +81,7 @@ public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest { oneHundredOneConstitutions = getTestDataSupplier(); oneHundredOneConstitutionsMD5 = oneHundredOneConstitutions.hash(md5()).asBytes(); File file = new File("target/const.txt"); - Files.copy(oneHundredOneConstitutions, file); + oneHundredOneConstitutions.copyTo(Files.asByteSink(file)); String containerName = getContainerName(); try { @@ -100,7 +100,7 @@ public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest { final long limit = MultipartUploadStrategy.MAX_BLOCK_SIZE; ByteSource input = repeatingArrayByteSource(new byte[1024]).slice(0, limit); File file = new File("target/const.txt"); - Files.copy(input, file); + input.copyTo(Files.asByteSink(file)); String containerName = getContainerName(); try { diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/filters/LicenseHeaderFilter.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/filters/LicenseHeaderFilter.java index c84e42e5e3..ed31362251 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/filters/LicenseHeaderFilter.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/filters/LicenseHeaderFilter.java @@ -16,8 +16,6 @@ */ package org.jclouds.scriptbuilder.functionloader.filters; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.io.CharStreams.newReaderSupplier; -import static com.google.common.io.CharStreams.readLines; import java.io.IOException; @@ -26,6 +24,7 @@ import org.jclouds.scriptbuilder.domain.ShellToken; import org.jclouds.scriptbuilder.functionloader.FunctionLoader; import org.jclouds.scriptbuilder.functionloader.FunctionNotFoundException; +import com.google.common.io.CharSource; import com.google.common.io.LineProcessor; /** @@ -55,7 +54,7 @@ public class LicenseHeaderFilter implements FunctionLoader { */ public String filter(String lines, OsFamily family) { try { - return readLines(newReaderSupplier(checkNotNull(lines, "lines")), + return CharSource.wrap(checkNotNull(lines, "lines")).readLines( new LicenseHeaderProcessor(checkNotNull(family, "family"))); } catch (IOException e) { // Don't fail; just return the original text with the comments