Package com.google.common.io

Examples of com.google.common.io.ByteSource


    }

    @Test
    public void testBlobMetadata() throws Exception {
        String blobName = "blob";
        ByteSource byteSource = ByteSource.wrap(new byte[1]);
        Blob blob1 = s3BlobStore.blobBuilder(blobName)
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        s3BlobStore.putBlob(containerName, blob1);

        BlobMetadata metadata = s3BlobStore.blobMetadata(containerName,
                blobName);
        assertThat(metadata.getName()).isEqualTo(blobName);
        assertThat(metadata.getContentMetadata().getContentLength())
                .isEqualTo(byteSource.size());

        assertThat(s3BlobStore.blobMetadata(containerName,
                "fake-blob")).isNull();
    }
View Full Code Here


    }

    @Test
    public void testBlobRemove() throws Exception {
        String blobName = "blob";
        ByteSource byteSource = ByteSource.wrap(new byte[1]);
        Blob blob = s3BlobStore.blobBuilder(blobName)
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        s3BlobStore.putBlob(containerName, blob);
        assertThat(s3BlobStore.blobExists(containerName, blobName)).isTrue();

        s3BlobStore.removeBlob(containerName, blobName);
View Full Code Here

    public void testUrlSigning() throws Exception {
        HttpClient httpClient = s3Context.utils().http();
        BlobRequestSigner signer = s3Context.getSigner();

        String blobName = "blob";
        ByteSource byteSource = ByteSource.wrap(new byte[1]);
        Blob blob = s3BlobStore.blobBuilder(blobName)
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        HttpRequest putRequest = signer.signPutBlob(containerName, blob, 10);
        HttpResponse putResponse = httpClient.invoke(putRequest);
        assertThat(putResponse.getStatusCode())
                .isEqualTo(HttpServletResponse.SC_OK);
View Full Code Here

         closeQuietly(input);
      }
   }

   private void assertValidMd5(final InputStream input) throws IOException {
      assertEquals(base64().encode(new ByteSource() {
         @Override
         public InputStream openStream() {
            return input;
         }
      }.hash(md5()).asBytes()), md5);
View Full Code Here

    * @param in
    *           stream to always return
    */
   public static ByteSource asByteSource(final InputStream in) {
      checkNotNull(in, "in");
      return new ByteSource() {
         @Override
         public InputStream openStream() throws IOException {
            return in;
         }
      };
View Full Code Here

      // Create a container
      String containerName = "jclouds_putAndRetrieveBlobExample_" + UUID.randomUUID().toString();
      blobstore.createContainerInLocation(null, containerName); // Create a vault

      // Create a blob
      ByteSource payload = ByteSource.wrap("data".getBytes(Charsets.UTF_8));
      Blob blob = blobstore.blobBuilder("ignored") // The blob name is ignored in Glacier
            .payload(payload)
            .contentLength(payload.size())
            .build();

      // Put the blob in the container
      String blobId = blobstore.putBlob(containerName, blob);
View Full Code Here

      // Create a container
      String containerName = "jclouds_multipartUploadExample_" + UUID.randomUUID().toString();
      blobstore.createContainerInLocation(null, containerName); // Create a vault

      // Create a blob
      ByteSource payload = buildData(16 * MiB);
      Blob blob = blobstore.blobBuilder("ignored") // The blob name is ignored in Glacier
            .payload(payload)
            .contentLength(payload.size())
            .build();

      // Create the PutOptions
      PutOptions options = PutOptions.Builder.multipart(true);

View Full Code Here

      // Create a container
      final String containerName =  "jclouds_interruptionExample_" + UUID.randomUUID().toString();
      blobstore.createContainerInLocation(null, containerName); // Create a vault

      // Create a blob
      ByteSource payload = ByteSource.wrap("data".getBytes(Charsets.UTF_8));
      Blob blob = blobstore.blobBuilder("ignored") // The blob name is ignored in Glacier
            .payload(payload)
            .contentLength(payload.size())
            .build();

      // Put the blob in the container
      final String blobId = blobstore.putBlob(containerName, blob);
View Full Code Here

         // Create Container
         BlobStore blobStore = context.getBlobStore();
         blobStore.createContainerInLocation(null, containerName);
         String blobName = "test";
         ByteSource payload = ByteSource.wrap("testdata".getBytes(Charsets.UTF_8));

         // List Container Metadata
         for (StorageMetadata resourceMd : blobStore.list()) {
            if (containerName.equals(resourceMd.getName())) {
               System.out.println(resourceMd);
            }
         }

         // Add Blob
         Blob blob = blobStore.blobBuilder(blobName)
            .payload(payload)
            .contentLength(payload.size())
            .build();
         blobStore.putBlob(containerName, blob);

         // Use Provider API
         ApiMetadata apiMetadata = context.unwrap().getProviderMetadata().getApiMetadata();
View Full Code Here

      try {
         Files.write("Hello Cloud Files", tempFile, Charsets.UTF_8);

         ObjectApi objectApi = cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER_PUBLISH);

         ByteSource byteSource = Files.asByteSource(tempFile);
         Payload payload = Payloads.newByteSourcePayload(byteSource);

         objectApi.put(FILENAME + SUFFIX, payload);
      } finally {
         tempFile.delete();
View Full Code Here

TOP

Related Classes of com.google.common.io.ByteSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.