mirror of
https://github.com/apache/jclouds.git
synced 2025-02-09 03:25:39 +00:00
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:
parent
6d9784c4b5
commit
f3dcd3fe86
@ -18,6 +18,7 @@ package org.jclouds.io;
|
|||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.google.common.io.InputSupplier;
|
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.
|
* 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();
|
InputStream getInput();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +44,7 @@ public abstract class BaseCipherPayload extends DelegatingPayload {
|
|||||||
public abstract Cipher initializeCipher(Key key);
|
public abstract Cipher initializeCipher(Key key);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CipherInputStream getInput() {
|
public CipherInputStream openStream() {
|
||||||
return new CipherInputStream(super.getInput(), initializeCipher(key));
|
return new CipherInputStream(super.getInput(), initializeCipher(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
|
||||||
import org.jclouds.io.MutableContentMetadata;
|
import org.jclouds.io.MutableContentMetadata;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
|
|
||||||
@ -45,6 +47,15 @@ public abstract class BasePayload<V> implements Payload {
|
|||||||
this.contentMetadata = checkNotNull(contentMetadata, "contentMetadata");
|
this.contentMetadata = checkNotNull(contentMetadata, "contentMetadata");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getInput() {
|
||||||
|
try {
|
||||||
|
return openStream();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw Throwables.propagate(ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -41,7 +41,7 @@ public class ByteArrayPayload extends BasePayload<byte[]> {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() {
|
||||||
return new ByteArrayInputStream(content);
|
return new ByteArrayInputStream(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,14 @@ public class DelegatingPayload implements Payload {
|
|||||||
this.delegate = checkNotNull(delegate, "delegate");
|
this.delegate = checkNotNull(delegate, "delegate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public InputStream openStream() throws IOException {
|
||||||
|
return delegate.openStream();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -20,10 +20,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
@ -40,12 +39,8 @@ public class FilePayload extends BasePayload<File> {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() throws IOException {
|
||||||
try {
|
|
||||||
return new FileInputStream(content);
|
return new FileInputStream(content);
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class InputStreamPayload extends BasePayload<InputStream> {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.io.InputSupplier;
|
import com.google.common.io.InputSupplier;
|
||||||
|
|
||||||
@ -40,14 +39,10 @@ public class InputStreamSupplierPayload extends BasePayload<InputSupplier<? exte
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() throws IOException {
|
||||||
try {
|
|
||||||
InputStream returnVal = content.getInput();
|
InputStream returnVal = content.getInput();
|
||||||
toClose.add(returnVal);
|
toClose.add(returnVal);
|
||||||
return returnVal;
|
return returnVal;
|
||||||
} catch (IOException e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.io.payloads;
|
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.collect.Lists.newArrayList;
|
||||||
import static com.google.common.io.ByteStreams.join;
|
import static com.google.common.io.ByteStreams.join;
|
||||||
import static com.google.common.io.ByteStreams.newInputStreamSupplier;
|
import static com.google.common.io.ByteStreams.newInputStreamSupplier;
|
||||||
@ -89,13 +88,8 @@ public class MultipartForm extends BasePayload<Iterable<? extends Part>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() throws IOException {
|
||||||
try {
|
|
||||||
return chain.getInput();
|
return chain.getInput();
|
||||||
} catch (IOException e) {
|
|
||||||
propagate(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,7 +46,7 @@ public class PhantomPayload extends BasePayload<Object> {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,15 @@ public class StreamingPayload implements Payload {
|
|||||||
throw new UnsupportedOperationException("this payload is for streaming writes only");
|
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
|
* @throws UnsupportedOperationException
|
||||||
* this payload is for streaming writes only
|
* this payload is for streaming writes only
|
||||||
|
@ -43,7 +43,7 @@ public class StringPayload extends BasePayload<String> {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() {
|
||||||
return new ByteArrayInputStream(bytes);
|
return new ByteArrayInputStream(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class UrlEncodedFormPayload extends BasePayload<String> {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() {
|
||||||
return toInputStream(content);
|
return toInputStream(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,15 +178,12 @@ public class ApacheHCUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() {
|
public InputStream openStream() throws IOException {
|
||||||
try {
|
try {
|
||||||
return content.getContent();
|
return content.getContent();
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
} catch (IOException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user