Package org.jclouds.blobstore.domain

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


        @Override
        public Map.Entry<Integer , byte[]> call () throws Exception {
            byte[] data = mByteCache.getIfPresent(mBucketId);
            if (data == null) {
                // long time = System.currentTimeMillis();
                Blob blob = mStore.getBlob(mContainerName, Integer.toString(mBucketId));
                if (blob == null) {
                    data = new byte[SIZE_PER_BUCKET];
                    // // DEBUG CODE
                    // download.write(Integer.toString(mBucketId) + ", empty, "
                    // + (System.currentTimeMillis() - time) + "\n");
                    // download.flush();
                } else {
                    data = ByteStreams.toByteArray(blob.getPayload().getInput());
                    // download.write(Integer.toString(mBucketId) + "," +
                    // data.length + " , "
                    // + (System.currentTimeMillis() - time) + "\n");
                    // download.flush();
                    while (data.length < SIZE_PER_BUCKET) {
                        blob = mStore.getBlob(mContainerName, Integer.toString(mBucketId));
                        data = ByteStreams.toByteArray(blob.getPayload().getInput());
                        // // DEBUG CODE
                        // download.write(Integer.toString(mBucketId) + "," +
                        // data.length + " , "
                        // + (System.currentTimeMillis() - time) + "\n");
                        // download.flush();
View Full Code Here


                    // long time = System.currentTimeMillis();
                    byte[] data = mData;
                    if (ENCRYPT) {
                        data = mCipher.doFinal(mData);
                    }
                    Blob blob = mStore.blobBuilder(Integer.toString(mBucketIndex)).build();
                    blob.setPayload(data);
                    mStore.putBlob(mContainerName, blob);
                    // // DEBUG CODE
                    // upload.write(Integer.toString(mBucketIndex) + ", " +
                    // (System.currentTimeMillis() -
                    // time)
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) throws IOException {
        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().openStream();
            }
        }
        return is;
    }
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

     * @param container the blob store container.
     * @param name the blob store name.
     * @param data the blob store data.
     */
    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

            throw new IOException(response.getStatusLine());
         }
         return response.getPayload().openStream();
      }

      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().openStream();
   }
View Full Code Here

     * @param payload
     */
    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

     * @return
     */
    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

      ObjectApi objectApi = api.objectApiInRegionForContainer(region.getId(), container);
      SwiftObject object = objectApi.get(name, toGetOptions.apply(options));
      if (object == null) {
         return null;
      }
      Blob blob = new BlobImpl(toBlobMetadata(container).apply(object));
      blob.setPayload(object.payload());
      blob.setAllHeaders(object.headers());
      return blob;
   }
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.