• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Payloads类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jclouds.io.Payloads的典型用法代码示例。如果您正苦于以下问题:Java Payloads类的具体用法?Java Payloads怎么用?Java Payloads使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Payloads类属于org.jclouds.io包,在下文中一共展示了Payloads类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
   }
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:26,代码来源:UploadObjectsWithServiceNet.java


示例2: uploadObjectFromStringWithMetadata

import org.jclouds.io.Payloads; //导入依赖的package包/类
/**
 * Upload an object from a String with metadata using the BlobStore API.
 */
private void uploadObjectFromStringWithMetadata() {
   System.out.format("Upload Object From String With Metadata%n");

   String filename = "uploadObjectFromStringWithMetadata.txt";

   Map<String, String> userMetadata = new HashMap<String, String>();
   userMetadata.put("key1", "value1");

   ByteSource source = ByteSource.wrap("uploadObjectFromString".getBytes());

   Blob blob = blobStore.blobBuilder(filename)
         .payload(Payloads.newByteSourcePayload(source))
         .userMetadata(userMetadata)
         .build();

   blobStore.putBlob(CONTAINER, blob);

   System.out.format("  %s%n", filename);
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:23,代码来源:UploadObjectsWithServiceNet.java


示例3: 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);
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:24,代码来源:UploadLargeObject.java


示例4: 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();
   }
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:22,代码来源:CloudFilesPublish.java


示例5: 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);
   }
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:26,代码来源:GenerateTempURL.java


示例6: copyFileToNode

import org.jclouds.io.Payloads; //导入依赖的package包/类
/**
 * Copies a file or a directory (TODO!) from local path to the node. If {@code remoteTarget} is null, the current working
 * directory on the remote machine is taken as a default destination.
 *
 * @param localSrc a path to a file on the local machine that is to be copied
 * @param remoteTarget a path on the target machine where the file is to be copied to
 * @throws OperationNotSupportedException if this node implementation doesn't provide ssh access
 * @throws NullPointerException if {@code localSrc} is null ({@code remoteTarget} has a default)
 * @throws IllegalArgumentException if {@code localSrc} is not a regular file
 * @throws FileNotFoundException if {@code localSrc} does not exist
 */
@Override
public void copyFileToNode(Path localSrc, String remoteTarget) throws OperationNotSupportedException,
        IllegalArgumentException, NullPointerException, IOException, InterruptedException {
    if (localSrc == null) {
        throw new NullPointerException("Local path to copy file from can't be null.");
    }
    if (!Files.exists(localSrc)) {
        throw new FileNotFoundException("Local path to copy file from doesn't exist: " + localSrc);
    }
    if (!Files.isRegularFile(localSrc)) {
        throw new IllegalArgumentException("Local path to copy file from has to be a single regular file: " + localSrc);
    }

    SunstoneCoreLogger.SSH.debug("Copying local path '{}' to remote target '{}' on node '{}'", localSrc, remoteTarget,
            getName());

    if (Strings.isNullOrEmpty(remoteTarget)) {
        remoteTarget = exec("sh", "-c", "echo -n $PWD").getOutput();
    }
    SshUtils.FileType remoteFileType = SshUtils.FileType
            .fromExitCode(exec("sh", "-c", SshUtils.FileType.getShellTestStr(remoteTarget)).getExitCode());

    if (remoteFileType == SshUtils.FileType.DIRECTORY) {
        remoteTarget = remoteTarget + "/" + localSrc.getFileName();
    }

    SshClient sshClient = null;
    try {
        sshClient = getSsh();
        sshClient.put(remoteTarget, Payloads.newPayload(localSrc.toFile()));
        SunstoneCoreLogger.SSH.debug("Copied local path '{}' to remote target '{}' on node '{}'", localSrc, remoteTarget,
                getName());
    } finally {
        if (sshClient != null) {
            sshClient.disconnect();
        }
    }
}
 
开发者ID:wildfly-extras,项目名称:sunstone,代码行数:50,代码来源:AbstractJCloudsNode.java


示例7: saveInputStream

import org.jclouds.io.Payloads; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
    public long saveInputStream(String id, String root, String filePath, InputStream stream) throws IOException {
        if(stream == null){
            return 0L;
        }
        ContainerAndName can = getContainerAndName(id, root, filePath);
        createContainerIfNotExist(can.container);

        InputStream in = markableInputStream(stream);
        long size = markableStreamLength(in);

        Payload payload = Payloads.newInputStreamPayload(in);

        try {
            BlobStore store = getBlobStore();
            String asciiID = Base64.encodeBase64String(id.getBytes("UTF8"));

            Blob blob = store.blobBuilder(can.name)
                .payload(payload)
                .contentLength(size)
                .userMetadata(ImmutableMap.of("id", asciiID, "path", filePath))
                .build();
            store.putBlob(can.container, blob);
        } finally {
            payload.release();
            Closeables.close(stream, true);
            Closeables.close(in, true);
        }

        return size;
    }
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:35,代码来源:BlobStoreFileSystemHandler.java


示例8: call

import org.jclouds.io.Payloads; //导入依赖的package包/类
public BlobDetail call() throws Exception {
   ByteSource byteSource = Files.asByteSource(toBeUploadedBlobDetail.getLocalFile());

   Blob blob = blobStore.blobBuilder(toBeUploadedBlobDetail.getRemoteBlobName())
         .payload(Payloads.newByteSourcePayload(byteSource))
         .contentType("") // allows Cloud Files to determine the content type
         .build();
   String eTag = blobStore.putBlob(container, blob);
   BlobDetail uploadedBlobDetail = new BlobDetail(
         toBeUploadedBlobDetail.getRemoteBlobName(), toBeUploadedBlobDetail.getLocalFile(), eTag);

   return uploadedBlobDetail;
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:14,代码来源:UploadDirectoryToCDN.java


示例9: apply

import org.jclouds.io.Payloads; //导入依赖的package包/类
@Override
public Blob apply(GridFSDBFile input) {
    MutableBlobMetadata blobMetadata = dbFileToBlobMetadata.apply(input);
    Payload payload = Payloads.newInputStreamPayload(input.getInputStream());
    payload.setContentMetadata(blobMetadata.getContentMetadata());
    Blob blob = blobFactory.create(blobMetadata);
    blob.setPayload(payload);
    return blob;
}
 
开发者ID:mhurne,项目名称:jclouds-gridfs-blobstore,代码行数:10,代码来源:DBFileToBlob.java


示例10: put

import org.jclouds.io.Payloads; //导入依赖的package包/类
@Override
public void put(String path, Supplier<InputStream> data) {
    jclouds.put(path, Payloads.newInputStreamPayload(data.get()));
}
 
开发者ID:wildfly-extras,项目名称:sunstone,代码行数:5,代码来源:JCloudsSshClient.java


示例11: 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() );
}
 
开发者ID:ClouDesire,项目名称:janine,代码行数:7,代码来源:BlobStoreServiceImpl.java


示例12: handlePut

import org.jclouds.io.Payloads; //导入依赖的package包/类
@Override
public void handlePut(HttpExchange request, Map<String, String> params) throws IOException {
    if (!params.containsKey("upload")) {
        Util.sendNotFound("Upload", params.get("upload"), request);
        return;
    }

    for (String header : REQUIRED_PUT_HEADERS) {
        if (!request.getRequestHeaders().containsKey(header)) {
            Util.sendBadRequest(String.format("Header %s not found", header), request);
            return;
        }
    }

    UUID uploadId = UUID.fromString(params.get("upload"));
    Upload upload = proxy.getUpload(params.get("vault"), uploadId);
    if (upload == null) {
        Util.sendNotFound("Upload", params.get("upload"), request);
        return;
    }
    Matcher rangeMatcher = CONTENT_RANGE_RE.matcher(request.getRequestHeaders().getFirst("Content-Range"));
    if (!rangeMatcher.matches()) {
        Util.sendBadRequest("Invalid content range", request);
        return;
    }
    String startRangeString = rangeMatcher.group("start");
    String endRangeString = rangeMatcher.group("end");
    long start;
    long end;
    try {
        start = Long.parseLong(startRangeString);
        end = Long.parseLong(endRangeString);
    } catch (NumberFormatException e) {
        Util.sendBadRequest("Invalid range", request);
        return;
    }
    long size = end - start + 1;
    if (size > upload.partSize) {
        Util.sendBadRequest(String.format("Part size must be smaller than %s", upload.partSize), request);
        return;
    }

    if (start % upload.partSize != 0) {
        Util.sendBadRequest(String.format("Starting part range does not align %d", start), request);
        return;
    }

    if (upload.parts.size() > 10000) {
        Util.sendBadRequest("Cannot have more than 10000 parts", request);
        return;
    }

    // parts are 1-indexed
    int partNumber = (int) (start/upload.partSize + 1);

    Payload payload = Payloads.newInputStreamPayload(request.getRequestBody());
    MultipartPart uploadedPart = proxy.getBlobStore().uploadMultipartPart(upload.jcloudsUpload, partNumber,
            payload);
    if (uploadedPart == null) {
        Util.sendServerError("Failed to save the part", request);
        return;
    }
    String sha256TreeHash = request.getRequestHeaders().getFirst("x-amz-sha256-tree-hash");
    upload.parts.add(new UploadPart(sha256TreeHash, size));

    request.getResponseHeaders().put("x-amz-sha256-tree-hash",
            request.getRequestHeaders().get("x-amz-sha256-tree-hash"));
    request.sendResponseHeaders(Response.Status.NO_CONTENT.getStatusCode(), -1);
}
 
开发者ID:bouncestorage,项目名称:glacier-proxy,代码行数:70,代码来源:Multipart.java


示例13: 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);
    }
}
 
开发者ID:gaul,项目名称:s3proxy,代码行数:48,代码来源:NullBlobStoreTest.java


示例14: 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);
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:16,代码来源:UploadObjectsWithServiceNet.java



注:本文中的org.jclouds.io.Payloads类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ChannelListener类代码示例发布时间:2022-05-22
下一篇:
Java ExceptionDialog类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap