diff --git a/core/src/main/java/org/jclouds/io/Payload.java b/core/src/main/java/org/jclouds/io/Payload.java index 30d767152b..6d08ce7e23 100644 --- a/core/src/main/java/org/jclouds/io/Payload.java +++ b/core/src/main/java/org/jclouds/io/Payload.java @@ -18,6 +18,7 @@ package org.jclouds.io; import java.io.Closeable; import java.io.InputStream; +import java.io.IOException; import com.google.common.io.InputSupplier; @@ -29,6 +30,14 @@ public interface Payload extends InputSupplier, WriteTo, Closeable /** * Creates a new InputStream object of the payload. */ + InputStream openStream() throws IOException; + + /** + * Creates a new InputStream object of the payload. + * + * @deprecated see openStream + */ + @Deprecated InputStream getInput(); /** diff --git a/core/src/main/java/org/jclouds/io/payloads/BaseCipherPayload.java b/core/src/main/java/org/jclouds/io/payloads/BaseCipherPayload.java index d802cec08e..b1bd930c01 100644 --- a/core/src/main/java/org/jclouds/io/payloads/BaseCipherPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/BaseCipherPayload.java @@ -44,7 +44,7 @@ public abstract class BaseCipherPayload extends DelegatingPayload { public abstract Cipher initializeCipher(Key key); @Override - public CipherInputStream getInput() { + public CipherInputStream openStream() { return new CipherInputStream(super.getInput(), initializeCipher(key)); } diff --git a/core/src/main/java/org/jclouds/io/payloads/BasePayload.java b/core/src/main/java/org/jclouds/io/payloads/BasePayload.java index dff38205a1..6fdd8e51ed 100644 --- a/core/src/main/java/org/jclouds/io/payloads/BasePayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/BasePayload.java @@ -25,6 +25,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import com.google.common.base.Throwables; + import org.jclouds.io.MutableContentMetadata; import org.jclouds.io.Payload; @@ -45,6 +47,15 @@ public abstract class BasePayload implements Payload { this.contentMetadata = checkNotNull(contentMetadata, "contentMetadata"); } + @Override + public InputStream getInput() { + try { + return openStream(); + } catch (IOException ioe) { + throw Throwables.propagate(ioe); + } + } + /** * {@inheritDoc} */ diff --git a/core/src/main/java/org/jclouds/io/payloads/ByteArrayPayload.java b/core/src/main/java/org/jclouds/io/payloads/ByteArrayPayload.java index 539fcde4b5..68aeaf78e9 100644 --- a/core/src/main/java/org/jclouds/io/payloads/ByteArrayPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/ByteArrayPayload.java @@ -41,7 +41,7 @@ public class ByteArrayPayload extends BasePayload { * {@inheritDoc} */ @Override - public InputStream getInput() { + public InputStream openStream() { return new ByteArrayInputStream(content); } diff --git a/core/src/main/java/org/jclouds/io/payloads/DelegatingPayload.java b/core/src/main/java/org/jclouds/io/payloads/DelegatingPayload.java index ef5cc9dedd..452441110b 100644 --- a/core/src/main/java/org/jclouds/io/payloads/DelegatingPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/DelegatingPayload.java @@ -37,6 +37,14 @@ public class DelegatingPayload implements Payload { this.delegate = checkNotNull(delegate, "delegate"); } + /** + * {@inheritDoc} + */ + @Override + public InputStream openStream() throws IOException { + return delegate.openStream(); + } + /** * {@inheritDoc} */ diff --git a/core/src/main/java/org/jclouds/io/payloads/FilePayload.java b/core/src/main/java/org/jclouds/io/payloads/FilePayload.java index 338a6e7a58..430f5d8529 100644 --- a/core/src/main/java/org/jclouds/io/payloads/FilePayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/FilePayload.java @@ -20,10 +20,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.InputStream; +import java.io.IOException; -import com.google.common.base.Throwables; /** * @author Adrian Cole @@ -40,12 +39,8 @@ public class FilePayload extends BasePayload { * {@inheritDoc} */ @Override - public InputStream getInput() { - try { - return new FileInputStream(content); - } catch (FileNotFoundException e) { - throw Throwables.propagate(e); - } + public InputStream openStream() throws IOException { + return new FileInputStream(content); } } diff --git a/core/src/main/java/org/jclouds/io/payloads/InputStreamPayload.java b/core/src/main/java/org/jclouds/io/payloads/InputStreamPayload.java index 450a6cbb90..22a17521fa 100644 --- a/core/src/main/java/org/jclouds/io/payloads/InputStreamPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/InputStreamPayload.java @@ -33,7 +33,7 @@ public class InputStreamPayload extends BasePayload { * {@inheritDoc} */ @Override - public InputStream getInput() { + public InputStream openStream() { return content; } diff --git a/core/src/main/java/org/jclouds/io/payloads/InputStreamSupplierPayload.java b/core/src/main/java/org/jclouds/io/payloads/InputStreamSupplierPayload.java index bd94cd3d4e..54f0123be7 100644 --- a/core/src/main/java/org/jclouds/io/payloads/InputStreamSupplierPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/InputStreamSupplierPayload.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; -import com.google.common.base.Throwables; import com.google.common.collect.Lists; import com.google.common.io.InputSupplier; @@ -40,14 +39,10 @@ public class InputStreamSupplierPayload extends BasePayload> { } @Override - public InputStream getInput() { - try { - return chain.getInput(); - } catch (IOException e) { - propagate(e); - return null; - } + public InputStream openStream() throws IOException { + return chain.getInput(); } @Override diff --git a/core/src/main/java/org/jclouds/io/payloads/PhantomPayload.java b/core/src/main/java/org/jclouds/io/payloads/PhantomPayload.java index 2824d5322b..4023ee1083 100644 --- a/core/src/main/java/org/jclouds/io/payloads/PhantomPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/PhantomPayload.java @@ -46,7 +46,7 @@ public class PhantomPayload extends BasePayload { * {@inheritDoc} */ @Override - public InputStream getInput() { + public InputStream openStream() { throw new UnsupportedOperationException(); } diff --git a/core/src/main/java/org/jclouds/io/payloads/StreamingPayload.java b/core/src/main/java/org/jclouds/io/payloads/StreamingPayload.java index ef34b69b66..2343091288 100644 --- a/core/src/main/java/org/jclouds/io/payloads/StreamingPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/StreamingPayload.java @@ -56,6 +56,15 @@ public class StreamingPayload implements Payload { throw new UnsupportedOperationException("this payload is for streaming writes only"); } + /** + * @throws UnsupportedOperationException + * this payload is for streaming writes only + */ + @Override + public InputStream openStream() { + throw new UnsupportedOperationException("this payload is for streaming writes only"); + } + /** * @throws UnsupportedOperationException * this payload is for streaming writes only diff --git a/core/src/main/java/org/jclouds/io/payloads/StringPayload.java b/core/src/main/java/org/jclouds/io/payloads/StringPayload.java index da1566f8cf..2452a944b9 100644 --- a/core/src/main/java/org/jclouds/io/payloads/StringPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/StringPayload.java @@ -43,7 +43,7 @@ public class StringPayload extends BasePayload { * {@inheritDoc} */ @Override - public InputStream getInput() { + public InputStream openStream() { return new ByteArrayInputStream(bytes); } diff --git a/core/src/main/java/org/jclouds/io/payloads/UrlEncodedFormPayload.java b/core/src/main/java/org/jclouds/io/payloads/UrlEncodedFormPayload.java index 8cbfccae01..fa906dfe2b 100644 --- a/core/src/main/java/org/jclouds/io/payloads/UrlEncodedFormPayload.java +++ b/core/src/main/java/org/jclouds/io/payloads/UrlEncodedFormPayload.java @@ -37,7 +37,7 @@ public class UrlEncodedFormPayload extends BasePayload { * {@inheritDoc} */ @Override - public InputStream getInput() { + public InputStream openStream() { return toInputStream(content); } diff --git a/drivers/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java b/drivers/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java index 5d86df6fe4..47d790318d 100644 --- a/drivers/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java +++ b/drivers/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java @@ -178,15 +178,12 @@ public class ApacheHCUtils { } @Override - public InputStream getInput() { + public InputStream openStream() throws IOException { try { return content.getContent(); } catch (IllegalStateException e) { - Throwables.propagate(e); - } catch (IOException e) { - Throwables.propagate(e); + throw Throwables.propagate(e); } - return null; } @Override