JCLOUDS-410: Remove InputStreamSupplierPayload

ByteSourcePayload replaces this.  jclouds 1.7 deprecated
InputStreamSupplierPayload and Guava 16 deprecated InputSupplier
itself.
This commit is contained in:
Andrew Gaul 2014-03-02 22:19:03 -08:00
parent b432acd834
commit 66dab8d96e
3 changed files with 28 additions and 49 deletions

View File

@ -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());
}

View File

@ -14,48 +14,27 @@
* 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;
package org.jclouds.io;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.IOException;
import java.io.InputStream;
import com.google.common.io.Closer;
import com.google.common.annotations.Beta;
import com.google.common.io.ByteSource;
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);
@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();
}
};
}
}

View File

@ -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;
}