Package org.jclouds.blobstore.domain

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


         builder.payload(file).calculateMD5();
      } catch (IOException e) {
         logger.error("An error occurred calculating MD5 for blob %s from container ", key, container);
         Throwables.propagateIfPossible(e);
      }
      Blob blob = builder.build();
      if (blob.getPayload().getContentMetadata().getContentMD5() != null)
         blob.getMetadata().setETag(base16().lowerCase().encode(blob.getPayload().getContentMetadata().getContentMD5()));
      return blob;
   }
View Full Code Here


     * Writes {@link Payload} to the the {@link BlobStore}.
     */
    public static void writeBlob(BlobStore blobStore, String container, String blobName, Payload payload) {
        if (blobName != null && payload != null) {
            mkDirs(blobStore, container, blobName);
            Blob blob = blobStore.blobBuilder(blobName).payload(payload).contentType(MediaType.APPLICATION_OCTET_STREAM).contentDisposition(blobName).build();
            blobStore.putBlob(container, blob, multipart());
        }
    }
View Full Code Here

     * Reads from a {@link BlobStore}. It returns an Object.
     */
    public static InputStream readBlob(BlobStore blobStore, String container, String blobName) {
        InputStream is = null;
        if (!Strings.isNullOrEmpty(blobName)) {
            Blob blob = blobStore.getBlob(container, blobName);
            if (blob != null && blob.getPayload() != null) {
                is = blobStore.getBlob(container, blobName).getPayload().getInput();
            }
        }
        return is;
    }
View Full Code Here

     * @param blobName
     * @param payload
     */
    public static void writeBlob(BlobStore blobStore, String container, String blobName, Object payload) {
        if (blobName != null && payload != null) {
            Blob blob = blobStore.blobBuilder(blobName).build();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = null;
            try {
                oos = new ObjectOutputStream(baos);
                oos.writeObject(payload);
                blob.setPayload(baos.toByteArray());
                blobStore.putBlob(container, blob);
            } catch (IOException e) {
                LOG.error("Error while writing blob", e);
            } finally {
                IOHelper.close(oos);
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.newBlob(blobName);
    blob.setPayload(serialize(cluster));
    store.putBlob(container, blob);

    LOG.info("Saved cluster state to '{}' ", context.getSigner()
      .signGetBlob(container, blobName).getEndpoint().toString());
  }
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

    * @param blobName
    * @return
    */
   public InputSupplier<InputStream> getBlobInputStream(BlobStore blobStore, String containerName, String blobName)
         throws Exception {
      Blob blob = blobStore.getBlob(containerName, blobName);
      if (blob == null) {
         if (!blobStore.containerExists(containerName)) {
            throw new ContainerNotFoundException(containerName, "while getting blob");
         }
         throw new KeyNotFoundException(containerName, blobName, "while getting blob");
      }
      return blob.getPayload();
   }
View Full Code Here

   }

   public Blob apply(HttpResponse from) {
      checkNotNull(from, "request");
      MutableBlobMetadata metadata = metadataParser.apply(from);
      Blob blob = blobFactory.create(metadata);
      blob.getAllHeaders().putAll(from.getHeaders());
      blob.setPayload(from.getPayload());
      return blob;
   }
View Full Code Here

         }
      } finally {
         Closeables2.closeQuietly(input);
      }

      Blob newBlob = createUpdatedCopyOfBlobInContainer(containerName, blob, payload, actualHashCode);
      Map<String, Blob> map = containerToBlobs.get(containerName);
      map.put(newBlob.getMetadata().getName(), newBlob);
      return base16().lowerCase().encode(actualHashCode.asBytes());
   }
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.