diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/filters/SignRequest.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/filters/SignRequest.java index aeb6b4550e..c382970106 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/filters/SignRequest.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/filters/SignRequest.java @@ -35,7 +35,6 @@ import javax.inject.Provider; import javax.inject.Singleton; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants; import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders; import org.jclouds.date.TimeStamp; @@ -47,6 +46,7 @@ import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpUtils; import org.jclouds.http.internal.SignatureWire; import org.jclouds.logging.Logger; +import org.jclouds.util.Utils; import com.google.common.annotations.VisibleForTesting; @@ -65,6 +65,8 @@ public class SignRequest implements HttpRequestFilter { private final byte[] key; private final Provider timeStampProvider; private final EncryptionService encryptionService; + @Resource + Logger logger = Logger.NULL; @Resource @Named(HttpConstants.SIGNATURE_LOGGER) @@ -106,7 +108,7 @@ public class SignRequest implements HttpRequestFilter { throws HttpException { String signature = signString(toSign); if (signatureWire.enabled()) - signatureWire.input(IOUtils.toInputStream(signature)); + signatureWire.input(Utils.toInputStream(signature)); request.getHeaders().replaceValues(AtmosStorageHeaders.SIGNATURE, Collections.singletonList(signature)); } diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientLiveTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientLiveTest.java index 3e5a79ee5a..f232d51547 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientLiveTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientLiveTest.java @@ -33,7 +33,6 @@ import java.security.SecureRandom; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.apache.commons.io.IOUtils; import org.jclouds.atmosonline.saas.blobstore.strategy.RecursiveRemove; import org.jclouds.atmosonline.saas.domain.AtmosObject; import org.jclouds.atmosonline.saas.domain.BoundedSortedSet; @@ -218,7 +217,7 @@ public class AtmosStorageClientLiveTest { } Object makeData(String in, boolean stream) { - return stream ? IOUtils.toInputStream(in) : in; + return stream ? Utils.toInputStream(in) : in; } private void createOrReplaceObject(String name, Object data, String metadataValue) @@ -274,7 +273,7 @@ public class AtmosStorageClientLiveTest { String metadataValue) throws InterruptedException, ExecutionException, TimeoutException, IOException { AtmosObject getBlob = connection.headFile(path); - assertEquals(IOUtils.toString(getBlob.getContent()), ""); + assertEquals(Utils.toStringAndClose(getBlob.getContent()), ""); verifyMetadata(metadataValue, getBlob); } @@ -282,7 +281,7 @@ public class AtmosStorageClientLiveTest { String metadataValue) throws InterruptedException, ExecutionException, TimeoutException, IOException { AtmosObject getBlob = connection.readFile(path); - assertEquals(IOUtils.toString(getBlob.getContent()), compare); + assertEquals(Utils.toStringAndClose(getBlob.getContent()), compare); verifyMetadata(metadataValue, getBlob); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/filters/FormSigner.java b/aws/core/src/main/java/org/jclouds/aws/ec2/filters/FormSigner.java index 868d59f58e..5bd3cb3011 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/filters/FormSigner.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/filters/FormSigner.java @@ -45,7 +45,6 @@ import javax.inject.Provider; import javax.inject.Singleton; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.util.RequestSigner; import org.jclouds.date.TimeStamp; @@ -59,6 +58,7 @@ import org.jclouds.http.internal.SignatureWire; import org.jclouds.logging.Logger; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Utils; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; @@ -162,7 +162,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner { try { signature = encryptionService.hmacSha256Base64(stringToSign, secretKey.getBytes()); if (signatureWire.enabled()) - signatureWire.input(IOUtils.toInputStream(signature)); + signatureWire.input(Utils.toInputStream(signature)); } catch (Exception e) { throw new HttpException("error signing request", e); } diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java b/aws/core/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java index 61d3d0068b..36925fb753 100755 --- a/aws/core/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java @@ -37,7 +37,6 @@ import javax.inject.Provider; import javax.inject.Singleton; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.util.RequestSigner; import org.jclouds.date.TimeStamp; @@ -49,6 +48,7 @@ import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpUtils; import org.jclouds.http.internal.SignatureWire; import org.jclouds.logging.Logger; +import org.jclouds.util.Utils; import com.google.common.annotations.VisibleForTesting; @@ -111,7 +111,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign throws HttpException { String signature = signString(toSign); if (signatureWire.enabled()) - signatureWire.input(IOUtils.toInputStream(signature)); + signatureWire.input(Utils.toInputStream(signature)); request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION, Collections.singletonList("AWS " + accessKey + ":" + signature)); } diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/xml/AccessControlListHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/xml/AccessControlListHandlerTest.java index b42a8d9309..ce5f010b51 100755 --- a/aws/core/src/test/java/org/jclouds/aws/s3/xml/AccessControlListHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/xml/AccessControlListHandlerTest.java @@ -26,14 +26,13 @@ package org.jclouds.aws.s3.xml; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.domain.AccessControlList; import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI; import org.jclouds.aws.s3.domain.AccessControlList.Permission; -import org.jclouds.aws.s3.xml.AccessControlListHandler; import org.jclouds.http.HttpException; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; +import org.jclouds.util.Utils; import org.testng.annotations.Test; @Test(groups = "unit", testName = "s3.AccessControlListHandlerTest") @@ -50,7 +49,7 @@ public class AccessControlListHandlerTest extends BaseHandlerTest { @Test public void testAccessControlListOwnerOnly() throws HttpException { String ownerId = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c"; - AccessControlList acl = createParser().parse(IOUtils.toInputStream(aclOwnerOnly)); + AccessControlList acl = createParser().parse(Utils.toInputStream(aclOwnerOnly)); assertEquals(acl.getOwner().getId(), ownerId); assertEquals(acl.getOwner().getDisplayName(), "jamesmurty"); assertEquals(acl.getPermissions(ownerId).size(), 1); @@ -64,7 +63,7 @@ public class AccessControlListHandlerTest extends BaseHandlerTest { @Test public void testAccessControlListExtreme() throws HttpException { String ownerId = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c"; - AccessControlList acl = createParser().parse(IOUtils.toInputStream(aclExtreme)); + AccessControlList acl = createParser().parse(Utils.toInputStream(aclExtreme)); assertEquals(acl.getOwner().getId(), ownerId); assertEquals(acl.getOwner().getDisplayName(), "jamesmurty"); assertEquals(acl.getPermissions(ownerId).size(), 3); diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java index 61e9fcf1e1..bb9d3bf874 100755 --- a/aws/core/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java @@ -28,7 +28,6 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.TreeSet; -import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.domain.CanonicalUser; import org.jclouds.aws.s3.domain.ListBucketResponse; import org.jclouds.aws.s3.domain.ObjectMetadata; @@ -41,6 +40,7 @@ import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.http.HttpException; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; +import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -135,7 +135,7 @@ public class ListBucketHandlerTest extends BaseHandlerTest { public void testListMyBucketsWithDelimiterSlashAndCommonPrefixesAppsSlash() throws HttpException { ListBucketResponse bucket = createParser().parse( - IOUtils.toInputStream(listBucketWithSlashDelimiterAndCommonPrefixApps)); + Utils.toInputStream(listBucketWithSlashDelimiterAndCommonPrefixApps)); assertEquals(bucket.getCommonPrefixes().iterator().next(), "apps/"); assertEquals(bucket.getDelimiter(), "/"); assert bucket.getMarker() == null; @@ -145,7 +145,7 @@ public class ListBucketHandlerTest extends BaseHandlerTest { public void testListMyBucketsWithPrefixAppsSlash() throws HttpException { ListBucketResponse bucket = createParser().parse( - IOUtils.toInputStream(listBucketWithPrefixAppsSlash)); + Utils.toInputStream(listBucketWithPrefixAppsSlash)); assertEquals(bucket.getPrefix(), "apps/"); assertEquals(bucket.getMaxKeys(), 1000); assert bucket.getMarker() == null; diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/xml/S3ParserTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/xml/S3ParserTest.java index 3bcab602f7..2dc4672e0a 100755 --- a/aws/core/src/test/java/org/jclouds/aws/s3/xml/S3ParserTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/xml/S3ParserTest.java @@ -34,7 +34,6 @@ import java.util.concurrent.CompletionService; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorCompletionService; -import org.apache.commons.io.IOUtils; import org.jclouds.PerformanceTest; import org.jclouds.aws.s3.domain.BucketMetadata; import org.jclouds.aws.s3.domain.CanonicalUser; @@ -45,6 +44,7 @@ import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.http.HttpException; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.util.Utils; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -87,7 +87,7 @@ public class S3ParserTest extends PerformanceTest { private SortedSet runParseListAllMyBuckets() throws HttpException { return (SortedSet) factory.create( injector.getInstance(ListAllMyBucketsHandler.class)).parse( - IOUtils.toInputStream(listAllMyBucketsResultOn200)); + Utils.toInputStream(listAllMyBucketsResultOn200)); } @Test @@ -148,14 +148,14 @@ public class S3ParserTest extends PerformanceTest { private ListBucketResponse runParseListContainerResult() throws HttpException { return (ListBucketResponse) factory.create(injector.getInstance(ListBucketHandler.class)) - .parse(IOUtils.toInputStream(listContainerResult)); + .parse(Utils.toInputStream(listContainerResult)); } public static final String successfulCopyObject200 = "2009-03-19T13:23:27.000Z\"92836a3ea45a6984d1b4d23a747d46bb\""; private ObjectMetadata runParseCopyObjectResult() throws HttpException { return (ObjectMetadata) factory.create(injector.getInstance(CopyObjectHandler.class)).parse( - IOUtils.toInputStream(successfulCopyObject200)); + Utils.toInputStream(successfulCopyObject200)); } public void testCanParseCopyObjectResult() throws HttpException, UnsupportedEncodingException { diff --git a/aws/core/src/test/java/org/jclouds/aws/xml/ErrorHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/xml/ErrorHandlerTest.java index 03987cf3a7..0243f2d440 100755 --- a/aws/core/src/test/java/org/jclouds/aws/xml/ErrorHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/xml/ErrorHandlerTest.java @@ -25,11 +25,11 @@ package org.jclouds.aws.xml; import static org.testng.Assert.assertEquals; -import org.apache.commons.io.IOUtils; import org.jclouds.aws.domain.AWSError; import org.jclouds.http.HttpException; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; +import org.jclouds.util.Utils; import org.testng.annotations.Test; @Test(groups = "unit", testName = "s3.ErrorHandlerTest") @@ -45,7 +45,7 @@ public class ErrorHandlerTest extends BaseHandlerTest { @Test public void testErrorFromAmazonIfYouDontRemoveTransferEncodingHeader() throws HttpException { ParseSax parser = createParser(); - AWSError error = parser.parse(IOUtils + AWSError error = parser.parse(Utils .toInputStream(errorFromAmazonIfYouDontRemoveTransferEncodingHeader)); assertEquals(error.getCode(), "NotImplemented"); assertEquals(error.getMessage(), diff --git a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java index db80268271..53b51fb3bb 100755 --- a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java +++ b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java @@ -33,7 +33,6 @@ import java.util.Properties; import javax.servlet.ServletContextEvent; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.blobstore.reference.BlobStoreConstants; @@ -42,6 +41,7 @@ import org.jclouds.samples.googleappengine.GetAllContainersController; import com.google.appengine.repackaged.com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; +import com.google.common.io.Closeables; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.TypeLiteral; @@ -90,7 +90,7 @@ public class GuiceServletConfig extends GuiceServletContextListener { } catch (IOException e) { throw new RuntimeException(e); } finally { - IOUtils.closeQuietly(input); + Closeables.closeQuietly(input); } return props; } diff --git a/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java b/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java index 03c27a21b7..06574ce81e 100755 --- a/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java +++ b/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java @@ -37,13 +37,13 @@ import java.io.InputStream; import java.net.URL; import java.util.Properties; -import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.S3PropertiesBuilder; import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder; import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder; import org.jclouds.azure.storage.blob.blobstore.AzureBlobStoreContextBuilder; import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder; import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder; +import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -94,7 +94,7 @@ public class GoogleAppEngineLiveTest { @Test public void shouldPass() throws InterruptedException, IOException { InputStream i = url.openStream(); - String string = IOUtils.toString(i); + String string = Utils.toStringAndClose(i); assert string.indexOf("Welcome") >= 0 : string; } @@ -102,7 +102,7 @@ public class GoogleAppEngineLiveTest { public void testGuiceJCloudsSerial() throws InterruptedException, IOException { URL gurl = new URL(url, "/guice/containers.blobstore"); InputStream i = gurl.openStream(); - String string = IOUtils.toString(i); + String string = Utils.toStringAndClose(i); assert string.indexOf("List") >= 0 : string; } @@ -110,7 +110,7 @@ public class GoogleAppEngineLiveTest { public void testGuiceJCloudsParallel() throws InterruptedException, IOException { URL gurl = new URL(url, "/guice/containers.blobstore"); InputStream i = gurl.openStream(); - String string = IOUtils.toString(i); + String string = Utils.toStringAndClose(i); assert string.indexOf("List") >= 0 : string; } } diff --git a/aws/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceLiveTest.java b/aws/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceLiveTest.java index dc0401346f..72576dba47 100755 --- a/aws/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceLiveTest.java +++ b/aws/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceLiveTest.java @@ -42,7 +42,6 @@ import java.util.concurrent.TimeoutException; import javax.ws.rs.core.MediaType; -import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.S3AsyncClient; import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.domain.ListBucketResponse; @@ -50,6 +49,7 @@ import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI; import org.jclouds.aws.s3.domain.AccessControlList.Permission; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; +import org.jclouds.util.Utils; import org.jets3t.service.S3ObjectsChunk; import org.jets3t.service.S3Service; import org.jets3t.service.S3ServiceException; @@ -190,7 +190,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest extends BaseBlobStoreIntegrationTest< @DataProvider(name = "putTests") public Object[][] createData1() throws IOException { - String realObject = IOUtils.toString(new FileInputStream("pom.xml")); + String realObject = Utils.toStringAndClose(new FileInputStream("pom.xml")); return new Object[][] { { "file", "text/xml", new File("pom.xml"), realObject }, { "string", "text/xml", realObject, realObject }, diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java index 6544a08931..1f8359ceac 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java @@ -36,10 +36,10 @@ import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.util.BlobStoreUtils; +import org.jclouds.util.Utils; import org.testng.annotations.Test; /** @@ -163,11 +163,11 @@ public class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest map = createMap(context, bucketName); Blob object = newBlob("one"); - object.setPayload(IOUtils.toInputStream("apple")); + object.setPayload(Utils.toInputStream("apple")); object.generateMD5(); Blob old = map.put(object.getMetadata().getName(), object); getOneReturnsAppleAndOldValueIsNull(map, old); - object.setPayload(IOUtils.toInputStream("bear")); + object.setPayload(Utils.toInputStream("bear")); object.generateMD5(); Blob apple = map.put(object.getMetadata().getName(), object); getOneReturnsBearAndOldValueIsApple(map, apple); diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseInputStreamMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseInputStreamMapIntegrationTest.java index 7b598459d3..e6487b4431 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseInputStreamMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseInputStreamMapIntegrationTest.java @@ -36,7 +36,6 @@ import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.InputStreamMap; import org.jclouds.util.Utils; @@ -102,12 +101,12 @@ public class BaseInputStreamMapIntegrationTest extends Set> entries = map.entrySet(); assertEquals(entries.size(), 5); for (Entry entry : entries) { - assertEquals(fiveStrings.get(entry.getKey()), IOUtils.toString(entry.getValue())); - entry.setValue(IOUtils.toInputStream("")); + assertEquals(fiveStrings.get(entry.getKey()), Utils.toStringAndClose(entry.getValue())); + entry.setValue(Utils.toInputStream("")); } assertConsistencyAwareMapSize(map, 5); for (InputStream value : map.values()) { - assertEquals(IOUtils.toString(value), ""); + assertEquals(Utils.toStringAndClose(value), ""); } } finally { returnContainer(bucketName); diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseMapIntegrationTest.java index 05c52af4e5..0aed170e82 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseMapIntegrationTest.java @@ -28,7 +28,6 @@ import static org.testng.Assert.assertTrue; import java.io.File; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Map; @@ -37,18 +36,20 @@ import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.ListableMap; +import org.jclouds.util.Utils; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import org.testng.annotations.Test; +import com.google.common.base.Charsets; import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import com.google.common.io.Files; public abstract class BaseMapIntegrationTest extends BaseBlobStoreIntegrationTest { @@ -75,7 +76,7 @@ public abstract class BaseMapIntegrationTest extends BaseBlobStoreInteg protected void setUpInputStreams() { fiveInputs = Maps.transformValues(fiveStrings, new Function() { public InputStream apply(String from) { - return IOUtils.toInputStream(from); + return Utils.toInputStream(from); } }); } @@ -93,7 +94,7 @@ public abstract class BaseMapIntegrationTest extends BaseBlobStoreInteg fiveFiles = Maps.newHashMap(); for (Entry entry : fiveStrings.entrySet()) { File file = new File(tmpDirectory, entry.getKey()); - IOUtils.write(entry.getValue().getBytes(), new FileOutputStream(file)); + Files.write(entry.getValue().getBytes(Charsets.UTF_8), file); fiveFiles.put(entry.getKey(), file); } } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/StubAsyncBlobStore.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/StubAsyncBlobStore.java index 22c8a2c600..dcb82f7010 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/StubAsyncBlobStore.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/StubAsyncBlobStore.java @@ -26,6 +26,7 @@ package org.jclouds.blobstore.integration.internal; import static com.google.common.base.Preconditions.checkNotNull; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -54,8 +55,6 @@ import java.util.concurrent.TimeoutException; import javax.inject.Inject; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.output.ByteArrayOutputStream; import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.KeyNotFoundException; @@ -93,6 +92,8 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import com.google.common.io.ByteStreams; +import com.google.common.io.Closeables; import com.google.inject.internal.Nullable; /** @@ -148,8 +149,8 @@ public class StubAsyncBlobStore implements AsyncBlobStore { } else if (data instanceof File || data instanceof InputStream) { InputStream io = (data instanceof InputStream) ? (InputStream) data : new FileInputStream( (File) data); - bytes = IOUtils.toByteArray(io); - IOUtils.closeQuietly(io); + bytes = ByteStreams.toByteArray(io); + Closeables.closeQuietly(io); } else { throw new UnsupportedOperationException("Content not supported " + data.getClass()); } @@ -594,7 +595,7 @@ public class StubAsyncBlobStore implements AsyncBlobStore { if (options.getRanges() != null && options.getRanges().size() > 0) { byte[] data; try { - data = IOUtils.toByteArray(returnVal.getPayload().getContent()); + data = ByteStreams.toByteArray(returnVal.getPayload().getContent()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/RetryOnNotFoundGetAllBlobsStrategyTest.java b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/RetryOnNotFoundGetAllBlobsStrategyTest.java index 92a7f1d488..88fd3d686d 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/RetryOnNotFoundGetAllBlobsStrategyTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/RetryOnNotFoundGetAllBlobsStrategyTest.java @@ -37,13 +37,13 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.config.BlobStoreObjectModule; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob.Factory; import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder; +import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -86,7 +86,7 @@ public class RetryOnNotFoundGetAllBlobsStrategyTest { map.ifNotFoundRetryOtherwiseAddToSet("container", "key", futureObject, objects); // should have retried once assert System.currentTimeMillis() >= time + map.requestRetryMilliseconds; - assertEquals(IOUtils.toString((InputStream) objects.iterator().next().getContent()), "goo"); + assertEquals(Utils.toStringAndClose((InputStream) objects.iterator().next().getContent()), "goo"); assert !objects.contains(null); } diff --git a/codegen/ec2/src/main/java/org/jclouds/codegen/ec2/queryapi/parser/AmazonEC2QueryAPIParser.java b/codegen/ec2/src/main/java/org/jclouds/codegen/ec2/queryapi/parser/AmazonEC2QueryAPIParser.java index 7d828926c0..6e330ec6d2 100644 --- a/codegen/ec2/src/main/java/org/jclouds/codegen/ec2/queryapi/parser/AmazonEC2QueryAPIParser.java +++ b/codegen/ec2/src/main/java/org/jclouds/codegen/ec2/queryapi/parser/AmazonEC2QueryAPIParser.java @@ -29,10 +29,10 @@ import java.io.FileNotFoundException; import java.io.InputStream; import java.io.InputStreamReader; -import org.apache.commons.io.IOUtils; import org.jclouds.codegen.ec2.queryapi.AmazonEC2QueryAPI; import com.google.gson.Gson; +import com.google.common.io.Closeables; /** * Converts object models representing AWS API beans into Java classes. @@ -65,7 +65,7 @@ public class AmazonEC2QueryAPIParser { validator.validateCategories().validateCommands().validateDomain(); return validator.getModel(); } finally { - IOUtils.closeQuietly(in); + Closeables.closeQuietly(in); } } diff --git a/core/pom.xml b/core/pom.xml index ea861eae78..81204b322d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -61,11 +61,6 @@ resteasy-jaxrs-client 1.1.GA - - commons-io - commons-io - 1.4 - com.google.code.guice guice @@ -79,7 +74,7 @@ com.google.collections google-collections - 1.0-rc4 + 1.0-rc5 javax.annotation diff --git a/core/src/main/java/org/jclouds/encryption/internal/JCEEncryptionService.java b/core/src/main/java/org/jclouds/encryption/internal/JCEEncryptionService.java index 3dc2f665aa..4feb59a25f 100644 --- a/core/src/main/java/org/jclouds/encryption/internal/JCEEncryptionService.java +++ b/core/src/main/java/org/jclouds/encryption/internal/JCEEncryptionService.java @@ -12,8 +12,9 @@ import java.security.NoSuchProviderException; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.output.ByteArrayOutputStream; +import java.io.ByteArrayOutputStream; + +import com.google.common.io.Closeables; /** * @@ -75,7 +76,7 @@ public class JCEEncryptionService extends BaseEncryptionService { } catch (IOException e) { throw new RuntimeException(e); } finally { - IOUtils.closeQuietly(i); + Closeables.closeQuietly(i); } return eTag.digest(); } @@ -102,8 +103,8 @@ public class JCEEncryptionService extends BaseEncryptionService { } catch (IOException e) { throw new RuntimeException(e); } finally { - IOUtils.closeQuietly(out); - IOUtils.closeQuietly(toEncode); + Closeables.closeQuietly(out); + Closeables.closeQuietly(toEncode); } return new MD5InputStreamResult(out.toByteArray(), eTag.digest(), length); } diff --git a/core/src/main/java/org/jclouds/http/HttpUtils.java b/core/src/main/java/org/jclouds/http/HttpUtils.java index 2526172d80..e0abcff35e 100644 --- a/core/src/main/java/org/jclouds/http/HttpUtils.java +++ b/core/src/main/java/org/jclouds/http/HttpUtils.java @@ -41,7 +41,6 @@ import java.util.regex.Pattern; import javax.annotation.Resource; -import org.apache.commons.io.IOUtils; import org.jclouds.logging.Logger; import com.google.common.base.Function; @@ -52,6 +51,8 @@ import com.google.common.collect.MapMaker; import com.google.common.collect.Multimap; import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.TreeMultimap; +import com.google.common.io.ByteStreams; +import com.google.common.io.Closeables; public class HttpUtils { public static final Pattern URI_PATTERN = Pattern.compile("([a-z0-9]+)://([^:]*):(.*)@(.*)"); @@ -107,13 +108,13 @@ public class HttpUtils { public static byte[] closeClientButKeepContentStream(HttpResponse response) { if (response.getContent() != null) { try { - byte[] data = IOUtils.toByteArray(response.getContent()); + byte[] data = ByteStreams.toByteArray(response.getContent()); response.setContent(new ByteArrayInputStream(data)); return data; } catch (IOException e) { logger.error(e, "Error consuming input"); } finally { - IOUtils.closeQuietly(response.getContent()); + Closeables.closeQuietly(response.getContent()); } } return null; @@ -216,7 +217,7 @@ public class HttpUtils { } while (numRead != -1); } finally { output.close(); - IOUtils.closeQuietly(input); + Closeables.closeQuietly(input); } } diff --git a/core/src/main/java/org/jclouds/http/MultipartForm.java b/core/src/main/java/org/jclouds/http/MultipartForm.java index ad84cec39c..dbeea7df7e 100644 --- a/core/src/main/java/org/jclouds/http/MultipartForm.java +++ b/core/src/main/java/org/jclouds/http/MultipartForm.java @@ -30,8 +30,8 @@ import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map.Entry; -import org.apache.commons.io.IOUtils; import org.jclouds.util.InputStreamChain; +import org.jclouds.util.Utils; import com.google.common.collect.Multimap; @@ -95,7 +95,7 @@ public class MultipartForm { } public Part(Multimap headers, String data) { - this(headers, IOUtils.toInputStream(data), data.length()); + this(headers, Utils.toInputStream(data), data.length()); } public Part(Multimap headers, File data) throws FileNotFoundException { diff --git a/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java b/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java index 04c08d3f9e..60370daec9 100644 --- a/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java +++ b/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java @@ -131,7 +131,7 @@ public class TransformingHttpCommandImpl implements TransformingHttpCommand= 300) { - * IOUtils.closeQuietly(getResponse().getContent()); throw new + * Closeables.closeQuietly(getResponse().getContent()); throw new * IllegalStateException("incorrect code for this operation: " + getResponse()); } } **/ public HttpRequest getRequest() { diff --git a/core/src/main/java/org/jclouds/http/functions/ParseContentMD5FromHeaders.java b/core/src/main/java/org/jclouds/http/functions/ParseContentMD5FromHeaders.java index ad441e4fb6..0611ff4d4b 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseContentMD5FromHeaders.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseContentMD5FromHeaders.java @@ -25,7 +25,6 @@ package org.jclouds.http.functions; import javax.annotation.Resource; -import org.apache.commons.io.IOUtils; import org.jclouds.encryption.internal.Base64; import org.jclouds.http.HttpResponse; import org.jclouds.logging.Logger; @@ -33,6 +32,7 @@ import org.jclouds.rest.InvocationContext; import org.jclouds.rest.internal.GeneratedHttpRequest; import com.google.common.base.Function; +import com.google.common.io.Closeables; /** * @author Adrian Cole @@ -67,7 +67,7 @@ public class ParseContentMD5FromHeaders implements Function request; public byte[] apply(HttpResponse from) { - IOUtils.closeQuietly(from.getContent()); + Closeables.closeQuietly(from.getContent()); String contentMD5 = from.getFirstHeaderOrNull("Content-MD5"); if (contentMD5 != null) { return Base64.decode(contentMD5); diff --git a/core/src/main/java/org/jclouds/http/functions/ParseETagHeader.java b/core/src/main/java/org/jclouds/http/functions/ParseETagHeader.java index 6cc642e90b..862d578ca7 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseETagHeader.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseETagHeader.java @@ -26,11 +26,11 @@ package org.jclouds.http.functions; import javax.inject.Singleton; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpException; import org.jclouds.http.HttpResponse; import com.google.common.base.Function; +import com.google.common.io.Closeables; /** * Parses an MD5 checksum from the header {@link HttpHeaders#ETAG}. @@ -41,7 +41,7 @@ import com.google.common.base.Function; public class ParseETagHeader implements Function { public String apply(HttpResponse from) { - IOUtils.closeQuietly(from.getContent()); + Closeables.closeQuietly(from.getContent()); String eTag = from.getFirstHeaderOrNull(HttpHeaders.ETAG); if (eTag == null) { diff --git a/core/src/main/java/org/jclouds/http/functions/ParseJson.java b/core/src/main/java/org/jclouds/http/functions/ParseJson.java index 42bf42abd3..7ed73fa7ed 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseJson.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseJson.java @@ -28,12 +28,12 @@ import java.io.InputStream; import javax.annotation.Resource; import javax.inject.Singleton; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponseException; import org.jclouds.logging.Logger; import com.google.common.base.Function; +import com.google.common.io.Closeables; import com.google.gson.Gson; /** @@ -66,7 +66,7 @@ public abstract class ParseJson implements Function { logger.error(e, message.toString()); throw new HttpResponseException(message.toString() + "\n" + from, null, from, e); } finally { - IOUtils.closeQuietly(gson); + Closeables.closeQuietly(gson); } } diff --git a/core/src/main/java/org/jclouds/http/functions/ParseSax.java b/core/src/main/java/org/jclouds/http/functions/ParseSax.java index 7fbc1b79f5..6fdaed17e2 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseSax.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseSax.java @@ -30,7 +30,6 @@ import java.io.InputStream; import javax.annotation.Resource; import javax.inject.Inject; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpException; import org.jclouds.http.HttpResponse; import org.jclouds.logging.Logger; @@ -41,6 +40,7 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import com.google.common.base.Function; +import com.google.common.io.Closeables; /** * This object will parse the body of an HttpResponse and return the result of type back to the @@ -99,7 +99,7 @@ public class ParseSax implements Function { Utils. rethrowIfRuntimeOrSameType(e); throw new HttpException(message.toString(), e); } finally { - IOUtils.closeQuietly(xml); + Closeables.closeQuietly(xml); } } diff --git a/core/src/main/java/org/jclouds/http/functions/ReturnTrueIf2xx.java b/core/src/main/java/org/jclouds/http/functions/ReturnTrueIf2xx.java index 20260e7d82..f20d5b4304 100644 --- a/core/src/main/java/org/jclouds/http/functions/ReturnTrueIf2xx.java +++ b/core/src/main/java/org/jclouds/http/functions/ReturnTrueIf2xx.java @@ -25,10 +25,10 @@ package org.jclouds.http.functions; import javax.inject.Singleton; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpResponse; import com.google.common.base.Function; +import com.google.common.io.Closeables; /** * Simply returns true when the http response code is in the range 200-299. @@ -39,7 +39,7 @@ import com.google.common.base.Function; public class ReturnTrueIf2xx implements Function { public Boolean apply(HttpResponse from) { - IOUtils.closeQuietly(from.getContent()); + Closeables.closeQuietly(from.getContent()); int code = from.getStatusCode(); if (code >= 300 || code < 200) { throw new IllegalStateException("incorrect code for this operation: " + from); diff --git a/core/src/main/java/org/jclouds/http/functions/ReturnVoidIf2xx.java b/core/src/main/java/org/jclouds/http/functions/ReturnVoidIf2xx.java index 955168a681..6fb8f704e9 100644 --- a/core/src/main/java/org/jclouds/http/functions/ReturnVoidIf2xx.java +++ b/core/src/main/java/org/jclouds/http/functions/ReturnVoidIf2xx.java @@ -27,10 +27,10 @@ import java.lang.reflect.Constructor; import javax.inject.Singleton; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpResponse; import com.google.common.base.Function; +import com.google.common.io.Closeables; /** * Simply returns true when the http response code is in the range 200-299. @@ -52,7 +52,7 @@ public class ReturnVoidIf2xx implements Function { } public Void apply(HttpResponse from) { - IOUtils.closeQuietly(from.getContent()); + Closeables.closeQuietly(from.getContent()); int code = from.getStatusCode(); if (code >= 300 || code < 200) { throw new IllegalStateException("incorrect code for this operation: " + from); diff --git a/core/src/main/java/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java b/core/src/main/java/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java index 5be70e39c1..92572b58f2 100644 --- a/core/src/main/java/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java +++ b/core/src/main/java/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java @@ -26,7 +26,6 @@ package org.jclouds.http.handlers; import javax.annotation.Resource; import javax.inject.Named; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpConstants; import org.jclouds.http.HttpResponse; @@ -34,6 +33,7 @@ import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.TransformingHttpCommand; import org.jclouds.logging.Logger; +import com.google.common.io.Closeables; import com.google.inject.Inject; /** @@ -85,7 +85,7 @@ public class BackoffLimitedRetryHandler implements HttpRetryHandler { protected Logger logger = Logger.NULL; public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { - IOUtils.closeQuietly(response.getContent()); + Closeables.closeQuietly(response.getContent()); command.incrementFailureCount(); diff --git a/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java b/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java index 915ffc038a..200df89ef8 100644 --- a/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java +++ b/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java @@ -32,7 +32,6 @@ import javax.inject.Named; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriBuilder; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpConstants; import org.jclouds.http.HttpResponse; @@ -40,6 +39,8 @@ import org.jclouds.http.HttpRetryHandler; import org.jclouds.logging.Logger; import com.google.common.annotations.VisibleForTesting; +import com.google.common.io.ByteStreams; +import com.google.common.io.Closeables; import com.google.inject.Inject; /** @@ -91,12 +92,12 @@ public class RedirectionRetryHandler implements HttpRetryHandler { void closeClientButKeepContentStream(HttpResponse response) { if (response.getContent() != null) { try { - byte[] data = IOUtils.toByteArray(response.getContent()); + byte[] data = ByteStreams.toByteArray(response.getContent()); response.setContent(new ByteArrayInputStream(data)); } catch (IOException e) { logger.error(e, "Error consuming input"); } finally { - IOUtils.closeQuietly(response.getContent()); + Closeables.closeQuietly(response.getContent()); } } } diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index 18ae7bc028..e313e7f935 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -38,7 +38,6 @@ import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpCommandExecutorService; import org.jclouds.http.HttpConstants; import org.jclouds.http.HttpRequest; @@ -47,6 +46,7 @@ import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import com.google.common.collect.Maps; +import com.google.common.io.Closeables; import com.google.inject.Inject; /** @@ -135,7 +135,7 @@ public class JavaUrlHttpCommandExecutorService extends try { request.getPayload().writeTo(out); } finally { - IOUtils.closeQuietly(out); + Closeables.closeQuietly(out); } } else { connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, "0"); diff --git a/core/src/main/java/org/jclouds/http/payloads/ByteArrayPayload.java b/core/src/main/java/org/jclouds/http/payloads/ByteArrayPayload.java index dd214276cb..6b2175a03a 100644 --- a/core/src/main/java/org/jclouds/http/payloads/ByteArrayPayload.java +++ b/core/src/main/java/org/jclouds/http/payloads/ByteArrayPayload.java @@ -30,13 +30,16 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; import org.jclouds.http.Payload; +import org.jclouds.util.Utils; + +import com.google.common.io.ByteStreams; /** * @author Adrian Cole */ public class ByteArrayPayload implements Payload { + private final byte[] content; public ByteArrayPayload(byte[] content) { @@ -68,7 +71,7 @@ public class ByteArrayPayload implements Payload { */ @Override public void writeTo(OutputStream outstream) throws IOException { - IOUtils.write(content, outstream); + ByteStreams.write(content, Utils.newOutputStreamSupplier(outstream)); } @Override diff --git a/core/src/main/java/org/jclouds/http/payloads/FilePayload.java b/core/src/main/java/org/jclouds/http/payloads/FilePayload.java index 8e986bb511..94c3efd4d0 100644 --- a/core/src/main/java/org/jclouds/http/payloads/FilePayload.java +++ b/core/src/main/java/org/jclouds/http/payloads/FilePayload.java @@ -33,9 +33,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; import org.jclouds.http.Payload; +import com.google.common.io.Closeables; +import com.google.common.io.Files; + /** * @author Adrian Cole */ @@ -78,9 +80,9 @@ public class FilePayload implements Payload { public void writeTo(OutputStream outstream) throws IOException { InputStream in = getContent(); try { - IOUtils.copy(getContent(), outstream); + Files.copy(content, outstream); } finally { - IOUtils.closeQuietly(in); + Closeables.closeQuietly(in); } } diff --git a/core/src/main/java/org/jclouds/http/payloads/InputStreamPayload.java b/core/src/main/java/org/jclouds/http/payloads/InputStreamPayload.java index 0783ca4854..993b9b094e 100644 --- a/core/src/main/java/org/jclouds/http/payloads/InputStreamPayload.java +++ b/core/src/main/java/org/jclouds/http/payloads/InputStreamPayload.java @@ -29,9 +29,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; import org.jclouds.http.Payload; +import com.google.common.io.ByteStreams; +import com.google.common.io.Closeables; + /** * @author Adrian Cole */ @@ -69,9 +71,9 @@ public class InputStreamPayload implements Payload { public void writeTo(OutputStream outstream) throws IOException { InputStream in = getContent(); try { - IOUtils.copy(getContent(), outstream); + ByteStreams.copy(getContent(), outstream); } finally { - IOUtils.closeQuietly(in); + Closeables.closeQuietly(in); } } diff --git a/core/src/main/java/org/jclouds/http/payloads/StringPayload.java b/core/src/main/java/org/jclouds/http/payloads/StringPayload.java index 720333a15b..893a4798a1 100644 --- a/core/src/main/java/org/jclouds/http/payloads/StringPayload.java +++ b/core/src/main/java/org/jclouds/http/payloads/StringPayload.java @@ -29,8 +29,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; import org.jclouds.http.Payload; +import org.jclouds.util.Utils; + +import com.google.common.io.ByteStreams; /** * @author Adrian Cole @@ -51,7 +53,7 @@ public class StringPayload implements Payload { */ @Override public InputStream getContent() { - return IOUtils.toInputStream(content); + return Utils.toInputStream(content); } /** @@ -67,7 +69,7 @@ public class StringPayload implements Payload { */ @Override public void writeTo(OutputStream outstream) throws IOException { - IOUtils.write(content.getBytes(), outstream); + ByteStreams.copy(Utils.toInputStream(content), outstream); } /** diff --git a/core/src/main/java/org/jclouds/io/TeeInputStream.java b/core/src/main/java/org/jclouds/io/TeeInputStream.java new file mode 100644 index 0000000000..9cd1e62bad --- /dev/null +++ b/core/src/main/java/org/jclouds/io/TeeInputStream.java @@ -0,0 +1,209 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.io; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Ported from org.apache.commons.io.input.TeeInputStream + * + * InputStream proxy that transparently writes a copy of all bytes read from the delegate stream to + * a given OutputStream. Using {@link #skip(long)} or {@link #mark(int)}/{@link #reset()} on the + * stream will result on some bytes from the input stream being skipped or duplicated in the output + * stream. + *

+ * The delegate input stream is closed when the {@link #close()} method is called on this proxy. It + * is configurable whether the associated output stream will also closed. + * + * @see Commons IO 1.4 + * @see org.apache.commons.io.input.TeeInputStream + */ +public class TeeInputStream extends InputStream { + + /** + * The input stream to delegate to. + */ + private final InputStream delegate; + + /** + * The output stream that will receive a copy of all bytes read from the delegate input stream. + */ + private final OutputStream branch; + + /** + * Flag for closing also the associated output stream when this stream is closed. + */ + private final boolean closeBranch; + + /** + * Creates a TeeInputStream that delegates to the given {@link InputStream} and copies all read + * bytes to the given {@link OutputStream}. The given output stream will not be closed when this + * stream gets closed. + * + * @param input + * input stream to be delegate + * @param branch + * output stream that will receive a copy of all bytes read + */ + public TeeInputStream(InputStream delegate, OutputStream branch) { + this(delegate, branch, false); + } + + /** + * Creates a TeeInputStream that proxies the given {@link InputStream} and copies all read bytes + * to the given {@link OutputStream}. The given output stream will be closed when this stream + * gets closed if the closeBranch parameter is true. + * + * @param input + * input stream to be delegate + * @param branch + * output stream that will receive a copy of all bytes read + * @param closeBranch + * flag for closing also the output stream when this stream is closed + */ + public TeeInputStream(InputStream delegate, OutputStream branch, boolean closeBranch) { + this.delegate = delegate; + this.branch = branch; + this.closeBranch = closeBranch; + } + + /** + * Closes the delegate input stream and, if so configured, the associated output stream. An + * exception thrown from one stream will not prevent closing of the other stream. + * + * @throws IOException + * if either of the streams could not be closed + */ + @Override + public void close() throws IOException { + try { + delegate.close(); + } finally { + if (closeBranch) { + branch.close(); + } + } + } + + /** + * Reads a single byte from the delegate input stream and writes it to the associated output + * stream. + * + * @return next byte from the stream, or -1 if the stream has ended + * @throws IOException + * if the stream could not be read (or written) + */ + public int read() throws IOException { + int ch = delegate.read(); + if (ch != -1) { + branch.write(ch); + } + return ch; + } + + /** + * Reads bytes from the delegate input stream and writes the read bytes to the associated output + * stream. + * + * @param bts + * byte buffer + * @param st + * start offset within the buffer + * @param end + * maximum number of bytes to read + * @return number of bytes read, or -1 if the stream has ended + * @throws IOException + * if the stream could not be read (or written) + */ + @Override + public int read(byte[] bts, int st, int end) throws IOException { + int n = delegate.read(bts, st, end); + if (n != -1) { + branch.write(bts, st, n); + } + return n; + } + + /** + * Reads bytes from the delegate input stream and writes the read bytes to the associated output + * stream. + * + * @param bts + * byte buffer + * @return number of bytes read, or -1 if the stream has ended + * @throws IOException + * if the stream could not be read (or written) + */ + @Override + public int read(byte[] bts) throws IOException { + int n = delegate.read(bts); + if (n != -1) { + branch.write(bts, 0, n); + } + return n; + } + + /** + * {@inheritDoc} + */ + @Override + public int available() throws IOException { + return delegate.available(); + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized void mark(int readlimit) { + delegate.mark(readlimit); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean markSupported() { + return delegate.markSupported(); + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized void reset() throws IOException { + delegate.reset(); + } + + /** + * {@inheritDoc} + */ + @Override + public long skip(long n) throws IOException { + return delegate.skip(n); + } + +} 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 65876a6b17..cfed4c9625 100644 --- a/core/src/main/java/org/jclouds/logging/internal/Wire.java +++ b/core/src/main/java/org/jclouds/logging/internal/Wire.java @@ -38,10 +38,12 @@ import java.util.concurrent.ExecutorService; import javax.annotation.Resource; import javax.inject.Inject; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.TeeInputStream; import org.jclouds.concurrent.SingleThreaded; +import org.jclouds.io.TeeInputStream; import org.jclouds.logging.Logger; + +import com.google.common.io.ByteStreams; +import com.google.common.io.Closeables; /** * Logs data to the wire LOG. * @@ -98,13 +100,13 @@ public abstract class Wire { public InputStream copy(final String header, InputStream instream) { try { - byte[] data = IOUtils.toByteArray(instream); + byte[] data = ByteStreams.toByteArray(instream); wire(header, new ByteArrayInputStream(data)); return new ByteArrayInputStream(data); } catch (IOException e) { throw new RuntimeException("Error tapping line", e); } finally { - IOUtils.closeQuietly(instream); + Closeables.closeQuietly(instream); } } @@ -119,7 +121,7 @@ public abstract class Wire { try { wire(header, line); } finally { - IOUtils.closeQuietly(line); + Closeables.closeQuietly(line); } } }); @@ -166,7 +168,7 @@ public abstract class Wire { } catch (FileNotFoundException e) { logger.error(e, "Error tapping file: %s", out); } finally { - IOUtils.closeQuietly(in); + Closeables.closeQuietly(in); } } }); diff --git a/core/src/main/java/org/jclouds/util/InputStreamChain.java b/core/src/main/java/org/jclouds/util/InputStreamChain.java index 5dca55e933..16d8ed3319 100644 --- a/core/src/main/java/org/jclouds/util/InputStreamChain.java +++ b/core/src/main/java/org/jclouds/util/InputStreamChain.java @@ -27,8 +27,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; -import org.apache.commons.io.IOUtils; - /** * {@link InputStream} implementation that allows chaining of various streams for seamless * sequential reading @@ -83,7 +81,7 @@ public class InputStreamChain extends InputStream { * @return instance of self (for fluent calls) */ public InputStreamChain addAsInputStream(final String value) { - return addInputStream(IOUtils.toInputStream(value)); + return addInputStream(Utils.toInputStream(value)); } @Override diff --git a/core/src/main/java/org/jclouds/util/Utils.java b/core/src/main/java/org/jclouds/util/Utils.java index 9cf02a2361..48919e574a 100644 --- a/core/src/main/java/org/jclouds/util/Utils.java +++ b/core/src/main/java/org/jclouds/util/Utils.java @@ -23,8 +23,11 @@ */ package org.jclouds.util; +import static com.google.common.base.Preconditions.checkNotNull; + import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -33,11 +36,14 @@ import java.util.regex.Pattern; import javax.annotation.Resource; -import org.apache.commons.io.IOUtils; import org.jclouds.logging.Logger; +import com.google.common.base.Charsets; import com.google.common.base.Supplier; import com.google.common.collect.ComputationException; +import com.google.common.io.ByteStreams; +import com.google.common.io.Closeables; +import com.google.common.io.OutputSupplier; /** * // TODO: Adrian: Document this! @@ -47,6 +53,23 @@ import com.google.common.collect.ComputationException; public class Utils { public static final String UTF8_ENCODING = "UTF-8"; + /** + * Returns a factory that will supply instances of {@link OutputStream} that read from the given + * outputStream. + * + * @param url + * the URL to read from + * @return the factory + */ + public static OutputSupplier newOutputStreamSupplier(final OutputStream output) { + checkNotNull(output, "output"); + return new OutputSupplier() { + public OutputStream getOutput() throws IOException { + return output; + } + }; + } + public static boolean enventuallyTrue(Supplier assertion, long inconsistencyMillis) throws InterruptedException { @@ -116,9 +139,18 @@ public class Utils { public static String toStringAndClose(InputStream input) throws IOException { try { - return IOUtils.toString(input); + return new String(ByteStreams.toByteArray(input), Charsets.UTF_8); } finally { - IOUtils.closeQuietly(input); + Closeables.closeQuietly(input); + } + } + + public static InputStream toInputStream(String in) { + try { + return ByteStreams.newInputStreamSupplier(in.getBytes(Charsets.UTF_8)).getInput(); + } catch (IOException e) { + logger.warn(e, "Failed to convert %s to an inputStream", in); + throw new RuntimeException(e); } } diff --git a/core/src/test/java/org/jclouds/http/IntegrationTestAsyncClient.java b/core/src/test/java/org/jclouds/http/IntegrationTestAsyncClient.java index 2938715e90..0388f804c1 100644 --- a/core/src/test/java/org/jclouds/http/IntegrationTestAsyncClient.java +++ b/core/src/test/java/org/jclouds/http/IntegrationTestAsyncClient.java @@ -34,7 +34,6 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import org.apache.commons.io.IOUtils; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.rest.annotations.BinderParam; @@ -48,6 +47,7 @@ import org.jclouds.rest.binders.BindMapToMatrixParams; import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.internal.RestAnnotationProcessorTest.Localhost; +import org.jclouds.util.Utils; import com.google.common.base.Function; @@ -108,7 +108,7 @@ public interface IntegrationTestAsyncClient { @Override public void bindToRequest(HttpRequest request, Object payload) { super.bindToRequest(request, payload); - request.setPayload(IOUtils.toInputStream(payload.toString())); + request.setPayload(Utils.toInputStream(payload.toString())); } } diff --git a/core/src/test/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20xTest.java b/core/src/test/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20xTest.java index 499fbed5f2..2f683f9107 100644 --- a/core/src/test/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20xTest.java +++ b/core/src/test/java/org/jclouds/http/functions/ParseURIFromListOrLocationHeaderIf20xTest.java @@ -36,10 +36,10 @@ import java.util.concurrent.TimeoutException; import javax.ws.rs.ext.RuntimeDelegate; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpResponse; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RuntimeDelegateImpl; +import org.jclouds.util.Utils; import org.mortbay.jetty.HttpHeaders; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -90,7 +90,7 @@ public class ParseURIFromListOrLocationHeaderIf20xTest { HttpResponse response = createMock(HttpResponse.class); expect(response.getStatusCode()).andReturn(200).atLeastOnce(); expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list"); - expect(response.getContent()).andReturn(IOUtils.toInputStream("http://locahost")) + expect(response.getContent()).andReturn(Utils.toInputStream("http://locahost")) .atLeastOnce(); replay(response); assertEquals(function.apply(response), URI.create("http://locahost")); diff --git a/core/src/test/java/org/jclouds/http/functions/ReturnStringIf200Test.java b/core/src/test/java/org/jclouds/http/functions/ReturnStringIf200Test.java index 3b885643b6..ffda6cc1a8 100644 --- a/core/src/test/java/org/jclouds/http/functions/ReturnStringIf200Test.java +++ b/core/src/test/java/org/jclouds/http/functions/ReturnStringIf200Test.java @@ -33,9 +33,8 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ReturnStringIf200; +import org.jclouds.util.Utils; import org.testng.annotations.Test; import com.google.common.base.Function; @@ -81,7 +80,7 @@ public class ReturnStringIf200Test { Function function = new ReturnStringIf200(); HttpResponse response = createMock(HttpResponse.class); expect(response.getStatusCode()).andReturn(200).atLeastOnce(); - expect(response.getContent()).andReturn(IOUtils.toInputStream("hello")); + expect(response.getContent()).andReturn(Utils.toInputStream("hello")); replay(response); assertEquals(function.apply(response), "hello"); verify(response); diff --git a/core/src/test/java/org/jclouds/http/internal/WireLiveTest.java b/core/src/test/java/org/jclouds/http/internal/WireLiveTest.java index 0c021cbe5c..d3e0b37566 100644 --- a/core/src/test/java/org/jclouds/http/internal/WireLiveTest.java +++ b/core/src/test/java/org/jclouds/http/internal/WireLiveTest.java @@ -37,13 +37,14 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import org.apache.commons.io.IOUtils; import org.jclouds.concurrent.WithinThreadExecutorService; import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.internal.JCEEncryptionService; import org.jclouds.logging.Logger; import org.testng.annotations.Test; +import com.google.common.io.ByteStreams; + /** * * @author Adrian Cole @@ -66,8 +67,8 @@ public class WireLiveTest { public Void call() throws Exception { HttpWire wire = setUp(); InputStream in = wire.input(fromServer); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - IOUtils.copy(in, out); + ByteArrayOutputStream out = new ByteArrayOutputStream();//TODO + ByteStreams.copy(in, out); byte[] compare = encryptionService.md5(new ByteArrayInputStream(out.toByteArray())); Thread.sleep(100); assertEquals(encryptionService.toHexString(compare), checkNotNull(sysHttpStreamMd5, diff --git a/core/src/test/java/org/jclouds/rest/RestClientTest.java b/core/src/test/java/org/jclouds/rest/RestClientTest.java index 91dfa0e65d..0a91b9fe61 100644 --- a/core/src/test/java/org/jclouds/rest/RestClientTest.java +++ b/core/src/test/java/org/jclouds/rest/RestClientTest.java @@ -29,7 +29,6 @@ import static org.testng.Assert.assertNull; import java.io.IOException; import java.lang.reflect.Method; -import org.apache.commons.io.IOUtils; import org.jclouds.concurrent.WithinThreadExecutorService; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpUtils; @@ -37,6 +36,7 @@ import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.rest.config.RestModule; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Utils; import org.testng.annotations.BeforeClass; import com.google.inject.Guice; @@ -71,7 +71,7 @@ public abstract class RestClientTest { if (httpMethod.getPayload() == null) { assertNull(toMatch); } else { - String payload = IOUtils.toString(httpMethod.getPayload().getContent()); + String payload = Utils.toStringAndClose(httpMethod.getPayload().getContent()); assertEquals(payload, toMatch); } } diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index f10e2f0c61..836743900a 100755 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -60,7 +60,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import org.apache.commons.io.IOUtils; import org.jclouds.concurrent.WithinThreadExecutorService; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.date.DateService; @@ -102,6 +101,7 @@ import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.config.RestModule; import org.jclouds.util.Jsr330; +import org.jclouds.util.Utils; import org.mortbay.jetty.HttpHeaders; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; @@ -1651,7 +1651,7 @@ public class RestAnnotationProcessorTest { if (httpMethod.getPayload() == null) { assertNull(toMatch); } else { - String payload = IOUtils.toString(httpMethod.getPayload().getContent()); + String payload = Utils.toStringAndClose(httpMethod.getPayload().getContent()); assertEquals(payload, toMatch); } } diff --git a/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java b/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java index 73e35aec31..cf1398a920 100755 --- a/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java +++ b/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java @@ -36,7 +36,6 @@ import java.util.Properties; import javax.servlet.ServletContextEvent; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.demo.tweetstore.controller.AddTweetsController; @@ -50,6 +49,7 @@ import com.google.appengine.api.labs.taskqueue.QueueFactory; import com.google.appengine.api.labs.taskqueue.TaskOptions.Method; import com.google.appengine.repackaged.com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; +import com.google.common.io.Closeables; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.TypeLiteral; @@ -123,7 +123,7 @@ public class GuiceServletConfig extends GuiceServletContextListener { } catch (IOException e) { throw new RuntimeException(e); } finally { - IOUtils.closeQuietly(input); + Closeables.closeQuietly(input); } return props; } diff --git a/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java b/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java index 62bbb75294..352896bc3c 100644 --- a/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java +++ b/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java @@ -33,7 +33,6 @@ import java.util.SortedSet; import java.util.Map.Entry; import java.util.concurrent.ExecutionException; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.BlobMap; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.domain.Blob; @@ -42,6 +41,7 @@ import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; import org.jclouds.twitter.TwitterClient; import org.jclouds.twitter.domain.Status; import org.jclouds.twitter.domain.User; +import org.jclouds.util.Utils; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -103,14 +103,14 @@ public class StoreTweetsControllerTest { assertEquals(frankBlob.getMetadata().getUserMetadata() .get(TweetStoreConstants.SENDER_NAME), "frank"); assertEquals(frankBlob.getMetadata().getContentType(), "text/plain"); - assertEquals(IOUtils.toString((InputStream) frankBlob.getContent()), "I love beans!"); + assertEquals(Utils.toStringAndClose((InputStream) frankBlob.getContent()), "I love beans!"); Blob jimmyBlob = map.get("2"); assertEquals(jimmyBlob.getMetadata().getName(), "2"); assertEquals(jimmyBlob.getMetadata().getUserMetadata() .get(TweetStoreConstants.SENDER_NAME), "jimmy"); assertEquals(jimmyBlob.getMetadata().getContentType(), "text/plain"); - assertEquals(IOUtils.toString((InputStream) jimmyBlob.getContent()), "cloud is king"); + assertEquals(Utils.toStringAndClose((InputStream) jimmyBlob.getContent()), "cloud is king"); } } diff --git a/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java index 65423c9e94..d0a66889bb 100755 --- a/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ b/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java @@ -43,7 +43,6 @@ import java.util.Properties; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.S3PropertiesBuilder; import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder; import org.jclouds.aws.s3.blobstore.S3BlobStoreContextFactory; @@ -55,6 +54,7 @@ import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder; import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder; import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextFactory; import org.jclouds.twitter.TwitterPropertiesBuilder; +import org.jclouds.util.Utils; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; @@ -161,7 +161,7 @@ public class TweetStoreLiveTest { @Test public void shouldPass() throws InterruptedException, IOException { InputStream i = url.openStream(); - String string = IOUtils.toString(i); + String string = Utils.toStringAndClose(i); assert string.indexOf("Welcome") >= 0 : string; } @@ -180,7 +180,7 @@ public class TweetStoreLiveTest { connection.addRequestProperty("X-AppEngine-QueueName", "twitter"); connection.addRequestProperty("context", context); InputStream i = connection.getInputStream(); - String string = IOUtils.toString(i); + String string = Utils.toStringAndClose(i); assert string.indexOf("Done!") >= 0 : string; connection.disconnect(); } @@ -197,7 +197,7 @@ public class TweetStoreLiveTest { public void testSerial() throws InterruptedException, IOException { URL gurl = new URL(url, "/tweets/get"); InputStream i = gurl.openStream(); - String string = IOUtils.toString(i); + String string = Utils.toStringAndClose(i); assert string.indexOf("Tweets in Clouds") >= 0 : string; } @@ -205,7 +205,7 @@ public class TweetStoreLiveTest { public void testParallel() throws InterruptedException, IOException { URL gurl = new URL(url, "/tweets/get"); InputStream i = gurl.openStream(); - String string = IOUtils.toString(i); + String string = Utils.toStringAndClose(i); assert string.indexOf("Tweets in Clouds") >= 0 : string; } } diff --git a/extensions/bouncycastle/src/main/java/org/jclouds/encryption/bouncycastle/BouncyCastleEncryptionService.java b/extensions/bouncycastle/src/main/java/org/jclouds/encryption/bouncycastle/BouncyCastleEncryptionService.java index c59fc86404..ef24b87f77 100644 --- a/extensions/bouncycastle/src/main/java/org/jclouds/encryption/bouncycastle/BouncyCastleEncryptionService.java +++ b/extensions/bouncycastle/src/main/java/org/jclouds/encryption/bouncycastle/BouncyCastleEncryptionService.java @@ -23,6 +23,7 @@ */ package org.jclouds.encryption.bouncycastle; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -33,8 +34,6 @@ import java.security.NoSuchProviderException; import javax.inject.Singleton; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.output.ByteArrayOutputStream; import org.bouncycastle.crypto.Digest; import org.bouncycastle.crypto.digests.MD5Digest; import org.bouncycastle.crypto.digests.SHA1Digest; @@ -45,6 +44,8 @@ import org.bouncycastle.util.encoders.Base64; import org.jclouds.encryption.internal.BaseEncryptionService; import org.jclouds.util.Utils; +import com.google.common.io.Closeables; + /** * * @author Adrian Cole @@ -104,7 +105,7 @@ public class BouncyCastleEncryptionService extends BaseEncryptionService { } catch (IOException e) { throw new RuntimeException(e); } finally { - IOUtils.closeQuietly(i); + Closeables.closeQuietly(i); } eTag.doFinal(resBuf, 0); return resBuf; @@ -133,8 +134,8 @@ public class BouncyCastleEncryptionService extends BaseEncryptionService { } catch (IOException e) { throw new RuntimeException(e); } finally { - IOUtils.closeQuietly(out); - IOUtils.closeQuietly(toEncode); + Closeables.closeQuietly(out); + Closeables.closeQuietly(toEncode); } eTag.doFinal(resBuf, 0); return new MD5InputStreamResult(out.toByteArray(), resBuf, length); diff --git a/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java b/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java index 949c53d886..56f307dc61 100644 --- a/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java +++ b/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java @@ -36,7 +36,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; import org.jclouds.concurrent.SingleThreaded; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommandExecutorService; @@ -59,6 +58,8 @@ import com.google.appengine.api.urlfetch.HTTPRequest; import com.google.appengine.api.urlfetch.HTTPResponse; import com.google.appengine.api.urlfetch.URLFetchService; import com.google.common.annotations.VisibleForTesting; +import com.google.common.io.ByteStreams; +import com.google.common.io.Closeables; /** * Google App Engine version of {@link HttpCommandExecutorService} @@ -99,9 +100,9 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic } else if (content instanceof InputStreamPayload || content instanceof FilePayload) { InputStream i = content.getContent(); try { - request.setPayload(IOUtils.toByteArray(i)); + request.setPayload(ByteStreams.toByteArray(i)); } finally { - IOUtils.closeQuietly(i); + Closeables.closeQuietly(i); } } else { throw new UnsupportedOperationException("Content not supported " + content.getClass()); diff --git a/extensions/gae/src/test/java/org/jclouds/gae/GaeHttpCommandExecutorServiceTest.java b/extensions/gae/src/test/java/org/jclouds/gae/GaeHttpCommandExecutorServiceTest.java index 62c181b7cc..986c1f496b 100644 --- a/extensions/gae/src/test/java/org/jclouds/gae/GaeHttpCommandExecutorServiceTest.java +++ b/extensions/gae/src/test/java/org/jclouds/gae/GaeHttpCommandExecutorServiceTest.java @@ -30,7 +30,6 @@ import static org.easymock.classextension.EasyMock.replay; import static org.testng.Assert.assertEquals; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; @@ -42,13 +41,13 @@ import java.util.concurrent.ExecutorService; import javax.ws.rs.HttpMethod; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.Payloads; import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.internal.HttpWire; +import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -57,6 +56,8 @@ import com.google.appengine.api.urlfetch.HTTPHeader; import com.google.appengine.api.urlfetch.HTTPRequest; import com.google.appengine.api.urlfetch.HTTPResponse; import com.google.appengine.api.urlfetch.URLFetchService; +import com.google.appengine.repackaged.com.google.common.base.Charsets; +import com.google.common.io.Files; /** * @@ -107,7 +108,7 @@ public class GaeHttpCommandExecutorServiceTest { replay(gaeResponse); HttpResponse response = client.convert(gaeResponse); assertEquals(response.getStatusCode(), 200); - assertEquals(IOUtils.toString(response.getContent()), "hello"); + assertEquals(Utils.toStringAndClose(response.getContent()), "hello"); assertEquals(response.getHeaders().size(), 1); assertEquals(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "text/xml"); } @@ -153,7 +154,7 @@ public class GaeHttpCommandExecutorServiceTest { @Test void testConvertRequestInputStreamContent() throws IOException { HttpRequest request = new HttpRequest(HttpMethod.GET, endPoint); - request.setPayload(IOUtils.toInputStream("hoot!")); + request.setPayload(Utils.toInputStream("hoot!")); testHoot(request); } @@ -177,7 +178,7 @@ public class GaeHttpCommandExecutorServiceTest { HttpRequest request = new HttpRequest(HttpMethod.GET, endPoint); File file = new File(basedir, "target/testfiles/hoot"); file.getParentFile().mkdirs(); - IOUtils.write("hoot!", new FileOutputStream(file)); + Files.write("hoot!".getBytes(Charsets.UTF_8), file); request.setPayload(file); testHoot(request); } diff --git a/extensions/ssh/jsch/pom.xml b/extensions/ssh/jsch/pom.xml index 2bc5fb08e5..5c643aceac 100755 --- a/extensions/ssh/jsch/pom.xml +++ b/extensions/ssh/jsch/pom.xml @@ -41,5 +41,10 @@ jsch 0.1.41 + + commons-io + commons-io + 1.4 + diff --git a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java index 98ce5d8bd7..64ab66aae9 100644 --- a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java +++ b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java @@ -37,7 +37,6 @@ import javax.annotation.PreDestroy; import javax.annotation.Resource; import javax.inject.Inject; -import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.ProxyInputStream; import org.apache.commons.io.output.ByteArrayOutputStream; import org.jclouds.logging.Logger; @@ -46,6 +45,7 @@ import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; import org.jclouds.util.Utils; +import com.google.common.io.Closeables; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSch; @@ -148,7 +148,7 @@ public class JschSshClient implements SshClient { throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host .getHostAddress(), port, path), e); } finally { - IOUtils.closeQuietly(contents); + Closeables.closeQuietly(contents); } } diff --git a/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java b/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java index 91cb6f3ce4..dc8e84fece 100644 --- a/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java +++ b/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java @@ -34,7 +34,6 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; -import org.apache.commons.io.IOUtils; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.jsch.config.JschSshClientModule; @@ -78,9 +77,9 @@ public class JschSshClientLiveTest { public InputStream get(String path) { if (path.equals("/etc/passwd")) { - return IOUtils.toInputStream("root"); + return Utils.toInputStream("root"); } else if (path.equals(temp.getAbsolutePath())) { - return IOUtils.toInputStream("rabbit"); + return Utils.toInputStream("rabbit"); } throw new RuntimeException("path " + path + " not stubbed"); } @@ -121,7 +120,7 @@ public class JschSshClientLiveTest { temp = File.createTempFile("foo", "bar"); temp.deleteOnExit(); SshClient client = setupClient(); - client.put(temp.getAbsolutePath(), IOUtils.toInputStream("rabbit")); + client.put(temp.getAbsolutePath(), Utils.toInputStream("rabbit")); InputStream input = setupClient().get(temp.getAbsolutePath()); String contents = Utils.toStringAndClose(input); assertEquals(contents, "rabbit"); diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSClientLiveTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSClientLiveTest.java index 03db5c336e..0b8b1969d7 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSClientLiveTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSClientLiveTest.java @@ -38,7 +38,6 @@ import java.util.concurrent.TimeoutException; import javax.ws.rs.core.UriBuilder; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.ResourceType; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; @@ -48,6 +47,7 @@ import org.jclouds.mezeo.pcs2.domain.ContainerList; import org.jclouds.mezeo.pcs2.domain.FileInfoWithMetadata; import org.jclouds.mezeo.pcs2.domain.PCSFile; import org.jclouds.mezeo.pcs2.domain.ResourceInfo; +import org.jclouds.util.Utils; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -178,7 +178,7 @@ public class PCSClientLiveTest { } // Test GET of object (including updated metadata) InputStream file = connection.downloadFile(objectURI); - assertEquals(IOUtils.toString(file), data); + assertEquals(Utils.toStringAndClose(file), data); validateFileInfoAndNameIsInMetadata(container, objectURI, "object", new Long(data.length())); try { @@ -210,7 +210,7 @@ public class PCSClientLiveTest { validateFileInfoAndNameIsInMetadata(container, objectURI, name, new Long(data.length())); file = connection.downloadFile(objectURI); - assertEquals(IOUtils.toString(file), data); + assertEquals(Utils.toStringAndClose(file), data); // change data in an existing file data = "Here is my datum"; @@ -219,7 +219,7 @@ public class PCSClientLiveTest { validateFileInfoAndNameIsInMetadata(container, objectURI, name, new Long(data.length())); file = connection.downloadFile(objectURI); - assertEquals(IOUtils.toString(file), data); + assertEquals(Utils.toStringAndClose(file), data); connection.deleteFile(objectURI); connection.deleteContainer(container); diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/functions/AddMetadataAndReturnIdTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/functions/AddMetadataAndReturnIdTest.java index 55757c8b61..23ef47d238 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/functions/AddMetadataAndReturnIdTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/functions/AddMetadataAndReturnIdTest.java @@ -83,7 +83,7 @@ public class AddMetadataAndReturnIdTest { // AddMetadataAndReturnId function = new AddMetadataAndReturnId(fileCache, connection); // function.setContext(factory.createRequest(method, "container", new PCSFile("key"), URI // .create("http://localhost:8080"))); -// response.setContent(IOUtils +// response.setContent(Utils // .toInputStream("http://localhost/contents/7F143552-AAF5-11DE-BBB0-0BC388ED913B")); // String eTag = function.apply(response); // assertEquals(eTag, "7F143552-AAF5-11DE-BBB0-0BC388ED913B"); @@ -98,7 +98,7 @@ public class AddMetadataAndReturnIdTest { // // function.setContext(factory.createRequest(method, "container", pcsFile, URI // .create("http://localhost:8080"))); -// response.setContent(IOUtils +// response.setContent(Utils // .toInputStream("http://localhost/contents/7F143552-AAF5-11DE-BBB0-0BC388ED913B")); // String eTag = function.apply(response); // assertEquals(eTag, "7F143552-AAF5-11DE-BBB0-0BC388ED913B"); diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesClientLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesClientLiveTest.java index 0dba2dd378..9c8fdae906 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesClientLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesClientLiveTest.java @@ -37,7 +37,6 @@ import java.util.SortedSet; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.ListResponse; @@ -54,6 +53,7 @@ import org.jclouds.rackspace.cloudfiles.domain.MutableObjectInfoWithMetadata; import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo; import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions; import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions; +import org.jclouds.util.Utils; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -345,7 +345,7 @@ public class CloudFilesClientLiveTest extends } // Test GET of object (including updated metadata) CFObject getBlob = context.getApi().getObject(containerName, object.getInfo().getName()); - assertEquals(IOUtils.toString(getBlob.getContent()), data); + assertEquals(Utils.toStringAndClose(getBlob.getContent()), data); // TODO assertEquals(getBlob.getName(), object.getMetadata().getName()); assertEquals(getBlob.getContentLength(), new Long(data.length())); assertEquals(getBlob.getInfo().getContentType(), "text/plain"); @@ -390,7 +390,7 @@ public class CloudFilesClientLiveTest extends assertEquals(getBlob.getInfo().getHash(), encryptionService.fromHexString(newEtag)); getBlob = context.getApi().getObject(containerName, object.getInfo().getName(), GetOptions.Builder.startAt(8)); - assertEquals(IOUtils.toString(getBlob.getContent()), data.substring(8)); + assertEquals(Utils.toStringAndClose(getBlob.getContent()), data.substring(8)); } finally { returnContainer(containerName); diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/binders/BindCFObjectToPayloadTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/binders/BindCFObjectToPayloadTest.java index 9d309409cd..b268dc8ffd 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/binders/BindCFObjectToPayloadTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/binders/BindCFObjectToPayloadTest.java @@ -31,7 +31,6 @@ import java.net.URI; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob.Factory; import org.jclouds.http.HttpRequest; @@ -39,6 +38,7 @@ import org.jclouds.rackspace.cloudfiles.CloudFilesContextBuilder; import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder; import org.jclouds.rackspace.cloudfiles.blobstore.functions.BlobToObject; import org.jclouds.rackspace.cloudfiles.domain.CFObject; +import org.jclouds.util.Utils; import org.testng.annotations.Test; import com.google.inject.Injector; @@ -84,7 +84,7 @@ public class BindCFObjectToPayloadTest { HttpRequest request = new HttpRequest("GET", URI.create("http://localhost:8001")); binder.bindToRequest(request, testBlob()); - assertEquals(IOUtils.toString(request.getPayload().getContent()), "hello"); + assertEquals(Utils.toStringAndClose(request.getPayload().getContent()), "hello"); assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), 5 + ""); assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), MediaType.TEXT_PLAIN); } @@ -98,7 +98,7 @@ public class BindCFObjectToPayloadTest { HttpRequest request = new HttpRequest("GET", URI.create("http://localhost:8001")); binder.bindToRequest(request, blob); - assertEquals(IOUtils.toString(request.getPayload().getContent()), "hello"); + assertEquals(Utils.toStringAndClose(request.getPayload().getContent()), "hello"); assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), 5 + ""); assertEquals(request.getFirstHeaderOrNull(HttpHeaders.ETAG), "5d41402abc4b2a76b9719d911017c592"); diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponseTest.java index de7fe2721d..d10e301543 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponseTest.java @@ -28,9 +28,9 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.List; -import org.apache.commons.io.IOUtils; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata; +import org.jclouds.util.Utils; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; @@ -49,7 +49,7 @@ public class ParseContainerListFromJsonResponseTest { @Test public void testApplyInputStream() { - InputStream is = IOUtils + InputStream is = Utils .toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] "); List expects = ImmutableList.of(new ContainerMetadata("test_container_1", diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseBackupScheduleFromJsonResponseTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseBackupScheduleFromJsonResponseTest.java index 19ac94f4c5..f6587d01d9 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseBackupScheduleFromJsonResponseTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/functions/ParseBackupScheduleFromJsonResponseTest.java @@ -28,11 +28,11 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.UnknownHostException; -import org.apache.commons.io.IOUtils; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rackspace.cloudservers.domain.BackupSchedule; import org.jclouds.rackspace.cloudservers.domain.DailyBackup; import org.jclouds.rackspace.cloudservers.domain.WeeklyBackup; +import org.jclouds.util.Utils; import org.testng.annotations.Test; import com.google.gson.Gson; @@ -63,7 +63,7 @@ public class ParseBackupScheduleFromJsonResponseTest { ParseBackupScheduleFromJsonResponse parser = new ParseBackupScheduleFromJsonResponse(i .getInstance(Gson.class)); - BackupSchedule response = parser.apply(IOUtils + BackupSchedule response = parser.apply(Utils .toInputStream("{\"backupSchedule\":{\"enabled\" : false}}")); assertEquals(new BackupSchedule(), response); } diff --git a/tools/getpath/src/main/java/org/jclouds/blobstore/GetPath.java b/tools/getpath/src/main/java/org/jclouds/blobstore/GetPath.java index 89294565a9..6587b1a6d8 100755 --- a/tools/getpath/src/main/java/org/jclouds/blobstore/GetPath.java +++ b/tools/getpath/src/main/java/org/jclouds/blobstore/GetPath.java @@ -36,10 +36,11 @@ import java.net.URI; import java.util.Properties; import java.util.Map.Entry; -import org.apache.commons.io.IOUtils; import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.http.HttpUtils; +import com.google.common.io.ByteStreams; +import com.google.common.io.Closeables; import com.google.common.io.Resources; /** @@ -96,14 +97,14 @@ public class GetPath { input = entry.getValue(); File file = new File(destinationDir, entry.getKey()); OutputStream out = new FileOutputStream(file); - IOUtils.copyLarge(input, out); + ByteStreams.copy(input, out); out.flush(); out.close(); } } finally { // Close connecton - IOUtils.closeQuietly(input); + Closeables.closeQuietly(input); } } diff --git a/tools/vfs/src/test/java/org/jclouds/vfs/provider/blobstore/test/BlobStoreProviderTestCase.java b/tools/vfs/src/test/java/org/jclouds/vfs/provider/blobstore/test/BlobStoreProviderTestCase.java index a178bcbd1c..b387c53629 100644 --- a/tools/vfs/src/test/java/org/jclouds/vfs/provider/blobstore/test/BlobStoreProviderTestCase.java +++ b/tools/vfs/src/test/java/org/jclouds/vfs/provider/blobstore/test/BlobStoreProviderTestCase.java @@ -27,7 +27,6 @@ import java.io.IOException; import junit.framework.Test; -import org.apache.commons.io.IOUtils; import org.apache.commons.vfs.AllFileSelector; import org.apache.commons.vfs.FileContent; import org.apache.commons.vfs.FileObject; @@ -37,10 +36,13 @@ import org.apache.commons.vfs.impl.DefaultFileSystemManager; import org.apache.commons.vfs.test.AbstractProviderTestConfig; import org.jclouds.blobstore.BlobStore; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.util.Utils; import org.jclouds.vfs.provider.blobstore.BlobStoreFileObject; import org.jclouds.vfs.provider.blobstore.BlobStoreFileProvider; +import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; +import com.google.common.io.CharStreams; import com.google.inject.Module; /** @@ -111,7 +113,8 @@ public class BlobStoreProviderTestCase extends AbstractProviderTestConfig { IOException { FileObject file = base.resolveFile(name); FileContent content = file.getContent(); - IOUtils.write(value, content.getOutputStream()); + CharStreams.write(value, CharStreams.newWriterSupplier(Utils.newOutputStreamSupplier(content + .getOutputStream()), Charsets.UTF_8)); content.close(); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index 8467cd5c70..aac5ece888 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -41,7 +41,6 @@ import javax.inject.Named; import javax.inject.Singleton; import javax.ws.rs.core.HttpHeaders; -import org.apache.commons.io.IOUtils; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; @@ -93,7 +92,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { }); public void testApplyInputStream1() throws IOException { - String expected = IOUtils.toString(getClass().getResourceAsStream( + String expected = Utils.toStringAndClose(getClass().getResourceAsStream( "/newvapp-hosting.xml")); Multimap headers = Multimaps .synchronizedMultimap(HashMultimap. create()); @@ -125,7 +124,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { } public void testApplyInputStream2() throws IOException { - String expected = IOUtils.toString(getClass().getResourceAsStream( + String expected = Utils.toStringAndClose(getClass().getResourceAsStream( "/newvapp-hosting.xml")); Multimap headers = Multimaps .synchronizedMultimap(HashMultimap. create()); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java index 35673d2c15..c10eabf75c 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java @@ -43,7 +43,6 @@ import javax.inject.Named; import javax.inject.Provider; import javax.inject.Singleton; -import org.apache.commons.io.IOUtils; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.logging.Logger; @@ -115,7 +114,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest headers = Multimaps .synchronizedMultimap(HashMultimap. create()); @@ -135,7 +134,7 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest { public void testApplyInputStream2() throws IOException { - String expected = IOUtils.toString(getClass().getResourceAsStream( + String expected = Utils.toStringAndClose(getClass().getResourceAsStream( "/terremark/InstantiateVAppTemplateParams-test-2.xml")); Multimap headers = Multimaps .synchronizedMultimap(HashMultimap. create()); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java index 24f1b8bd89..145cfa0782 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java @@ -121,7 +121,7 @@ public class TerremarkVCloudComputeClientLiveTest { // bug creating more than one internet service returns 503 or 500 // InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22, // 80, - // 8080); + // 8080); InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22); assert addressTester.apply(publicIp); // client.exec(publicIp, "uname -a");