Repository: jclouds Updated Branches: refs/heads/master b432acd83 -> 66dab8d96
JCLOUDS-410: Remove InputStreamSupplierPayload ByteSourcePayload replaces this. jclouds 1.7 deprecated InputStreamSupplierPayload and Guava 16 deprecated InputSupplier itself. Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/66dab8d9 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/66dab8d9 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/66dab8d9 Branch: refs/heads/master Commit: 66dab8d96e323c0cbcbbfcb11753e79a91e807b0 Parents: b432acd Author: Andrew Gaul <[email protected]> Authored: Sun Mar 2 22:19:03 2014 -0800 Committer: Andrew Gaul <[email protected]> Committed: Thu Jul 10 20:43:08 2014 -0700 ---------------------------------------------------------------------- .../internal/BaseBlobIntegrationTest.java | 13 ++--- .../main/java/org/jclouds/io/ByteStreams2.java | 40 +++++++++++++ .../jclouds/io/internal/BasePayloadSlicer.java | 11 ++-- .../io/payloads/InputStreamSupplierPayload.java | 61 -------------------- 4 files changed, 52 insertions(+), 73 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/66dab8d9/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java ---------------------------------------------------------------------- diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java index 2a65d03..bf067e4 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java @@ -62,7 +62,6 @@ import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.io.payloads.ByteSourcePayload; -import org.jclouds.io.payloads.InputStreamSupplierPayload; import org.jclouds.logging.Logger; import org.testng.ITestContext; import org.testng.annotations.BeforeClass; @@ -182,7 +181,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest { try { final String name = "constitution.txt"; - uploadInputSupplier(container, name, expectedContentDisposition, supplier); + uploadByteSource(container, name, expectedContentDisposition, supplier); Map<Integer, ListenableFuture<?>> responses = Maps.newHashMap(); for (int i = 0; i < 10; i++) { @@ -215,14 +214,14 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest { } - private void uploadInputSupplier(String container, String name, String contentDisposition, - ByteSource supplier) throws IOException { + private void uploadByteSource(String container, String name, String contentDisposition, + ByteSource byteSource) throws IOException { BlobStore blobStore = view.getBlobStore(); blobStore.putBlob(container, blobStore.blobBuilder(name) - .payload(new InputStreamSupplierPayload(supplier)) + .payload(new ByteSourcePayload(byteSource)) .contentType("text/plain") - .contentMD5(supplier.hash(md5())) - .contentLength(supplier.size()) + .contentMD5(byteSource.hash(md5())) + .contentLength(byteSource.size()) .contentDisposition(contentDisposition) .build()); } http://git-wip-us.apache.org/repos/asf/jclouds/blob/66dab8d9/core/src/main/java/org/jclouds/io/ByteStreams2.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/io/ByteStreams2.java b/core/src/main/java/org/jclouds/io/ByteStreams2.java new file mode 100644 index 0000000..be3a67f --- /dev/null +++ b/core/src/main/java/org/jclouds/io/ByteStreams2.java @@ -0,0 +1,40 @@ +/* + * 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 static com.google.common.base.Preconditions.checkNotNull; + +import java.io.IOException; +import java.io.InputStream; +import com.google.common.annotations.Beta; +import com.google.common.io.ByteSource; +import com.google.common.io.InputSupplier; + +@Beta +public class ByteStreams2 { + @Deprecated + public static ByteSource asByteSource(final InputSupplier<? extends InputStream> supplier) { + checkNotNull(supplier, "supplier"); + return new ByteSource() { + @Override + public InputStream openStream() throws IOException { + return supplier.getInput(); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/66dab8d9/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java b/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java index e2ecb43..632ef82 100644 --- a/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java +++ b/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java @@ -31,6 +31,7 @@ import java.util.NoSuchElementException; import javax.inject.Singleton; +import org.jclouds.io.ByteStreams2; import org.jclouds.io.ContentMetadata; import org.jclouds.io.Payload; import org.jclouds.io.PayloadSlicer; @@ -38,7 +39,6 @@ import org.jclouds.io.payloads.BaseMutableContentMetadata; import org.jclouds.io.payloads.ByteArrayPayload; import org.jclouds.io.payloads.ByteSourcePayload; import org.jclouds.io.payloads.InputStreamPayload; -import org.jclouds.io.payloads.InputStreamSupplierPayload; import com.google.common.base.Charsets; import com.google.common.base.Throwables; @@ -157,7 +157,7 @@ public class BasePayloadSlicer implements PayloadSlicer { } protected Payload doSlice(Payload content, long offset, long length) { - return doSlice((InputSupplier<? extends InputStream>) content, offset, length); + return doSlice(ByteStreams2.asByteSource(content), offset, length); } protected Payload doSlice(String content, long offset, long length) { @@ -181,16 +181,17 @@ public class BasePayloadSlicer implements PayloadSlicer { return new ByteSourcePayload(content.slice(offset, length)); } + /** @deprecated use doSlice(ByteSource) instead */ + @Deprecated protected Payload doSlice(InputSupplier<? extends InputStream> content, long offset, long length) { - return new InputStreamSupplierPayload(ByteStreams.slice(content, offset, length)); + return doSlice(ByteStreams2.asByteSource(content), offset, length); } protected Payload doSlice(byte[] content, long offset, long length) { Payload returnVal; checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array"); checkArgument(length <= Integer.MAX_VALUE, "length is too big for an array"); - returnVal = new InputStreamSupplierPayload( - ByteSource.wrap(content).slice(offset, length)); + returnVal = new ByteSourcePayload(ByteSource.wrap(content).slice(offset, length)); return returnVal; } http://git-wip-us.apache.org/repos/asf/jclouds/blob/66dab8d9/core/src/main/java/org/jclouds/io/payloads/InputStreamSupplierPayload.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/io/payloads/InputStreamSupplierPayload.java b/core/src/main/java/org/jclouds/io/payloads/InputStreamSupplierPayload.java deleted file mode 100644 index 8b2f81f..0000000 --- a/core/src/main/java/org/jclouds/io/payloads/InputStreamSupplierPayload.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.payloads; - -import static org.jclouds.util.Closeables2.closeQuietly; - -import java.io.IOException; -import java.io.InputStream; - -import com.google.common.io.Closer; -import com.google.common.io.InputSupplier; - -/** - * @deprecated see ByteSourcePayload - */ -@Deprecated -public class InputStreamSupplierPayload extends BasePayload<InputSupplier<? extends InputStream>> { - private final Closer closer = Closer.create(); - - public InputStreamSupplierPayload(InputSupplier<? extends InputStream> content) { - super(content); - } - - /** - * {@inheritDoc} - */ - @Override - public InputStream openStream() throws IOException { - return closer.register(content.getInput()); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isRepeatable() { - return true; - } - - /** - * if we created the stream, then it is already consumed on close. - */ - @Override - public void release() { - closeQuietly(closer); - } -}
