Package org.jclouds.blobstore.domain

Examples of org.jclouds.blobstore.domain.Blob$Factory


     * Test of getBlob method, of class FilesystemAsyncBlobStore.
     */
    public void testGetBlob() throws IOException {
        String blobKey = TestUtils.createRandomBlobKey();
        GetOptions options = null;
        Blob resultBlob;

        blobStore.createContainerInLocation(null, CONTAINER_NAME);

        resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
        assertNull(resultBlob, "Blob exists");

        // create blob
        TestUtils.createBlobsInContainer(CONTAINER_NAME, blobKey);

        resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);

        assertNotNull(resultBlob, "Blob exists");
        // checks file content
        InputSupplier<FileInputStream> expectedFile =
                Files.newInputStreamSupplier(new File(
                TARGET_CONTAINER_NAME, blobKey));
        assertTrue(ByteStreams.equal(expectedFile, resultBlob.getPayload()),
                "Blob payload differs from file content");
        // metadata are verified in the test for blobMetadata, so no need to
        // perform a complete test here
        assertNotNull(resultBlob.getMetadata(), "Metadata null");
        MutableBlobMetadata metadata = resultBlob.getMetadata();
        assertEquals(blobKey, metadata.getName(), "Wrong blob metadata");
    }
View Full Code Here


    public void testRanges() throws IOException {
        blobStore.createContainerInLocation(null, CONTAINER_NAME);
        String input = "abcdefgh";
        Payload payload;
        Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(input)).build();
        blobStore.putBlob(CONTAINER_NAME, blob);

        GetOptions getOptionsRangeStartAt = new GetOptions();
        getOptionsRangeStartAt.startAt(1);
        Blob blobRangeStartAt = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
        payload = blobRangeStartAt.getPayload();
        try {
            assertEquals(input.substring(1), Strings2.toString(payload));
        } finally {
            Closeables2.closeQuietly(payload);
        }

        GetOptions getOptionsRangeTail = new GetOptions();
        getOptionsRangeTail.tail(3);
        Blob blobRangeTail = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
        payload = blobRangeTail.getPayload();
        try {
            assertEquals(input.substring(5), Strings2.toString(payload));
        } finally {
            Closeables2.closeQuietly(payload);
        }

        GetOptions getOptionsFragment = new GetOptions();
        getOptionsFragment.range(4, 6);
        Blob blobFragment = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
        payload = blobFragment.getPayload();
        try {
            assertEquals(input.substring(4, 7), Strings2.toString(payload));
        } finally {
            Closeables2.closeQuietly(payload);
        }
View Full Code Here

                .endpoint(endPoint)
                .headers(request.getHeaders())
                .build();
        assertEquals(expected, request);

        Blob blob = blobStore.blobBuilder(blobName).forSigning().build();
        request = signer.signPutBlob(containerName, blob);
        expected = HttpRequest.builder()
                .method("PUT")
                .endpoint(endPoint)
                .headers(request.getHeaders())
View Full Code Here

    /**
     * Create a blob with putBlob method
     */
    private void putBlobAndCheckIt(String blobKey) {
        Blob blob;

        TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, false);

        // create the blob
        blob = createBlob(blobKey, TestUtils.getImageForBlobPayload());
View Full Code Here

   private static final Factory BLOB_FACTORY = ContextBuilder.newBuilder("transient").buildInjector().getInstance(Blob.Factory.class);

   @Test
   public void testCorrect() throws SecurityException, NoSuchMethodException {

      Blob blob = BLOB_FACTORY.create(null);
      blob.getMetadata().setName("foo");

      assertEquals(fn.apply(blob), "foo");
   }
View Full Code Here

    return "sid";
  }

  public String uploadData(String sid, String cid, byte[] data, String id) {
   
    Blob blob = storage.blobBuilder(id).payload(data).build();
    blob.setPayload(data);
    storage.putBlob(bucketname, blob);   
    return id;

  }
View Full Code Here

    return id;

  }

  public byte[] downloadData(String sid, String cid, String idthrows StorageCloudException {
    Blob bl = storage.getBlob(bucketname, id);
    Payload b = bl.getPayload();
    InputStream in = b.getInput();
    byte[] array = null;
   
    try {
      array = getBytesFromInputStream(in);
View Full Code Here

      BlobStore store = context.getBlobStore();
      if (!store.blobExists(container, file.getName())) {
        LOG.info("Uploading '{}' to '{}' blob cache.", file.getName(), container);

        Blob blob = context.getBlobStore().blobBuilder(container)
                .name(file.getName())
                .payload(file)
                .contentLength(file.length())
                .build();
View Full Code Here

    }
  }

  @Override
  public Cluster load() throws IOException {
    Blob blob = context.getBlobStore().getBlob(container, blobName);
    if (blob != null) {
      return unserialize(spec,
        IOUtils.toString(blob.getPayload().getInput(), "utf-8"));
    }
    return null;
  }
View Full Code Here

  @Override
  public void save(Cluster cluster) throws IOException {
    BlobStore store = context.getBlobStore();

    Blob blob = store.blobBuilder(blobName).payload(serialize(cluster)).build();
    store.putBlob(container, blob);

    LOG.info("Saved cluster state to '{}' ", context.getSigner()
      .signGetBlob(container, blobName).getEndpoint().toString());
  }
View Full Code Here

TOP

Related Classes of org.jclouds.blobstore.domain.Blob$Factory

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.