mirror of https://github.com/apache/jclouds.git
JCLOUDS-410: Remove StreamingPayload
Only two tests use this class. Callers should use ByteSourcePayload or InputStreamPayload instead.
This commit is contained in:
parent
f5c9a72243
commit
9a1aae8cfc
|
@ -49,7 +49,7 @@ See http://code.google.com/p/jclouds for details."
|
||||||
domain.Blob domain.internal.BlobBuilderImpl options.PutOptions
|
domain.Blob domain.internal.BlobBuilderImpl options.PutOptions
|
||||||
options.PutOptions$Builder
|
options.PutOptions$Builder
|
||||||
options.CreateContainerOptions options.ListContainerOptions]
|
options.CreateContainerOptions options.ListContainerOptions]
|
||||||
[org.jclouds.io Payload Payloads payloads.StreamingPayload]
|
[org.jclouds.io Payload Payloads]
|
||||||
java.util.Arrays
|
java.util.Arrays
|
||||||
[java.security DigestOutputStream MessageDigest]
|
[java.security DigestOutputStream MessageDigest]
|
||||||
com.google.common.collect.ImmutableSet
|
com.google.common.collect.ImmutableSet
|
||||||
|
@ -74,14 +74,7 @@ See http://code.google.com/p/jclouds for details."
|
||||||
java.io.File
|
java.io.File
|
||||||
(payload [f] (Payloads/newFilePayload f))
|
(payload [f] (Payloads/newFilePayload f))
|
||||||
ByteSource
|
ByteSource
|
||||||
(payload [bs] (Payloads/newByteSourcePayload bs))
|
(payload [bs] (Payloads/newByteSourcePayload bs)))
|
||||||
clojure.lang.IFn
|
|
||||||
;; This will let you pass a closure to payload that takes an OutputStream
|
|
||||||
;; as argument and writes to it when called from a StreamingPayload.
|
|
||||||
(payload [func]
|
|
||||||
(StreamingPayload. (reify org.jclouds.io.WriteTo
|
|
||||||
(writeTo [this output-stream]
|
|
||||||
(func output-stream))))))
|
|
||||||
|
|
||||||
;; something in clojure 1.3 (namespaces?) does not like a private type called byte-array-type,
|
;; something in clojure 1.3 (namespaces?) does not like a private type called byte-array-type,
|
||||||
;; so we refer to (class (make-array ...)) directly; and it only parses if it is its own block,
|
;; so we refer to (class (make-array ...)) directly; and it only parses if it is its own block,
|
||||||
|
|
|
@ -186,7 +186,7 @@
|
||||||
(do
|
(do
|
||||||
(put-blob blobstore-stub "container"
|
(put-blob blobstore-stub "container"
|
||||||
(blob "blob4"
|
(blob "blob4"
|
||||||
:payload #(.write % (.getBytes "blob4"))))
|
:payload (ByteArrayInputStream. (.getBytes "blob4"))))
|
||||||
(Strings2/toStringAndClose (get-blob-stream blobstore-stub
|
(Strings2/toStringAndClose (get-blob-stream blobstore-stub
|
||||||
"container" "blob4")))))
|
"container" "blob4")))))
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import static org.testng.Assert.fail;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -62,9 +61,8 @@ import org.jclouds.http.BaseJettyTest;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.io.WriteTo;
|
import org.jclouds.io.payloads.ByteSourcePayload;
|
||||||
import org.jclouds.io.payloads.InputStreamSupplierPayload;
|
import org.jclouds.io.payloads.InputStreamSupplierPayload;
|
||||||
import org.jclouds.io.payloads.StreamingPayload;
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.testng.ITestContext;
|
import org.testng.ITestContext;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
@ -540,12 +538,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException {
|
public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException {
|
||||||
PayloadBlobBuilder blobBuilder = view.getBlobStore().blobBuilder("streaming").payload(
|
PayloadBlobBuilder blobBuilder = view.getBlobStore().blobBuilder("streaming").payload(
|
||||||
new StreamingPayload(new WriteTo() {
|
new ByteSourcePayload(ByteSource.wrap("foo".getBytes())));
|
||||||
@Override
|
|
||||||
public void writeTo(OutputStream outstream) throws IOException {
|
|
||||||
outstream.write("foo".getBytes());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
addContentMetadata(blobBuilder);
|
addContentMetadata(blobBuilder);
|
||||||
|
|
||||||
Blob blob = blobBuilder.build();
|
Blob blob = blobBuilder.build();
|
||||||
|
|
|
@ -1,150 +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 com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
import org.jclouds.io.MutableContentMetadata;
|
|
||||||
import org.jclouds.io.Payload;
|
|
||||||
import org.jclouds.io.WriteTo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Note that not all services accept streaming payloads. For example, Rackspace CloudFiles accepts
|
|
||||||
* streaming while Amazon S3 does not.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class StreamingPayload implements Payload {
|
|
||||||
|
|
||||||
protected transient volatile boolean written;
|
|
||||||
protected final WriteTo writeTo;
|
|
||||||
protected MutableContentMetadata contentMetadata;
|
|
||||||
|
|
||||||
public StreamingPayload(WriteTo writeTo) {
|
|
||||||
this(writeTo, new BaseMutableContentMetadata());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected StreamingPayload(WriteTo writeTo, MutableContentMetadata contentMetadata) {
|
|
||||||
this.writeTo = checkNotNull(writeTo, "writeTo");
|
|
||||||
this.contentMetadata = checkNotNull(contentMetadata, "contentMetadata");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws UnsupportedOperationException
|
|
||||||
* this payload is for streaming writes only
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object getRawContent() {
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public InputStream getInput() {
|
|
||||||
throw new UnsupportedOperationException("this payload is for streaming writes only");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void writeTo(OutputStream outstream) throws IOException {
|
|
||||||
writeTo.writeTo(outstream);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "[contentMetadata=" + contentMetadata + ", written=" + written + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* By default we are not repeatable.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isRepeatable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((contentMetadata == null) ? 0 : contentMetadata.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
StreamingPayload other = (StreamingPayload) obj;
|
|
||||||
if (contentMetadata == null) {
|
|
||||||
if (other.contentMetadata != null)
|
|
||||||
return false;
|
|
||||||
} else if (!contentMetadata.equals(other.contentMetadata))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* By default there are no resources to release.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void release() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delegates to release()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
release();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public MutableContentMetadata getContentMetadata() {
|
|
||||||
return contentMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentMetadata(MutableContentMetadata in) {
|
|
||||||
contentMetadata = in;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue