Package org.jclouds.blobstore.domain

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


      int partCount = algorithm.getParts();
      if (partCount > 0) {
         int part;
         while ((part = algorithm.getNextPart()) <= partCount) {
            Payload chunkedPart = slicer.slice(payload, algorithm.getNextChunkOffset(), chunkSize);
            Blob blobPart = blobBuilders.get()
                                        .name(key + PART_SEPARATOR + part)
                                        .payload(chunkedPart)
                                        .contentDisposition(key + PART_SEPARATOR + part).build();
            client.putObject(container, blob2Object.apply(blobPart));
         }
         long remaining = algorithm.getRemaining();
         if (remaining > 0) {
            Payload chunkedPart = slicer.slice(payload, algorithm.getNextChunkOffset(), remaining);
            Blob blobPart = blobBuilders.get()
                                        .name(key + PART_SEPARATOR + part)
                                        .payload(chunkedPart)
                                        .contentDisposition(key + PART_SEPARATOR + part).build();
            client.putObject(container, blob2Object.apply(blobPart));
         }
View Full Code Here


            final String destinationBucket, final String destinationObject, CopyObjectOptions... nullableOptions) {
      final CopyObjectOptions options = (nullableOptions.length == 0) ? new CopyObjectOptions() : nullableOptions[0];
      ConcurrentMap<String, Blob> source = containerToBlobs.get(sourceBucket);
      ConcurrentMap<String, Blob> dest = containerToBlobs.get(destinationBucket);
      if (source.containsKey(sourceObject)) {
         Blob object = source.get(sourceObject);
         if (options.getIfMatch() != null) {
            if (!object.getMetadata().getETag().equals(options.getIfMatch()))
               return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
         }
         if (options.getIfNoneMatch() != null) {
            if (object.getMetadata().getETag().equals(options.getIfNoneMatch()))
               return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
         }
         if (options.getIfModifiedSince() != null) {
            Date modifiedSince = dateService.rfc822DateParse(options.getIfModifiedSince());
            if (modifiedSince.after(object.getMetadata().getLastModified()))
               return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));

         }
         if (options.getIfUnmodifiedSince() != null) {
            Date unmodifiedSince = dateService.rfc822DateParse(options.getIfUnmodifiedSince());
            if (unmodifiedSince.before(object.getMetadata().getLastModified()))
               return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
         }
         Blob sourceS3 = source.get(sourceObject);
         MutableBlobMetadata newMd = BlobStoreUtils.copy(sourceS3.getMetadata(), destinationObject);
         if (options.getAcl() != null)
            keyToAcl.put(destinationBucket + "/" + destinationObject, options.getAcl());

         newMd.setLastModified(new Date());
         Blob newBlob = blobProvider.create(newMd);
         newBlob.setPayload(sourceS3.getPayload());
         dest.put(destinationObject, newBlob);
         return immediateFuture((ObjectMetadata) blob2ObjectMetadata.apply(BlobStoreUtils.copy(newMd)));
      }
      return immediateFailedFuture(new KeyNotFoundException(sourceBucket, sourceObject, sourceBucket + "/"
               + sourceObject));
View Full Code Here

       String containerName = getContainerName();

       try {
           BlobStore blobStore = view.getBlobStore();
           blobStore.createContainerInLocation(null, containerName);
           Blob blob = blobStore.blobBuilder("const.txt")
                   .payload(new File("target/const.txt")).contentMD5(oneHundredOneConstitutionsMD5).build();
           blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());
       } finally {
           returnContainer(containerName);
       }
View Full Code Here

      assertEquals(request.getFilters().size(), 0);
   }

   public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
            NoSuchMethodException, IOException {
      Blob blob = blobFactory.create(null);
      blob.getMetadata().setName("name");
      blob.setPayload("");
      blob.getPayload().getContentMetadata().setContentLength(2l);
      blob.getPayload().getContentMetadata().setContentMD5(new byte[] { 0, 2, 4, 8 });
      blob.getPayload().getContentMetadata().setContentType("text/plain");
      blob.getPayload().getContentMetadata().setExpires(new Date(1000));
     
      HttpRequest request = signer.signPutBlob("container", blob);

      assertRequestLineEquals(request,
               "POST https://accesspoint.atmosonline.com/rest/namespace/container/name HTTP/1.1");
View Full Code Here

        if (!blobStore.blobExists(cloudContainer, id)) {
            Map<String, String> metadata = Maps.newHashMap();
            metadata.put("level", String.valueOf(level));

            Blob blob = blobStore.blobBuilder(id)
                    .payload(data)
                    .userMetadata(metadata)
                    .build();
            String etag = blobStore.putBlob(cloudContainer, blob, multipart());
            LOG.debug("Blob " + id + " created with cloud tag : " + etag);
View Full Code Here

    protected byte[] readBlockFromBackend(BlockId blockId) throws Exception {
        Preconditions.checkNotNull(context);

        String id = StringUtils.convertBytesToHex(blockId.getDigest());

        Blob cloudBlob = context.getBlobStore().getBlob(cloudContainer, id);
        if (cloudBlob == null) {
            String message = "Did not find block " + id;
            LOG.error(message);
            throw new IOException(message);
        }

        Payload payload = cloudBlob.getPayload();
        try {
            byte[] data = ByteStreams.toByteArray(payload.getInput());

            if (blockId.getPos() == 0) {
                return data;
View Full Code Here

                    throw new IOException("Container " + containerName + " does not exists");
                } else if (!blobStore.blobExists(containerName, blobName)) {
                    throw new IOException("Blob " + blobName + " does not exists");
                }

                Blob blob = blobStore.getBlob(containerName, blobName);

                return blob.getPayload().getInput();
            } catch (Exception e) {
                throw (IOException) new IOException("Error opening blob protocol url").initCause(e);
            }
        }
View Full Code Here

                Runnable putBlob = new Runnable() {
                    @Override
                    public void run() {
                        try {
                            readLatch.await();
                            Blob blob = blobStore.blobBuilder(blobName).payload(tmpBlob).build();
                            blobStore.putBlob(containerName, blob);
                            tmpBlob.delete();
                            tmpDir.delete();
                        } catch (InterruptedException e) {
                            logger.error("Interrupted while waiting on blob read.", e);
View Full Code Here

        return result;
    }

    public void createBlob(String container, String name, Object data) {
        Blob blob;
        if (blobStore != null) {
            if (!blobStore.containerExists(container)) {
                blobStore.createContainerInLocation(null, container);
            }

            if (blobStore.blobExists(container, name)) {
                blob = blobStore.getBlob(container, name);
            } else {
                blob = blobStore.blobBuilder(name).build();
            }

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = null;
            try {
                oos = new ObjectOutputStream(baos);
                oos.writeObject(data);
                blob.setPayload(baos.toByteArray());
                blobStore.putBlob(container, blob);
            } catch (IOException e) {
                LOGGER.error("CELLAR CLOUD: failed to write blob", e);
            } finally {
                if (oos != null) {
View Full Code Here

      databags.createContainerInLocation(null, databagName);
   }

   @Override
   public DatabagItem createDatabagItem(String databagName, DatabagItem databagItem) {
      Blob blob = databags.blobBuilder(databagItem.getId()).payload(databagItem.toString()).build();
      databags.putBlob(databagName, blob);
      return databagItem;
   }
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.