本文整理汇总了Java中org.jclouds.io.Payloads.newByteSourcePayload方法的典型用法代码示例。如果您正苦于以下问题:Java Payloads.newByteSourcePayload方法的具体用法?Java Payloads.newByteSourcePayload怎么用?Java Payloads.newByteSourcePayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jclouds.io.Payloads
的用法示例。
在下文中一共展示了Payloads.newByteSourcePayload方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadObjectFromFile
import org.jclouds.io.Payloads; //导入方法依赖的package包/类
/**
* Upload an object from a File using the Swift API.
*/
private void uploadObjectFromFile() throws IOException {
System.out.format("Upload Object From File%n");
String filename = "uploadObjectFromFile";
String suffix = ".txt";
File tempFile = File.createTempFile(filename, suffix);
try {
Files.write("uploadObjectFromFile", tempFile, Charsets.UTF_8);
ByteSource byteSource = Files.asByteSource(tempFile);
Payload payload = Payloads.newByteSourcePayload(byteSource);
cloudFiles.getObjectApi(REGION, CONTAINER)
.put(filename + suffix, payload);
System.out.format(" %s%s%n", filename, suffix);
} finally {
tempFile.delete();
}
}
示例2: uploadLargeObjectFromFile
import org.jclouds.io.Payloads; //导入方法依赖的package包/类
/**
* Upload a large object from a File using the BlobStore API.
*
* @throws ExecutionException
* @throws InterruptedException
*/
private void uploadLargeObjectFromFile(File largeFile) throws InterruptedException, ExecutionException {
System.out.format("Upload Large Object From File%n");
ByteSource source = Files.asByteSource(largeFile);
// create the payload and set the content length
Payload payload = Payloads.newByteSourcePayload(source);
payload.getContentMetadata().setContentLength(largeFile.length());
Blob blob = blobStore.blobBuilder(largeFile.getName())
.payload(payload)
.build();
// configure the blobstore to use multipart uploading of the file
String eTag = blobStore.putBlob(CONTAINER, blob, multipart());
System.out.format(" Uploaded %s eTag=%s", largeFile.getName(), eTag);
}
示例3: createObjectFromFile
import org.jclouds.io.Payloads; //导入方法依赖的package包/类
/**
* This method will put a plain text object into the container.
*/
private void createObjectFromFile() throws IOException {
System.out.format("Create Object From File%n");
File tempFile = File.createTempFile(FILENAME, SUFFIX);
try {
Files.write("Hello Cloud Files", tempFile, Charsets.UTF_8);
ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER_PUBLISH);
ByteSource byteSource = Files.asByteSource(tempFile);
Payload payload = Payloads.newByteSourcePayload(byteSource);
objectApi.put(FILENAME + SUFFIX, payload);
} finally {
tempFile.delete();
}
}
示例4: generatePutTempURL
import org.jclouds.io.Payloads; //导入方法依赖的package包/类
private void generatePutTempURL() throws IOException {
System.out.format("Generate PUT Temp URL%n");
// Create the Payload
String data = "This object will be public for 10 minutes.";
ByteSource source = ByteSource.wrap(data.getBytes());
Payload payload = Payloads.newByteSourcePayload(source);
// Create the Blob
Blob blob = blobStore.blobBuilder(FILENAME).payload(payload).contentType("text/plain").build();
HttpRequest request = blobStoreContext.getSigner(REGION).signPutBlob(CONTAINER, blob, TEN_MINUTES);
System.out.format(" %s %s%n", request.getMethod(), request.getEndpoint());
// PUT the file using jclouds
HttpResponse response = blobStoreContext.utils().http().invoke(request);
int statusCode = response.getStatusCode();
if (statusCode >= 200 && statusCode < 299) {
System.out.format(" PUT Success (%s)%n", statusCode);
}
else {
throw new HttpResponseException(null, response);
}
}
示例5: uploadFile
import org.jclouds.io.Payloads; //导入方法依赖的package包/类
private void uploadFile( byte[] object, String filename, String container )
{
log.info( "Uploading file {} on {}", filename, container );
Payload payload = Payloads.newByteSourcePayload( ByteSource.wrap( object ) );
api.getBlobStore().putBlob( container, api.getBlobStore().blobBuilder( filename ).payload( payload ).build() );
}
示例6: testCreateMultipartBlobGetBlob
import org.jclouds.io.Payloads; //导入方法依赖的package包/类
@Test
public void testCreateMultipartBlobGetBlob() throws Exception {
String blobName = "multipart-upload";
BlobMetadata blobMetadata = makeBlob(nullBlobStore, blobName)
.getMetadata();
MultipartUpload mpu = nullBlobStore.initiateMultipartUpload(
containerName, blobMetadata, new PutOptions());
ByteSource byteSource = TestUtils.randomByteSource().slice(
0, nullBlobStore.getMinimumMultipartPartSize() + 1);
ByteSource byteSource1 = byteSource.slice(
0, nullBlobStore.getMinimumMultipartPartSize());
ByteSource byteSource2 = byteSource.slice(
nullBlobStore.getMinimumMultipartPartSize(), 1);
Payload payload1 = Payloads.newByteSourcePayload(byteSource1);
Payload payload2 = Payloads.newByteSourcePayload(byteSource2);
payload1.getContentMetadata().setContentLength(byteSource1.size());
payload2.getContentMetadata().setContentLength(byteSource2.size());
MultipartPart part1 = nullBlobStore.uploadMultipartPart(mpu, 1,
payload1);
MultipartPart part2 = nullBlobStore.uploadMultipartPart(mpu, 2,
payload2);
List<MultipartPart> parts = nullBlobStore.listMultipartUpload(mpu);
assertThat(parts.get(0).partNumber()).isEqualTo(1);
assertThat(parts.get(0).partSize()).isZero();
assertThat(parts.get(0).partETag()).isEqualTo(part1.partETag());
assertThat(parts.get(1).partNumber()).isEqualTo(2);
assertThat(parts.get(1).partSize()).isZero();
assertThat(parts.get(1).partETag()).isEqualTo(part2.partETag());
nullBlobStore.completeMultipartUpload(mpu, ImmutableList.of(part1,
part2));
Blob newBlob = nullBlobStore.getBlob(containerName, blobName);
validateBlobMetadata(newBlob.getMetadata(), byteSource);
// content differs, only compare length
try (InputStream actual = newBlob.getPayload().openStream();
InputStream expected = byteSource.openStream()) {
long actualLength = ByteStreams.copy(actual,
ByteStreams.nullOutputStream());
long expectedLength = ByteStreams.copy(expected,
ByteStreams.nullOutputStream());
assertThat(actualLength).isEqualTo(expectedLength);
}
}
示例7: uploadObjectFromString
import org.jclouds.io.Payloads; //导入方法依赖的package包/类
/**
* Upload an object from a String using the Swift API.
*/
private void uploadObjectFromString() {
System.out.format("Upload Object From String%n");
String filename = "uploadObjectFromString.txt";
ByteSource source = ByteSource.wrap("uploadObjectFromString".getBytes());
Payload payload = Payloads.newByteSourcePayload(source);
cloudFiles.getObjectApi(REGION, CONTAINER).put(filename, payload);
System.out.format(" %s%n", filename);
}