JCLOUDS-410. Deprecate Payload.getInput

We plan to transition Payload to ByteSource in the next major release.
Unfortunately Payload.getInput masks its checked exception and
ByteSource.getInput is final so we cannot continue to mask the
exceptions.  Deprecation of getInput and addition openStream allows us
to transition callers from the former to the latter.
This commit is contained in:
Andrew Gaul 2013-12-16 11:21:32 -08:00
parent 6d9784c4b5
commit f3dcd3fe86
14 changed files with 54 additions and 36 deletions

View File

@ -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<InputStream>, 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();
/**

View File

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

View File

@ -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<V> implements Payload {
this.contentMetadata = checkNotNull(contentMetadata, "contentMetadata");
}
@Override
public InputStream getInput() {
try {
return openStream();
} catch (IOException ioe) {
throw Throwables.propagate(ioe);
}
}
/**
* {@inheritDoc}
*/

View File

@ -41,7 +41,7 @@ public class ByteArrayPayload extends BasePayload<byte[]> {
* {@inheritDoc}
*/
@Override
public InputStream getInput() {
public InputStream openStream() {
return new ByteArrayInputStream(content);
}

View File

@ -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}
*/

View File

@ -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<File> {
* {@inheritDoc}
*/
@Override
public InputStream getInput() {
try {
public InputStream openStream() throws IOException {
return new FileInputStream(content);
} catch (FileNotFoundException e) {
throw Throwables.propagate(e);
}
}
}

View File

@ -33,7 +33,7 @@ public class InputStreamPayload extends BasePayload<InputStream> {
* {@inheritDoc}
*/
@Override
public InputStream getInput() {
public InputStream openStream() {
return content;
}

View File

@ -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<InputSupplier<? exte
* {@inheritDoc}
*/
@Override
public InputStream getInput() {
try {
public InputStream openStream() throws IOException {
InputStream returnVal = content.getInput();
toClose.add(returnVal);
return returnVal;
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
/**

View File

@ -16,7 +16,6 @@
*/
package org.jclouds.io.payloads;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.io.ByteStreams.join;
import static com.google.common.io.ByteStreams.newInputStreamSupplier;
@ -89,13 +88,8 @@ public class MultipartForm extends BasePayload<Iterable<? extends Part>> {
}
@Override
public InputStream getInput() {
try {
public InputStream openStream() throws IOException {
return chain.getInput();
} catch (IOException e) {
propagate(e);
return null;
}
}
@Override

View File

@ -46,7 +46,7 @@ public class PhantomPayload extends BasePayload<Object> {
* {@inheritDoc}
*/
@Override
public InputStream getInput() {
public InputStream openStream() {
throw new UnsupportedOperationException();
}

View File

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

View File

@ -43,7 +43,7 @@ public class StringPayload extends BasePayload<String> {
* {@inheritDoc}
*/
@Override
public InputStream getInput() {
public InputStream openStream() {
return new ByteArrayInputStream(bytes);
}

View File

@ -37,7 +37,7 @@ public class UrlEncodedFormPayload extends BasePayload<String> {
* {@inheritDoc}
*/
@Override
public InputStream getInput() {
public InputStream openStream() {
return toInputStream(content);
}

View File

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